-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinputs.py
108 lines (82 loc) · 4.24 KB
/
inputs.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
103
104
105
106
107
108
import argparse
import os
#Define arguments for each required and optional input
def define_arguments():
parser=argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
## Required inputs
parser.add_argument("--input-dir",dest="InputDir",required=True,help="InputDir")
parser.add_argument("--output-dir",dest="OutputDir",required=True,help="OutputDir")
parser.add_argument("--knowledge-graphs",dest="KGs",required=True,help="Knowledge Graph: either 'pkl' for PheKnowLator or 'kg-covid19' for KG-Covid19, enter as list")
## Optional inputs
parser.add_argument("--embedding-dimensions",dest="EmbeddingDimensions",required=False,default=128,help="EmbeddingDimensions")
parser.add_argument("--weights",dest="Weights",required=False,help="Weights", type = bool, default = True)
parser.add_argument("--search-type",dest="SearchType",required=False,default='all',help="SearchType")
parser.add_argument("--pdp-weight",dest="PdpWeight",required=False,default=0.4,help="PdpWeight")
parser.add_argument("--experiment-type",dest="ExperimentType",required=False,default='one_path',help="ExperimentType")
parser.add_argument("--input-type",dest="InputType",required=False,default='file',help="InputType")
return parser
# Wrapper function
def generate_arguments():
#Generate argument parser and define arguments
parser = define_arguments()
args = parser.parse_args()
input_dir = args.InputDir
output_dir = args.OutputDir
kg_types = args.KGs
embedding_dimensions = args.EmbeddingDimensions
weights = args.Weights
search_type = args.SearchType
pdp_weight = args.PdpWeight
experiment_type = args.ExperimentType
input_type = args.InputType
return input_dir,output_dir,kg_types,embedding_dimensions,weights,search_type,pdp_weight,experiment_type,input_type
def get_graph_files(input_dir,output_dir, kg_type, input_type):
if kg_type == "pkl":
existence_dict = {
'PheKnowLator_v3.0.2_full_instance_relationsOnly_OWLNETS_Triples_Identifiers':'false',
'PheKnowLator_v3.0.2_full_instance_relationsOnly_OWLNETS_NodeLabels':'false',
'_search_input':'false',
}
for fname in os.listdir(input_dir):
if '_search_input' in fname:
input_file = input_dir + '/' + fname
existence_dict['_search_input'] = 'true'
for k in list(existence_dict.keys()):
for fname in os.listdir(input_dir + '/' + kg_type):
if k in fname:
if k == 'PheKnowLator_v3.0.2_full_instance_relationsOnly_OWLNETS_Triples_Identifiers':
triples_list_file = input_dir + '/' + kg_type + '/' + fname
if k == 'PheKnowLator_v3.0.2_full_instance_relationsOnly_OWLNETS_NodeLabels':
labels_file = input_dir + '/' + kg_type + '/' + fname
existence_dict[k] = 'true'
if kg_type != "pkl":
existence_dict = {
'merged-kg_edges':'false',
'merged-kg_nodes':'false',
'_search_input':'false',
}
for fname in os.listdir(input_dir):
if '_search_input' in fname:
input_file = input_dir + '/' + fname
existence_dict['_search_input'] = 'true'
for k in list(existence_dict.keys()):
for fname in os.listdir(input_dir + '/' + kg_type):
if k in fname:
if k == 'merged-kg_edges':
triples_list_file = input_dir + '/' + kg_type + '/' + fname
if k == 'merged-kg_nodes':
labels_file = input_dir + '/' + kg_type + '/' + fname
existence_dict[k] = 'true'
#Check for existence of all necessary files, error if not
#### Add exception
for k in existence_dict:
if existence_dict[k] == 'false':
if input_type != 'file' and k == '_search_input':
input_file = ''
pass
else:
raise Exception('Missing file in input directory: ' + k)
#Check for existence of output directory
if not os.path.exists(output_dir):
os.makedirs(output_dir)
return triples_list_file,labels_file,input_file