def triples(self, xxx_todo_changeme3, context=None): """Generator over the triple store Returns triples that match the given triple pattern. If triple pattern does not provide a context, all contexts will be searched. """ (s, p, o) = xxx_todo_changeme3 url = self._statement_encode((s, p, o), context) req = Request(url) req.add_header('Accept', 'text/plain') # N-Triples is best for generator (one line per triple) log.debug("Request: %s" % req.get_full_url()) dumper = DumpSink() parser = NTriplesParser(dumper) for l in urlopen(req): log.debug('line: %s' % l) parser.parsestring(l) yield dumper.get_triple()
"""Generator over the triple store Returns triples that match the given triple pattern. If triple pattern does not provide a context, all contexts will be searched. """ url = self._statement_encode((s, p, o), context) req = Request(url) req.add_header('Accept','text/plain') # N-Triples is best for generator (one line per triple) log.debug("Request: %s" % req.get_full_url()) dumper=DumpSink() parser=NTriplesParser(dumper) for l in urlopen(req): log.debug('line: %s'%l) parser.parsestring(l) yield dumper.get_triple() def __len__(self): """Returns the number of triples in the graph calls http://{self.url}/size very fast """ return int(urlopen(self.url+"/size").read()) def set(self, (subject, predicate, object)): """Convenience method to update the value of object Remove any existing triples for subject and predicate before adding (subject, predicate, object). """ self.remove((subject, predicate, None)) self.add((subject, predicate, object))
does not provide a context, all contexts will be searched. """ ctx = context or self.context url = self._statement_encode((s, p, o), ctx) req = Request(url) req.add_header( 'Accept', 'text/plain' ) # N-Triples is best for generator (one line per triple) log.debug("Request: %s" % req.get_full_url()) dumper = DumpSink() parser = NTriplesParser(dumper) for l in urlopen(req): #log.debug('line: %s'%l) parser.parsestring(l) yield dumper.get_triple() def __len__(self): """Returns the number of triples in the graph calls http://{self.url}/size very fast """ return int(urlopen(self.url + "/size").read()) def set(self, (subject, predicate, object)): """Convenience method to update the value of object Remove any existing triples for subject and predicate before adding (subject, predicate, object). """ self.remove((subject, predicate, None)) self.add((subject, predicate, object))