Exemplo n.º 1
0
import csv
import shutil
from datetime import datetime

import surf
from rdflib.plugins.sleepycat import Sleepycat

__all__ = ('create_book', 'create_member', 'create_loan', 'populate', 'query', 
        'persist_to_rdf', 'Book', 'Member', 'Loan', 'persist', 'raw_query')

# create the store
sc = Sleepycat()
sc.open("db")
store = surf.Store(reader="rdflib", writer="rdflib", rdflib_store=sc)
session = surf.Session(store)

# defines the prefixes
NAMESPACES = {
    'bc': 'http://notmyidea.org/bookclub/',
    'foaf': 'http://xmlns.com/foaf/0.1/',
    'book': 'http://purl.org/NET/book/vocab/',
    'dct': 'http://purl.org/dc/terms/'
}

# register the namespaces used here
surf.ns.register(bc="http://notmyidea.org/bookclub/")
surf.ns.register(book="http://purl.org/NET/book/vocab/")

# map class with namespaces
Book = session.get_class(surf.ns.BC.Book)
Member = session.get_class(surf.ns.BC.Member)
Exemplo n.º 2
0
             for t in active_threads:
                 if not commit_pending_transaction:
                     self.rollback(rollback_root=True)
                 else:
                     self.commit(commit_root=True)
             
             sleep(0.1)
     
     # there may still be open transactions
     super(BerkeleyDB, self).close()
 
 def add(self, (subject, predicate, object_), context, quoted=False):
     
     @transaction
     def _add(self, (subject, predicate, object_), context, quoted, txn=None):
         Sleepycat.add(self, (subject, predicate, object_), context, quoted, txn)
     
     try:
         _add(self, (subject, predicate, object_), context, quoted)
     except Exception, e:
         # print "Got exception in _add: ", e
         raise e
 
 def remove(self, (subject, predicate, object_), context):
     
     @transaction
     def _remove(self, (subject, predicate, object_), context, txn=None):
         Sleepycat.remove(self, (subject, predicate, object_), context, txn=txn)
     
     try:
         _remove(self, (subject, predicate, object_), context)