def get_nsm(session): from .namespaces import namespace_manager from virtuoso.vstore import VirtuosoNamespaceManager nsm = VirtuosoNamespaceManager(Graph(), session) for prefix, namespace in namespace_manager.namespaces(): nsm.bind_virtuoso(session, prefix, namespace) return nsm
from rdflib import Graph, Namespace from rdflib.namespace import RDF from virtuoso.quadextractor import ClassPatternExtractor from virtuoso.vmapping import ( QuadMapPattern, PatternIriClass, QuadStorage, GraphQuadMapPattern) from virtuoso.vstore import Virtuoso, VirtuosoNamespaceManager from . import sqla_connection engine = create_engine(sqla_connection) Session = sessionmaker(bind=engine) session = Session(autocommit=False) metadata = MetaData(schema="test.DBA") TST = Namespace('http://example.com/test#') nsm = VirtuosoNamespaceManager(Graph(), session) nsm.bind('tst', TST) class MyClassPatternExtractor(ClassPatternExtractor): def iri_accessor(self, sqla_cls): return super(MyClassPatternExtractor, self).iri_accessor(sqla_cls) def get_base_conditions(self, alias_maker, cls, for_graph): return super(MyClassPatternExtractor, self).get_base_conditions( alias_maker, cls, for_graph) def make_column_name(self, cls, column, for_graph): return getattr(TST, 'col_pattern_%s_%s' % ( cls.__name__, column.key))