Exemplo n.º 1
0
def load_ontologies(session, reload=None):
    store = Virtuoso(connection=session.bind.connect())
    known_graphs = [g.identifier for g in store.contexts()]
    print 'known', known_graphs
    for fname in listdir(ontology_dir):
        ending = fname.rsplit('.')[-1]
        if ending not in formats:
            continue
        print fname,
        temp_graph = Graph()
        temp_graph.parse(join(ontology_dir, fname), format=formats[ending])
        ontologies = list(temp_graph.subjects(RDF.type, OWL.Ontology))
        print ontologies,
        if len(ontologies) != 1:
            continue
        ontology = ontologies[0]
        if ontology in known_graphs:
            print 'already there'
            continue
        for (s, p, o) in temp_graph.triples((None, None, None)):
            store.add((s, p, o), context=ontology)
        print "loaded"
Exemplo n.º 2
0
def load_ontologies(session, reload=None):
    store = Virtuoso(connection=session.bind.connect())
    known_graphs = [g.identifier for g in store.contexts()]
    print 'known', known_graphs
    for fname in listdir(ontology_dir):
        ending = fname.rsplit('.')[-1]
        if ending not in formats:
            continue
        print fname,
        temp_graph = Graph()
        temp_graph.parse(join(ontology_dir, fname), format=formats[ending])
        ontologies = list(temp_graph.subjects(RDF.type, OWL.Ontology))
        print ontologies,
        if len(ontologies) != 1:
            continue
        ontology = ontologies[0]
        if ontology in known_graphs:
            print 'already there'
            continue
        for (s, p, o) in temp_graph.triples((None, None, None)):
            store.add((s, p, o), context=ontology)
        print "loaded"
Exemplo n.º 3
0
    def setUp(cls):
        cls.store = Virtuoso(rdflib_connection)
        cls.id1 = URIRef("http://example2.org/g1")
        cls.g1 = Graph(cls.store, identifier=cls.id1)
        cls.g1.remove((None, None, None))
        cls.id2 = URIRef("http://example2.org/g2")
        cls.g2 = Graph(cls.store, identifier=cls.id2)
        cls.g2.remove((None, None, None))

        cls.tst = TST = Namespace('http://example.com/ns/')
        cls.g1.add((TST.g0, RDF.type, TST.Graph))
        cls.g1.add((TST.g1, RDF.type, TST.Graph))
        cls.g2.add((TST.g0, RDF.type, TST.Graph))
        cls.g2.add((TST.g2, RDF.type, TST.Graph))
Exemplo n.º 4
0
 def dataset(self):
     #pdb.set_trace()
     if hasattr(self._connection, 'dataset'):
         return getattr(self._connection, 'dataset')
     if self.store=='Sleepycat':
         dataset = Dataset(store=self.store, default_union=True)
         dataset.open(self.store_path, create = True)
     else:
         self.store = Virtuoso(self.connection)
         #dataset = Dataset(store=self.store, default_union=True)
         dataset = ConjunctiveGraph(store=self.store,identifier=CENDARI)
         self.store.connection # force connection
     setattr(self._connection, 'dataset', dataset)
     nm = NamespaceManager(dataset)
     for (prefix, ns) in INIT_NS.iteritems():
         nm.bind(prefix, ns)
     dataset.namespace_manager = nm
     return dataset
Exemplo n.º 5
0
def get_virtuoso(session, storage=None):
    storage = storage or AssemblQuadStorageManager.discussion_storage_name()
    v = Virtuoso(quad_storage=storage, connection=session.connection())
    return v
Exemplo n.º 6
0
 def get_store(self):
     return Virtuoso(virtuoso_store)
Exemplo n.º 7
0
        'select * from named <> { ?s ?p ?o }',
        'select * from <> from named <> { ?s ?p ?o }',
    ])
    def test_sparql_with_from(self, datasetname, sparql):
        dataset = getattr(self, datasetname)
        with assert_raises(ValueError):
            dataset.query(sparql)


