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
Prefixes are namespaces that are used to put Resource properties within a context.
forge.prefixes()
The type
property of a Resource can be associated to the available types in the Model. These types have a pre-defined set of properties.
forge.types()
The template will provide a set of properties for the givent type that is recomended to be used when creating Resources.
forge.template("Person")
forge.template("Person", only_required=True)
forge.template("Person", output="json", only_required=True)
data = {
"type": "Person",
"name": "Jane"
}
resource_json = forge.from_json(data)
print(resource_json)
template = forge.template("Person", output="dict", only_required=True)
template["name"] = "Jane"
resource_dict = forge.from_json(template)
print(resource_dict)
It is possible to verify that a Resource is compliant with the suggested type schema available in the Model.
jane = Resource(type="Person", name="Jane Doe")
john = Resource(type="Person", name="John Smith")
persons = [jane, john]
forge.validate(persons)
jane._last_action
jane._validated
jane.email = "jane.doe@epfl.ch"
jane._validated
distribution = forge.attach("../../data/persons.csv")
jane = Resource(type="Person", name="Jane Doe", distribution=distribution)
forge.validate(jane)
Note: DemoStore doesn't implement file operations yet. Please use another store for the following cell.
forge.validate(jane, execute_actions_before=True)
Note: DemoModel and RdfModel schemas have not been synchronized yet. This section is to be run with RdfModel. Commented lines are for DemoModel.
mistake = Resource(type="Person")
# resource = Resource(type="Association", agent=mistake)
resource = Resource(type="Dataset", contribution=mistake)
forge.validate(resource)
resource._last_action
resource._validated