Exemplo n.º 1
0
 def m3_opendb(self, dbfile):
     if '/' == self.home[-1]:
         rval = piglet.open(self.home+dbfile)
     else:
         rval = piglet.open(self.home+'/'+dbfile)
     if rval != None:
         return rval
     else:
         raise Error("Could not open database")
Exemplo n.º 2
0
    def __init__(self, address, dbfile):
        BaseHTTPServer.HTTPServer.__init__(self, address, PigletRequestHandler)
        self.db = piglet.open(dbfile)
        self.json = json.JsonWriter()
        self.helper = PigletHelper(self.db)
        self.methods = {
            '/query':         lambda p: self.db.query(int(p.get('s', 0)),
                                                      int(p.get('p', 0)),
                                                      int(p.get('o', 0))),
            '/sources':       lambda p: self.db.sources(int(p.get('s', 0)),
                                                        int(p.get('p', 0)),
                                                        int(p.get('o', 0))),
            '/add':           lambda p: self.db.count(int(p['s']),
                                                      int(p['p']),
                                                      int(p['o']),
                                                      int(p.get('source', 0)),
                                                      int(p.get('temporary', 0))),
            '/del':           lambda p: self.db.count(int(p['s']),
                                                      int(p['p']),
                                                      int(p['o']),
                                                      int(p.get('source', 0)),
                                                      int(p.get('temporary', 0))),
            '/count':         lambda p: self.db.count(int(p.get('s', 0)),
                                                      int(p.get('p', 0)),
                                                      int(p.get('o', 0)),
                                                      int(p.get('source', 0)),
                                                      int(p.get('temporary', 0))),
            '/info':          lambda p: self.db.info(int(p['id'])),
            '/node':          lambda p: self.db.node(p['uri']),
            '/literal':       lambda p: self.db.literal(p['string'],
                                                        int(p.get('dt', 0)),
                                                        p.get('lang', "")),
            '/load':          lambda p: self.db.load(int(p['source'])),
            '/addNamespace':  lambda p: self.db.addNamespace(p['prefix'],
                                                             p['uri']),
            '/delNamespace':  lambda p: self.db.delNamespace(p['prefix']),
            '/expand':        lambda p: self.db.expand(p['qname']),
            '/reverseExpand': lambda p: self.db.reverseExpand(p['uri']),
            '/values':        lambda p: self.helper.values(int(p['node']),
                                                           int(p['path'])),
            '/label':         lambda p: self.helper.label(int(p['id']))
}
Exemplo n.º 3
0
 def __init__(self, dbfile, seed=False):
     self.dbfile = dbfile
     self.nodeCache = {}
     self.memberProps = []
     self.home = os.getenv("PIGLET_HOME")
     self.qe = self.makeQueryEngine()
     self.db = piglet.open(dbfile)
     self.type = self['rdf:type']
     self.subprop = self['rdfs:subPropertyOf']
     self.subclass = self['rdfs:subClassOf']
     self.resource = self['rdfs:Resource']
     self.sa = self['owl:sameAs']
     self.reasoner = 0 # self['piglet:Reasoner']
     self.literalParser = LiteralParser(self)
     self.bootstrap()
     (sources, namespaces, triples) = self.seedData()
     if seed:
         for source in set(sources):
             self.load(source, True, True)
     for (prefix, uri) in set(namespaces):
         self.addNamespace(prefix, uri)
     for (s, p, o, temp) in set(triples):
         self.add(s, p, o, 0, temp)
     self.postProcess(0)