Пример #1
0
def get_distdb_cog(model_id):
    if not model_id in M2DDB:
        from cog.torque import Graph
        dbdir = os.path.join(DB_DIR, model_id, DB_NAMESPACE_DISTS)
        dbfn = os.path.join(DB_DIR, model_id,
                            DB_NAMESPACE_DISTS + '.edgelist.txt')
        if not os.path.exists(dbdir): os.makedirs(dbdir)

        g = Graph(graph_name=DB_NAMESPACE_DISTS, cog_dir=dbdir)

        if os.path.exists(dbfn):
            return g.load_edgelist(dbfn, DB_NAMESPACE_DISTS)

        M2DDB[model_id] = g
    return M2DDB[model_id]
Пример #2
0
 def test_torque_load_csv(self):
     csv_file = "test/test-data/books.csv"
     if os.path.exists("test-data/books.csv"):
         csv_file = "test-data/books.csv"
     g = Graph(graph_name="books5")
     g.load_csv(csv_file, "isbn")
     # print(g.scan())
     actual = g.scan(20, 'e')
     expected = {
         'result': [{
             'id': 'ratings_4'
         }, {
             'id': 'best_book_id'
         }, {
             'id': 'work_text_reviews_count'
         }, {
             'id': 'original_publication_year'
         }, {
             'id': 'average_rating'
         }, {
             'id': 'ratings_1'
         }, {
             'id': 'language_code'
         }, {
             'id': 'image_url'
         }, {
             'id': 'books_count'
         }, {
             'id': 'work_ratings_count'
         }, {
             'id': 'isbn13'
         }, {
             'id': 'title'
         }, {
             'id': 'ratings_5'
         }, {
             'id': 'ratings_3'
         }, {
             'id': 'small_image_url'
         }, {
             'id': 'ratings_count'
         }, {
             'id': 'isbn'
         }, {
             'id': 'book_id'
         }, {
             'id': 'authors'
         }, {
             'id': 'ratings_2'
         }]
     }
     self.assertTrue(actual == expected)
     self.assertTrue(
         ordered(g.v('Kathryn Stockett').inc().out("title").all()) ==
         ordered({'result': [{
             'id': 'The Help'
         }]}))
     g.close()
Пример #3
0
    def setUpClass(cls):

        if not os.path.exists("/tmp/" + DIR_NAME):
            os.mkdir("/tmp/" + DIR_NAME)

        data_dir = "test/test-data/test_func.nq"
        # choose appropriate path based on where the test is called from.
        if os.path.exists("test-data/test_func.nq"):
            data_dir = "test-data/test_func.nq"

        TorqueTest.g = Graph(graph_name="people", cog_home=DIR_NAME)
        TorqueTest.g.load_triples(data_dir, "people")
        print(">>> test setup complete.\n")
Пример #4
0
    def test_aaa_before_all_tests(self):

        if not os.path.exists("/tmp/" + DIR_NAME):
            os.mkdir("/tmp/" + DIR_NAME)

        if os.path.exists("test-data/test.nq"):
            loader = Loader("/tmp/" + DIR_NAME)
            loader.load_triples("test-data/test.nq", "people")
        else:
            loader = Loader("/tmp/" + DIR_NAME)
            loader.load_triples("test/test-data/test.nq", "people")

        TorqueTest.cog = Cog("/tmp/" + DIR_NAME)
        TorqueTest.g = Graph(graph_name="people", cog_dir="/tmp/" + DIR_NAME)
Пример #5
0
 def test_torque_2(self):
     TorqueTest2.g = Graph(graph_name="better_graph", cog_home=DIR_NAME)
     TorqueTest2.g.put("A", "is better than", "B")\
         .put("B", "is better than", "C")\
         .put("A", "is better than", "D")\
         .put("Z", "is better than", "D")\
         .put("D", "is smaller than", "F")
     expected = {'result': [{'id': 'B'}, {'id': 'D'}]}
     actual = TorqueTest2.g.v("A").out(["is better than"]).all()
     self.assertTrue(ordered(expected) == ordered(actual))
     self.assertTrue(
         TorqueTest2.g.v("A").out(["is better than"]).count() == 2)
     self.assertTrue(TorqueTest2.g.v().count() == 6)
     TorqueTest2.g.close()
Пример #6
0
def get_distdb_gt(model_id):
    if not model_id in M2DDB:
        dbdir = os.path.join(DB_DIR, model_id)
        dbfn = os.path.join(DB_DIR, model_id, DB_NAMESPACE_DISTS + '.gt')
        if not os.path.exists(dbdir): os.makedirs(dbdir)

        if os.path.exists(dbfn):
            g = load_graph(dbfn, fmt='gt')
        else:
            g = Graph()

        M2DDB[model_id] = g

    return M2DDB[model_id]
Пример #7
0
    def test_torque_load_nq(self):
        nq_file = "test/test-data/100lines.nq"
        if os.path.exists("test-data/100lines.nq"):
            nq_file = "test-data/100lines.nq"
        g = Graph(graph_name="movies3", cog_path_prefix="/tmp/" + DIR_NAME)
        g.load_triples(nq_file, 'movies3')
        res = g.v("</en/joe_palma>").inc(["</film/performance/actor>"]).count()
        g.close()
        self.assertEqual(res, 7)

        #reload test
        g2 = Graph(graph_name="movies3", cog_path_prefix="/tmp/" + DIR_NAME)
        res2 = g2.v("</en/joe_palma>").inc(["</film/performance/actor>"
                                            ]).count()
        g2.close()
        self.assertEqual(res2, 7, "reload test failed.")