本文整理汇总了Python中rdflib.graph.Graph.open方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.open方法的具体用法?Python Graph.open怎么用?Python Graph.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.graph.Graph
的用法示例。
在下文中一共展示了Graph.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def open(self, configuration, create=False):
"""Raise a ModificationException if create, as this graph is read-only.
"""
if create:
raise ModificationException() #ReadOnlyGraph does not support this
else:
Graph.open(self, configuration, create)
示例2: PychinkoTestCase
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
class PychinkoTestCase(unittest.TestCase):
backend = "default"
tmppath = None
def setUp(self):
self.g = Graph(store=self.backend)
self.tmppath = mkdtemp()
self.g.open(configuration=self.tmppath)
self.g.parse("test/a.n3", format="n3")
def tearDown(self):
self.g.close()
shutil.rmtree(tmppath)
def testPychinko(self):
rules = []
for s, p, o in self.g.triples((None, LOG.implies, None)):
lhs = list(patterns(s))
rhs = list(patterns(o))
rules.append(terms.Rule(lhs, rhs, (s, p, o)))
interp = Interpreter(rules)
f = Graph()
f.parse("http://eikeon.com/")
source = f
source = self.g
interp.addFacts(set(facts(source)), initialSet=True)
interp.run()
示例3: PostgreSQLStoreTests
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [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)
示例4: ParserTestCase
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
class ParserTestCase(unittest.TestCase):
backend = 'default'
path = 'store'
def setUp(self):
self.graph = Graph(store=self.backend)
self.graph.open(self.path)
def tearDown(self):
self.graph.close()
def testNoPathWithHash(self):
g = self.graph
g.parse(data="""\
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>
<rdfs:Class rdf:about="http://example.org#">
<rdfs:label>testing</rdfs:label>
</rdfs:Class>
</rdf:RDF>
""", publicID="http://example.org")
subject = URIRef("http://example.org#")
label = g.value(subject, RDFS.label)
self.assertEqual(label, Literal("testing"))
type = g.value(subject, RDF.type)
self.assertEqual(type, RDFS.Class)
示例5: Processor
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
class Processor(object):
def __init__(self, stream_urls):
self.client = client.Client(stream_urls,
event_callback=self._handle_event,
error_callback=self._handle_error,
separate_events=False)
self.triple_store = Graph('Sleepycat',
'http://www.it.uc3m.es/jaf/ns/slog/db')
self.db_dir = 'dbdir'
def start(self, loop=False):
self.triple_store.open(self.db_dir)
self.client.start(loop=loop)
def stop(self):
self.triple_store.close()
self.client.stop()
def _handle_error(self, message, http_error=None):
pass
def _handle_event(self, evs):
print('Received {} events.'.format(len(evs)))
for event in evs:
self.triple_store += event.body
print(len(self.triple_store))
示例6: test_05_persist
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_05_persist(self):
graph = Graph("SWIStore", identifier="test")
assert not graph.store.attached
graph.open("test.db")
assert graph.store.attached
graph.parse(cofog_test)
stat("test.db")
graph.close()
示例7: test_different_uris
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_different_uris():
""" Pass different URIs to __init__() and to open().
"""
store = ProxyStore(identifier="http://localhost:1234/foo")
graph = Graph(store=store)
graph.open({PS_CONFIG_URI: "http://localhost:1234/foo/group1/"})
graph.close()
示例8: test_no_uri
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_no_uri():
""" Pass no URI to __init__() nor to open().
"""
store = ProxyStore()
graph = Graph(store=store)
graph.open({})
graph.close()
示例9: test_no_uri
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_no_uri():
""" Pass no URI to __init__() nor to open().
"""
with assert_raises(StoreIdentifierError):
store = ProxyStore()
graph = Graph(store=store)
graph.open({})
graph.close()
示例10: test_06_retract
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_06_retract(self):
graph = Graph("SWIStore", identifier="test")
graph.open("test.db")
ntriples = len(list(graph.triples((None, RDFS.label, None))))
assert ntriples > 0
graph.remove((None, RDFS.label, None))
ntriples = len(list(graph.triples((None, RDFS.label, None))))
assert ntriples == 0
graph.store.unload(graph)
graph.close()
示例11: test_uri_with_good_credentials_in_open
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_uri_with_good_credentials_in_open():
""" Pass an URI to __init__() and good credentials in configuration.
Should be OK.
"""
store = ProxyStore(identifier="http://localhost:1234/foo")
graph = Graph(store=store)
graph.open(configuration={PS_CONFIG_USER: "user",
PS_CONFIG_PWD: "pwd"})
graph.close()
示例12: test_no_identifier_uri_in_open
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_no_identifier_uri_in_open():
""" Nothing passed to __init__(), uri passed to explicit open().
Should be OK.
"""
store = ProxyStore()
graph = Graph(store=store)
graph.open({PS_CONFIG_URI: "http://localhost:1234/foo"})
gs = graph.serialize()
#print gs
graph.close()
示例13: test_identifier_no_configuration
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_identifier_no_configuration():
""" Pass the URI as identifier to __init__() then call open() with no
configuration parameter.
"""
store = ProxyStore(identifier="http://localhost:1234/foo")
graph = Graph(store=store)
graph.open({})
gs = graph.serialize()
#print gs
graph.close()
示例14: test_uri_with_good_credentials_in_open
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [as 别名]
def test_uri_with_good_credentials_in_open():
""" Pass an URI to __init__() and good credentials in configuration.
Should be OK.
"""
store = ProxyStore(identifier="http://localhost:1234/foo/")
graph = Graph(store=store)
http = httplib2.Http()
http.add_credentials("user", "pwd")
graph.open(configuration={PS_CONFIG_HTTP_CX: http,})
graph.close()
示例15: MySQLStoreTests
# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import open [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()