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
It is possible to assign arbitrary properties to create a resource, and link them to other resources via properties.
jane = Resource(type="Person", name="Jane Doe")
association = Resource(type="Association", agent=jane)
print(association)
{ type: Association agent: { type: Person name: Jane Doe } }
association_json = {
"type" : "Association",
"agent": jane
}
association = Resource.from_json(association_json)
print(association)
{ type: Association agent: { type: Person name: Jane Doe } }
import numpy as np
association_json = {
"id": "https://id",
"type" : "Association",
"nanValue": np.nan,
"agent": jane
}
association = Resource.from_json(association_json, na=np.nan)
print(association)
{ id: https://id type: Association agent: { type: Person email: jane.doe@epfl.ch name: Jane Doe } }
import pandas as pd
dataframe = pd.read_csv("../../data/persons.csv")
display(dataframe)
resources = forge.from_dataframe(dataframe)
print(*resources, sep="\n")
type | name | |
---|---|---|
0 | Person | Marie Curie |
1 | Person | Albert Einstein |
{ type: Person name: Marie Curie } { type: Person name: Albert Einstein }
jane.email = "jane.doe@epfl.ch"
jane.email
'jane.doe@epfl.ch'
association.agent.email
'jane.doe@epfl.ch'
association.has_identifier(return_attribute=True)
(True, 'id')
association.get_identifier()
'https://id'
association.has_type(return_attribute=True)
(True, 'type')
association.get_type()
'Association'
print(jane)
{ type: Person email: jane.doe@epfl.ch name: Jane Doe }
print(association)
{ id: https://id type: Association agent: { type: Person email: jane.doe@epfl.ch name: Jane Doe } }