예제 #1
0
    def init_graph(self, name):
        config=getUtility(Interface, name='configuration')
        graph_descr=config['graph_'+name]
        contains=graph_descr.get('contains', None)
        identifier=graph_descr.get('id', name)
        storage=graph_descr['storage']
        load=graph_descr.get('load_from', None)

        sto_driver, sto_filepath=self.storages[storage]

        if contains == None:
            graph=rdflib.graph.Graph(
                store=sto_driver,
                identifier=identifier,
                namespace_manager=self.ns_man
            )
            if sto_filepath is not None:
                sto_filepath = os.path.abspath(sto_filepath)
                if not os.path.exists(sto_filepath):
                    os.makedirs(sto_filepath)
                graph.open(sto_filepath, create=True)

        else:
            if sto_driver != 'default':
                graph=rdflib.graph.ConjunctiveGraph(sto_driver, identifier=identifier)
                if sto_filepath != None:
                    graph.open(sto_filepath,create=True)
            else:
                graph=rdflib.graph.Dataset(sto_driver)
                for cg in contains.split(','):
                    cg=cg.strip()
                    g=self.graphs[cg]
                    graph.add_graph(g)

        if len(graph)==0 and load != None:
            try:
                graph.parse(load) # FIXME slashes in Windows
                graph.commit()
            except IOError:
                logger.warning ("Cannot load graph from URI:" + load)

        for nk,nv in NAMESPACES.items():
            graph.bind(nk,nv)

        if name=='ns':
            self.ns_man=graph

        self.graphs[name]=graph
        GSM=getGlobalSiteManager()
        GSM.registerUtility(graph, IGraph, name=name)
예제 #2
0
# -*- coding: utf-8 -*-
"""The application's model objects"""

import rdflib
import rdflib.graph

#endpoints = [
#endpoint = "http://redrugs.tw.rpi.edu/bigdata/sparql"
#endpoint = "http://drugbank.bio2rdf.org/sparql"
endpoint = "http://localhost:8080/bigdata/sparql"
#    ]
#graphs = []
#for endpoint in endpoints:
graph = rdflib.ConjunctiveGraph('SPARQLStore')
graph.open(endpoint)


def init_model(engine):
    """Call me before using any of the tables or classes in the model."""
    #DBSession.configure(bind=engine)

    # If you are using reflection to introspect your database and create
    # table objects for you, your tables must be defined and mapped inside
    # the init_model function, so that the engine is available if you
    # use the model outside tg2, you need to make sure this is called before
    # you use the model.

    #
    # See the following example:

    #global t_reflected
예제 #3
0
# -*- coding: utf-8 -*-
"""The application's model objects"""

import rdflib
import rdflib.graph

#endpoints = [
endpoint =  "http://redrugs.tw.rpi.edu/bigdata/sparql"
#"http://drugbank.bio2rdf.org/sparql",
#    ]
#graphs = []
#for endpoint in endpoints:
graph = rdflib.ConjunctiveGraph('SPARQLStore')
graph.open(endpoint)

def init_model(engine):
    """Call me before using any of the tables or classes in the model."""
    #DBSession.configure(bind=engine)

    # If you are using reflection to introspect your database and create
    # table objects for you, your tables must be defined and mapped inside
    # the init_model function, so that the engine is available if you
    # use the model outside tg2, you need to make sure this is called before
    # you use the model.

    #
    # See the following example:

    #global t_reflected

    #t_reflected = Table("Reflected", metadata,