Skip to content

Commit

Permalink
Set JSON-LD 1.1 as processing mode (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
MFSY authored Dec 8, 2020
1 parent 46070df commit 7289112
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions kgforge/core/conversions/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def from_graph(data: Graph, type: Optional[Union[str, List]] = None, frame: Dict
framed = _graph_free_jsonld(framed)
if isinstance(framed, list):
framed = [jsonld.compact(item, ctx=context,
options={'processingMode': 'json-ld-1.0'}) for item in framed]
options={'processingMode': 'json-ld-1.1'}) for item in framed]
else:
framed = jsonld.compact(framed, ctx=context,
options={'processingMode': 'json-ld-1.0'})
options={'processingMode': 'json-ld-1.1'})
return from_jsonld(framed)

def _graph_free_jsonld(jsonld_doc, context=None):
Expand Down Expand Up @@ -195,7 +195,7 @@ def _as_jsonld_one(resource: Resource, form: Form, store_metadata: bool,
if key and isinstance(v, str):
frame[key] = v
frame["@embed"] = "@link"
data_framed = jsonld.frame(data_expanded, frame, options={'processingMode': 'json-ld-1.0'})
data_framed = jsonld.frame(data_expanded, frame, options={'processingMode': 'json-ld-1.1'})
resource_graph_node = data_framed["@graph"][0] if "@graph" in data_framed else data_framed
if resource_types is None:
resource_graph_node.pop(TYPE)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"rdflib-jsonld"
],
extras_require={
"dev": ["tox", "pytest==3.10.1", "pytest-bdd==3.4.0", "pytest-cov", "pytest-mock", "codecov"],
"dev": ["tox", "pytest==3.10.1", "pytest-bdd==3.4.0", "pytest-cov==2.10.1", "pytest-mock==3.3.1", "codecov"],
"docs": ["sphinx", "sphinx-bluebrain-theme"],
},
classifiers=[
Expand Down
10 changes: 5 additions & 5 deletions tests/core/conversions/test_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from rdflib import Graph, BNode, term
from rdflib.namespace import RDF

from kgforge.core import Resource
from kgforge.core.commons.exceptions import NotSupportedError
from kgforge.core.conversions.rdf import _merge_jsonld, from_jsonld, as_jsonld, Form, as_graph, from_graph

Expand Down Expand Up @@ -186,12 +187,11 @@ def test_from_graph(self, building, organization, building_jsonld, model_context
graph.add((bNode,term.URIRef("http://schema.org/latitude"),term.Literal("40.75")))
results = from_graph(graph)

assert len(results) == 1

assert isinstance(results, Resource)
building.id = id
building.context = model_context.document["@context"]
expected = building_jsonld(building, "expanded", store_metadata, None)
assert as_jsonld(results[0], form="expanded", store_metadata=store_metadata,
assert as_jsonld(results, form="expanded", store_metadata=store_metadata,
model_context=model_context, metadata_context=metadata_context,
context_resolver=None) == expected

Expand Down Expand Up @@ -221,9 +221,9 @@ def test_from_graph(self, building, organization, building_jsonld, model_context
"@embed": True
}
results = from_graph(graph, frame=frame)
assert len(results) == 1
assert isinstance(results, Resource)
expected = {'@type': 'http://schema.org/Image', '@id': 'http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg'}
assert as_jsonld(results[0], form="expanded", store_metadata=store_metadata,
assert as_jsonld(results, form="expanded", store_metadata=store_metadata,
model_context=model_context, metadata_context=metadata_context,
context_resolver=None) == expected

Expand Down

0 comments on commit 7289112

Please sign in to comment.