本文整理汇总了Python中rdflib.store.Store类的典型用法代码示例。如果您正苦于以下问题:Python Store类的具体用法?Python Store怎么用?Python Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add
def add(self, triple, context=None, quoted=False):
""" Add a triple to the store.
Apply the modifications on the cache, trigger an exception if data
has already been modified on the server.
:param triple: Triple (subject, predicate, object) to add.
:param context:
:param quoted: The quoted argument is interpreted by formula-aware
stores to indicate this statement is quoted/hypothetical. It
should be an error to not specify a context and have the
quoted argument be True. It should also be an error for the
quoted argument to be True when the store is not
formula-aware.
:returns:
"""
LOG.debug("-- ProxyStore.add(triple=%s, context=%s, quoted=%s) --",
triple, context, quoted)
assert self._identifier is not None, "The store must be open."
# TODO LATER : Wrong, assert is made to test bugs
assert self._format is not None, "The store must be open."
assert quoted == False, "The store -proxyStore- is not formula-aware"
Store.add(self, triple, context, quoted)
# Instruction suivant extraite du plugin Sleepycat
# Store.add(self, (subject, predicate, object), context, quoted)
self._graph.add(triple)
开发者ID:fderbel,项目名称:ktbs,代码行数:31,代码来源:proxystore.py
示例2: add
def add(self, triple, context, quoted=False):
Store.add(self, triple, context, quoted)
if context is not None:
self.__all_contexts.add(context)
enctriple = self.__encodeTriple(triple)
sid, pid, oid = enctriple
self.__addTripleContext(enctriple, context, quoted)
if sid in self.__subjectIndex:
self.__subjectIndex[sid].add(enctriple)
else:
self.__subjectIndex[sid] = set([enctriple])
if pid in self.__predicateIndex:
self.__predicateIndex[pid].add(enctriple)
else:
self.__predicateIndex[pid] = set([enctriple])
if oid in self.__objectIndex:
self.__objectIndex[oid].add(enctriple)
else:
self.__objectIndex[oid] = set([enctriple])
开发者ID:RDFLib,项目名称:rdflib,代码行数:25,代码来源:memory.py
示例3: remove_graph
def remove_graph(self, graph):
if not self.graph_aware:
Store.remove_graph(self, graph)
elif graph.identifier == DATASET_DEFAULT_GRAPH_ID:
self.update("DROP DEFAULT")
else:
self.update("DROP GRAPH <%s>" % graph.identifier)
开发者ID:raeisi,项目名称:rdflib,代码行数:7,代码来源:sparqlstore.py
示例4: add
def add(self, triple, context, quoted=False):
# oldlen = len(self)
Store.add(self, triple, context, quoted)
context = getattr(context, 'identifier', context)
if context is None:
context = DEFAULT
if context is not DEFAULT and context not in self.__all_contexts:
self.__all_contexts.add(context)
enctriple = self.__encodeTriple(triple)
sid, pid, oid = enctriple
self.__addTripleContext(enctriple, context, quoted)
if sid in self.__subjectIndex:
self.__subjectIndex[sid].add(enctriple)
else:
self.__subjectIndex[sid] = self.family.OO.Set((enctriple,))
if pid in self.__predicateIndex:
self.__predicateIndex[pid].add(enctriple)
else:
self.__predicateIndex[pid] = self.family.OO.Set((enctriple,))
if oid in self.__objectIndex:
self.__objectIndex[oid].add(enctriple)
else:
self.__objectIndex[oid] = self.family.OO.Set((enctriple,))
开发者ID:RDFLib,项目名称:rdflib-zodb,代码行数:28,代码来源:ZODB.py
示例5: remove_graph
def remove_graph(self, graph):
if not self.graph_aware:
Store.remove_graph(self, graph)
elif graph.identifier == DATASET_DEFAULT_GRAPH_ID:
self.update("DROP DEFAULT")
else:
self.update(
"DROP GRAPH %s" % self.node_to_sparql(graph.identifier))
开发者ID:Dataliberate,项目名称:rdflib,代码行数:8,代码来源:sparqlstore.py
示例6: remove_graph
def remove_graph(self, graph):
if not self.graph_aware:
Store.remove_graph(self, graph)
else:
self.remove((None, None, None), graph)
try:
self.__all_contexts.remove(graph)
except KeyError:
pass # we didn't know this graph, no problem
开发者ID:RDFLib,项目名称:rdflib,代码行数:9,代码来源:memory.py
示例7: remove
def remove(self, triple, context=None):
Store.remove(self, triple, context)
if context is not None:
if context == self:
context = None
# f = self.forward
r = self.reverse
if context is None:
for triple, cg in self.triples(triple):
subject, predicate, object = triple
si, pi, oi = self.identifierToInt((subject, predicate, object))
contexts = list(self.contexts(triple))
for context in contexts:
ci = r[context]
del self.cspo[ci][si][pi][oi]
del self.cpos[ci][pi][oi][si]
del self.cosp[ci][oi][si][pi]
self._removeNestedIndex(self.spo, si, pi, oi, ci)
self._removeNestedIndex(self.pos, pi, oi, si, ci)
self._removeNestedIndex(self.osp, oi, si, pi, ci)
# grr!! hafta ref-count these before you can collect
# them dumbass!
# del f[si], f[pi], f[oi]
# del r[subject], r[predicate], r[object]
else:
subject, predicate, object = triple
ci = r.get(context, None)
if ci:
for triple, cg in self.triples(triple, context):
si, pi, oi = self.identifierToInt(triple)
del self.cspo[ci][si][pi][oi]
del self.cpos[ci][pi][oi][si]
del self.cosp[ci][oi][si][pi]
try:
self._removeNestedIndex(self.spo, si, pi, oi, ci)
self._removeNestedIndex(self.pos, pi, oi, si, ci)
self._removeNestedIndex(self.osp, oi, si, pi, ci)
except KeyError:
# the context may be a quoted one in which
# there will not be a triple in spo, pos or
# osp. So ignore any KeyErrors
pass
# TODO delete references to resources in
# self.forward/self.reverse that are not in use anymore...
if subject is None and predicate is None and object is None:
# remove context
try:
ci = self.reverse[context]
del self.cspo[ci], self.cpos[ci], self.cosp[ci]
except KeyError:
# TODO: no exception when removing non-existant context?
pass
开发者ID:fetus94,项目名称:ordigRDFmapper,代码行数:56,代码来源:memory.py
示例8: remove
def remove(self, triple, context):
(subject, predicate, object) = triple
assert self.__open, "The Store must be open."
Store.remove(self, (subject, predicate, object), context)
_to_string = self._to_string
if context is not None:
if context == self:
context = None
if subject is not None \
and predicate is not None \
and object is not None \
and context is not None:
s = _to_string(subject)
p = _to_string(predicate)
o = _to_string(object)
c = _to_string(context)
value = self.__indices[0].get(bb("%s^%s^%s^%s^" % (c, s, p, o)))
if value is not None:
self.__remove((bb(s), bb(p), bb(o)), bb(c))
self.__needs_sync = True
else:
cspo, cpos, cosp = self.__indices
index, prefix, from_key, results_from_key = self.__lookup(
(subject, predicate, object), context)
needs_sync = False
for key in index.match_prefix(prefix):
c, s, p, o = from_key(key)
if context is None:
contexts_value = index.get(key) or b("")
# remove triple from all non quoted contexts
contexts = set(contexts_value.split(b("^")))
contexts.add(b("")) # and from the conjunctive index
for c in contexts:
for i, _to_key, _ in self.__indices_info:
i.remove(_to_key((s, p, o), c))
else:
self.__remove((s, p, o), c)
needs_sync = True
if context is not None:
if subject is None and predicate is None and object is None:
# TODO: also if context becomes empty and not just on
# remove((None, None, None), c)
try:
self.__contexts.remove(bb(_to_string(context)))
# except db.DBNotFoundError, e:
# pass
except Exception as e: # pragma: NO COVER
print("%s, Failed to delete %s" % (
e, context)) # pragma: NO COVER
pass # pragma: NO COVER
self.__needs_sync = needs_sync
开发者ID:RDFLib,项目名称:rdflib-kyotocabinet,代码行数:54,代码来源:KyotoCabinet.py
示例9: __init__
def __init__(self, configuration=None, identifier=None):
""" ProxyStore initialization.
Creates an empty Graph, intializes the HTTP client.
Use the defaut for internal graph storage, i.e IOMemory.
The URIref of the graph must be supplied either in identifier or
in configuration parameter. It will be checked by open().
The cache file path could be given in the configuration dictionary
(__init__ only). We have to search about the memory cache.
"""
LOG.debug("-- ProxyStore.init(configuration=%s, identifer=%s) --\n",
configuration, identifier)
self._identifier = identifier
self._format = None
self._etags = None
self._req_headers = {}
self.configuration = None
configuration = self._configuration_extraction(configuration)
self._graph = Graph()
# Most important parameter : identifier and graph address
# If not given, we can not go further
if (identifier is not None) and len(identifier) > 0:
if len(configuration) == 0:
configuration = {PS_CONFIG_URI: identifier}
# Show the network activity
if PS_CONFIG_DEBUG_HTTP in configuration.keys():
httplib2.debuglevel = 1
# File path for HTTPLIB2 cache
# As it is a file cache, it is conserved between two executions
# Should we delete the directory on application end (i.e close()) ?
if PS_CONFIG_HTTP_CACHE in configuration.keys():
self.httpserver = httplib2.Http(configuration[PS_CONFIG_HTTP_CACHE])
else:
self.httpserver = httplib2.Http(CACHE_DIR)
# Store will call open() if configuration is not None
Store.__init__(self, configuration)
开发者ID:fderbel,项目名称:ktbs,代码行数:45,代码来源:proxystore.py
示例10: triples
def triples(self, triple, context=None):
""" Returns an iterator over all the triples (within the conjunctive
graph or just the given context) matching the given pattern.
:param triple: Triple (subject, predicate, object) to remove.
:param context: ProxyStore is not context aware but it's internal
cache IOMemory store is. Avoid context parameter.
:returns: An iterator over the triples.
"""
LOG.debug("-- ProxyStore.triples(triple=%s, context=%s) --",
triple, context)
Store.triples(self, triple) #, context=None)
self._pull()
return self._graph.store.triples(triple) #, context=None)
开发者ID:fderbel,项目名称:ktbs,代码行数:18,代码来源:proxystore.py
示例11: add
def add(self, triple, context, quoted=False, txn=None):
"""\
Add a triple to the store of triples.
"""
(subject, predicate, object) = triple
assert self.__open, "The Store must be open."
assert context != self, "Can not add triple directly to store"
Store.add(self, (subject, predicate, object), context, quoted)
_to_string = self._to_string
s = _to_string(subject, txn=txn)
p = _to_string(predicate, txn=txn)
o = _to_string(object, txn=txn)
c = _to_string(context, txn=txn)
cspo, cpos, cosp = self.__indicies
value = cspo.get(bb("%s^%s^%s^%s^" % (c, s, p, o)), txn=txn)
if value is None:
self.__contexts.put(bb(c), "", txn=txn)
contexts_value = cspo.get(
bb("%s^%s^%s^%s^" % ("", s, p, o)), txn=txn) or b("")
contexts = set(contexts_value.split(b("^")))
contexts.add(bb(c))
contexts_value = b("^").join(contexts)
assert contexts_value is not None
cspo.put(bb("%s^%s^%s^%s^" % (c, s, p, o)), "", txn=txn)
cpos.put(bb("%s^%s^%s^%s^" % (c, p, o, s)), "", txn=txn)
cosp.put(bb("%s^%s^%s^%s^" % (c, o, s, p)), "", txn=txn)
if not quoted:
cspo.put(bb(
"%s^%s^%s^%s^" % ("", s, p, o)), contexts_value, txn=txn)
cpos.put(bb(
"%s^%s^%s^%s^" % ("", p, o, s)), contexts_value, txn=txn)
cosp.put(bb(
"%s^%s^%s^%s^" % ("", o, s, p)), contexts_value, txn=txn)
self.__needs_sync = True
开发者ID:3mcorp,项目名称:schemaorg,代码行数:41,代码来源:sleepycat.py
示例12: remove
def remove(self, triple, context):
"""Remove the set of triples matching the pattern from the store
:param triple: Triple (subject, predicate, object) to remove.
:param context:
:returns:
"""
# pylint: disable-msg=W0222
# Signature differs from overriden method
LOG.debug("-- ProxyStore.remove(triple=%s, context=%s) --",
triple, context)
Store.remove(self, triple, context)
if triple == (None, None, None):
self._graph = Graph()
# the default implementation of Graph is not efficient in doing
# this, so better create a new empty one
else:
self._graph.store.remove(triple)
开发者ID:fderbel,项目名称:ktbs,代码行数:21,代码来源:proxystore.py
示例13: add
def add(self, xxx_todo_changeme, context, quoted=False):
"""\
Add a triple to the store of triples.
"""
(subject, predicate, object) = xxx_todo_changeme
assert self.__open, "The Store must be open."
assert context != self, "Can not add triple directly to store"
# Add the triple to the Store, triggering TripleAdded events
Store.add(self, (subject, predicate, object), context, quoted)
_to_string = self._to_string
s = _to_string(subject)
p = _to_string(predicate)
o = _to_string(object)
c = _to_string(context)
cspo, cpos, cosp = self.__indices
value = cspo.get(bb("%s^%s^%s^%s^" % (c, s, p, o)))
if value is None:
self.__contexts.set(bb(c), "")
contexts_value = cspo.get(bb(
"%s^%s^%s^%s^" % ("", s, p, o))) or b("")
contexts = set(contexts_value.split(b("^")))
contexts.add(bb(c))
contexts_value = b("^").join(contexts)
assert contexts_value != None
cspo.set(bb("%s^%s^%s^%s^" % (c, s, p, o)), "")
cpos.set(bb("%s^%s^%s^%s^" % (c, p, o, s)), "")
cosp.set(bb("%s^%s^%s^%s^" % (c, o, s, p)), "")
if not quoted:
cspo.set(bb("%s^%s^%s^%s^" % ("", s, p, o)), contexts_value)
cpos.set(bb("%s^%s^%s^%s^" % ("", p, o, s)), contexts_value)
cosp.set(bb("%s^%s^%s^%s^" % ("", o, s, p)), contexts_value)
self.__needs_sync = True
开发者ID:mwatts15,项目名称:rdflib-kyotocabinet,代码行数:38,代码来源:KyotoCabinet.py
示例14: add_graph
def add_graph(self, graph):
if not self.graph_aware:
Store.add_graph(self, graph)
elif graph.identifier != DATASET_DEFAULT_GRAPH_ID:
self.update("CREATE GRAPH <%s>" % graph.identifier)
开发者ID:raeisi,项目名称:rdflib,代码行数:5,代码来源:sparqlstore.py
示例15: b
for i, _to_key, _from_key in self.__indicies_info:
i.delete(_to_key((s, p, o), c), txn=txn)
if not quoted:
if contexts_value:
for i, _to_key, _from_key in self.__indicies_info:
i.put(_to_key((s, p, o), b("")), contexts_value, txn=txn)
else:
for i, _to_key, _from_key in self.__indicies_info:
try:
i.delete(_to_key((s, p, o), b("")), txn=txn)
except db.DBNotFoundError:
pass # TODO: is it okay to ignore these?
def remove(self, (subject, predicate, object), context, txn=None):
assert self.__open, "The Store must be open."
Store.remove(self, (subject, predicate, object), context)
_to_string = self._to_string
if context is not None:
if context == self:
context = None
if subject is not None \
and predicate is not None \
and object is not None \
and context is not None:
s = _to_string(subject, txn=txn)
p = _to_string(predicate, txn=txn)
o = _to_string(object, txn=txn)
c = _to_string(context, txn=txn)
value = self.__indicies[0].get(bb("%s^%s^%s^%s^" %
开发者ID:3mcorp,项目名称:schemaorg,代码行数:31,代码来源:sleepycat.py
示例16: add
def add(self, triple, context, quoted=False):
"""\
Add a triple to the store.
"""
Store.add(self, triple, context, quoted)
for triple, cg in self.triples(triple, context):
# triple is already in the store.
return
subject, predicate, object = triple
f = self.forward
r = self.reverse
# assign keys for new identifiers
if subject not in r:
si = randid()
while si in f:
si = randid()
f[si] = subject
r[subject] = si
else:
si = r[subject]
if predicate not in r:
pi = randid()
while pi in f:
pi = randid()
f[pi] = predicate
r[predicate] = pi
else:
pi = r[predicate]
if object not in r:
oi = randid()
while oi in f:
oi = randid()
f[oi] = object
r[object] = oi
else:
oi = r[object]
if context not in r:
ci = randid()
while ci in f:
ci = randid()
f[ci] = context
r[context] = ci
else:
ci = r[context]
# add dictionary entries for cspo[c][s][p][o] = 1,
# cpos[c][p][o][s] = 1, and cosp[c][o][s][p] = 1, creating the
# nested {} where they do not yet exits.
self._setNestedIndex(self.cspo, ci, si, pi, oi)
self._setNestedIndex(self.cpos, ci, pi, oi, si)
self._setNestedIndex(self.cosp, ci, oi, si, pi)
if not quoted:
self._setNestedIndex(self.spo, si, pi, oi, ci)
self._setNestedIndex(self.pos, pi, oi, si, ci)
self._setNestedIndex(self.osp, oi, si, pi, ci)
开发者ID:fetus94,项目名称:ordigRDFmapper,代码行数:63,代码来源:memory.py
示例17: destroy
def destroy(self, configuration=''):
import os
path = configuration or self.homeDir
if os.path.exists(path):
for f in os.listdir(path):
os.unlink(path+'/'+f)
os.rmdir(path)
def add(self, (subject, predicate, object), context, quoted=False):
"""\
Add a triple to the store of triples.
"""
assert self.__open, "The Store must be open."
assert context != self, "Can not add triple directly to store"
# Add the triple to the Store, triggering TripleAdded events
Store.add(self, (subject, predicate, object), context, quoted)
_to_string = self._to_string
s = _to_string(subject)
p = _to_string(predicate)
o = _to_string(object)
c = _to_string(context)
cspo, cpos, cosp = self.__indices
value = cspo.get(bb("%s^%s^%s^%s^" % (c, s, p, o)))
if value is None:
self.__contexts.set(bb(c), "")
contexts_value = cspo.get(bb("%s^%s^%s^%s^" % ("", s, p, o))) or b("")
开发者ID:pebbie,项目名称:rdflib-kyotocabinet,代码行数:31,代码来源:KyotoCabinet.py
示例18: remove
def remove(self, spo, context, txn=None):
subject, predicate, object = spo
assert self.__open, "The Store must be open."
Store.remove(self, (subject, predicate, object), context)
_to_string = self._to_string
if context is not None:
if context == self:
context = None
if subject is not None \
and predicate is not None \
and object is not None \
and context is not None:
s = _to_string(subject, txn=txn)
p = _to_string(predicate, txn=txn)
o = _to_string(object, txn=txn)
c = _to_string(context, txn=txn)
value = self.__indicies[0].get(bb("%s^%s^%s^%s^" %
(c, s, p, o)), txn=txn)
if value is not None:
self.__remove((bb(s), bb(p), bb(o)), bb(c), txn=txn)
self.__needs_sync = True
else:
cspo, cpos, cosp = self.__indicies
index, prefix, from_key, results_from_key = self.__lookup(
(subject, predicate, object), context, txn=txn)
cursor = index.cursor(txn=txn)
try:
current = cursor.set_range(prefix)
needs_sync = True
except db.DBNotFoundError:
current = None
needs_sync = False
cursor.close()
while current:
key, value = current
cursor = index.cursor(txn=txn)
try:
cursor.set_range(key)
# Hack to stop 2to3 converting this to next(cursor)
current = getattr(cursor, 'next')()
except db.DBNotFoundError:
current = None
cursor.close()
if key.startswith(prefix):
c, s, p, o = from_key(key)
if context is None:
contexts_value = index.get(key, txn=txn) or b("")
# remove triple from all non quoted contexts
contexts = set(contexts_value.split(b("^")))
# and from the conjunctive index
contexts.add(b(""))
for c in contexts:
for i, _to_key, _ in self.__indicies_info:
i.delete(_to_key((s, p, o), c), txn=txn)
else:
self.__remove((s, p, o), c, txn=txn)
else:
break
if context is not None:
if subject is None and predicate is None and object is None:
# TODO: also if context becomes empty and not just on
# remove((None, None, None), c)
try:
self.__contexts.delete(
bb(_to_string(context, txn=txn)), txn=txn)
except db.DBNotFoundError:
pass
self.__needs_sync = needs_sync
开发者ID:RDFLib,项目名称:rdflib,代码行数:73,代码来源:sleepycat.py
示例19: add_graph
def add_graph(self, graph):
if not self.graph_aware:
Store.add_graph(self, graph)
elif graph.identifier != DATASET_DEFAULT_GRAPH_ID:
self.update(
"CREATE GRAPH %s" % self.node_to_sparql(graph.identifier))
开发者ID:Dataliberate,项目名称:rdflib,代码行数:6,代码来源:sparqlstore.py
示例20: addN
def addN(self, quads):
Store.addN(self,quads)
开发者ID:cc-archive,项目名称:cc.libreoffice,代码行数:2,代码来源:SPARQL.py
注:本文中的rdflib.store.Store类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论