Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- When compacting, expands the index mapping first, then compacts that expanded IRI, matching the JSON-LD API compaction correction for compact-IRI index mappings. Fixes testcases [compact#t0112](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#t0112) and [compact#t0113](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#t0113).
- Fixes `AttributeError` when compacting with `@none`: the `@type` map compaction path now only calls `.pop()` and inspects keys when `compacted_item` is actually an object. Fixes [compact#tm023](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#tm023)
- An empty property-scoped context no longer resets the active context in `_create_term_definition`. Now only explicit null becomes False; empty contexts are preserved. Fixes [compact#tc028](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#tc028) and [toRdf#tc036](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#tc036).

### Added
- `pyld.DocumentLoader` abstract base class for class-based document loaders,
Expand Down
6 changes: 4 additions & 2 deletions lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -5709,8 +5709,10 @@ def _create_term_definition(

# scoped contexts
if '@context' in value:
# record as falss, if None
mapping['@context'] = value['@context'] if value['@context'] else False
# record as false, if None
mapping['@context'] = (
False if value['@context'] is None else value['@context']
)

if '@language' in value and '@type' not in value:
language = value['@language']
Expand Down
6 changes: 1 addition & 5 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,7 @@ def write(self, filename):
# skip tests where behavior changed for a 1.1 processor
# see JSON-LD 1.0 Errata
'specVersion': ['json-ld-1.0'],
'idRegex': [
# uncategorized
'.*compact-manifest#tc028$',
],
'idRegex': [],
},
'fn': 'compact',
'params': [
Expand Down Expand Up @@ -1033,7 +1030,6 @@ def write(self, filename):
'.*toRdf-manifest#ter56$',
'.*toRdf-manifest#tli12$',
'.*toRdf-manifest#tli14$',
'.*toRdf-manifest#tc036$',
'.*toRdf-manifest#tc037$',
]
},
Expand Down
31 changes: 31 additions & 0 deletions tests/test_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,37 @@ def test_node_reference_compacts_to_string_value_of_type_map(self):
"location": {"@none": "http://kg.artsdata.ca/resource/K11-200"},
}

def test_empty_property_scoped_context_preserves_outer_terms(self):
"""
An empty property-scoped context should not reset the active context
during compaction.
"""
expanded = [
{
"http://example.com/title": [{"@value": "top"}],
"http://example.com/thing": [
{
"http://example.com/title": [{"@value": "sub"}],
}
],
}
]
context = {
"@context": {
"ex": "http://example.com/",
"thing": {"@id": "ex:thing", "@context": {}},
"title": "ex:title",
}
}

compacted = jsonld.compact(expanded, context, {"skipExpansion": True})

assert compacted == {
"@context": context["@context"],
"title": "top",
"thing": {"title": "sub"},
}

# Issue 91
def test_empty_context(self):
"""
Expand Down
Loading