Package com.articulate.sigma
Class Formula
java.lang.Object
com.articulate.sigma.Formula
- All Implemented Interfaces:
Serializable,Comparable
- Direct Known Subclasses:
FormulaAST
Handle operations on an individual formula. This includes
formatting for presentation as well as pre-processing for sending
to the inference engine.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final StringbooleanSUO-KIF mathematical comparison predicates.static booleanstatic final StringlongThe length of the file in bytes at the position immediately after the end of the formula.intThe line in the file on which the formula ends.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringbooleanstatic final Stringstatic final StringSUO-KIF mathematical comparison predicates.booleanbooleanbooleanstatic final Stringstatic final Stringstatic final StringThe SUO-KIF logical operators.static final Stringstatic final Stringstatic final StringThe SUO-KIF mathematical functions are implemented in Vampire, but not yet EProver.static final intThis constant indicates the maximum predicate arity supported by the current implementation of Sigma.static final Stringstatic final Stringstatic final Stringstatic final StringThe Formula's Question Liststatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringbooleanstatic final Stringstatic final StringThe source file in which the formula appears.static final StringintThe line in the file on which the formula starts.static final Stringstatic final Stringstatic final StringFOF (First-Order Form) translation cache - separate from TFF to prevent overwritesTFF (Typed First-order Form) translation cache - separate from FOF to prevent overwritesA list of TPTP formulas (Strings) that together constitute the translation of theFormula.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringWarnings found during execution.static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllNoDup(Collection<String> thisCol, Collection<String> arg) Collects all String terms from one Collection and adds them to another, without duplicationReturns the LISP 'append' of the formulas Note that this operation has no side effect on the Formula.argumentsToArrayList(int start) Deprecated.argumentsToArrayListString(int start) Return all the arguments in a simple formula as a list, starting at the given argument.booleanatom()Test whether the Formula is a LISP atom.static booleanTest whether the String is a LISP atom.Deprecated.caddr()Returns the LISP 'caddr' of the formula, which is the third list element of the formula.cadr()Returns the LISP 'cadr' (the second list element) of the formula.car()Returns the LISP 'car' of the formula as a new Formula, if possible, else returns null.cddr()Returns the LISP 'cddr' of the formula - the rest of the rest, or the list minus its first two elements.Returns the LISP 'cddr' of the formula as a new Formula, if possible, else returns null.cdr()Return the LISP 'cdr' of the formula - the rest of a list minus its first element.Returns the LISP 'cdr' of the formula as a new Formula, if possible, else returns null.voidThis method clears the list of clauses that together constitute the resolution form of this Formula, and can be used in preparation for recomputing the clauses.Collects all variables in this Formula.Collects all variables in this Formula in lexical order.voidcollectQuantifiedUnquantifiedVariablesRecurse(Formula f, Map<String, Boolean> varFlag, Set<String> unquantifiedVariables, Set<String> quantifiedVariables) Collect quantified and unquantified variables recursivelyCollects all quantified variables in this Formula.Collect all the terms in a formulaCollect all the unquantified variables in a formulaCollects all variables in this Formula.intImplement the Comparable interface by defining the compareTo method.complexArgumentsToArrayList(int start) Return all the arguments in a formula as a list, starting at the given argument.complexArgumentsToArrayListString(int start) Return all the arguments in a formula as a list, starting at the given argument.Returns a new Formula which is the result of 'consing' a String into this Formula, similar to the LISP procedure of the same name.copy()Copy the Formula.static FormulacreateComment(String input) the textual version of the formulacreateID()deepCopy()booleanTest if the contents of the formula are equal to the argument.booleanempty()Test whether the Formula is an empty list.static booleanTest whether the String is an empty formula.booleanTest if the contents of the formula are equal to the argument.booleanTest if the contents of the formula are equal to the String argument.Format a formula for either text or HTML presentation by inserting the proper hyperlink code, characters for indentation and end of line.Returns a HashSet of all atomic KIF Relation constants that occur as Predicates or Functions (argument 0 terms) in this Formula.Returns a HashMap in which the keys are the Relation constants gathered from this Formula, and the values are ArrayLists in which the ordinal positions 0 - n are occupied by the names of the corresponding argument types.getArgument(int argnum) Return the numbered argument of the given formula.Returns a List of List objects.protected static StringReturns the dual logical operator of op, or null if op is not an operator or has no dual.the textual version of the formulaintgetStringArgument(int argnum) Return the numbered argument of the given formula.Returns a List of the clauses that together constitute the resolution form of this Formula.Accessor method for backward compatibility.Returns a map of the variable renames that occurred during the translation of this Formula into the clausal (resolution) form accessible via this.getClauses().getVarType(KB kb, String var) Returns the type of a variable or null if it doesn't exist.getVarTypes(KB kb) Returns a map of the variable types.inthashCode()If equals is overridden, hashCode must use the same "significant" fields.htmlFormat(KB kb, String href) Format a formula for HTML presentation.htmlFormat(String html) Format a formula for HTML presentation.booleanReturns true if the Formula contains no unbalanced parentheses or unbalanced quote characters, otherwise returns false.booleanisBinary()Returns true if formula is a simple binary relation (note that because the argument list includes the predicate, which is argument 0, there will be three elements)booleanisCached()Test whether the Formula is automatically created by cachingstatic booleanisCommutative(String obj) A static utility method.static booleanisComparisonOperator(String term) Returns true if term is a SUO-KIF predicate for comparing two (typically numeric) terms, else returns false.booleanisEpistemic(KB kb) booleanTests if this formula is an existentially quantified formulastatic booleanisFunction(String term) Deprecated.booleanDeprecated.static booleanDeprecated.booleanisGround()Returns true if formula does not have variables, else returns false.static booleanReturns true if formula is a valid formula with no variables, else returns false.booleanisHigherOrder(KB kb) Test whether a Formula contains a Formula as an argument to other than a logical operator.booleanReturns true only if this Formula is a horn clause or is simply modified to be horn by breaking out a conjunctive conclusion.static booleanisInequality(String term) Returns true if term is a SUO-KIF inequality, else returns false.static booleanisLogicalOperator(String term) Returns true if term is a constant true or constant false, else returns false.static booleanisMathFunction(String term) Returns true if term is a SUO-KIF mathematical function, else returns false.booleanstatic booleanisNegatedQuery(String query, String formulaString) Compare the given formula to the negated query and return whether they are the same (minus the negation).booleanisOtherHOL(KB kb) static booleanisQuantifier(String pred) Test whether a predicate is a logical quantifierstatic booleanisQuantifierList(String listPred, String previousPred) Test whether a list with a predicate is a quantifier liststatic booleanCompare the given formula to the query and return whether they are the same.booleanTest whether the Formula is a regular '?' variablebooleanisRowVar()Test whether the Formula is a row variablebooleanisRule()Returns true only if this Formula, explicitly quantified or not, starts with "=>" or "invalid input: '<'=>", else returns false.booleanisSimpleClause(KB kb) Test whether a Formula is a simple list of terms (including functional terms).booleanTest whether a Formula is a simple clause wrapped in a negation.static booleanisSkolemTerm(String term) Returns true if term is a SUO-KIF Skolem term, else returns falsebooleanisTemporal(KB kb) static booleanReturns true if term is a valid SUO-KIF term, else returns false.booleanstatic booleanisTrueFalse(String term) Returns true if term is a standard FOL logical operator, else returns false.booleanTests if this formula is an universally quantified formulabooleanTest whether the Formula is a variablestatic booleanisVariable(String term) Test whether a String formula is a variableintReturns a non-negative int value indicating the top-level list length of this Formula if it is a proper listP(), else returns -1.booleanlistP()Test whether the Formula is a list.static booleanTest whether the String is a list.booleanTests if this is logically equal with the parameter formula.booleanDeprecated.static voidmakeQuantifiersExplicit(boolean query) Makes implicit quantification explicit.static List<Set<VariableMapping>> mapFormulaVariables(Formula f1, Formula f2, KB kb, Map<FormulaUtil.FormulaMatchMemoMapKey, List<Set<VariableMapping>>> memoMap) Compares two formulae by recursively traversing its predicate structure and by building possible variable maps between the variables of the two formulae.negate()static StringRemove the 'holds' prefix wherever it appears.voidvoidRead a String into the variable 'theFormula'.static StringremoveTemporalRelations(String p_f, KB kb) The purpose is to take simple HOL formula with temporal aspects and remove temporal aspects of it in an attempt to take it to FOL.Replace term2 with term1renameVariableArityRelations(KB kb, Map<String, String> relationMap) replaceQuantifierVars(String quantifier, List<String> vars) replaceVar(String v, String term) Replace v with term.voidsetFormula(String f) the textual version of the formulavoidsetSourceFile(String filename) static voidshowHelp()Replace variables with a value as given by the map argumentstatic voidA test method.static voidA test method.static voidtestCar1()A test method.static voidA test method.static voidA test method.static voidA test method.static voidA test method.static StringtextFormat(String input) Format a formula for text presentation.toProlog()Format a formula as a prolog statement.toString()Format a formula for text presentation.Format a formula for text presentation include file and line#.booleanDeprecated.Test whether the Formula uses logical operators and predicates with the correct number of arguments.Test whether the Formula uses logical operators and predicates with the correct number of arguments.
-
Field Details
-
debug
public static boolean debug -
AND
- See Also:
-
OR
- See Also:
-
XOR
- See Also:
-
NOT
- See Also:
-
IF
- See Also:
-
IFF
- See Also:
-
UQUANT
- See Also:
-
EQUANT
- See Also:
-
EQUAL
- See Also:
-
GT
- See Also:
-
GTET
- See Also:
-
LT
- See Also:
-
LTET
- See Also:
-
KAPPAFN
- See Also:
-
PLUSFN
- See Also:
-
MINUSFN
- See Also:
-
TIMESFN
- See Also:
-
DIVIDEFN
- See Also:
-
FLOORFN
- See Also:
-
ROUNDFN
- See Also:
-
CEILINGFN
- See Also:
-
REMAINDERFN
- See Also:
-
SKFN
- See Also:
-
SK_PREF
- See Also:
-
FN_SUFF
- See Also:
-
V_PREF
- See Also:
-
R_PREF
- See Also:
-
VX
- See Also:
-
VVAR
- See Also:
-
RVAR
- See Also:
-
LP
- See Also:
-
RP
- See Also:
-
SPACE
- See Also:
-
LOG_TRUE
- See Also:
-
LOG_FALSE
- See Also:
-
TERM_MENTION_SUFFIX
- See Also:
-
CLASS_SYMBOL_SUFFIX
- See Also:
-
TERM_SYMBOL_PREFIX
- See Also:
-
TERM_VARIABLE_PREFIX
- See Also:
-
LOGICAL_OPERATORS
The SUO-KIF logical operators. -
COMPARISON_OPERATORS
SUO-KIF mathematical comparison predicates. -
INEQUALITIES
SUO-KIF mathematical comparison predicates. -
MATH_FUNCTIONS
The SUO-KIF mathematical functions are implemented in Vampire, but not yet EProver. -
DOC_PREDICATES
-
DEFN_PREDICATES
-
qlist
The Formula's Question List -
sourceFile
The source file in which the formula appears. -
startLine
public int startLineThe line in the file on which the formula starts. -
endLine
public int endLineThe line in the file on which the formula ends. -
endFilePosition
public long endFilePositionThe length of the file in bytes at the position immediately after the end of the formula. This value is used only for formulas entered via KB.tell(). In general, you should not count on it being set to a value other than -1L. -
errors
-
warnings
Warnings found during execution. -
derivation
-
higherOrder
public boolean higherOrder -
simpleClause
public boolean simpleClause -
comment
public boolean comment -
isFunctional
public boolean isFunctional -
isGround
public boolean isGround -
isTFF
public boolean isTFF -
relation
-
stringArgs
-
args
-
allVarsCache
-
allVarsPairCache
-
quantVarsCache
-
unquantVarsCache
-
existVarsCache
-
univVarsCache
-
termCache
-
predVarCache
-
rowVarCache
-
varTypeCache
-
theTptpFormulas
A list of TPTP formulas (Strings) that together constitute the translation of theFormula. This member is a Set, because predicate variable instantiation and row variable expansion might cause theFormula to expand to several TPTP formulas. -
theFofFormulas
FOF (First-Order Form) translation cache - separate from TFF to prevent overwrites -
theTffFormulas
TFF (Typed First-order Form) translation cache - separate from FOF to prevent overwrites -
tffSorts
-
MAX_PREDICATE_ARITY
public static final int MAX_PREDICATE_ARITYThis constant indicates the maximum predicate arity supported by the current implementation of Sigma.- See Also:
-
-
Constructor Details
-
Formula
Constructor to build a formula from an existing formula. This isn't a complete deepCopy() since it leaves out the errors and warnings variables -
Formula
public Formula() -
Formula
Just set the textual version of the formula
-
-
Method Details
-
getSourceFile
-
setSourceFile
-
getLineNumber
public int getLineNumber() -
getErrors
-
getTheTptpFormulas
Accessor method for backward compatibility. Returns the most recently populated TPTP cache: prefers TFF, then FOF, then legacy theTptpFormulas. -
getFormula
the textual version of the formula -
setFormula
the textual version of the formula -
createComment
the textual version of the formula -
printCaches
public void printCaches() -
getTheClausalForm
Returns a List of the clauses that together constitute the resolution form of this Formula. The list could be empty if the clausal form has not yet been computed.- Returns:
- ArrayList
-
clearTheClausalForm
public void clearTheClausalForm()This method clears the list of clauses that together constitute the resolution form of this Formula, and can be used in preparation for recomputing the clauses. -
getClauses
Returns a List of List objects. Each such object contains, in turn, a pair of List objects. Each List object in a pair contains Formula objects. The Formula objects contained in the first List object (0) of a pair represent negative literals (antecedent conjuncts). The Formula objects contained in the second List object (1) of a pair represent positive literals (consequent conjuncts). Taken together, all of the clauses constitute the resolution form of this Formula.- Returns:
- A List of Lists.
-
getVarMap
Returns a map of the variable renames that occurred during the translation of this Formula into the clausal (resolution) form accessible via this.getClauses().- Returns:
- A Map of String (SUO-KIF variable) key-value pairs.
-
getVarTypes
Returns a map of the variable types.- Returns:
- A Map of String (SUO-KIF variable) key-value pairs.
-
getVarType
Returns the type of a variable or null if it doesn't exist. -
read
Read a String into the variable 'theFormula'. -
createID
- Returns:
- a unique ID by appending the hashCode() of the formula String to the file name in which it appears
-
copy
Copy the Formula. This is in effect a deep copy although it ignores the errors and warnings variables. -
deepCopy
-
compareTo
Implement the Comparable interface by defining the compareTo method. Formulas are equal if their formula strings are equal.- Specified by:
compareToin interfaceComparable- Throws:
ClassCastException
-
isBalancedList
public boolean isBalancedList()Returns true if the Formula contains no unbalanced parentheses or unbalanced quote characters, otherwise returns false.- Returns:
- boolean
-
car
- Returns:
- the LISP 'car' of the formula as a String - the first element of the list. Note that this operation has no side effect on the Formula. Currently (10/24/2007) this method returns the empty string ("") when invoked on an empty list. Technically, this is wrong. In most LISPS, the car of the empty list is the empty list (or nil). But some parts of the Sigma code apparently expect this method to return the empty string when invoked on an empty list.
-
cdr
Return the LISP 'cdr' of the formula - the rest of a list minus its first element. Note that this operation has no side effect on the Formula. -
cons
Returns a new Formula which is the result of 'consing' a String into this Formula, similar to the LISP procedure of the same name. This procedure is a little bit of a kluge, since this Formula is treated simply as a LISP object (presumably, a LISP list), and could be degenerate or malformed as a Formula. Note that this operation has no side effect on the original Formula.- Parameters:
obj- The String object that will become the 'car' (or head) of the resulting Formula (list).- Returns:
- a new Formula, or the original Formula if the cons fails.
-
cons
- Returns:
- a new Formula, or the original Formula if the cons fails.
-
cdrAsFormula
Returns the LISP 'cdr' of the formula as a new Formula, if possible, else returns null. Note that this operation has no side effect on the Formula.- Returns:
- a Formula, or null.
-
carAsFormula
Returns the LISP 'car' of the formula as a new Formula, if possible, else returns null. Note that this operation has no side effect on the Formula.- Returns:
- a Formula, or null.
-
cadr
Returns the LISP 'cadr' (the second list element) of the formula. Note that this operation has no side effect on the Formula.- Returns:
- a String, or the empty string if the is no cadr.
-
cddr
Returns the LISP 'cddr' of the formula - the rest of the rest, or the list minus its first two elements. Note that this operation has no side effect on the Formula.- Returns:
- a String, or null.
-
cddrAsFormula
Returns the LISP 'cddr' of the formula as a new Formula, if possible, else returns null. Note that this operation has no side effect on the Formula.- Returns:
- a Formula, or null.
-
caddr
Returns the LISP 'caddr' of the formula, which is the third list element of the formula. Note that this operation has no side effect on the Formula.- Returns:
- a String, or the empty string if there is no caddr.
-
append
Returns the LISP 'append' of the formulas Note that this operation has no side effect on the Formula.- Returns:
- a Formula
-
atom
Test whether the String is a LISP atom. -
atom
public boolean atom()Test whether the Formula is a LISP atom. -
empty
public boolean empty()Test whether the Formula is an empty list. -
empty
Test whether the String is an empty formula. Not to be confused with a null string or empty string. There must be parentheses with nothing or whitespace in the middle. -
listP
public boolean listP()Test whether the Formula is a list. -
listP
Test whether the String is a list. -
validArgs
Test whether the Formula uses logical operators and predicates with the correct number of arguments. "equals", "invalid input: '<'=>", and "=>" are strictly binary. "or", "xor" and "and" are binary or greater. "not" is unary. "forall" and "exists" are unary with an argument list. Warn if we encounter a formula that has more arguments than MAX_PREDICATE_ARITY.- Parameters:
filename- If not null, denotes the name of the file being parsed.lineNo- If not null, indicates the location of the expression (formula) being parsed in the file being read.- Returns:
- an empty String if there are no problems or an error message if there are.
-
validArgs
Test whether the Formula uses logical operators and predicates with the correct number of arguments. "equals", "invalid input: '<'=>", and "=>" are strictly binary. "or", "xor" and "and" are binary or greater. "not" is unary. "forall" and "exists" are unary with an argument list. Warn if we encounter a formula that has more arguments than MAX_PREDICATE_ARITY.- Returns:
- an empty String if there are no problems or an error message if there are.
-
badQuantification
Deprecated.TODO: Not yet implemented! Test whether the Formula has variables that are not properly quantified. The case tested for is whether a quantified variable in the antecedent appears in the consequent or vice versa.- Returns:
- an empty String if there are no problems or an error message if there are.
-
logicallyEquals
Deprecated.Test if the contents of the formula are equal to the argument at a deeper level than a simple string equals. The only logical manipulation is to treat conjunctions and disjunctions as unordered bags of clauses. So (and A B C) will be logicallyEqual(s) for example, to (and B A C). Note that this is a fairly time-consuming operation and should not generally be used for comparing large sets of formulas. -
hashCode
public int hashCode()If equals is overridden, hashCode must use the same "significant" fields. -
equals
Test if the contents of the formula are equal to the argument. Normalize all variables so that formulas can be equal independent of their variable names, which have no semantics. -
equals
Test if the contents of the formula are equal to the String argument. Normalize all variables. -
logicallyEquals
Tests if this is logically equal with the parameter formula. It employs three equality tests starting with the fastest and finishing with the slowest: - string comparisons: if the strings of the two formulae are equal return true as the formulae are also equal, otherwise try comparing them by more complex means - compare the predicate structure of the formulae (deepEquals(...)): this comparison only checks if the two formulae have an equal structure of predicates disregarding variable equivalence. Example: (and (instance ?A Human) (instance ?A Mushroom)) according to deepEquals(...) would be equal to (and (instance ?A Human) (instance ?B Mushroom)) even though the first formula uses only one variable but the second one uses two, and as such they are not logically equal. This method generates false positives, but only true negatives. If the result of the comparison is false, we return false, otherwise keep trying. - try to logically unify the formulae by matching the predicates and the variables- Parameters:
f-- Returns:
-
unifyWith
Deprecated.Compares this formula with the parameter by trying to compare the predicate structure of the two and logically unify their variables. The helper method mapFormulaVariables(....) returns a logical mapping between the variables of two formulae of one exists. -
mapFormulaVariables
public static List<Set<VariableMapping>> mapFormulaVariables(Formula f1, Formula f2, KB kb, Map<FormulaUtil.FormulaMatchMemoMapKey, List<Set<VariableMapping>>> memoMap) Compares two formulae by recursively traversing its predicate structure and by building possible variable maps between the variables of the two formulae. If a complete mapping is possible, it is returned. Each recursive call returns a list of sets of variable pairs. Each pair is a variable from the first formula and its potential corresponding variable in the second formula. Each set is a potential complete mapping between all the variables in the first formula and the ones in the second. The returned list contains all possible sets, so in essence all possible valid mappings of variables between the two formulas. The method will reconcile the list returned by all one level deeper recursive calls and return the list of sets which offer no contradictions. Note: for clauses with commutative- Parameters:
memoMap- a memo-ization mechanism designed to reduce the number of recursive calls in "dynamic programming" fashion- Returns:
- null - if the formulas cannot be equals (due to having different predicates for example) empty list- formulas are equal, but there are no variables to map list 0f variable mapping sets the list of possible variable mapping sets which will make formulas equal
-
deepEquals
Test if the contents of the formula are equal to the argument. -
getStringArgument
Return the numbered argument of the given formula. The first element of a formula (i.e. the predicate position) is number 0. Returns the empty string if there is no such argument position. -
getArgument
Return the numbered argument of the given formula. The first element of a formula (i.e. the predicate position) is number 0. Returns null if there is no such argument position. -
listLength
public int listLength()Returns a non-negative int value indicating the top-level list length of this Formula if it is a proper listP(), else returns -1. One caveat: This method assumes that neither null nor the empty string are legitimate list members in a wff. The return value is likely to be wrong if this assumption is mistaken.- Returns:
- A non-negative int, or -1.
-
argumentsToArrayListString
Return all the arguments in a simple formula as a list, starting at the given argument. If formula is complex (i.e. an argument is a function or sentence), then return null. If the starting argument is greater than the number of arguments, also return null. -
argumentsToArrayList
Deprecated.Return all the arguments in a simple formula as a list, starting at the given argument. If formula is complex (i.e. an argument is a function or sentence), then return null. If the starting argument is greater than the number of arguments, also return null. Deprecated - use complexArgumentsToArrayList() -
complexArgumentsToArrayList
Return all the arguments in a formula as a list, starting at the given argument. If the starting argument is greater than the number of arguments, return null. -
complexArgumentsToArrayListString
Return all the arguments in a formula as a list, starting at the given argument. If the starting argument is greater than the number of arguments, return null. -
collectVariables
Collects all variables in this Formula. Returns an ArrayList containing a pair of ArrayLists. The first contains all explicitly quantified variables in the Formula. The second contains all variables in Formula that are not within the scope of some explicit quantifier.- Returns:
- An ArrayList containing two ArrayLists, each of which could be empty
-
collectQuantifiedUnquantifiedVariablesRecurse
public void collectQuantifiedUnquantifiedVariablesRecurse(Formula f, Map<String, Boolean> varFlag, Set<String> unquantifiedVariables, Set<String> quantifiedVariables) Collect quantified and unquantified variables recursively -
addAllNoDup
Collects all String terms from one Collection and adds them to another, without duplication -
collectAllVariables
Collects all variables in this Formula. Returns an Set of String variable names (with initial '?').- Returns:
- A Set of String variable names
-
collectAllVariablesOrdered
Collects all variables in this Formula in lexical order. Returns an ArrayList of String variable names (with initial '?'). Note that unlike collectAllVariables() this is not cached and therefore potentially much slower, although it does fill the cache of variable names so using this method first, will make calls to collectAllVariables() fast if that method is called on the same formula after this method is called.- Returns:
- An ArrayList of String variable names
-
collectQuantifiedVariables
Collects all quantified variables in this Formula. Returns an ArrayList of String variable names (with initial '?'). Note that duplicates are not removed.- Returns:
- An ArrayList of String variable names
-
collectUnquantifiedVariables
Collect all the unquantified variables in a formula -
collectTerms
Collect all the terms in a formula -
substituteVariables
Replace variables with a value as given by the map argument -
makeQuantifiersExplicit
Makes implicit quantification explicit.- Parameters:
query- controls whether to add universal or existential quantification. If true, add existential.
-
renameVariableArityRelations
- Parameters:
kb- - The KB used to compute variable arity relations.relationMap- is a Map of String keys and values where the key is the renamed relation and the value is the original name. This is set as a side effect of this method.- Returns:
- A new version of the Formula in which every VariableArityRelation has been renamed to include a numeric suffix corresponding to the actual number of arguments in the Formula.
-
gatherRelationsWithArgTypes
Returns a HashMap in which the keys are the Relation constants gathered from this Formula, and the values are ArrayLists in which the ordinal positions 0 - n are occupied by the names of the corresponding argument types. n should never be greater than the value of Formula.MAX_PREDICATE_ARITY. For each Predicate key, the length of its ArrayList should be equal to the predicate's valence + 1. For each Function, the length of its ArrayList should be equal to its valence. Only Functions will have argument types in the 0th position of the ArrayList, since this position contains a function's range type. This means that all Predicate ArrayLists will contain at least one null value. A null value will also be added to the nth position of an ArrayList when no value can be obtained for that position.- Returns:
- A HashMap that maps every Relation occurring in this Formula to an ArrayList indicating the Relation's argument types. Some HashMap keys may map to null values or empty ArrayLists, and most ArrayLists will contain some null values.
-
gatherRelationConstants
Returns a HashSet of all atomic KIF Relation constants that occur as Predicates or Functions (argument 0 terms) in this Formula.- Returns:
- a HashSet containing the String constants that denote KIF Relations in this Formula, or an empty HashSet.
-
isFunctionalTerm
Deprecated.Test whether a Formula is a functional term. Note this assumes the textual convention of all functions ending with "Fn". -
isFunctionalTerm
Deprecated.Test whether a Formula is a functional term -
isHigherOrder
Test whether a Formula contains a Formula as an argument to other than a logical operator. TODO: get var types in case there is a function variable, and copy that var type list down to the arguments -
isVariable
Test whether a String formula is a variable -
isVariable
public boolean isVariable()Test whether the Formula is a variable -
isRegularVariable
public boolean isRegularVariable()Test whether the Formula is a regular '?' variable -
isRowVar
public boolean isRowVar()Test whether the Formula is a row variable -
isCached
public boolean isCached()Test whether the Formula is automatically created by caching -
isRule
public boolean isRule()Returns true only if this Formula, explicitly quantified or not, starts with "=>" or "invalid input: '<'=>", else returns false. It would be better to test for the occurrence of at least one positive literal with one or more negative literals, but this test would require converting the Formula to clausal form. -
isHorn
Returns true only if this Formula is a horn clause or is simply modified to be horn by breaking out a conjunctive conclusion. -
isQuantifierList
Test whether a list with a predicate is a quantifier list -
isSimpleClause
Test whether a Formula is a simple list of terms (including functional terms).- Parameters:
kb- the current knowledge base- Returns:
- true if a Formula is a simple list of terms (including functional terms)
-
isSimpleNegatedClause
Test whether a Formula is a simple clause wrapped in a negation. -
isQuantifier
Test whether a predicate is a logical quantifier -
isExistentiallyQuantified
public boolean isExistentiallyQuantified()Tests if this formula is an existentially quantified formula- Returns:
-
isUniversallyQuantified
public boolean isUniversallyQuantified()Tests if this formula is an universally quantified formula- Returns:
-
isCommutative
A static utility method.- Parameters:
obj- Any object, but should be a String.- Returns:
- true if obj is a SUO-KIF commutative logical operator, else false.
-
findType
- Returns:
- a String with the type(s) of the formula
-
getDualOperator
Returns the dual logical operator of op, or null if op is not an operator or has no dual.- Parameters:
op- A String, assumed to be a SUO-KIF logical operator- Returns:
- A String, the dual operator of op, or null.
-
isTrueFalse
Returns true if term is a standard FOL logical operator, else returns false.- Parameters:
term- A String, assumed to be an atomic SUO-KIF term.
-
isLogicalOperator
Returns true if term is a constant true or constant false, else returns false.- Parameters:
term- A String, assumed to be an atomic SUO-KIF term.
-
isTerm
Returns true if term is a valid SUO-KIF term, else returns false.- Parameters:
term- A String, assumed to be an atomic SUO-KIF term.
-
isComparisonOperator
Returns true if term is a SUO-KIF predicate for comparing two (typically numeric) terms, else returns false.- Parameters:
term- A String.
-
isInequality
Returns true if term is a SUO-KIF inequality, else returns false.- Parameters:
term- A String.
-
isMathFunction
Returns true if term is a SUO-KIF mathematical function, else returns false.- Parameters:
term- A String.
-
isModal
-
isEpistemic
-
isTemporal
-
removeTemporalRelations
The purpose is to take simple HOL formula with temporal aspects and remove temporal aspects of it in an attempt to take it to FOL. Note: This may change the semantic meaning of the formal logic. -
isOtherHOL
-
isTFF
-
isGround
Returns true if formula is a valid formula with no variables, else returns false. -
isGround
public boolean isGround()Returns true if formula does not have variables, else returns false. -
isBinary
public boolean isBinary()Returns true if formula is a simple binary relation (note that because the argument list includes the predicate, which is argument 0, there will be three elements) -
isFunction
Deprecated.Returns true if term is a SUO-KIF function, else returns false. Note that this test is purely syntactic, and could fail for functions that do not adhere to the convention of ending all functions with "Fn".- Parameters:
term- A String.
-
isSkolemTerm
Returns true if term is a SUO-KIF Skolem term, else returns false- Parameters:
term- A String.- Returns:
- true or false
-
literalToArrayList
- Returns:
- An ArrayList (ordered tuple) representation of the Formula, in which each top-level element of the Formula is either an atom (String) or another list.
-
replaceVar
Replace v with term. TODO: See if a regex replace is faster (commented out buggy code below) -
replaceQuantifierVars
- Parameters:
quantifier-vars-- Returns:
- Throws:
Exception
-
isQuery
Compare the given formula to the query and return whether they are the same. -
isNegatedQuery
Compare the given formula to the negated query and return whether they are the same (minus the negation). -
postProcess
Remove the 'holds' prefix wherever it appears. -
format
Format a formula for either text or HTML presentation by inserting the proper hyperlink code, characters for indentation and end of line. A standard LISP-style pretty printing is employed where an open parenthesis triggers a new line and added indentation.- Parameters:
hyperlink- - the URL to be referenced to a hyperlinked term.indentChars- - the proper characters for indenting text.eolChars- - the proper character for end of line.
-
textFormat
Format a formula for text presentation. -
toString
Format a formula for text presentation. -
toStringMeta
Format a formula for text presentation include file and line#. -
htmlFormat
Format a formula for HTML presentation. -
htmlFormat
Format a formula for HTML presentation. -
toProlog
Format a formula as a prolog statement. Note that only tuples are converted properly at this time. Statements with any embedded formulas or functions will be rejected with a null return. -
rename
Replace term2 with term1 -
testCollectVariables
public static void testCollectVariables()A test method. -
testIsSimpleClause
public static void testIsSimpleClause()A test method. -
testReplaceVar
public static void testReplaceVar()A test method. -
testComplexArgs
public static void testComplexArgs()A test method. -
testBigArgs
public static void testBigArgs()A test method. -
testCar1
public static void testCar1()A test method. -
testArg2ArrayList
public static void testArg2ArrayList()A test method. -
negate
-
showHelp
public static void showHelp() -
main
- Throws:
IOException
-