本文整理汇总了Python中rdflib.graph.Graph.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.destroy方法的具体用法?Python Graph.destroy怎么用?Python Graph.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.graph.Graph
的用法示例。
在下文中一共展示了Graph.destroy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostgreSQLStoreTests
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class PostgreSQLStoreTests(unittest.TestCase):
storetest = True
store_name = "PostgreSQL"
path = configString
create = True
def setUp(self):
self.graph = Graph(store=self.store_name)
self.graph.open(self.path, create=self.create)
def tearDown(self):
self.graph.destroy(self.path)
self.graph.close()
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 test_PostgreSQL_testN3_store(self):
testN3Store("PostgreSQL", configString)
示例2: MySQLStoreTests
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class MySQLStoreTests(unittest.TestCase):
storetest = True
store_name = "MySQL"
path = configString
create = True
identifier = "rdflib_test"
def setUp(self):
self.graph = Graph(store=self.store_name)
self.graph.destroy(self.path)
self.graph.open(self.path, create=self.create)
def tearDown(self):
self.graph.destroy(self.path)
self.graph.close()
示例3: PostgreSQLStoreTests
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class PostgreSQLStoreTests(unittest.TestCase):
storetest = True
store_name = "PostgreSQL"
path = configString
create = True
def setUp(self):
self.graph = Graph(store=self.store_name)
self.graph.open(self.path, create=self.create)
def tearDown(self):
self.graph.destroy(self.path)
self.graph.close()
def test_PostgreSQL_testN3_store(self):
testN3Store('PostgreSQL', configString)
示例4: GraphTest
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class GraphTest(test.TestCase):
"""
Testing the basic graph functionality.
Heavily based on https://github.com/RDFLib/rdflib-postgresql/blob/master/test/graph_case.py
"""
store_name = "Django"
storetest = True
path = ''
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')
def setUp(self):
self.graph = Graph(store=self.store_name)
self.graph.destroy(self.path)
self.graph.open(self.path, create=self.create)
def tearDown(self):
self.graph.destroy(self.path)
self.graph.close()
def addStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
self.graph.add((tarek, likes, pizza))
self.graph.add((tarek, likes, cheese))
self.graph.add((michel, likes, pizza))
self.graph.add((michel, likes, cheese))
self.graph.add((bob, likes, cheese))
self.graph.add((bob, hates, pizza))
self.graph.add((bob, hates, michel))
self.graph.commit()
def removeStuff(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
self.graph.remove((tarek, likes, pizza))
self.graph.remove((tarek, likes, cheese))
self.graph.remove((michel, likes, pizza))
self.graph.remove((michel, likes, cheese))
self.graph.remove((bob, likes, cheese))
self.graph.remove((bob, hates, pizza))
self.graph.remove((bob, hates, michel))
def testAdd(self):
self.addStuff()
def testRemove(self):
self.addStuff()
self.removeStuff()
def testTriples(self):
tarek = self.tarek
michel = self.michel
bob = self.bob
likes = self.likes
hates = self.hates
pizza = self.pizza
cheese = self.cheese
triples = self.graph.triples
Any = None
self.addStuff()
# unbound subjects
self.assertEquals(len(list(triples((Any, likes, pizza)))), 2)
self.assertEquals(len(list(triples((Any, hates, pizza)))), 1)
self.assertEquals(len(list(triples((Any, likes, cheese)))), 3)
self.assertEquals(len(list(triples((Any, hates, cheese)))), 0)
# unbound objects
self.assertEquals(len(list(triples((michel, likes, Any)))), 2)
self.assertEquals(len(list(triples((tarek, likes, Any)))), 2)
self.assertEquals(len(list(triples((bob, hates, Any)))), 2)
self.assertEquals(len(list(triples((bob, likes, Any)))), 1)
# unbound predicates
self.assertEquals(len(list(triples((michel, Any, cheese)))), 1)
self.assertEquals(len(list(triples((tarek, Any, cheese)))), 1)
self.assertEquals(len(list(triples((bob, Any, pizza)))), 1)
self.assertEquals(len(list(triples((bob, Any, michel)))), 1)
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class SWAnalyzer:
def __init__(self, sparql_endpoint, identifier, configstring, store=None, proxy=None, subprocess=True):
self.sparql_endpoint = sparql_endpoint
self.store = store
if store is None:
print "Creating SPARQLStore for %s" % self.sparql_endpoint
store = SPARQLStore(self.sparql_endpoint)
self.graph = Graph(store)
else:
self.identifier = URIRef(identifier)
self.configstring = configstring
self.graph = Graph(store, identifier=self.identifier)
self.subprocess = subprocess
if proxy != None:
print "Initilizing proxy..."
proxy = urllib2.ProxyHandler({"http": urlparse(proxy).netloc})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
# @abc.abstractmethod
def open(self):
if self.store is not None:
self.graph.open(self.configstring, create=True)
def close(self):
if self.store is not None:
self.graph.destroy(self.configstring)
self.graph.close()
def load_graph(self):
self.uri_pattern = self.get_uri_pattern()[1]
def get_triples(self):
query = "SELECT DISTINCT * { ?s ?p ?o }"
qres = self.graph.query(query)
return qres.result
def get_triples_count(self):
query = "SELECT (COUNT(*) AS ?no) { ?s ?p ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_classes(self):
query = "SELECT DISTINCT ?class WHERE { [] a ?class }"
qres = self.graph.query(query)
return qres.result
def get_classes_count(self):
query = "SELECT COUNT(distinct ?o) AS ?no { ?s rdf:type ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_properties(self):
query = "SELECT DISTINCT ?p WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return qres.result
def get_properties_count(self):
query = "SELECT COUNT(distinct ?p) AS ?no WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_subjects(self):
query = "SELECT DISTINCT ?s WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return qres.result
def get_subjects_count(self):
query = "SELECT COUNT(distinct ?s) WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_properties_count(self):
query = "SELECT COUNT(distinct ?s) AS ?no WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_objects(self):
query = "SELECT DISTINCT ?o WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return qres.result
def get_objects_count(self):
query = "SELECT COUNT(distinct ?o) AS ?no WHERE { ?s ?p ?o }"
qres = self.graph.query(query)
return int(qres.result[0][0])
def get_class_instances(self, class_name):
query = "SELECT DISTINCT ?s WHERE { ?s a <" + class_name + "> }"
qres = self.graph.query(query)
return qres.result
def get_class_instances_count(self, class_name):
query = "SELECT COUNT(distinct ?s) AS ?no WHERE { ?s a <" + class_name + "> }"
qres = self.graph.query(query)
return int(qres.result[0][0])
#.........这里部分代码省略.........
示例6: TestKyotoCabinetGraphCore
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import destroy [as 别名]
class TestKyotoCabinetGraphCore(unittest.TestCase):
def setUp(self):
store = "KyotoCabinet"
self.graph = Graph(store=store)
self.path = configString
self.graph.open(self.path, create=True)
def tearDown(self):
self.graph.destroy(self.path)
try:
self.graph.close()
except:
pass
if getattr(self, "path", False) 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 test_namespaces(self):
self.graph.bind("dc", "http://http://purl.org/dc/elements/1.1/")
self.graph.bind("foaf", "http://xmlns.com/foaf/0.1/")
self.assert_(len(list(self.graph.namespaces())) == 5)
self.assert_(("foaf", rdflib.term.URIRef(u"http://xmlns.com/foaf/0.1/")) in list(self.graph.namespaces()))
def test_play_journal(self):
self.assertRaises(NotImplementedError, self.graph.store.play_journal, {"graph": self.graph})
def test_readable_index(self):
print(readable_index(111))
def test_create_db(self):
michel = rdflib.URIRef(u"michel")
likes = rdflib.URIRef(u"likes")
pizza = rdflib.URIRef(u"pizza")
cheese = rdflib.URIRef(u"cheese")
self.graph.add((michel, likes, pizza))
self.graph.add((michel, likes, cheese))
self.graph.commit()
self.graph.store.close()
if getattr(self, "path", False) 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)
self.graph.store.open(self.path, create=True)
ntriples = self.graph.triples((None, None, None))
self.assert_(len(list(ntriples)) == 0)
def test_missing_db_exception(self):
self.graph.store.close()
if getattr(self, "path", False) 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)
self.graph.store.open(self.path, create=True)
ntriples = self.graph.triples((None, None, None))
self.assert_(len(list(ntriples)) == 0)
def test_reopening_db(self):
michel = rdflib.URIRef(u"michel")
likes = rdflib.URIRef(u"likes")
pizza = rdflib.URIRef(u"pizza")
cheese = rdflib.URIRef(u"cheese")
self.graph.add((michel, likes, pizza))
self.graph.add((michel, likes, cheese))
self.graph.commit()
self.graph.store.close()
self.graph.store.open(self.path, create=False)
ntriples = self.graph.triples((None, None, None))
self.assert_(len(list(ntriples)) == 2)
def test_reopening_missing_db(self):
self.graph.store.close()
self.assertRaises(ValueError, self.graph.store.open, ("/tmp/NotAnExistingDB"), create=False)
def test_isopen_db(self):
self.assert_(self.graph.store.is_open() == True)
self.graph.store.close()
self.assert_(self.graph.store.is_open() == False)