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)
<count> 2 <action> _register_many <succeeded> True
association = Resource(type="Association", agent=persons)
forge.register(association)
<action> _register_one <succeeded> True
pp(forge.as_json(association, store_metadata=True))
{ "id": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/101a874a-0e59-404f-aa89-4e9fc9119520", "type": "Association", "agent": [ { "id": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/caccdb9d-a374-4ab4-85b1-01efb1d8d5e9", "type": "Person", "address": { "type": "PostalAddress", "country": "Switzerland", "locality": "Geneva" }, "name": "Jane Doe" }, { "id": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/e3817898-d82c-442c-a53e-6367fde62beb", "type": "Person", "email": "john.smith@epfl.ch", "name": "John Smith" } ], "_constrainedBy": "https://bluebrain.github.io/nexus/schemas/unconstrained.json", "_createdAt": "2022-04-12T22:22:23.988Z", "_createdBy": "https://bbp.epfl.ch/nexus/v1/realms/bbp/users/sy", "_deprecated": false, "_incoming": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/101a874a-0e59-404f-aa89-4e9fc9119520/incoming", "_outgoing": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/101a874a-0e59-404f-aa89-4e9fc9119520/outgoing", "_project": "https://bbp.epfl.ch/nexus/v1/projects/dke/kgforge", "_rev": 1, "_schemaProject": "https://bbp.epfl.ch/nexus/v1/projects/dke/kgforge", "_self": "https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/101a874a-0e59-404f-aa89-4e9fc9119520", "_updatedAt": "2022-04-12T22:22:23.988Z", "_updatedBy": "https://bbp.epfl.ch/nexus/v1/realms/bbp/users/sy" }
address = Resource(type="PostalAddress", country="Switzerland", locality="Geneva")
jane = Resource(type="Person", name="Jane Doe", address=address, award=["Nobel"])
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",
"award":["Nobel"]
},
{
"type": "Person",
"email": "john.smith@epfl.ch",
"name": "John Smith"
}
]
}
resource = forge.from_json(data, na="(missing)")
resource == association
True