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", debug=True)
from kgforge.core.commons.strategies import ResolvingStrategy
With the forge.resolvers()
method, the user can inspect the available scopes, resolvers, and targets.
A scope is linked to a data source (directory, store, or URL). Each scope will have at least one resolver, which is an implementation of the Forge Resolver. A resolver can have multiple targets, and it will delimitate the resolution within the resolver's scope.
forge.resolvers()
To find resources using resolver, you can use regex expressions within the provided string.
Resolve a resource for female
in the terms.
female = forge.resolve("female", scope="terms")
type(female)
print(female)
print(forge.resolve("female", scope="terms", target="sex"))
print(forge.resolve("female", scope="terms", type="Class"))
Resolving a resource for EPFL
in the entities.
epfl = forge.resolve("EPFL", scope="entities")
type(epfl)
print(epfl)
print(forge.resolve("EPFL", scope="entities", target="agents"))
print(forge.resolve("EPFL", scope="entities", type="Organization"))
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"))
print(forge.resolve(text, scope="terms", strategy=ResolvingStrategy.EXACT_MATCH))
The result list is ordered by matching relevance.
results = forge.resolve(text, scope="terms", strategy=ResolvingStrategy.ALL_MATCHES, limit=3)
type(results)
len(results)
type(results[0])
print(*results, sep="\n")