from kgforge.core import KnowledgeGraphForge
forge = KnowledgeGraphForge("../../configurations/forge.yml")
from kgforge.core import Resource
jane = Resource(type="Person", name="Jane Doe")
forge.register(jane)
graph = forge.as_graph(jane)
len(graph)
len(graph) == 2
for triple in graph:
print(triple)
graph_store_metadata = forge.as_graph(jane, store_metadata=True)
len(graph_store_metadata)
for triple in graph_store_metadata:
print(triple)
#data in n3 format
data = '''
@prefix schema: <http://schema.org/> .
[] a schema:Person;
schema:name "Jane Doe" ;
schema:knows <http://example.org/JohnDoe>;
schema:affiliation <https://www.grid.ac/institutes/grid.5333.6>.
<http://example.org/JohnDoe> a schema:Person;
schema:name "John Doe" .
<https://www.grid.ac/institutes/grid.5333.6> a schema:Organization;
schema:name "EPFL" .
'''
import rdflib
graph = rdflib.Graph()
graph.parse(data=data, format="n3")
len(graph)
resources = forge.from_graph(graph)
len(resources) == 3
frame = {
"@type": [ 'http://schema.org/Person'],
"@embed": True
}
resources = forge.from_graph(data=graph, frame= frame)
len(resources) == 2
forge.as_jsonld(resources)
_type= ["http://schema.org/Organization"]
resources = forge.from_graph(data=graph, type= _type)
len(resources) == 1
True
epfl_json = {'id': 'https://www.grid.ac/institutes/grid.5333.6',
'type': 'schema:Organization',
'schema:name': 'EPFL'}
epfl_json == forge.as_json(resources[0])
True
_type= ["http://schema.org/Organization"]
resources = forge.from_graph(data=graph, type= _type, use_model_context=True)
len(resources) == 1
True