Skip to content

Commit 0115d2d

Browse files
committed
Many changes to tidy up use of TFF labels and pass LEO-III-STC checks
Signed-off-by: apease <apease@articulatesoftware.com>
1 parent 85d1ef6 commit 0115d2d

File tree

4 files changed

+106
-34
lines changed

4 files changed

+106
-34
lines changed

src/java/com/articulate/sigma/Formula.java

+10
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,16 @@ public static boolean isComparisonOperator(String term) {
26122612
return (!StringUtil.emptyString(term) && COMPARISON_OPERATORS.contains(term));
26132613
}
26142614

2615+
/** ***************************************************************
2616+
* Returns true if term is a SUO-KIF inequality, else returns false.
2617+
*
2618+
* @param term A String.
2619+
*/
2620+
public static boolean isInequality(String term) {
2621+
2622+
return (!StringUtil.emptyString(term) && INEQUALITIES.contains(term));
2623+
}
2624+
26152625
/** ***************************************************************
26162626
* Returns true if term is a SUO-KIF mathematical function, else
26172627
* returns false.

src/java/com/articulate/sigma/trans/SUMOKBtoTFAKB.java

+51-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SUMOKBtoTFAKB extends SUMOKBtoTPTPKB {
2020

2121
public static boolean initialized = false;
2222

23-
public static boolean debug = false;
23+
public static boolean debug = true;
2424

2525
public static Set<String> qChildren = new HashSet<>();
2626
public static Set<String> iChildren = new HashSet<>();
@@ -220,20 +220,38 @@ public static String translateName(String s) {
220220
*/
221221
public void writeSort(String t, PrintWriter pw) {
222222

223-
String label = translateName(t) + "_sig";
223+
String label;
224+
label = translateName(t) + "_sig";
225+
pw.println("% writeSort(): term: " + t);
226+
String bareTerm = SUMOtoTFAform.getBareTerm(t);
227+
pw.println("% bare term: " + bareTerm);
224228
if (sortLabels.contains(label)) {
225229
pw.println("% duplicate label " + label + " for " + t);
226230
return;
227231
}
228232
else {
229-
pw.println("% add label " + label);
233+
pw.println("% add label (writeSort) " + label);
230234
sortLabels.add(label);
231235
}
232-
String output = "tff(" + label + ",type,s__" + t;
233-
if (Formula.isLogicalOperator(SUMOtoTFAform.getBareTerm(t)) ||
234-
SUMOtoTFAform.getBareTerm(t).equals("equal") ||
235-
kb.isRelation(SUMOtoTFAform.getBareTerm(t)))
236-
output = output + "__m";
236+
String output;
237+
if (Formula.isInequality(bareTerm))
238+
t = translateName(t);
239+
if (!t.startsWith(Formula.termSymbolPrefix))
240+
t = Formula.termSymbolPrefix + t;
241+
output = "tff(" + label + ",type," + t;
242+
//if (Formula.isLogicalOperator(bareTerm) ||
243+
if (kb.isRelation(bareTerm) ||
244+
bareTerm.equals("equal")) {
245+
// ||
246+
// (kb.isRelation(bareTerm) && !Formula.isMathFunction(bareTerm))) {
247+
// && !Formula.isInequality(bareTerm))) {
248+
pw.println("% logop: " + Formula.isLogicalOperator(bareTerm));
249+
pw.println("% is relation: " + kb.isRelation(bareTerm));
250+
pw.println("% is inequality: " + Formula.isInequality(bareTerm));
251+
pw.println("% is math: " + Formula.isMathFunction(bareTerm));
252+
if (!output.endsWith(Formula.termMentionSuffix))
253+
output = output + Formula.termMentionSuffix;
254+
}
237255
output = output + " : $i ).";
238256
pw.println(output);
239257
}
@@ -257,11 +275,16 @@ public int getVariableAritySuffix(String t) {
257275
*/
258276
public void writeRelationSort(String t, PrintWriter pw) {
259277

260-
if (debug) System.out.println("SUMOKBtoTFAKB.writeRelationSort(): " + t);
278+
pw.println("% SUMOKBtoTFAKB.writeRelationSort(): " + t);
261279
if (t.endsWith("Fn") != kb.isFunction(t))
262280
System.out.println("ERROR in writeRelationSort(): is function mismatch with term name : " + t + ", " + kb.isFunction(t));
263-
if (Formula.isLogicalOperator(t) || Formula.isMathFunction(t))
281+
if (Formula.isLogicalOperator(t) || Formula.isMathFunction(t) || Formula.isComparisonOperator(t)) {
282+
String label = translateName(t);
283+
String output = "tff(" + label + ",type," + label +
284+
" : $i ).";
285+
pw.println(output);
264286
return;
287+
}
265288
List<String> sig = kb.kbCache.signatures.get(t);
266289
int endIndex = sig.size();
267290
if (KButilities.isVariableArity(kb,SUMOtoTFAform.withoutSuffix(t)))
@@ -289,6 +312,10 @@ public void writeRelationSort(String t, PrintWriter pw) {
289312
if (sigBuf.length() == 0) {
290313
pw.println("% Error in SUMOKBtoTFAKB.writeRelationSort(): " + t);
291314
pw.println("% Error in SUMOKBtoTFAKB.writeRelationSort(): signature: " + sig);
315+
String label = translateName(t);
316+
String output = "tff(" + label + ",type," + label +
317+
" : $i ).";
318+
pw.println(output);
292319
pw.flush();
293320
return;
294321
//Thread.dumpStack();
@@ -299,15 +326,15 @@ public void writeRelationSort(String t, PrintWriter pw) {
299326
relname = relname.substring(0,relname.length()-3);
300327
String range = sig.get(0);
301328
String label = translateName(t);
302-
if (label.endsWith("_m"))
329+
if (label.endsWith(Formula.termMentionSuffix))
303330
label = label.substring(0,label.length()-2);
304331
label = label + "_sig_rel";
305332
if (sortLabels.contains(label)) {
306333
pw.println("% duplicate label " + label + " for " + relname);
307334
return;
308335
}
309336
else {
310-
pw.println("% add label " + label);
337+
pw.println("% add label (relation sort) " + label);
311338
sortLabels.add(label);
312339
}
313340
if (kb.isFunction(t)) {
@@ -320,7 +347,7 @@ public void writeRelationSort(String t, PrintWriter pw) {
320347
" : ( " + sigStr + " ) > $o ).";
321348
pw.println(output);
322349
}
323-
String output = "tff(" + label + "_m,type," + relname + "_m" +
350+
String output = "tff(" + label + Formula.termMentionSuffix + ",type," + relname + Formula.termMentionSuffix +
324351
" : $i ).";
325352
pw.println(output);
326353
}
@@ -589,16 +616,18 @@ public void writeSorts(PrintWriter pw) {
589616
handleListFn(toExtend);
590617
String fnSuffix;
591618
for (String t : kb.getTerms()) {
619+
String bareTerm = SUMOtoTFAform.getBareTerm(t);
592620
pw.println("% SUMOKBtoTFAKB.writeSorts(): " + t);
593-
if (debug) System.out.println("SUMOKBtoTFAKB.writeSorts(): " + t);
621+
if (debug) System.out.println("SUMOKBtoTFAKB.writeSorts(): t: " + t);
622+
if (debug) System.out.println("SUMOKBtoTFAKB.writeSorts(): bareTerm: " + bareTerm);
594623
if (debug) System.out.println("kb.isRelation(t) " + kb.isRelation(t));
595624
if (debug) System.out.println("!alreadyExtended(t): " + !alreadyExtended(t));
596625
if (debug) System.out.println("!Formula.isComparisonOperator(t)): " + !Formula.isComparisonOperator(t));
597626
if (debug) System.out.println("!Formula.isMathFunction(t)): " + !Formula.isMathFunction(t));
598627
if (!Character.isLetter(t.charAt(0)) || Formula.isTrueFalse(t))
599628
continue;
600-
if (kb.isFunction(t)) {
601-
if (Formula.isLogicalOperator(t) || t.equals("equal") ) {
629+
if (kb.isFunction(bareTerm)) {
630+
if (Formula.isLogicalOperator(bareTerm) || t.equals("equal") ) {
602631
continue;
603632
}
604633
else {
@@ -607,9 +636,9 @@ public void writeSorts(PrintWriter pw) {
607636
processRelationSort(toExtend, t);
608637
}
609638
}
610-
else if (kb.isRelation(t) && !alreadyExtended(t) && !t.equals("ListFn")
611-
&& !Formula.isComparisonOperator(t) && !Formula.isMathFunction(t)) {
612-
if (hasNumericSuperArg(t) || listOperator(t)) {
639+
else if (kb.isRelation(bareTerm) && !alreadyExtended(t) && !bareTerm.equals("ListFn")
640+
&& !Formula.isComparisonOperator(bareTerm) && !Formula.isMathFunction(bareTerm)) {
641+
if (hasNumericSuperArg(bareTerm) || listOperator(bareTerm)) {
613642
writeRelationSort(t, pw);
614643
processRelationSort(toExtend, t);
615644
}
@@ -623,9 +652,10 @@ else if (kb.isRelation(t) && !alreadyExtended(t) && !t.equals("ListFn")
623652
String sep, newTerm;
624653
pw.println("% SUMOKBtoTFAKB.writeSorts(): starting on toExtend sorts");
625654
for (String k : toExtend.keySet()) {
626-
vals = toExtend.get(k);
655+
String bareTerm = SUMOtoTFAform.getBareTerm(k);
656+
vals = toExtend.get(bareTerm);
627657
fnSuffix = "";
628-
if (kb.isFunction(k) || k.endsWith("Fn")) // variable arity functions with numerical suffixes not in kb yet
658+
if (kb.isFunction(bareTerm) || bareTerm.endsWith("Fn")) // variable arity functions with numerical suffixes not in kb yet
629659
fnSuffix = "Fn";
630660
for (String e : vals) {
631661
kb.kbCache.extendInstance(k, e + fnSuffix);

src/java/com/articulate/sigma/trans/SUMOformulaToTPTPformula.java

+21-7
Original file line numberDiff line numberDiff line change
@@ -133,46 +133,60 @@ private static String translateWord_1(String st, int type, boolean hasArguments)
133133
char ch1 = ((st.length() > 1)
134134
? st.charAt(1)
135135
: 'x');
136+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here1: ");
136137
if (ch0 == '?' || ch0 == '@')
137138
return(Formula.termVariablePrefix + st.substring(1).replace('-','_'));
138-
139+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here2: ");
139140
//----Translate special predicates
140141
if (lang.equals("tff")) {
142+
if (Formula.isInequality(st) && !hasArguments)
143+
return Formula.termSymbolPrefix + st + Formula.termMentionSuffix;
141144
translateIndex = kifPredicates.indexOf(st);
142145
if (translateIndex != -1)
143146
return (tptpPredicates.get(translateIndex) + (hasArguments ? "" : mentionSuffix));
144147
}
148+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here3: ");
145149
//----Translate special constants
146150
translateIndex = kifConstants.indexOf(st);
147151
if (translateIndex != -1)
148152
return(tptpConstants.get(translateIndex) + (hasArguments ? "" : mentionSuffix));
153+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here4: ");
149154
//----Translate special functions
150155
if (lang.equals("tff")) {
151156
translateIndex = kifFunctions.indexOf(st);
152157
if (translateIndex != -1)
153158
return (tptpFunctions.get(translateIndex) + (hasArguments ? "" : mentionSuffix));
154159
}
160+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here5: ");
155161
//----Translate operators
156162
translateIndex = kifOps.indexOf(st);
157163
if (translateIndex != -1 && hasArguments) {
158164
return (tptpOps.get(translateIndex));
159165
}
166+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here6: ");
160167
//----Do nothing to numbers
161168
if (type == StreamTokenizer.TT_NUMBER ||
162169
(st != null && (Character.isDigit(ch0) ||
163170
(ch0 == '-' && Character.isDigit(ch1))))) {
164171
return(st);
165172
}
166173
String term = st;
167-
174+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): here7: ");
168175
if (!hasArguments) {
169-
if ((!term.endsWith(mentionSuffix) && Character.isLowerCase(ch0))
170-
|| term.endsWith("Fn")
171-
|| KB.isRelationInAnyKB(term)) {
172-
term += mentionSuffix;
176+
if (debug) System.out.println("INFO in SUMOformulaToTPTPformula.translateWord_1(): no arguments: " + term);
177+
if (!Formula.isInequality(term)) {
178+
if ((!term.endsWith(mentionSuffix) && Character.isLowerCase(ch0))
179+
|| term.endsWith("Fn")
180+
|| KB.isRelationInAnyKB(term)) {
181+
term += mentionSuffix;
182+
}
173183
}
184+
else {
185+
return (Formula.termSymbolPrefix + st.substring(1).replace('-','_'));
186+
}
187+
174188
}
175-
if (kifOps.contains(term))
189+
if (kifOps.contains(term) && hasArguments)
176190
return(term);
177191
else
178192
return(Formula.termSymbolPrefix + term);

src/java/com/articulate/sigma/trans/SUMOtoTFAform.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,11 @@ else if (op.startsWith("lessThan"))
838838
public static String getBareTerm(String s) {
839839

840840
String result = s;
841-
result = result.replaceFirst(Formula.termSymbolPrefix, "");
842-
Pattern p = Pattern.compile("(.*)__.*");
841+
if (result.startsWith(Formula.termSymbolPrefix))
842+
result = result.substring(3);
843+
Pattern p = Pattern.compile("^(.+)__.*");
843844
Matcher m = p.matcher(result);
844-
while (m.matches()) {
845+
while (m.lookingAt()) {
845846
result = m.group(1);
846847
m = p.matcher(result);
847848
}
@@ -1183,10 +1184,14 @@ public static String processRecurse(Formula f, String parentType) {
11831184
if (Character.isDigit(ttype))
11841185
ttype = StreamTokenizer_s.TT_NUMBER;
11851186
String promotion = numTypePromotion(f,parentType);
1187+
String result = null;
1188+
if (debug) System.out.println("SUMOtoTFAform.processRecurse(): promotion: " + promotion);
11861189
if (promotion != null)
1187-
return promotion + SUMOformulaToTPTPformula.translateWord(f.getFormula(),ttype,false) + ")";
1190+
result = promotion + SUMOformulaToTPTPformula.translateWord(f.getFormula(),ttype,false) + ")";
11881191
else
1189-
return SUMOformulaToTPTPformula.translateWord(f.getFormula(),ttype,false);
1192+
result = SUMOformulaToTPTPformula.translateWord(f.getFormula(),ttype,false);
1193+
if (debug) System.out.println("SUMOtoTFAform.processRecurse(): result: " + result);
1194+
return result;
11901195
}
11911196
Formula car = f.carAsFormula();
11921197
String op = car.getFormula();
@@ -2391,14 +2396,23 @@ public static String process(Formula f, boolean query) {
23912396
*/
23922397
public static String process(String s, boolean query) {
23932398

2399+
if (s.startsWith("(domain greaterThan")) {
2400+
SUMOtoTFAform.debug = true;
2401+
SUMOformulaToTPTPformula.debug = true;
2402+
}
23942403
filterMessage = "";
23952404
if (s.contains("ListFn"))
23962405
filterMessage = "SUMOtoTFAform.process(): Formula contains a list operator";
23972406
//if (StringUtil.emptyString(s) || numConstAxioms.contains(s))
23982407
if (StringUtil.emptyString(s)) // || numConstAxioms.contains(s))
23992408
return "";
24002409
Formula f = new Formula(s);
2401-
return process(f,query);
2410+
String res = process(f,query);
2411+
if (s.startsWith("(domain greaterThan")) {
2412+
SUMOtoTFAform.debug = false;
2413+
SUMOformulaToTPTPformula.debug = false;
2414+
}
2415+
return res;
24022416
}
24032417

24042418
/** *************************************************************
@@ -2862,6 +2876,7 @@ else if (args != null && args.length > 0 && args[0].equals("-h"))
28622876
}
28632877
else if (args != null && args.length > 1 && args[0].equals("-f")) {
28642878
debug = true;
2879+
SUMOformulaToTPTPformula.debug = true;
28652880
Formula f = new Formula(args[1]);
28662881
System.out.println("in TFA: " + process(f,false));
28672882
}
@@ -2870,6 +2885,9 @@ else if (args != null && args.length > 0 && args[0].equals("-t")) {
28702885
System.out.println(bare);
28712886
KB kb = KBmanager.getMgr().getKB("SUMO");
28722887
System.out.println(kb.isRelation(bare));
2888+
bare = getBareTerm("refers__1En2In");
2889+
System.out.println(bare);
2890+
System.out.println(kb.isRelation(bare));
28732891
/**
28742892
if (debug) System.out.println("SUMOtoTFAform.main(): contains ListFn__1Fn: " + kb.terms.contains("ListFn__1Fn"));
28752893
String kbName = KBmanager.getMgr().getPref("sumokbname");

0 commit comments

Comments
 (0)