Skip to content

Commit

Permalink
[Terry N.] use try w/ resources for ensuring flush/close of files, dec.
Browse files Browse the repository at this point in the history
vars outside of loops, use html entity for &ontologyportal#58; for the colon (:) vice
&58;, convert to switch blocks over if/else,
  • Loading branch information
git committed Dec 5, 2024
1 parent 2a0c00c commit fc769d0
Show file tree
Hide file tree
Showing 11 changed files with 653 additions and 691 deletions.
15 changes: 1 addition & 14 deletions src/java/com/articulate/sigma/InferenceTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,8 @@ public String test(KB inputKB, int defaultTimeout, String TPTPlocation)
System.out.println("INFO in InferenceTestSuite.test(): Note that any prior user assertions will be deleted.");
System.out.println("INFO in InferenceTestSuite.test(): Prover: " + KBmanager.getMgr().prover);
StringBuilder result = new StringBuilder();
FileWriter fw = null;
int fail = 0;
int pass = 0;
PrintWriter pw = null;
String proof = null;

String language = "EnglishLanguage";
Expand Down Expand Up @@ -537,9 +535,7 @@ public String test(KB inputKB, int defaultTimeout, String TPTPlocation)
resultsFilename = rfn.substring(0,rfn.length()-3) + "-res.html";
resultsFile = new File(outputDir, resultsFilename);
tpp = new TPTP3ProofProcessor();
try {
fw = new FileWriter(resultsFile);
pw = new PrintWriter(fw);
try (FileWriter fw = new FileWriter(resultsFile); PrintWriter pw = new PrintWriter(fw)) {
tpp.parseProofOutput(proof, kb);
System.out.println("InferenceTestSuite.test() proof status: " + tpp.status + " for " + itd.note);
itd.SZSstatus = tpp.status;
Expand All @@ -554,15 +550,6 @@ public String test(KB inputKB, int defaultTimeout, String TPTPlocation)
catch (IOException e) {
throw new IOException("Error writing file " + resultsFile.getCanonicalPath());
}
finally {
try {
if (pw != null) { pw.close(); }
if (fw != null) { fw.close(); }
}
catch (IOException ex) {
ex.printStackTrace();
}
}
if (tpp.inconsistency) {
result.append("<h1>InferenceTestSuite.inferenceUnitTest(): Danger! possible inconsistency!</h1>");
itd.inconsistent = true;
Expand Down
18 changes: 9 additions & 9 deletions src/java/com/articulate/sigma/KB.java
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ private ArrayList<Formula> stringsToFormulas(ArrayList<String> strings) {
*/
public ArrayList<Formula> ask(String kind, int argnum, String term) {

ArrayList<Formula> result = new ArrayList<Formula>();
ArrayList<Formula> result = new ArrayList<>();
String msg;
if (StringUtil.emptyString(term)) {
msg = ("Error in KB.ask(\"" + kind + "\", " + argnum + ", \"" + term + "\"), "
Expand Down Expand Up @@ -1968,7 +1968,7 @@ public String askEngine(String suoKifFormula, int timeout, int maxAnswers, Infer
}
catch (IOException ioe) {
ioe.printStackTrace();
String message = ioe.getMessage().replaceAll(":", "&58;");
String message = ioe.getMessage().replaceAll(":", "&#58;");
errors.add(message);
result = ioe.getMessage();
}
Expand Down Expand Up @@ -2002,7 +2002,7 @@ public String askSInE(String suoKifFormula, int timeout, int maxAnswers) {
}
catch (IOException ioe) {
ioe.printStackTrace();
String message = ioe.getMessage().replaceAll(":", "&58;");
String message = ioe.getMessage().replaceAll(":", "&#58;");
errors.add(message);
result = ioe.getMessage();
}
Expand Down Expand Up @@ -2743,7 +2743,7 @@ public KIF readConstituent(String filename) {
error.append(" at line ").append(((ParseException) ex1).getErrorOffset());
error.append(" in file ").append(canonicalPath);
errors.add(error.toString());
System.out.println("Error in KB.addConstituent(): " + error.toString());
System.err.println("Error in KB.addConstituent(): " + error.toString());
ex1.printStackTrace();
}
file.filename = filename;
Expand Down Expand Up @@ -3388,10 +3388,9 @@ public String formatStaticDocumentation(String documentation, String language, b
String formatted = documentation;
if (StringUtil.isNonEmptyString(formatted)) {
StringBuilder sb = new StringBuilder(formatted);
int i;
int j;
int start = 0;
int i, j, start = 0;
String term = "";
StringBuilder hsb;
while ((start < sb.length()) && ((i = sb.indexOf("&%", start)) != -1)) {
sb.delete(i, (i + 2));
j = i;
Expand All @@ -3404,7 +3403,7 @@ public String formatStaticDocumentation(String documentation, String language, b
j--;
}
if (j > i) {
StringBuilder hsb = new StringBuilder("<a href=\"");
hsb = new StringBuilder("<a href=\"");
if (!onePage)
hsb.append(term.charAt(0) );
hsb.append("dict.html#");
Expand Down Expand Up @@ -3736,7 +3735,7 @@ public static void addToAxiomCount(HashMap<String,Integer> currentCount,
*/
public void addTermFormat(String lang, String term, String format) {

HashMap<String, String> forLang = null;
HashMap<String, String> forLang;
if (termFormatMap.containsKey(lang))
forLang = termFormatMap.get(lang);
else {
Expand Down Expand Up @@ -3898,6 +3897,7 @@ public static void test() {

/** ***************************************************************
*/
@Override
public String toString() {

StringBuilder sb = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion src/java/com/articulate/sigma/KIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ else if (st.ttype != StreamTokenizer.TT_EOF) {
}
}
catch (IOException | ParseException ex) {
String message = ex.getMessage().replaceAll(":", "&58;"); // HTMLformatter.formatErrors depends on :
String message = ex.getMessage().replaceAll(":", "&#58;"); // HTMLformatter.formatErrors depends on :
warningSet.add("Warning in KIF.parse() " + message);
ex.printStackTrace();
}
Expand Down
Loading

0 comments on commit fc769d0

Please sign in to comment.