Пример #1
0
 def test_mutate_dataset(self):
     data = dataset.Dataset()
     data.triple(self.sub, self.pred, self.obj)
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data2", "xs:string"))
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data3", "xs:string"))
     dgraphapi.mutate_add_dataset(data)
Пример #2
0
 def test_send(self):
     dgraphapi.drop_all()
     data = dataset.Dataset()
     batch_consumer = consumer.BatchConsumer(data)
     data.triple(self.sub, self.pred, self.obj)
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data2", "xs:string"))
     result = batch_consumer.send()
     self.assertFalse(data)
Пример #3
0
 def test_formatter(self):
     data = dataset.Dataset()
     data.triple(self.sub, self.pred, self.obj)
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data2", "xs:string"))
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data3", "xs:string"))
     data.lookup_nodes()
     print(data.formatter.to_rdf())
Пример #4
0
 def test_lookup_nodes(self):
     rdfuri.NodeRegistryMeta.clear_registry(rdfuri.NodeType.XID)
     data = dataset.Dataset()
     data.triple(self.sub2, self.pred, self.obj)
     data.triple(self.sub2, self.pred, self.obj)
     data.triple(self.sub2, self.pred, self.obj)
     self.assertFalse(data.are_nodes_set())
     data.lookup_nodes()
     self.assertTrue(data.are_nodes_set())
Пример #5
0
 def test_triple(self):
     data = dataset.Dataset()
     data.triple(self.sub, self.pred, self.obj)
     self.assertTrue(self.obj in data[self.sub][self.pred])
     self.assertTrue(self.sub in data.keys())
     self.assertTrue(self.pred in data[self.sub].keys())
     data.triple(self.sub, self.pred, self.obj)
     self.assertTrue(len(data[self.sub][self.pred]) == 2)
     pprint.pprint(data.triples())
Пример #6
0
 def test_batch(self):
     dgraphapi.drop_all()
     data = dataset.Dataset()
     processor = batcher.BatchProcessor(data, batch_size=10)
     batch_count = 0
     for i in range(1, 100):
         data.triple(self.sub, self.pred,
                     rdfuri.Literal("literal data-%s" % i, "xs:string"))
         processor.increment()
         if processor.count == 0:
             batch_count += 1
     self.assertTrue(batch_count > 4)
Пример #7
0
 def test_clear(self):
     data = dataset.Dataset()
     data.triple(self.sub, self.pred, self.obj)
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data2", "xs:string"))
     data.triple(self.sub, self.pred,
                 rdfuri.Literal("literal data3", "xs:string"))
     data.triple(self.sub, self.pred2, self.obj)
     data.triple(self.sub2, self.pred, self.obj)
     data.triple(self.sub2, self.pred,
                 rdfuri.Literal("literal data2", "xs:string"))
     data.triple(self.sub2, self.pred,
                 rdfuri.Literal("literal data3", "xs:string"))
     data.triple(self.sub2, self.pred2, self.obj)
     data.clear()
Пример #8
0
 def __init__(self,
              sink=None,
              use_tracker=False,
              tracker=None,
              use_batcher=False,
              batcher=None):
     if not sink:
         sink = dataset.Dataset()
     super().__init__(sink)
     self.tracker = None
     if use_tracker or tracker:
         if tracker:
             self.tracker = tracker
         else:
             self.tracker = Tracker()
     if use_batcher or batcher:
         if batcher:
             self.batcher = batcher
         else:
             self.batcher = BatchProcessor(sink)
Пример #9
0
 def test_init(self):
     data = dataset.Dataset()
     processor = batcher.BatchProcessor(data)
     # test default destination function
     self.assertEqual(processor.batch_consumer.destination,
                      dgraphapi.mutate_add_dataset)
Пример #10
0
 def test_init(self):
     data = dataset.Dataset()
     batch_consumer = consumer.BatchConsumer(data)
     # test default destination function
     self.assertEqual(batch_consumer.destination,
                      dgraphapi.mutate_add_dataset)
Пример #11
0
 def test_are_nodes_set(self):
     data = dataset.Dataset()
     data.triple(self.sub, self.pred, self.obj)
     self.assertFalse(data.are_nodes_set())
Пример #12
0
 def test_parse_error_normal(self):
     parser = ntparse.NtParser(dataset.Dataset())
     fo = open(self.error_data_file, "rb")
     data = parser.parse(fo)
     fo.close()
     self.assertTrue(data.triples())