本文整理汇总了Python中store.Store.triples方法的典型用法代码示例。如果您正苦于以下问题:Python Store.triples方法的具体用法?Python Store.triples怎么用?Python Store.triples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类store.Store
的用法示例。
在下文中一共展示了Store.triples方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStore
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import triples [as 别名]
class TestStore(unittest2.TestCase):
def setUp(self):
self.store = Store(name="scratch")
self.ns = Namespace('http://example.com/#')
def tearDown(self):
self.store.close()
def testSize(self):
""" Tests the size of the repository """
self.assertEqual(len(self.store),0)
def testAdd(self):
bob = self.ns['bob']
name = self.ns['name']
value = Literal('Bob Bilbins')
self.store.add((bob, name, value))
self.assertEqual(len(self.store),1)
def testRemove(self):
triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
self.store.add(triple)
self.assertEqual(len(self.store),1)
self.store.remove(triple)
self.assertEqual(len(self.store),0)
def testTriples(self):
""" Tests the search by triple. """
triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
self.store.add(triple)
for tri in self.store.triples((self.ns['alice'],None, None)):
for i in range(3):
self.assertEqual(tri[i], triple[i])
def testSimpleSparql(self):
triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
self.store.add(triple)
for tri in self.store.query("SELECT ?s ?p ?o WHERE {?s ?p ?o .}"):
for i in range(3):
self.assertEqual(tri[i], triple[i])
def testNamespacedSparql(self):
triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
self.store.add(triple)
self.store.add((self.ns['bob'],self.ns['name'],Literal('Bob')))
for tri in self.store.query("SELECT ?p ?o WHERE { ex:alice ?p ?o .}", initNs={'ex':self.ns}):
for i in range(1,3):
self.assertEqual(tri[i-1], triple[i])
def testBindedSparql(self):
triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
self.store.add(triple)
self.store.add((self.ns['bob'],self.ns['name'],Literal('Bob')))
for tri in self.store.query("SELECT ?p ?o WHERE { ?s ?p ?o .}", initBindings={'s':self.ns['alice']}):
for i in range(1,3):
self.assertEqual(tri[i-1], triple[i])
def testDataTypes(self):
birth = Literal('2006-01-03', datatype=_XSD_NS.date)
comp = Literal('2006-01-01', datatype=_XSD_NS.date)
triple = (self.ns['alice'],self.ns['birthdate'],birth)
self.store.add(triple)
for s, p, o in self.store.query("SELECT ?s ?p ?o WHERE {?s ?p ?o .}"):
self.assertLess(comp,birth)