Пример #1
0
 def __init__(self, source='dummy', defaultStatements=(), **kw):
     # Create a new hash memory store
     storage = RDF.HashStorage(
         source, options="new='yes',hash-type='memory',contexts='yes'")
     model = RDF.Model(storage)
     super(RedlandHashMemModel, self).__init__(model)
     for stmt in defaultStatements:
         self.addStatement(stmt)
     model.sync()
Пример #2
0
 def __init__(self, source='', defaultStatements=(), **kw):
     if os.path.exists(source + '-sp2o.db'):
         storage = RDF.HashStorage(
             source, options="hash-type='bdb',contexts='yes'")
         model = RDF.Model(storage)
     else:
         # Create a new BDB store
         storage = RDF.HashStorage(
             source, options="new='yes',hash-type='bdb',contexts='yes'")
         model = RDF.Model(storage)
         for stmt in defaultStatements:
             if stmt.scope:
                 context = URI2node(stmt.scope)
             else:
                 context = None
             model.add_statement(statement2Redland(stmt),
                                 context=context)
         model.sync()
     super(RedlandHashBdbModel, self).__init__(model)
Пример #3
0
    def __init__(self, ns_tbl, large=False):

        if large:
            self._storage = RDF.HashStorage(
                'db4', options="new='yes',hash-type='bdb'")
        else:
            self._storage = RDF.MemoryStorage()

        self._model = RDF.Model(self._storage)

        self._g_pred_map = {}
        self._pred_tbl = {}

        self.l_true = Literal('true')
        self.l_false = Literal('false')

        self.namespace_tbl = ns_tbl
Пример #4
0
    def createModel(self):
        """Creates a Redland RDF Model.

        Returns:
            RDF.Model
        """

        storage = RDF.HashStorage("temp",
                                  options="new='yes',hash-type='memory'")

        if storage is None:
            raise Exception("new RDF.Storage failed")

        model = RDF.Model(storage)

        if model is None:
            raise Exception("new RDF.model failed")

        self.model = model
Пример #5
0
from pymongo import MongoClient

# Fix up handling of utf8

reload(sys)
sys.setdefaultencoding('utf8')

# Warm up the parser.

if len(sys.argv) < 2:
    raise RuntimeError('Missing file argument')

file = sys.argv[1]

parser = RDF.Parser(name="ntriples")
store = RDF.HashStorage("db4", options="new='yes', hash-type='bdb'")
model = RDF.Model()
stream = parser.parse_into_model(model, 'file:' + file)

# Connect to our database.

db = MongoClient('mongodb://{}:{}@{}:{}'.format('mhucka', 'casics4me',
                                                'hyponym.caltech.edu', 9988),
                 tz_aware=True,
                 connect=True,
                 socketKeepAlive=True)
lcsh_db = db['lcsh']
lcsh = lcsh_db.terms

# Helper functions
Пример #6
0
import RDF

storage = RDF.HashStorage('music', options="hash-type='bdb',bulk='no'")
model = RDF.Model(storage)

def state(s, p, o):
  model.append(RDF.Statement(s, p, o))

def forget(s, p, o):
  '''delete all statements matching the given s, p, o (None matches anything)'''
  for st in model.find_statements(RDF.Statement(s, p, o)):
    del model[st]