virtuoso_store = os.environ.get('RDFREST_VIRTUOSO_STORED')
if virtuoso_store:
    try:
        import pyodbc
        from virtuoso.vstore import Virtuoso
        try:
            _ = Virtuoso(virtuoso_store)

            class TestVirtuoso(TestDefaultStore):
                def get_store(self):
                    return Virtuoso(virtuoso_store)

        except pyodbc.Error:

            @skip('Virtuoso store not available')
            def TestVirtuoso():
                pass
    except ImportError:

        @skip('Virtuoso store not completely installed')
        def TestVirtuoso():
            pass
Exemplo n.º 8
0
 def setup_class(cls):
     clean()
     metadata.create_all(engine)
     cls.store = Virtuoso(connection=session.bind.connect(),
                          quad_storage=cls.qsname)
Exemplo n.º 9
0
class SemanticHandler(object):
    def __init__(self):
        try:
            if settings.SEMANTIC_STORE=='Sleepycat':
                self.store = settings.SEMANTIC_STORE
                self.store_path = settings.SEMANTIC_PATH
            elif settings.SEMANTIC_STORE=='Virtuoso':
                pwd=settings.VIRTUOSO.get('dba_password','dba')
                uid=settings.VIRTUOSO.get('dba_user','dba')
                dsn=settings.VIRTUOSO.get('dsn','VOS')
                self.connection = ('DSN=%s;UID=%s;PWD=%s;WideAsUTF16=Y' % (dsn, uid, pwd))
                self.store = 'Virtuoso'
            else:
                raise ImproperlyConfigured("SEMANTIC_STORE invalid in the settings file'")
        except ValueError:
            raise ImproperlyConfigured("SEMANTIC_PATH must be configured in the settings file'")
        self._connection = local()

    def dataset(self):
        #pdb.set_trace()
        if hasattr(self._connection, 'dataset'):
            return getattr(self._connection, 'dataset')
        if self.store=='Sleepycat':
            dataset = Dataset(store=self.store, default_union=True)
            dataset.open(self.store_path, create = True)
        else:
            self.store = Virtuoso(self.connection)
            #dataset = Dataset(store=self.store, default_union=True)
            dataset = ConjunctiveGraph(store=self.store,identifier=CENDARI)
            self.store.connection # force connection
        setattr(self._connection, 'dataset', dataset)
        nm = NamespaceManager(dataset)
        for (prefix, ns) in INIT_NS.iteritems():
            nm.bind(prefix, ns)
        dataset.namespace_manager = nm
        return dataset

    def graph(self, identifier):
        if isinstance(identifier, six.string_types):
            uri = URIRef(identifier)
        if self.store == 'Sleepycat':
            return self.dataset().graph(identifier)
        return self.dataset().get_context(identifier)

    def remove_graph(self, g):
        if self.store == 'Sleepycat':
            self.dataset().remove_graph(g)
        g.remove((None, None, None))
        return g

    def query(self, query_object, processor='sparql',
              result='sparql', initNs=None, initBindings=None,
              **kwargs):
        return self.dataset().query(query_object, processor,
                                    result, initNs, initBindings,
                                    **kwargs)

    def _close(self):
        if hasattr(self._connection, 'dataset'):
            self.dataset().close()
            self._connection.dataset = None
            delattr(self._connection, 'dataset')
            logger.info("Closing SEMANTIC connection")

    def commit(self):
        if self.store!='Sleepycat':
            self.store.commit()
Exemplo n.º 10
0
 def setUp(cls):
     cls.store = Virtuoso(rdflib_connection)
     cls.identifier = URIRef("http://example2.org/")
     cls.graph = Graph(cls.store, identifier=cls.identifier)
     cls.graph.remove((None, None, None))
Exemplo n.º 11
0
 def test_open(self):
     store = Virtuoso(rdflib_connection)
     graph = Graph(store)
     result = graph.query("ASK { ?s ?p ?o }")
     assert not result
Exemplo n.º 12
0
 def get_store(self):
     return Virtuoso("DSN=VOS;UID=dba;PWD=dba;WideAsUTF16=Y")