Пример #1
0
 def test_db(self):
     data = ('testKey', 'testVal')
     cogdb = Cog("/tmp/" + DIR_NAME + "/test")
     cogdb.create_namespace("test")
     cogdb.create_table("db_test", "test")
     cogdb.put(data)
     self.assertEqual(cogdb.get("testKey"), ('0', ('testKey', 'testVal')))
Пример #2
0
class Loader:

    def __init__(self, db_path=None, config=cfg):
         self.cog = Cog(db_path=db_path, config=config)

    def load_triples(self, graph_data_path, graph_name):
         self.cog.create_namespace(graph_name)
         with open(graph_data_path) as f:
             for line in f:
                 tokens = line.split()
                 this_vertex = tokens[0].strip()
                 predicate = tokens[1].strip()
                 other_vertex = tokens[2].strip()
                 self.cog.create_table(predicate, graph_name) #it wont create if it exists.
                 put_node(self.cog,this_vertex, predicate, other_vertex)


    def load_edgelist(self, edgelist_file_path, graph_name, predicate="none"):
        self.cog.create_namespace(graph_name)
        with open(edgelist_file_path) as f:
            for line in f:
                tokens = line.split()
                v1 = tokens[0].strip()
                v2 = tokens[1].strip()
                self.cog.create_table(predicate, graph_name)
                put_node(self.cog, v1, predicate, v2)
Пример #3
0
    def test_db(self):
        db_path = '/tmp/cogtestdb2'
        try:
            os.makedirs(db_path)
        except OSError:
            if not os.path.isdir(db_path):
                raise
        config.CUSTOM_COG_DB_PATH = db_path

        cogdb = Cog()

        # create a namespace
        cogdb.create_namespace("my_namespace")

        # create new table
        cogdb.create_table("new_db", "my_namespace")

        # put some data
        cogdb.put(Record('A', 'val'))
        cogdb.put(Record('B', 'val'))
        cogdb.put(Record('key3', 'val'))
        cogdb.put(Record('key3', 'val_updated'))

        self.assertEqual(cogdb.get('key3').value, 'val_updated')

        cogdb.close()
Пример #4
0
 def test_db(self):
     data = Record('testKey','testVal')
     cogdb = Cog()
     cogdb.create_namespace("test")
     cogdb.create_table("db_test", "test")
     cogdb.put(data)
     self.assertTrue(cogdb.get("testKey").is_equal_val(Record('testKey', 'testVal')))
     cogdb.close()
Пример #5
0
 def test_list_tables(self):
     cogdb = Cog()
     cogdb.create_namespace("test_ns")
     cogdb.create_table("table1", "test_ns")
     cogdb.create_table("table2", "test_ns")
     cogdb.create_table("table3", "test_ns")
     self.assertEqual(set(cogdb.list_tables()), {'table2', 'table3', 'table1'})
     cogdb.close()
Пример #6
0
 def test_db(self):
     data = ('user100', '{"firstname":"Hari","lastname":"seldon"}')
     cogdb = Cog(config=config)
     cogdb.create_namespace("test")
     cogdb.create_table("db_test", "test")
     cogdb.put(data)
     scanner = cogdb.scanner()
     for r in scanner:
         print r
Пример #7
0
 def test_db(self):
     data = Record('user100','{"firstname":"Hari","lastname":"seldon"}')
     cogdb = Cog()
     cogdb.create_namespace("test")
     cogdb.create_table("db_test", "test")
     cogdb.put(data)
     scanner = cogdb.scanner()
     res = None
     for r in scanner:
         res = r
     print(res)
     self.assertTrue(data.is_equal_val(res))
     cogdb.close()