Skip to content

Commit f6a722e

Browse files
authored
Merge pull request #556 from ontologyportal/install_test_7-10-26
Added Editor Querying / Search, Syntax Diagnostics, & EAxFilter Updates
2 parents 16ba456 + cae7dd3 commit f6a722e

25 files changed

Lines changed: 2417 additions & 191 deletions

src/java/com/articulate/sigma/Diagnostics.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.articulate.sigma.parsing.Expr;
1616
import com.articulate.sigma.trans.*;
1717
import com.articulate.sigma.tp.e.*;
18+
import com.articulate.sigma.editor.ErrRec;
19+
import com.articulate.sigma.editor.KifFileChecker;
1820

1921
import com.articulate.sigma.utils.FileUtil;
2022
import com.articulate.sigma.utils.StringUtil;
@@ -93,6 +95,27 @@ public static List<String> termsWithoutRelation(KB kb, String rel, int argnum, c
9395
return result;
9496
}
9597

98+
/**
99+
* Parses every constituent and returns only parser errors.
100+
*/
101+
public static Map<String, Set<String>> kifSyntaxErrors(KB kb) {
102+
103+
Map<String, Set<String>> result = new LinkedHashMap<>();
104+
if (kb == null || kb.constituents == null) return result;
105+
for (String constituent : kb.constituents) {
106+
try {
107+
KIF kif = new KIF();
108+
kif.readFile(constituent);
109+
if (!kif.errorSet.isEmpty()) result.put(constituent, new TreeSet<>(kif.errorSet));
110+
}
111+
catch (IOException e) {
112+
result.put(constituent, Collections.singleton("Could not read constituent: " + e.getMessage()));
113+
}
114+
}
115+
116+
return result;
117+
}
118+
96119
/** *****************************************************************
97120
* Return a list of terms that do not have a documentation string.
98121
*/
@@ -246,7 +269,7 @@ private static Map<Formula, Set<String>> formulaeWithTypeViolations(KB kb) {
246269
KButilities.clearErrors();
247270
kb.kbCache.errors.clear();
248271
SUMOtoTFAform.errors.clear();
249-
if(result.size() > 20) break;
272+
// if(result.size() > 20) break;
250273
}
251274
return result;
252275
}

src/java/com/articulate/sigma/editor/EditorServlet.java

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
import com.articulate.sigma.trans.SUMOformulaToTPTPformula;
44
import com.articulate.sigma.*;
5+
import com.articulate.sigma.tp.ATPQuery;
6+
import com.articulate.sigma.tp.ATPResult;
7+
import com.articulate.sigma.tp.ProverCrashedException;
8+
import com.articulate.sigma.tp.ProverTimeoutException;
9+
import com.articulate.sigma.tp.TheoremProverController;
10+
511

612
import javax.servlet.*;
713
import javax.servlet.http.*;
@@ -70,6 +76,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
7076
case "translatetotptp":
7177
handleTranslateToTPTP(req, resp);
7278
break;
79+
case "query":
80+
handleQuery(req, resp);
81+
break;
7382
case "format":
7483
case "check":
7584
default:
@@ -296,6 +305,91 @@ private void handleTranslateToTPTP(HttpServletRequest req, HttpServletResponse r
296305
}
297306
}
298307

