Esempio n. 1
0
def get_toolkit(schema: Optional[str] = None) -> Toolkit:
    """
    Get an instance of bmt.Toolkit
    If there no instance defined, then one is instantiated and returned.
    """
    global toolkit
    if toolkit is None:
        if not schema:
            config = get_config()
            schema = config['biolink-model']
        toolkit = Toolkit(schema=schema)
    return toolkit
Esempio n. 2
0
class CurieLookupService(object):
    """
    A service to lookup label for a given CURIE.
    """

    config = get_config()
    ontologies = config['ontologies']
    ontology_graph = None

    def __init__(self, curie_map: dict = None):
        if curie_map:
            self.curie_map = CURIE_MAP
            self.curie_map.update(curie_map)
        else:
            self.curie_map = CURIE_MAP
        self.ontology_graph = nx.MultiDiGraph()
        self.load_ontologies()

    def load_ontologies(self):
        """
        Load all required ontologies.
        """
        for ontology in self.ontologies.values():
            rdfgraph = rdflib.Graph()
            input_format = rdflib.util.guess_format(ontology)
            rdfgraph.parse(ontology, format=input_format)
            # triples = rdfgraph.triples((None, rdflib.RDFS.subClassOf, None))
            # for s,p,o in triples:
            #     subject_curie = contract(s)
            #     object_curie = contract(o)
            #     self.ontology_graph.add_node(subject_curie)
            #     self.ontology_graph.add_node(object_curie)
            #     key = generate_edge_key(subject_curie, 'subclass_of', object_curie)
            #     self.ontology_graph.add_edge(subject_curie, object_curie, key, **{'predicate': 'subclass_of', 'relation': 'rdfs:subClassOf'})

            triples = rdfgraph.triples((None, rdflib.RDFS.label, None))
            for s, p, o in triples:
                key = contract(s)
                value = o.value
                value = value.replace(' ', '_')
                self.curie_map[key] = value
                self.ontology_graph.add_node(key, name=value)
Esempio n. 3
0
from kgx.cli.cli_utils import (
    get_input_file_types,
    parse_source,
    apply_operations,
    graph_summary,
    validate,
    neo4j_download,
    neo4j_upload,
    transform,
    merge,
    summary_report_types,
    get_report_format_types,
)

log = get_logger()
config = get_config()


def error(msg):
    log.error(msg)
    quit()


@click.group()
@click.version_option(version=kgx.__version__, prog_name=kgx.__name__)
def cli():
    """
    Knowledge Graph Exchange CLI entrypoint.
    \f

    """