forked from mitdbg/aurum-datadiscovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ddapi_path_queries.py
102 lines (76 loc) · 2.77 KB
/
test_ddapi_path_queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import unittest
from api.apiutils import Relation
from ddapi import API
from modelstore.elasticstore import StoreHandler
from knowledgerepr.fieldnetwork import deserialize_network
class TestDDApiPathQueries(unittest.TestCase):
# create store handler
store_client = StoreHandler()
# read graph
path = 'models/chemical/'
network = deserialize_network(path)
api = API(network)
api.init_store()
"""
TC primitive API
"""
def test_paths_between_field_mode(self):
print(self._testMethodName)
field1 = ('chembl_21', 'drug_indication', 'record_id')
field2 = ('chembl_21', 'compound_records', 'record_id')
drs1 = self.api.drs_from_raw_field(field1)
drs2 = self.api.drs_from_raw_field(field2)
res = self.api.paths_between(drs1, drs2, Relation.PKFK)
data = [x for x in res]
print("Total results: " + str(len(data)))
for el in data:
print(str(el))
def test_paths_between_table_mode(self):
print(self._testMethodName)
field1 = ('chembl_21', 'drug_indication', 'record_id')
field2 = ('chembl_21', 'compound_records', 'record_id')
drs1 = self.api.drs_from_raw_field(field1)
drs2 = self.api.drs_from_raw_field(field2)
drs1.set_table_mode()
drs2.set_table_mode()
res = self.api.paths_between(drs1, drs2, Relation.PKFK)
data = [x for x in res]
print("Total results: " + str(len(data)))
for el in data:
print(str(el))
print("Paths: ")
res.visualize_provenance()
res.debug_print()
paths = res.paths()
for p in paths:
print(str(p))
def test_paths_between_from_tables(self):
print(self._testMethodName)
table1_name = "drug_indication"
table2_name = "compound_records"
table1 = self.api.drs_from_table(table1_name)
table2 = self.api.drs_from_table(table2_name)
table1.set_table_mode()
table2.set_table_mode()
res = self.api.paths_between(table1, table2, Relation.PKFK)
data = [x for x in res]
print("Total results: " + str(len(data)))
for el in data:
print(str(el))
print("Paths: ")
paths = res.paths()
for p in paths:
print(str(p))
def test_paths(self):
print(self._testMethodName)
return
def test_traverse(self):
print(self._testMethodName)
field1 = ('chembl_21', 'drug_indication', 'record_id')
drs_field = self.api.drs_from_raw_field(field1)
res = self.api.traverse(drs_field, Relation.SCHEMA_SIM, 1)
data = [x for x in res]
print("Total results: " + str(len(data)))
for el in data:
print(str(el))
return