308+
/**
309+
* Run a highlighted SUO-KIF expression as a query without leaving the editor.
310+
* The first version intentionally mirrors AskTell's basic Vampire defaults.
311+
*/
312+
private void handleQuery(HttpServletRequest req, HttpServletResponse resp) throws IOException {
313+
314+
resp.setContentType("application/json; charset=UTF-8");
315+
String statement = Optional.ofNullable(req.getParameter("stmt")).orElse("").trim();
316+
String kbName = Optional.ofNullable(req.getParameter("kb")).orElse("SUMO").trim();
317+
if (kbName.isEmpty()) kbName = "SUMO";
318+
319+
if (statement.isEmpty()) {
320+
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
321+
writeJson(resp, false, "Highlight a SUO-KIF expression first.", null);
322+
return;
323+
}
324+
if (statement.indexOf('@') >= 0) {
325+
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
326+
writeJson(resp, false, "Row variables (@) are not allowed in queries.", null);
327+
return;
328+
}
329+
330+
HttpSession session = req.getSession(false);
331+
if (session == null) {
332+
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
333+
writeJson(resp, false, "Your session has expired. Please log in again.", null);
334+
return;
335+
}
336+
337+
try {
338+
KBmanager.getMgr().initializeOnce();
339+
KB kb = KBmanager.getMgr().getKB(kbName);
340+
if (kb == null) {
341+
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
342+
writeJson(resp, false, "Knowledge base not found: " + kbName, null);
343+
return;
344+
}
345+
346+
ATPQuery atpQuery = new ATPQuery(
347+
kb,
348+
session.getId(),
349+
statement,
350+
null,
351+
"custom",
352+
"Vampire",
353+
"fof",
354+
"CASC",
355+
false,
356+
false,
357+
false,
358+
false,
359+
30,
360+
1
361+
);
362+
ATPResult result = new TheoremProverController().ask(atpQuery);
363+
364+
if (result == null) {
365+
writeJson(resp, false, "No result returned by Vampire.", null);
366+
return;
367+
}
368+
369+
List<String> stdout = result.getStdout();
370+
String proof = stdout == null || stdout.isEmpty()
371+
? "Vampire completed, but returned no proof output."
372+
: String.join(System.lineSeparator(), stdout);
373+
writeJson(resp, true, proof, null);
374+
}
375+
catch (ProverTimeoutException e) {
376+
resp.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
377+
writeJson(resp, false, "Vampire timed out after 30 seconds.", null);
378+
}
379+
catch (ProverCrashedException e) {
380+
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
381+
String detail = e.getResult() == null || e.getResult().getStdout() == null
382+
? ""
383+
: System.lineSeparator() + String.join(System.lineSeparator(), e.getResult().getStdout());
384+
writeJson(resp, false, "Vampire crashed." + detail, null);
385+
}
386+
catch (Exception e) {
387+
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
388+
writeJson(resp, false, "Unable to run query: " +
389+
(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage()), null);
390+
}
391+
}
392+
299393
private void handleFormatOrCheck(HttpServletRequest req, HttpServletResponse resp)
300394
throws IOException, ServletException {
301395

@@ -622,4 +716,4 @@ private static String stripTqMetaPredicatesForCheck(String text) {
622716

623717
return out.toString();
624718
}
625-
}
719+
}

src/java/com/articulate/sigma/jobscheduler/JobScheduleXML.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ private Element createJobElement(Document document, Job job) throws IOException
180180
appendTextElement(document, jobElement, "filterTimeout", Integer.toString(axJob.getFilterTimeout()));
181181
appendTextElement(document, jobElement, "vampireTimeout", Integer.toString(axJob.getVampireTimeout()));
182182
}
183+
else if (job instanceof SInEContradictionJob sineJob) {
184+
appendTextElement(document, jobElement, "kbName", sineJob.getKbName());
185+
appendTextElement(document, jobElement, "attempts", Integer.toString(sineJob.getAttempts()));
186+
appendTextElement(document, jobElement, "scope", Integer.toString(sineJob.getScope()));
187+
appendTextElement(document, jobElement, "vampireTimeout", Integer.toString(sineJob.getVampireTimeout()));
188+
appendTextElement(document, jobElement, "maxAxioms", Integer.toString(sineJob.getMaxAxioms()));
189+
}
183190
else if (job instanceof ConsistencyCheckJob consistencyJob) appendTextElement(document, jobElement, "kbName", consistencyJob.getKbName());
184191
else if (!(job instanceof SumoUpdateJob)) throw new IOException("Unsupported job class: " + job.getClass().getName());
185192
return jobElement;
@@ -261,6 +268,9 @@ private Job parseJob(Element jobElement) throws IOException {
261268
parseRequiredInt(jobElement, "filterTimeout"),
262269
parseRequiredInt(jobElement, "vampireTimeout"));
263270
break;
271+
case "sine-contradiction":
272+
job = new SInEContradictionJob(id, requireChildText(jobElement, "kbName"), schedule, parseRequiredInt(jobElement, "attempts"), parseRequiredInt(jobElement, "scope"), parseRequiredInt(jobElement, "vampireTimeout"), parseRequiredInt(jobElement, "maxAxioms"));
273+
break;
264274
case "consistency-check":
265275
job = new ConsistencyCheckJob(id, requireChildText(jobElement, "kbName"), schedule);
266276
break;

0 commit comments

Comments
 (0)