This notebooks demonstrates how to use configured Formatting string patterns to normalise resource identifiers.
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
from uuid import uuid4
uuid = str(uuid4())
# here "identifier" is the formatter name as configured while "persons" can be seen as a type
# by default, the type of formatter is str.format()
uid = forge.format("identifier", "persons", uuid)
resource = Resource(id=uid, type="Person", name="Jane Doe")
print(resource)
{ id: https://kg.example.ch/persons/9be10b3c-470c-4a1c-b212-5c118934e055 type: Person name: Jane Doe }
This is a store based URI formatter. Using BlueBrainNexus store, this formatter will output a fully expanded resource._store_metadata._self url value
from kgforge.core.commons.formatter import Formatter
# List the supported formatter types
[f"{fm.name}" for fm in Formatter]
['STR', 'URI_REWRITER']
# When using BlueBrainNexus store, set is_file to True to rewrite a file id or _self
forge.format(uri=resource.id, formatter=Formatter.URI_REWRITER, is_file=False)