Reshaping will create a copy of a Resource but keeping a set of specified properites.
from kgforge.core import KnowledgeGraphForge
forge = KnowledgeGraphForge("../../configurations/demo-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 } }
jane = Resource(type="Person", name="Jane Doe")
forge.register(jane)
<action> _register_one <succeeded> True
resource = forge.reshape(jane, keep=["id", "type"], versioned=True)
print(jane)
{ id: b961b363-6e85-495d-88ae-bf891d77fa4f type: Person name: Jane Doe }
print(resource)
{ id: b961b363-6e85-495d-88ae-bf891d77fa4f_version=1 type: Person }
john = Resource(type="Person", name="John Smith")
resource = forge.reshape(john, keep=["id", "type"], versioned=True)
<action> _reshape <error> AttributeError: 'Resource' object has no attribute 'id'
print(resource)
None