Ejemplo n.º 1
0
    def test_from_jsonld(self, building, model_context, building_jsonld):
        building.context = model_context.document["@context"]
        payload = building_jsonld(building, "compacted", False, None)
        resource = from_jsonld(payload)
        assert resource == building

        payload_with_atvalue = deepcopy(payload)
        payload_with_atvalue["status"] = {
            "@type": "xsd:string",
            "@value": "opened"
        }
        resource_with_atvalue = from_jsonld(payload_with_atvalue)
        assert "value" not in LD_KEYS.keys()
        assert hasattr(resource_with_atvalue, "status")
        assert resource_with_atvalue.status == Resource.from_json({"type":"xsd:string", "@value":"opened"})
Ejemplo n.º 2
0
    def test_from_jsonld_2(self, building, model_context, building_jsonld):
        payload = {
            "@context": {
                "sh": "http://www.w3.org/ns/shacl#",
                "ex": "http://test/vocab#",
                "parent": {
                    "@id": "ex:parent",
                    "@type": "@id"
                },
                "nodeKind": {
                    "@id": "sh:nodeKind",
                    "@type": "@id"
                },
                "BlankNode": {
                    "@id": "sh:BlankNode"
                },
                "NodeShape": {
                    "@id": "sh:NodeShape"
                },
                "SuperClass": {
                    "@id": "ex:SuperClass"
                }
            },
            "@id": "http://test/data/123",
            "@type": "NodeShape",
            "parent": "ex:SuperClass",
            "nodeKind": "sh:BlankNode"
        }
        resource_dict = from_jsonld(payload)
        print(resource_dict)

        assert True
Ejemplo n.º 3
0
 def triples_to_resource(iri, triples):
     graph = Graph().parse(data=triples, format="nt")
     data_expanded = json.loads(graph.serialize(format="json-ld").decode("utf-8"))
     frame = {"@id": iri}
     data_framed = jsonld.frame(data_expanded, frame)
     context = self.model_context or self.context
     compacted = jsonld.compact(data_framed, context.document)
     resource = from_jsonld(compacted)
     resource.context = context.iri if context.is_http_iri() else context.document["@context"]
     return resource
Ejemplo n.º 4
0
 def from_jsonld(self, data: Union[Dict, List[Dict]]) -> Union[Resource, List[Resource]]:
     return from_jsonld(data)
Ejemplo n.º 5
0
 def test_unresolvable_context(self, building, building_jsonld):
     building.context = "http://unresolvable.context.example.org/"
     payload = building_jsonld(building, "compacted", False, None)
     with pytest.raises(ValueError):
         from_jsonld(payload)
Ejemplo n.º 6
0
 def test_from_jsonld(self, building, model_context, building_jsonld):
     building.context = model_context.document["@context"]
     payload = building_jsonld(building, "compacted", False, None)
     resource = from_jsonld(payload)
     assert resource == building