Package com.articulate.sigma.trans
Class SUMOtoTFAform
java.lang.Object
com.articulate.sigma.trans.SUMOtoTFAform
Created by apease on 7/23/18.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic Stringstatic FormulaPreprocessorstatic booleanstatic KBstatic int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbestOfPair(String t1, String t2) Pick the most general number among two numbers or the most specific term otherwisebestSignature(List<String> args1, List<String> args2) Find the best type at every argument positionstatic StringbestSpecificTerm(Collection<String> args) Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF.protected static StringcomposeSuffix(String op, String suffix) if the operator already has a suffix, revise it with the new suffix in the case where the new argument type is more specificstatic StringconstrainPair(String t1, String t2) Pick the most specific number type that is a TFF type or superclassstatic StringconstrainTerm(String t1, String t2) Constrain a type based on a second type.static StringRecursive routine to eliminate occurrences of 'forall', 'exists', 'invalid input: '<'=>', '=>', 'and', 'xor' and 'or' that have only one or zero argumentsstatic booleanCheck if type signatures of SUMO would be equivalent TFF signatures.static voidFill the indicated elements with "Entity", starting at start and ending at end-1static voidFill the indicated elements with the given string, starting at start and ending at end-1static Stringstatic StringGet just the bare SUMO term without prefixes or suffixesstatic booleanhasNumeric(List<String> argTypes) Check if at least one of the types in the list is a numeric typestatic booleanhasNumericSuper(List<String> argTypes) The arg type list requires expansion since it contains a superclass of Integer, and therefore could be used with more than one TF) numerical type.static booleanCheck whether variables have multiple mutually exclusive typesstatic voidstatic voidinitOnce()static FormulaSubstitute the values of numeric constants for their names.static booleanstatic booleancomparison ops are EQUAL, GT, GTET, LT, LTETstatic booleanstatic booleanmath ops are PLUSFN, MINUSFN, TIMESFN, DIVIDEFN, FLOORFN, RemainderFn, CeilingFn, RoundFnstatic booleana number, a variable with a numeric type or a function symbol or function with a numeric typestatic booleanstatic voidprotected static Stringremove statements of the form (instance ?X term) if 'term' is Integer or RealNumber and ?X is already of that type in the quantifier list for the formulaprotected static Stringreplace type statements of the form (instance ?X term), where term is a subtype of Integer or RealNumber with a constraint that defines that typemostSpecificSignature(List<String> args1, List<String> args2) Find the most specific TFF type or superclass at every argument positionstatic StringmostSpecificTFFTerm(Collection<String> args) Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF.static StringmostSpecificType(Collection<String> args) Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF.static StringnumTypePromotion(Formula f, String parentType) if the formula is a numeric atom or variable or a function with a number range and that type is more specific that the parentType, promote it with $to_real or invalid input: '&to_rat'static StringThis is the primary method of the class.static StringParse a single formula into TPTP format.static Collection<String> static StringprocessRecurse(Formula f, String parentType) process a formula into TF0static StringPromote type to the most specific number that is a TFF type or superclassReturn the full signatureExtract modifications to the relation signature from annotations embedded in the suffixes to its name.Extract modifications to the relation signature from annotations embedded in the suffixes to its name.static StringWhen predicate variable substitution occurs it can result in an argument to the predicate being defined as a particular type.static voidIf there's no such element index, fill the previous elements with Entitystatic voidSet the cached information of automatically generated functions and relations needed to cover the polymorphic type signatures of build-in TFF termsstatic voidshowHelp()static StringsortFromRelation(String rel) Create a sort spec from the relation name with embedded typesstatic voidtest1()static voidtest10()static voidtest2()static voidtest3()static voidtest4()static voidtest5()static voidtest6()static voidtest7()static voidtest8()static voidtest9()static voidstatic voidstatic voidstatic booleanReject formulas that wind up with type conflicts despite all attempts to resolve themstatic String
-
Field Details
-
kb
-
debug
public static boolean debug -
varmap
-
initialized
public static boolean initialized -
fp
-
numericConstraints
-
numericVars
-
numConstAxioms
-
numericConstantTypes
-
numericConstantValues
-
numericConstantCount
public static int numericConstantCount -
filterMessage
-
sorts
-
errors
-
-
Constructor Details
-
SUMOtoTFAform
public SUMOtoTFAform()
-
-
Method Details
-
isComparisonOperator
comparison ops are EQUAL, GT, GTET, LT, LTET -
isMathFunction
math ops are PLUSFN, MINUSFN, TIMESFN, DIVIDEFN, FLOORFN, RemainderFn, CeilingFn, RoundFn -
isEqualTypeOp
-
withoutSuffix
-
setNumericFunctionInfo
public static void setNumericFunctionInfo()Set the cached information of automatically generated functions and relations needed to cover the polymorphic type signatures of build-in TFF terms -
fill
Fill the indicated elements with "Entity", starting at start and ending at end-1 -
fill
Fill the indicated elements with the given string, starting at start and ending at end-1 -
safeSet
If there's no such element index, fill the previous elements with Entity -
relationExtractNonNumericSig
Return the full signature -
relationExtractSigFromName
Extract modifications to the relation signature from annotations embedded in the suffixes to its name. Note that the first argument to a relation is number 1, so getting the 0th argument of the returned ArrayList would give an empty string result for a relation. -
relationExtractUpdateSigFromName
Extract modifications to the relation signature from annotations embedded in the suffixes to its name. Note that the first argument to a relation is number 1, so getting the 0th argument of the returned ArrayList would give an empty string result for a relation. -
getBareTerm
Get just the bare SUMO term without prefixes or suffixes -
hasNumericSuper
The arg type list requires expansion since it contains a superclass of Integer, and therefore could be used with more than one TF) numerical type. -
findType
- Returns:
- the TF0-relevant type of the term whether it's a literal number, variable with a numeric type or function
-
isNumeric
a number, a variable with a numeric type or a function symbol or function with a numeric type -
isNumericType
-
isBuiltInNumericType
-
hasNumeric
Check if at least one of the types in the list is a numeric type -
equalTFFsig
Check if type signatures of SUMO would be equivalent TFF signatures.- Parameters:
pred- is used just to give a meaningful error message
-
numTypePromotion
if the formula is a numeric atom or variable or a function with a number range and that type is more specific that the parentType, promote it with $to_real or invalid input: '&to_rat'- Returns:
- promotion function call with learning parent, or null otherwise
-
processRecurse
process a formula into TF0- Parameters:
f- the formula to processparentType- is the type restriction that applies to this formula, if it's part of a larger formula
-
composeSuffix
if the operator already has a suffix, revise it with the new suffix in the case where the new argument type is more specific -
mostSpecificType
Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF. Prefer a built-in numeric type (equivalents to $int, $rat, $real) over any more specific type in SUMO -
promoteToBuiltIn
Promote type to the most specific number that is a TFF type or superclass -
constrainPair
Pick the most specific number type that is a TFF type or superclass -
bestOfPair
Pick the most general number among two numbers or the most specific term otherwise -
constrainTerm
Constrain a type based on a second type. If the second type is built-in type and first is not, pick the built-in type. If the second type and first type are both built-in types, pick the more specific. If the second type is more general than the first, throw an error. -
mostSpecificSignature
Find the most specific TFF type or superclass at every argument position -
bestSignature
Find the best type at every argument position -
mostSpecificTFFTerm
Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF. Prefer the most specific type but no subclasses of a built-in numeric type (equivalents to $int, $rat, $real) -
bestSpecificTerm
Create a specialized version of KB.mostSpecificTerm() that biases the results for TFF. Prefer a built-in numeric type (equivalents to $int, $rat, $real) over any more specific type in SUMO. Prefer the most general numeric type. -
elimUnitaryLogops
Recursive routine to eliminate occurrences of 'forall', 'exists', 'invalid input: '<'=>', '=>', 'and', 'xor' and 'or' that have only one or zero arguments- Returns:
- the corrected formula as a string
-
instantiateNumericConstants
Substitute the values of numeric constants for their names. Note that this is risky since it must be kept up to date with the content of the knowledge base. TODO: generalize this -
removeNumericInstance
When predicate variable substitution occurs it can result in an argument to the predicate being defined as a particular type. If that type is numeric, it will conflict with TFF's built in types and need to be removed, since the type will be specified in the quantifier list, albeit with a constraint from the numericConstraints list if the type is not a TFF fundamental type of $int, $rat, or $real -
inconsistentVarTypes
public static boolean inconsistentVarTypes()Check whether variables have multiple mutually exclusive types -
typeConflict
Reject formulas that wind up with type conflicts despite all attempts to resolve them -
sortFromRelation
Create a sort spec from the relation name with embedded types -
missingSorts
- Returns:
- a list of TFF relation sort definitions to cover ListFn statements that have diverse sorts
-
process
This is the primary method of the class. It takes a SUO-KIF formula and returns a TFF formula. -
process
Parse a single formula into TPTP format.- Parameters:
suoString- the formula entry to parsequery- true if the suoString is a query
-
processList
-
modifyPrecond
remove statements of the form (instance ?X term) if 'term' is Integer or RealNumber and ?X is already of that type in the quantifier list for the formula- Returns:
- the modified formula
-
modifyTypesToConstraints
replace type statements of the form (instance ?X term), where term is a subtype of Integer or RealNumber with a constraint that defines that type- Returns:
- String version of the modified formula
-
initNumericConstantTypes
public static void initNumericConstantTypes() -
initOnce
public static void initOnce() -
test1
public static void test1() -
test2
public static void test2() -
test3
public static void test3() -
test4
public static void test4() -
test5
public static void test5() -
test6
public static void test6() -
test7
public static void test7() -
test8
public static void test8() -
test9
public static void test9() -
test10
public static void test10() -
testRelEmbed
public static void testRelEmbed() -
testRelExtract
public static void testRelExtract() -
testCourse
public static void testCourse() -
showHelp
public static void showHelp() -
main
- Throws:
IOException
-