-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathManifest.jsp
301 lines (285 loc) · 11.2 KB
/
Manifest.jsp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<%@ include file="Prelude.jsp" %>
<%
/** This code is copyright Articulate Software (c) 2003. Some portions
copyright Teknowledge (c) 2003 and reused under the terms of the GNU license.
This software is released under the GNU Public License <http://www.gnu.org/copyleft/gpl.html>.
Users of this code also consent, by use of this code, to credit Articulate Software
and Teknowledge in any writings, briefings, publications, presentations, or
other representations of any software which incorporates, builds on, or uses this
code. Please cite the following article in any publication with references:
Pease, A., (2003). The Sigma Ontology Development Environment,
in Working Notes of the IJCAI-2003 Workshop on Ontology and Distributed Systems,
August 9, Acapulco, Mexico. See also https://github.com/ontologyportal/sigmakee
*/
/** This jsp page handles listing the files which comprise a knowledge base,
adding new constituents (files), and deleting constituents. It redirects
to AddConstituent.jsp to add new constituents. The page takes several
parameters:
kbName - the name of the knowledge base for which the manifest is displayed.
constituent - a constituent to be added to the KB.
delete - a constituent to be deleted from the KB.
reload - a request to reload the constituents of the KB.
refetch - a request to 'git pull' to update the constituents of the KB.
*/
String kbDir = KBmanager.getMgr().getPref("kbDir");
File kbDirFile = new File(kbDir);
String saveAs = request.getParameter("saveAs");
String constituent = request.getParameter("constituent");
String saveFile = request.getParameter("saveFile");
String delete = request.getParameter("delete");
String reload = request.getParameter("reload");
String refetch = request.getParameter("refetch");
String result = "";
if (role == null || !role.equalsIgnoreCase("admin")) {
saveAs = null;
saveFile = null;
constituent = null;
delete = null;
}
if ((kb == null) || StringUtil.emptyString(kbName))
response.sendRedirect("KBs.jsp"); // That KB does not exist
else if (StringUtil.isNonEmptyString(saveAs)) {
if (saveAs.equalsIgnoreCase("prolog")) {
File plFile = new File(kbDirFile, (kb.name + ".pl"));
String pfcp = null;
String prologFile = null;
try {
pfcp = plFile.getCanonicalPath();
Prolog.kb = kb;
prologFile = Prolog.writePrologFile(pfcp);
}
catch (Exception pfe) {
pfe.printStackTrace();
}
result = ((StringUtil.isNonEmptyString(prologFile) && plFile.canRead())
? ("Wrote the Prolog file " + prologFile)
: "Could not write a Prolog file");
}
else if (saveAs.equalsIgnoreCase("TPTP") || saveAs.equalsIgnoreCase("tptpFOL")) {
// Force translation of the KB to TPTP, even if the user has not
// requested this on the Preferences page.
boolean onlyPlainFOL = saveAs.equalsIgnoreCase("tptpFOL");
File tptpf = new File(kbDirFile, (saveFile + ".tptp"));
String tptpfcp = null;
String tptpFile = null;
try {
tptpfcp = tptpf.getCanonicalPath();
com.articulate.sigma.trans.SUMOKBtoTPTPKB skbtptpkb = new com.articulate.sigma.trans.SUMOKBtoTPTPKB();
skbtptpkb.kb = kb;
PrintWriter pw = new PrintWriter(new FileWriter(tptpfcp));
tptpFile = skbtptpkb.writeFile(tptpfcp, null, false, pw);
}
catch (Exception tptpfe) {
tptpfe.printStackTrace();
}
if (StringUtil.isNonEmptyString(tptpFile))
result = ("Wrote the TPTP file " + tptpFile);
else
result = "Could not write a TPTP file";
}
else if (saveAs.equalsIgnoreCase("OWL")) {
com.articulate.sigma.trans.OWLtranslator ot = new com.articulate.sigma.trans.OWLtranslator();
ot.kb = KBmanager.getMgr().getKB(kbName);
File owlFile = new File(kbDirFile, (saveFile + ".owl"));
String ofcp = null;
try {
ofcp = owlFile.getCanonicalPath();
ot.writeKB(ofcp);
}
catch (Exception ofe) {
ofe.printStackTrace();
}
result = ((StringUtil.isNonEmptyString(ofcp) && owlFile.canRead())
? ("Wrote the OWL file " + ofcp)
: "Could not write an OWL file");
}
else if (saveAs.equalsIgnoreCase("KIF")) {
File kifFile = new File(kbDirFile, (kbName + ".kif"));
String kfcp = null;
try {
kfcp = kifFile.getCanonicalPath();
kb.writeFile(kfcp);
}
catch (Exception kfe) {
kfe.printStackTrace();
}
result = ((StringUtil.isNonEmptyString(kfcp) && kifFile.canRead())
? ("Wrote the KIF file " + kfcp)
: "Could not write a KIF file");
}
}
if (delete != null) {
int i = kb.constituents.indexOf(constituent.intern());
if (i == -1)
System.out.println("Error in Manifest.jsp: No such constituent: " + constituent.intern());
else {
kb.constituents.remove(i);
KBmanager.getMgr().writeConfiguration();
}
result = kb.reload();
}
else if (constituent != null) {
kb.addConstituent(constituent);
KBmanager.getMgr().writeConfiguration();
if (KBmanager.getMgr().getPref("cache").equalsIgnoreCase("yes")) {
kb.kbCache = new KBcache(kb);
kb.kbCache.buildCaches();
kb.kbCache.writeCacheFile();
}
kb.loadEProver();
}
else if (reload != null)
result = kb.reload();
else if (refetch != null) {
/* collect all the dirs the constituents appear in */
Map<String, Integer> dirs = new HashMap<String, Integer>();
for (int i = 0 ; i < kb.constituents.size() ; i++) {
String cname = (String) kb.constituents.get(i);
File file = new File(cname);
String dir = file.getParent();
if (!dirs.containsKey(dir)) {
dirs.put(dir,0);
}
}
for (String dir : dirs.keySet()) {
ProcessBuilder pb = new ProcessBuilder("git", "pull");
pb.directory(new File(dir));
Process p = pb.start();
p.waitFor();
int exitvalue = p.exitValue();
java.util.Scanner s = new java.util.Scanner(p.getInputStream()).useDelimiter("\\A");
String stdout = s.hasNext() ? s.next() : "";
s = new java.util.Scanner(p.getErrorStream()).useDelimiter("\\A");
String stderr = s.hasNext() ? s.next() : "";
System.out.println("INFO git pull (" + dir + ") exitValue: " + exitvalue);
System.out.println("INFO git pull (" + dir + ") stdout: " + stdout);
System.out.println("INFO git pull (" + dir + ") stderr: " + stderr);
}
}
%>
<HTML>
<HEAD>
<TITLE>Sigma Knowledge Engineering Environment - Constituents of <%=kbName %></TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<%
String pageName = "Manifest";
String pageString = "Manifest";
%>
<%@include file="CommonHeader.jsp" %>
<table ALIGN="LEFT" WIDTH=80%><tr><TD BGCOLOR='#AAAAAA'><IMG SRC='pixmaps/1pixel.gif' width=1 height=1 border=0></TD></tr></table><BR>
<b>Files which are the <I>constituents</I> of the <B><%=kbName %></b> knowledge base </b>
<%
if (kb.constituents == null || kb.constituents.size() <= 0) {
%>
<H3>No source files have been added to this knowledge base.</H3>
<P>
<%
}
else {
%>
<P>
<TABLE border="0" cellspacing="2" cellpadding="2">
<Td>File Name</Td>
<Td>Operations</Td>
<%
for (int i = 0; i < kb.constituents.size(); i++) {
String aConstituent = (String) kb.constituents.get(i);
%>
<TR VALIGN="center" <%= (i % 2)==0? "bgcolor=#eeeeee":""%> >
<TD><%=aConstituent%> </TD>
<TD>
<% if (role != null && role.equalsIgnoreCase("admin")) { %>
<A href="Manifest.jsp?delete=true&constituent=<%=aConstituent%>&kb=<%=kbName%>">Remove</A>
<% } %>
</TD>
</TR>
<%
} // for
%>
</TABLE>
<BR>
<%
} // if
%>
<P>
<%
if (role != null && role.equalsIgnoreCase("admin")) {
// if (Files.isDirectory(Paths.get(new File(kbDirFile, ".git")))) {
%>
<hr><b>Refetch constituents (git pull)</b>
<form name="refetch" id="refetch" action="Manifest.jsp" method="GET">
<input type="hidden" name="kb" value=<%=kbName%>>
<input type="submit" name="refetch" value="Refetch">
</form>
<%
// }
}
%>
<P>
<hr><b>Reload constituents</b>
<form name="reload" id="reload" action="Manifest.jsp" method="GET">
<input type="hidden" name="kb" value=<%=kbName%>>
<input type="submit" name="reload" value="Reload">
</form>
<P>
<% if (role != null && role.equalsIgnoreCase("admin")) { %>
<hr><b>Add a new constituent</b>
<form name="kbUploader" id="kbUploader" action="AddConstituent.jsp" method="POST" enctype="multipart/form-data">
<input type="hidden" name="kb" value=<%=kbName%>><br>
<table>
<tr>
<td>
<b>KB Constituent:</b>
</td>
<td>
<input type="file" name="constituent">
</td>
</tr>
</table>
<input type="submit" name="submit" value="Load">
</form>
<hr>
<p><b>Save KB to other formats</b></p>
<% if (StringUtil.isNonEmptyString(result)) {
out.println("<p>");
out.println(result);
out.println("</p>");
result = "";
} %>
<FORM name=save ID=save action="Manifest.jsp" method="GET">
<INPUT type="hidden" name="kb" value=<%=kbName%>><br>
<B>Filename:</B> <INPUT type="text" name="saveFile" value=<%=kbName%>><BR>
<INPUT type="submit" NAME="submit" VALUE="Save">
<select name="saveAs">
<option value="OWL">OWL
<option value="prolog">Prolog
<option value="KIF">KIF
<option value="TPTP">TPTP
<option value="tptpFOL">TPTP FOL
</select>
</FORM>
<% }
HTMLformatter.kbHref = HTMLformatter.createHrefStart() + "/sigma/Browse.jsp?";
String er = KBmanager.getMgr().getError();
if (!kb.errors.isEmpty()) {
TreeSet<String> errors = kb.errors;
out.println("<br/><b>Errors in KB " + kb.name + "</b><br>\n");
out.println(HTMLformatter.formatErrorsWarnings(errors,kb));
}
if (!kb.warnings.isEmpty()) {
TreeSet<String> warns = kb.warnings;
out.println("<br/><b>Warnings in KB " + kb.name + "</b><br>\n");
out.println(HTMLformatter.formatErrorsWarnings(warns,kb));
}
if (StringUtil.isNonEmptyString(er))
out.println(er);
else
if (StringUtil.isNonEmptyString(constituent) && StringUtil.emptyString(delete))
out.println("File " + constituent + " loaded successfully.");
%>
<P>
<a href="KBs.jsp">Return to home page</a><p>
<%@ include file="Postlude.jsp" %>
</BODY>
</HTML>