from kgforge.core import KnowledgeGraphForge
A configuration file is needed in order to create a KnowledgeGraphForge session. A configuration can be generated using the notebook 00-Initialization.ipynb.
forge = KnowledgeGraphForge("../../configurations/forge.yml")
import json
from kgforge.core import Resource
def pp(x): print(json.dumps(x, indent=4))
address = Resource(type="PostalAddress", country="Switzerland", locality="Geneva")
jane = Resource(type="Person", name="Jane Doe", address=address)
john = Resource(type="Person", name="John Smith", email="john.smith@epfl.ch")
persons = [jane, john]
forge.register(persons)
association = Resource(type="Association", agent=persons)
forge.register(association)
pp(forge.as_json(association))
pp(forge.as_json(association, store_metadata=True))
address = Resource(type="PostalAddress", country="Switzerland", locality="Geneva")
jane = Resource(type="Person", name="Jane Doe", address=address)
john = Resource(type="Person", name="John Smith", email="john.smith@epfl.ch")
persons = [jane, john]
association = Resource(type="Association", agent=[jane, john])
data = {
"type": "Association",
"agent": [
{
"type": "Person",
"address": {
"type": "PostalAddress",
"country": "Switzerland",
"locality": "Geneva",
},
"email": "(missing)",
"name": "Jane Doe"
},
{
"type": "Person",
"email": "john.smith@epfl.ch",
"name": "John Smith"
}
]
}
resource = forge.from_json(data, na="(missing)")
resource == association