本文整理汇总了Python中rdflib.ConjunctiveGraph.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.destroy方法的具体用法?Python ConjunctiveGraph.destroy怎么用?Python ConjunctiveGraph.destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.destroy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ContextTestCase
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import destroy [as 别名]
class ContextTestCase(unittest.TestCase):
store_name = 'default'
path = None
storetest = True
create = True
michel = URIRef(u'michel')
tarek = URIRef(u'tarek')
bob = URIRef(u'bob')
likes = URIRef(u'likes')
hates = URIRef(u'hates')
pizza = URIRef(u'pizza')
cheese = URIRef(u'cheese')
c1 = URIRef(u'context-1')
c2 = URIRef(u'context-2')
def setUp(self):
self.graph = ConjunctiveGraph(store=self.store_name)
self.graph.destroy(self.path)
if isinstance(self.path, type(None)):
if self.store_name == "SQLite":
self.path = mkstemp(prefix='test',dir='/tmp')
else:
self.path = mkdtemp(prefix='test',dir='/tmp')
self.graph.open(self.path, create=self.create)
def tearDown(self):
self.graph.destroy(self.path)
try:
self.graph.close()
except:
pass
import os
if hasattr(self,'path') and self.path is not None:
if os.path.exists(self.path):
if os.path.isdir(self.path):
for f in os.listdir(self.path): os.unlink(self.path+'/'+f)
os.rmdir(self.path)
elif len(self.path.split(':')) == 1:
os.unlink(self.path)
else:
os.remove(self.path)
def get_context(self, identifier):
assert isinstance(identifier, URIRef) or \
isinstance(identifier, BNode), type(identifier)
return Graph(store=self.graph.store, identifier=identifier,
namespace_manager=self)
def addStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
c1 = self.c1
graph = Graph(self.graph.store, c1)
graph.add((tarek, likes, pizza))
graph.add((tarek, likes, cheese))
graph.add((michel, likes, pizza))
graph.add((michel, likes, cheese))
graph.add((bob, likes, cheese))
graph.add((bob, hates, pizza))
graph.add((bob, hates, michel)) # gasp!
def removeStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
c1 = self.c1
graph = Graph(self.graph.store, c1)
graph.remove((tarek, likes, pizza))
graph.remove((tarek, likes, cheese))
graph.remove((michel, likes, pizza))
graph.remove((michel, likes, cheese))
graph.remove((bob, likes, cheese))
graph.remove((bob, hates, pizza))
graph.remove((bob, hates, michel)) # gasp!
def addStuffInMultipleContexts(self):
c1 = self.c1
c2 = self.c2
triple = (self.pizza, self.hates, self.tarek) # revenge!
# add to default context
self.graph.add(triple)
# add to context 1
graph = Graph(self.graph.store, c1)
graph.add(triple)
# add to context 2
graph = Graph(self.graph.store, c2)
graph.add(triple)
def testConjunction(self):
#.........这里部分代码省略.........
示例2: ContextTestCase
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import destroy [as 别名]
class ContextTestCase(unittest.TestCase):
storetest = True
identifier = URIRef("rdflib_test")
michel = URIRef(u'michel')
tarek = URIRef(u'tarek')
bob = URIRef(u'bob')
likes = URIRef(u'likes')
hates = URIRef(u'hates')
pizza = URIRef(u'pizza')
cheese = URIRef(u'cheese')
c1 = URIRef(u'context-1')
c2 = URIRef(u'context-2')
def setUp(self, uri='sqlite://', storename=None):
store = plugin.get(storename, Store)(identifier=self.identifier)
self.graph = ConjunctiveGraph(store, identifier=self.identifier)
self.graph.open(uri, create=True)
def tearDown(self, uri='sqlite://'):
self.graph.destroy(uri)
try:
self.graph.close()
except:
pass
def get_context(self, identifier):
assert isinstance(identifier, URIRef) or \
isinstance(identifier, BNode), type(identifier)
return Graph(store=self.graph.store, identifier=identifier,
namespace_manager=self)
def addStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
c1 = self.c1
graph = Graph(self.graph.store, c1)
graph.add((tarek, likes, pizza))
graph.add((tarek, likes, cheese))
graph.add((michel, likes, pizza))
graph.add((michel, likes, cheese))
graph.add((bob, likes, cheese))
graph.add((bob, hates, pizza))
graph.add((bob, hates, michel)) # gasp!
def removeStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
c1 = self.c1
graph = Graph(self.graph.store, c1)
graph.remove((tarek, likes, pizza))
graph.remove((tarek, likes, cheese))
graph.remove((michel, likes, pizza))
graph.remove((michel, likes, cheese))
graph.remove((bob, likes, cheese))
graph.remove((bob, hates, pizza))
graph.remove((bob, hates, michel)) # gasp!
def addStuffInMultipleContexts(self):
c1 = self.c1
c2 = self.c2
triple = (self.pizza, self.hates, self.tarek) # revenge!
# add to default context
self.graph.add(triple)
# add to context 1
graph = Graph(self.graph.store, c1)
graph.add(triple)
# add to context 2
graph = Graph(self.graph.store, c2)
graph.add(triple)
def testConjunction(self):
self.addStuffInMultipleContexts()
triple = (self.pizza, self.likes, self.pizza)
# add to context 1
graph = Graph(self.graph.store, self.c1)
graph.add(triple)
# print("Graph", graph.identifier, graph.serialize(format="nt"))
# print("Selfgraph", self.graph.identifier,
# self.graph.serialize(format="nt"))
self.assertEquals(len(self.graph.store), len(graph.store))
def testAdd(self):
self.addStuff()
def testRemove(self):
self.addStuff()
#.........这里部分代码省略.........
示例3: SQLATestCase
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import destroy [as 别名]
class SQLATestCase(unittest.TestCase):
identifier = URIRef("rdflib_test")
dburi = Literal('sqlite://')
def setUp(self):
self.store = plugin.get(
"SQLAlchemy", Store)(identifier=self.identifier)
self.graph = ConjunctiveGraph(self.store, identifier=self.identifier)
self.graph.open(self.dburi, create=True)
def tearDown(self):
self.graph.destroy(self.dburi)
try:
self.graph.close()
except:
pass
def test_registerplugins(self):
# I doubt this is quite right for a fresh pip installation,
# this test is mainly here to fill a coverage gap.
from rdflib_sqlalchemy import registerplugins
from rdflib import plugin
from rdflib.store import Store
registerplugins()
self.assert_(plugin.get('SQLAlchemy', Store) is not None)
p = plugin._plugins
self.assert_(('SQLAlchemy', Store) in p, p)
del p[('SQLAlchemy', Store)]
plugin._plugins = p
registerplugins()
self.assert_(('SQLAlchemy', Store) in p, p)
def test_skolemisation(self):
from rdflib_sqlalchemy.SQLAlchemy import skolemise
testbnode = BNode()
statemnt = (michel, likes, testbnode)
res = skolemise(statemnt)
self.assert_('bnode:N' in str(res[2]), res)
def test_deskolemisation(self):
from rdflib_sqlalchemy.SQLAlchemy import deskolemise
testbnode = BNode()
statemnt = (michel, likes, testbnode)
res = deskolemise(statemnt)
self.assert_(str(res[2]).startswith('N'), res)
def test_redeskolemisation(self):
from rdflib_sqlalchemy.SQLAlchemy import skolemise, deskolemise
testbnode = BNode()
statemnt = skolemise((michel, likes, testbnode))
res = deskolemise(statemnt)
self.assert_(str(res[2]).startswith('N'), res)
def test__parse_rfc1738_args(self):
from rdflib_sqlalchemy.SQLAlchemy import _parse_rfc1738_args
self.assertRaises(ValueError, _parse_rfc1738_args, 'Not parseable')
def test_namespaces(self):
self.assert_(list(self.graph.namespaces()) != [])
def test_contexts_without_triple(self):
self.assert_(list(self.graph.contexts()) == [])
def test_contexts_with_triple(self):
statemnt = (michel, likes, pizza)
self.assert_(self.graph.contexts(triple=statemnt) != [])
def test__len(self):
self.assert_(self.store.__len__() == 0)
def test__remove_context(self):
self.store._remove_context(self.identifier)