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")
from kgforge.core import Resource
jane = Resource(type="Person", name="Jane Doe")
john = Resource(type="Person", name="John Smith")
persons = [jane, john]
resources = forge.reshape(persons, keep=["name"])
type(resources)
list
type(resources[0])
kgforge.core.resource.Resource
print(jane)
{ type: Person name: Jane Doe }
print(resources[0])
{ name: Jane Doe }
jane = Resource(type="Person", name="Jane Doe")
association = Resource(type="Association", agent=jane)
resource = forge.reshape(association, keep=["type", "agent.name"])
print(association)
{ type: Association agent: { type: Person name: Jane Doe } }
print(resource)
{ type: Association agent: { name: Jane Doe } }
This is useful to switch resource references to versioned identifiers.
jane = Resource(type="Person", name="Jane Doe")
forge.register(jane)
<action> _register_one <succeeded> True
resource = forge.reshape(jane, keep=["id", "type"], versioned=True)
forge.as_json(jane)
{'id': 'https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/9c0d1bac-2f14-4a8b-ad6f-dc7495cc10e7', 'type': 'Person', 'name': 'Jane Doe'}
print(resource)
{ id: https://bbp.epfl.ch/nexus/v1/resources/dke/kgforge/_/9c0d1bac-2f14-4a8b-ad6f-dc7495cc10e7?rev=1 type: Person }
john = Resource(type="Person", name="John Smith")
resource = forge.reshape(john, keep=["id"], versioned=True)
resource is None
True