import os
import json
from kgforge.core import KnowledgeGraphForge
from kgforge.specializations.resources import Dataset
import getpass
TOKEN = getpass.getpass()
BUCKET = "dke/kgforge"
forge = KnowledgeGraphForge("../use-cases/prod-forge-nexus.yml",
bucket=BUCKET,
token=TOKEN
)
forge.resolvers(output='dict')
{'agent': {'agents': {'bucket': 'bbp/agents', 'filters': None}}, 'ontology': {'terms': {'bucket': 'neurosciencegraph/datamodels', 'filters': None}, 'CellType': {'bucket': 'neurosciencegraph/datamodels', 'filters': {'subClassOf*.id': 'BrainCellType'}}, 'BrainRegion': {'bucket': 'neurosciencegraph/datamodels', 'filters': {'subClassOf*.id': 'BrainRegion'}}, 'Species': {'bucket': 'neurosciencegraph/datamodels', 'filters': {'has_rank.id': 'http://purl.obolibrary.org/obo/NCBITaxon_species'}}, 'Strain': {'bucket': 'neurosciencegraph/datamodels', 'filters': {'has_rank.id': 'http://purl.obolibrary.org/obo/NCBITaxon_strain'}}}}
case_insensitive = forge.resolve('Pv+', scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH')
exact = forge.resolve('PV+', scope='ontology', strategy='EXACT_MATCH')
assert case_insensitive == exact
similar = forge.resolve('pv-', scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH')
similar1 = forge.resolve('pv:', scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH')
assert similar is None
assert similar1 is None
print(forge.resolve('229_l6 it ctx', scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH'))
{ id: https://bbp.epfl.ch/ontologies/core/ttypes/229_L6_IT_CTX type: Class label: 229_L6 IT CTX subClassOf: [ https://bbp.epfl.ch/ontologies/core/ttypes/L4_5_6_IT_Car3 https://bbp.epfl.ch/ontologies/core/celltypes/NeuronTranscriptomicType ] }
print(forge.resolve('264_L5/6 np CTX', scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH'))
{ id: https://bbp.epfl.ch/ontologies/core/ttypes/264_L5_6_NP_CTX type: Class label: 264_L5/6 NP CTX subClassOf: [ https://bbp.epfl.ch/ontologies/core/ttypes/L5_6_NP_CTX https://bbp.epfl.ch/ontologies/core/celltypes/NeuronTranscriptomicType ] }
This is particularly useful when two entities have a similar acronym like the example below, where there is a brain region called BAC, and a electrical cell type labelled bAC.
Without any specification, it will return the first result in the list of matches (no priority or ranking).
list(forge.resolvers(output='dict')['ontology'].keys()) # terms is for resolving accross all ontologies
['terms', 'CellType', 'BrainRegion', 'Species', 'Strain']
from kgforge.core.commons.strategies import ResolvingStrategy
print(forge.resolve("bAC", scope="ontology", target="terms",
strategy=ResolvingStrategy.EXACT_CASE_INSENSITIVE_MATCH))
{ id: http://uri.interlex.org/base/ilx_0738199 type: Class label: bAC notation: bAC prefLabel: Burst accommodating electrical type subClassOf: [ nsg:EType bmo:NeuronElectricalType ] }
print(forge.resolve("bAC", scope="ontology", target="CellType", strategy="EXACT_CASE_INSENSITIVE_MATCH"))
{ id: http://uri.interlex.org/base/ilx_0738199 type: Class label: bAC notation: bAC prefLabel: Burst accommodating electrical type subClassOf: [ nsg:EType bmo:NeuronElectricalType ] }
print(forge.resolve("bAC", scope="ontology", target="BrainRegion", strategy="EXACT_CASE_INSENSITIVE_MATCH"))
{ id: http://api.brain-map.org/api/v2/data/Structure/287 type: Class label: Bed nucleus of the anterior commissure isDefinedBy: http://bbp.epfl.ch/neurosciencegraph/ontologies/core/brainregion notation: BAC prefLabel: Bed nucleus of the anterior commissure subClassOf: nsg:BrainRegion }
print(forge.resolve("rat", scope="ontology", target="Species", strategy="EXACT_CASE_INSENSITIVE_MATCH"))
{ id: http://purl.obolibrary.org/obo/NCBITaxon_10116 type: Class label: Rattus norvegicus altLabel: rat atlasRelease: { id: https://bbp.epfl.ch/neurosciencegraph/data/4906ab85-694f-469d-962f-c0174e901885 } subClassOf: [ nsg:Species NCBITaxon:10114 ] }
print(forge.resolve("Wistar", scope="ontology", target="Strain", strategy="EXACT_CASE_INSENSITIVE_MATCH"))
{ id: http://www.ebi.ac.uk/efo/EFO_0001342 type: Class label: Wistar altLabel: [ Rats, Wistar Wistar rat Wistar rats ] atlasRelease: { id: https://bbp.epfl.ch/neurosciencegraph/data/4906ab85-694f-469d-962f-c0174e901885 } subClassOf: NCBITaxon:10116 }
resource = forge.resolve("AOB_MC", scope="ontology", target="terms", strategy="EXACT_MATCH")
assert isinstance(resource.label, str)
excitatory = forge.resolve("exc", scope='ontology', strategy='EXACT_CASE_INSENSITIVE_MATCH')
assert isinstance(excitatory.label, str)
print(excitatory)
{ id: https://neuroshapes.org/ExcitatoryNeuron type: Class label: Excitatory Neuron notation: Exc prefLabel: Excitatory Neuron subClassOf: bmo:NeurotransmitterType }