Exemple #1
0
    def __init__(self,
                 greentConf=None,
                 config_file=os.path.join(os.path.dirname(__file__),
                                          "rosetta.yml"),
                 delete_type_graph=False,
                 init_db=False,
                 build_indexes=False,
                 debug=False):
        """ The constructor loads the config file an prepares the type graph.
        If delete_type_graph flag is true, the graph is deleted entirely. 
        If the init_db flag is true, the type_graph will be loaded from the config file. """

        self.debug = False

        logger.debug("-- rosetta init.")
        self.service_context = ServiceContext(greentConf)
        self.core = self.service_context.core
        """ Load configuration. """
        with open(config_file, 'r') as stream:
            self.config = yaml.load(stream)
        self.operators = self.config["@operators"]
        self.type_checks = self.config["@type_checks"]

        # Abbreviation
        self.cache = self.service_context.cache  # core.service_context.cache
        """ Initialize type graph. """
        self.type_graph = TypeGraph(self.service_context, debug=debug)
        self.synonymizer = Synonymizer(self.type_graph.concept_model, self)
        """ Merge identifiers.org vocabulary into Rosetta vocab. """
        self.identifiers = Identifiers()

        if delete_type_graph:
            logger.debug("--Deleting type graph")
            self.type_graph.delete_all()

        if init_db:
            """ Initialize type graph metadata. """
            '''
            for k, v in self.identifiers.vocab.items():
                if isinstance(v, str):
                    self.type_graph.find_or_create(k, v)
            '''
            self.type_graph.find_or_create_list(self.identifiers.vocab.items())
            # self.configure_local_operators ()
            self.type_graph.configure_operators(self.operators.items())
            # self.configure_translator_registry ()
            self.type_graph.cast_edges(self.type_checks)

        if build_indexes:
            """Create neo4j indices for identifier on different labels"""
            self.type_graph.create_constraints()
Exemple #2
0
 def __init__(self):
     self.context = service_context = ServiceContext(
         config=os.environ.get('greent.conf'))
     self.generic_ont = GenericOntology(self.context, '')