-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOWL_NETS.py
executable file
·161 lines (114 loc) · 5.31 KB
/
OWL_NETS.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#################################################
# OWL_NETS.py
# Purpose: primary script for OWL-NETS method
# version 1.2.2
# date: 07.20.2017
###############################################
## import module/script dependencies
import argparse
import tkFileDialog
from Tkinter import *
import tkMessageBox
import NETSRepresentation
import OWLRepresentation
class ProgramGUI:
def __init__(self, master):
self.master = master
master.title("OWL-NETS") # window title
self.label = Label(master, text='\n' + 'OWL-NETS: NEtwork Entity Transformation for Statistical learning' + '\n')
self.label.grid(row = 0, columnspan = 3, sticky=N+W)
# buttons
self.button_go= Button(master, text="Go", command=self.ButtonGoCall)
self.button_go.grid(row=1, column=0)
self.browse_button = Button(master, text="Browse", command=self.ButtonBrowseCall)
self.browse_button.grid(row=1, column=1)
self.close_button = Button(master, text="Exit", command=master.quit)
self.close_button.grid(row=1, column=2)
# check-box
self.var1 = IntVar()
self.check1 = Checkbutton(master, text="OWL-NETS Network", variable=self.var1, command = self.Checkbutton1)
self.check1.grid(row=3, column = 0)
self.var2 = IntVar()
self.check2 = Checkbutton(master, text="OWL Network ", variable=self.var2, command=self.Checkbutton2)
self.check2.grid(row=3, column=2)
# value entry
self.entry = Entry(master, width=50)
self.entry.grid(row = 2, columnspan = 3, sticky=N+W)
# add message to bottom of window
self.statusText = StringVar(master)
self.statusText.set('\n' + 'To get started, please press Browse or enter the path/name to your query, '
'choose which kind of network you would like to build, then press Go' + '\n')
self.message = Label(master, textvariable=self.statusText, wraplength=375, justify = CENTER)
self.message.grid(row = 5, columnspan = 3)
# define button functionality
def ButtonGoCall(self):
'''Function stores the functionality for the 'GO' button '''
val_check = self.Validate() # check to make sure that input was provided
# if func is correct return 0
if val_check != 0:
return
input_file = self.entry.get()
# output = self.GetOutputName(input_file)
# run program
if self.Checkbutton1() == 1:
NETSRepresentation.NETSNetworkBuilder(input_file)
if self.Checkbutton2() == 1:
OWLRepresentation.OWLNetworkBuilder(input_file)
self.Complete()
def ButtonBrowseCall(self):
'''Function stores the functionality for the 'Browse' button '''
filename = tkFileDialog.askopenfilename()
self.entry.delete(0, END)
self.entry.insert(0, filename)
def Checkbutton1(self):
'''Function stores the functionality for the NETS network checkbutton'''
if (self.var1.get()):
return 1
def Checkbutton2(self):
'''Function stores the functionality for the OWL network checkbutton'''
if (self.var2.get()):
return 1
def Validate(self):
if self.Checkbutton1() != 1 and self.Checkbutton2() != 1:
tkMessageBox.showwarning("Error", "Please select your file and indicate the type of network to build")
return 99
return 0 # means there is no error
def Complete(self):
tkMessageBox.showinfo("Program Finished", "Program is complete, you can find your files are in the same "
"directory as your query")
root.quit()
return
def InputParser():
''' Function parses the input information if the user chooses to run the program via the command line '''
parser = argparse.ArgumentParser(
description='OWL-NETS: NEtwork Entity Transformation for Statistical Learning. For program to run correctly the '
'input arguments must be formatted as shown below.')
parser.add_argument('-a', '--input', help='name/path to SPARQL query file (e.g., Folder/Query1_query)')
parser.add_argument('-b', '--owl', help='type "owl" to generate OWL representation')
parser.add_argument('-c', '--nets', help='type "owl-nets" to generate OWL-NETS representation')
parser.add_argument('-d', '--both', help='type "both" to generate both representations')
return parser
def CommandLine(args):
'''Function stores the information needed to execute the program via the command line '''
# runs only OWL-NETS
if args.nets == 'owl-nets' and args.owl != 'owl':
NETSRepresentation.NETSNetworkBuilder(args.input)
# runs only OWL
if args.owl == 'owl' and args.nets != 'owl-nets':
OWLRepresentation.OWLNetworkBuilder(args.input)
# runs both OWL-NETS and OWL
if args.both == 'both':
NETSRepresentation.NETSNetworkBuilder(args.input)
OWLRepresentation.OWLNetworkBuilder(args.input)
print "Program is complete!"
if __name__ == "__main__":
parser = InputParser()
args = parser.parse_args()
if args.input:
CommandLine(args)
else:
root = Tk()
root.lift()
root.attributes('-topmost', True)
my_gui = ProgramGUI(root)
root.mainloop()