Resolvers are helpers to find commonly used resources that one may want to link resources to. Resolvers are configured in the Resolvers
section of the configuration file.
from kgforge.core import KnowledgeGraphForge
forge = KnowledgeGraphForge("../../configurations/demo-forge.yml")
from kgforge.core.commons.strategies import ResolvingStrategy
Resolve a resource for female
in the terms.
female = forge.resolve("female", scope="terms")
type(female)
kgforge.core.resource.Resource
print(female)
{ id: http://purl.obolibrary.org/obo/PATO_0000383 label: female }
print(forge.resolve("female", scope="terms", target="sex"))
{ id: http://purl.obolibrary.org/obo/PATO_0000383 label: female }
print(forge.resolve("female", scope="terms", type="Class"))
{ id: http://purl.obolibrary.org/obo/PATO_0000383 label: female }
Resolving a resource for EPFL
in the entities.
epfl = forge.resolve("EPFL", scope="entities")
type(epfl)
kgforge.core.resource.Resource
print(epfl)
{ id: https://www.grid.ac/institutes/grid.5333.6 label: École Polytechnique Fédérale de Lausanne acronym: EPFL }
print(forge.resolve("EPFL", scope="entities", target="agents"))
{ id: https://www.grid.ac/institutes/grid.5333.6 label: École Polytechnique Fédérale de Lausanne acronym: EPFL }
print(forge.resolve("EPFL", scope="entities", type="Organization"))
{ id: https://www.grid.ac/institutes/grid.5333.6 label: École Polytechnique Fédérale de Lausanne acronym: EPFL }
Different strategies can be used to resolve terms.
In the following example, the missing 'e' at the end is intended for the demonstration.
text = "mal"
The default applied strategy is strategy=ResolvingStrategy.BEST_MATCH
.
print(forge.resolve(text, scope="terms"))
{ id: http://purl.obolibrary.org/obo/PATO_0000384 label: male }
print(forge.resolve(text, scope="terms", strategy=ResolvingStrategy.EXACT_MATCH))
None
The result list is ordered by matching relevance.
results = forge.resolve(text, scope="terms", strategy=ResolvingStrategy.ALL_MATCHES)
type(results)
list
len(results)
2
type(results[0])
kgforge.core.resource.Resource
print(*results, sep="\n")
{ id: http://purl.obolibrary.org/obo/PATO_0000384 label: male } { id: http://purl.obolibrary.org/obo/PATO_0000383 label: female }