public class Formula
extends java.lang.Object
implements java.lang.Comparable
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
AND |
static java.lang.String |
classSymbolSuffix |
protected static java.lang.String |
DIVIDEFN |
static java.util.List<java.lang.String> |
DOC_PREDICATES |
long |
endFilePosition
The length of the file in bytes at the position immediately
after the end of the formula.
|
int |
endLine
The line in the file on which the formula ends.
|
protected static java.lang.String |
EQUAL |
static java.lang.String |
EQUANT |
java.util.ArrayList<java.lang.String> |
errors |
protected static java.lang.String |
FN_SUFF |
protected static java.lang.String |
GT |
protected static java.lang.String |
GTET |
protected static java.lang.String |
IF |
protected static java.lang.String |
IFF |
protected static java.lang.String |
KAPPAFN |
protected static java.lang.String |
LOG_FALSE |
protected static java.lang.String |
LOG_TRUE |
static java.util.List<java.lang.String> |
LOGICAL_OPERATORS
The SUO-KIF logical operators.
|
protected static java.lang.String |
LP |
protected static java.lang.String |
LT |
protected static java.lang.String |
LTET |
protected static int |
MAX_PREDICATE_ARITY
This constant indicates the maximum predicate arity supported
by the current implementation of Sigma.
|
protected static java.lang.String |
MINUSFN |
protected static java.lang.String |
NOT |
protected static java.lang.String |
OR |
protected static java.lang.String |
PLUSFN |
protected static java.lang.String |
R_PREF |
protected static java.lang.String |
RP |
protected static java.lang.String |
RVAR |
protected static java.lang.String |
SK_PREF |
protected static java.lang.String |
SKFN |
protected java.lang.String |
sourceFile
The source file in which the formula appears.
|
protected static java.lang.String |
SPACE |
int |
startLine
The line in the file on which the formula starts.
|
static java.lang.String |
termMentionSuffix |
static java.lang.String |
termSymbolPrefix |
static java.lang.String |
termVariablePrefix |
java.lang.String |
theFormula
The formula.
|
java.util.ArrayList<java.lang.String> |
theTptpFormulas
A list of TPTP formulas (Strings) that together constitute the
translation of theFormula.
|
protected static java.lang.String |
TIMESFN |
static java.lang.String |
UQUANT |
protected static java.lang.String |
V_PREF |
protected static java.lang.String |
VVAR |
protected static java.lang.String |
VX |
Constructor and Description |
---|
Formula() |
Formula(Formula f) |
Formula(java.lang.String f) |
Modifier and Type | Method and Description |
---|---|
Formula |
append(Formula f)
Returns the LISP 'append' of the formulas
Note that this operation has no side effect on the Formula.
|
java.util.ArrayList<java.lang.String> |
argumentsToArrayList(int start)
Return all the arguments in a simple formula as a list, starting
at the given argument.
|
boolean |
atom()
Test whether the Formula is a LISP atom.
|
static boolean |
atom(java.lang.String s)
Test whether the String is a LISP atom.
|
java.lang.String |
badQuantification()
Not yet implemented! Test whether the Formula has variables that are not properly
quantified.
|
java.lang.String |
caddr()
Returns the LISP 'caddr' of the formula, which is the third
list element of the formula.
|
java.lang.String |
cadr()
Returns the LISP 'cadr' (the second list element) of the
formula.
|
java.lang.String |
car() |
Formula |
carAsFormula()
Returns the LISP 'car' of the formula as a new Formula, if
possible, else returns null.
|
java.lang.String |
cddr()
Returns the LISP 'cddr' of the formula - the rest of the rest,
or the list minus its first two elements.
|
Formula |
cddrAsFormula()
Returns the LISP 'cddr' of the formula as a new Formula, if
possible, else returns null.
|
java.lang.String |
cdr()
Return the LISP 'cdr' of the formula - the rest of a list minus its
first element.
|
Formula |
cdrAsFormula()
Returns the LISP 'cdr' of the formula as a new Formula, if
possible, else returns null.
|
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.
|
void |
clearTheTptpFormulas()
Clears theTptpFormulas if the ArrayList exists, else does
nothing.
|
java.util.Set<java.lang.String> |
collectAllVariables()
Collects all variables in this Formula.
|
java.util.ArrayList<java.lang.String> |
collectExistentiallyQuantifiedVariables()
Collects all quantified variables in this Formula.
|
java.util.ArrayList<java.util.ArrayList<java.lang.String>> |
collectQuantifiedUnquantifiedVariables()
A new method to collect all quantified and unquantified variables
in this Formula.
|
void |
collectQuantifiedUnquantifiedVariablesRecurse(Formula f,
java.util.HashMap<java.lang.String,java.lang.Boolean> varFlag,
java.util.HashSet<java.lang.String> unquantifiedVariables,
java.util.HashSet<java.lang.String> quantifiedVariables)
Collect quantified and unquantified variables recursively
|
java.util.ArrayList<java.lang.String> |
collectQuantifiedVariables()
Collects all quantified variables in this Formula.
|
java.util.Set<java.lang.String> |
collectTerms()
Collect all the terms in a formula
|
java.util.ArrayList<java.lang.String> |
collectUnquantifiedVariables()
Collect all the unquantified variables in a formula
|
java.util.ArrayList<java.util.ArrayList<java.lang.String>> |
collectVariables()
Collects all variables in this Formula.
|
int |
compareTo(java.lang.Object f)
Implement the Comparable interface by defining the compareTo
method.
|
java.util.ArrayList<java.lang.String> |
complexArgumentsToArrayList(int start)
Return all the arguments in a formula as a list, starting
at the given argument.
|
Formula |
cons(Formula f) |
Formula |
cons(java.lang.String obj)
Returns a new Formula which is the result of 'consing' a String
into this Formula, similar to the LISP procedure of the same
name.
|
Formula |
copy()
Copy the Formula.
|
java.lang.String |
createID() |
Formula |
deepCopy() |
boolean |
deepEquals(Formula f)
Test if the contents of the formula are equal to the argument.
|
boolean |
empty()
Test whether the Formula is an empty list.
|
static boolean |
empty(java.lang.String s)
Test whether the String is an empty formula.
|
boolean |
equals(java.lang.Object o)
Test if the contents of the formula are equal to the
argument.
|
boolean |
equals(java.lang.String s)
Test if the contents of the formula are equal to the String argument.
|
java.lang.String |
format(java.lang.String hyperlink,
java.lang.String indentChars,
java.lang.String eolChars)
Format a formula for either text or HTML presentation by inserting
the proper hyperlink code, characters for indentation and end of line.
|
java.util.HashSet<java.lang.String> |
gatherRelationConstants()
Returns a HashSet of all atomic KIF Relation constants that
occur as Predicates or Functions (argument 0 terms) in this
Formula.
|
java.util.HashMap<java.lang.String,java.util.ArrayList> |
gatherRelationsWithArgTypes(KB kb)
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.
|
java.lang.String |
getArgument(int argnum)
Return the numbered argument of the given formula.
|
java.util.ArrayList |
getClauses()
Returns a List of List objects.
|
protected static java.lang.String |
getDualOperator(java.lang.String op)
Returns the dual logical operator of op, or null if op is not
an operator or has no dual.
|
java.util.ArrayList<java.lang.String> |
getErrors() |
boolean |
getIsComputed()
Should return false if this Formula occurs in and was loaded
from sourceFile.
|
java.lang.String |
getLineSeparator()
Returns the platform-specific line separator String
|
java.lang.String |
getSourceFile() |
java.util.ArrayList |
getTheClausalForm()
Returns a List of the clauses that together constitute the
resolution form of this Formula.
|
java.util.ArrayList<java.lang.String> |
getTheTptpFormulas()
Returns an ArrayList of the TPTP formulas (Strings) that
together constitute the TPTP translation of theFormula.
|
java.util.HashMap |
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().
|
int |
hashCode()
If equals is overridedden, hashCode must use the same
"significant" fields.
|
java.lang.String |
htmlFormat(KB kb)
Format a formula for HTML presentation.
|
java.lang.String |
htmlFormat(java.lang.String html)
Format a formula for HTML presentation.
|
static java.lang.String |
integerToPaddedString(int i,
int digits) |
boolean |
isBalancedList()
Returns true if the Formula contains no unbalanced parentheses
or unbalanced quote characters, otherwise returns false.
|
boolean |
isCached()
Test whether the Formula is automatically created by caching
|
static boolean |
isCommutative(java.lang.String obj)
A static utility method.
|
static boolean |
isComparisonOperator(java.lang.String term)
Returns true if term is a SUO-KIF predicate for comparing two
(typically numeric) terms, else returns false.
|
boolean |
isExistentiallyQuantified()
Tests if this formula is an existentially quantified formula
|
static boolean |
isFunction(java.lang.String term)
Returns true if term is a SUO-KIF function, else returns false.
|
boolean |
isFunctionalTerm()
Test whether a Formula is a functional term.
|
static boolean |
isFunctionalTerm(java.lang.String s)
Test whether a Formula is a functional term
|
boolean |
isGround()
Returns true if formula has variable, else returns false.
|
static boolean |
isGround(java.lang.String form)
Returns true if formula is a valid formula with no variables,
else returns false.
|
boolean |
isHigherOrder()
Test whether a Formula contains a Formula as an argument to
other than a logical operator.
|
boolean |
isHorn()
Returns true only if this Formula, is a horn clause or is simply
modified to be horn by breaking out a conjunctive conclusion.
|
static boolean |
isLogicalOperator(java.lang.String term)
Returns true if term is a standard FOL logical operator, else
returns false.
|
static boolean |
isMathFunction(java.lang.String term)
Returns true if term is a SUO-KIF mathematical function, else
returns false.
|
static boolean |
isNegatedQuery(java.lang.String query,
java.lang.String formulaString)
Compare the given formula to the negated query and return whether
they are the same (minus the negation).
|
static boolean |
isQuantifier(java.lang.String pred)
Test whether a predicate is a logical quantifier
|
static boolean |
isQuantifierList(java.lang.String listPred,
java.lang.String previousPred)
Test whether a list with a predicate is a quantifier list
|
static boolean |
isQuery(java.lang.String query,
java.lang.String formula)
Compare the given formula to the query and return whether
they are the same.
|
boolean |
isRule()
Returns true only if this Formula, explicitly quantified or
not, starts with "=>" or "<=>", else returns false.
|
boolean |
isSimpleClause()
Test whether a Formula is a simple list of terms (including
functional terms).
|
boolean |
isSimpleNegatedClause()
Test whether a Formula is a simple clause wrapped in a
negation.
|
static boolean |
isSkolemTerm(java.lang.String term)
Returns true if term is a SUO-KIF Skolem term, else returns false.
|
static boolean |
isTerm(java.lang.String term)
Returns true if term is a valid SUO-KIF term, else
returns false.
|
boolean |
isUniversallyQuantified()
Tests if this formula is an universally quantified formula
|
boolean |
isVariable()
Test whether the Formula is a variable
|
static boolean |
isVariable(java.lang.String term)
Test whether a String formula is a variable
|
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.
|
boolean |
listP()
Test whether the Formula is a list.
|
static boolean |
listP(java.lang.String s)
Test whether the String is a list.
|
java.util.ArrayList<java.lang.String> |
literalToArrayList() |
boolean |
logicallyEquals(Formula f)
Test if this is logically equal with the parameter formula
|
boolean |
logicallyEquals(java.lang.String s)
Test if the contents of the formula are equal to the argument
at a deeper level than a simple string equals.
|
static void |
main(java.lang.String[] args)
A test method.
|
java.lang.String |
makeQuantifiersExplicit(boolean query)
Makes implicit quantification explicit.
|
static java.util.List<java.util.Set<com.articulate.sigma.Formula.VariableMapping>> |
mapFormulaVariables(Formula f1,
Formula f2,
KB kb,
java.util.HashMap<FormulaUtil.FormulaMatchMemoMapKey,java.util.List<java.util.Set<com.articulate.sigma.Formula.VariableMapping>>> memoMap)
Compares recursively to formulas and returns possible variable maps between the variables of the two formulas
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
|
static java.lang.String |
postProcess(java.lang.String s)
Remove the 'holds' prefix wherever it appears.
|
void |
read(java.lang.String s)
Read a String into the variable 'theFormula'.
|
Formula |
rename(java.lang.String term2,
java.lang.String term1)
Replace term2 with term1
|
protected Formula |
renameVariableArityRelations(KB kb,
java.util.TreeMap<java.lang.String,java.lang.String> relationMap) |
Formula |
replaceQuantifierVars(java.lang.String quantifier,
java.util.List<java.lang.String> vars) |
Formula |
replaceVar(java.lang.String v,
java.lang.String term)
Replace v with term.
|
void |
setIsComputed(boolean val)
Sets the value of isComputed to val.
|
void |
setSourceFile(java.lang.String filename) |
Formula |
substituteVariables(java.util.Map<java.lang.String,java.lang.String> m)
Replace variables with a value as given by the map argument
|
static void |
testBigArgs()
A test method.
|
static void |
testClausifier(java.lang.String[] args)
A test method.
|
static void |
testCollectVariables()
A test method.
|
static void |
testComplexArgs()
A test method.
|
static void |
testIsSimpleClause()
A test method.
|
static void |
testReplaceVar()
A test method.
|
static java.lang.String |
textFormat(java.lang.String input)
Format a formula for text presentation.
|
java.lang.String |
toProlog()
Format a formula as a prolog statement.
|
java.lang.String |
toString()
Format a formula for text presentation.
|
boolean |
unifyWith(Formula f) |
java.lang.String |
validArgs()
Test whether the Formula uses logical operators and predicates
with the correct number of arguments.
|
java.lang.String |
validArgs(java.lang.String filename,
java.lang.Integer lineNo)
Test whether the Formula uses logical operators and predicates
with the correct number of arguments.
|
protected static final java.lang.String AND
protected static final java.lang.String OR
protected static final java.lang.String NOT
protected static final java.lang.String IF
protected static final java.lang.String IFF
public static final java.lang.String UQUANT
public static final java.lang.String EQUANT
protected static final java.lang.String EQUAL
protected static final java.lang.String GT
protected static final java.lang.String GTET
protected static final java.lang.String LT
protected static final java.lang.String LTET
protected static final java.lang.String KAPPAFN
protected static final java.lang.String PLUSFN
protected static final java.lang.String MINUSFN
protected static final java.lang.String TIMESFN
protected static final java.lang.String DIVIDEFN
protected static final java.lang.String SKFN
protected static final java.lang.String SK_PREF
protected static final java.lang.String FN_SUFF
protected static final java.lang.String V_PREF
protected static final java.lang.String R_PREF
protected static final java.lang.String VX
protected static final java.lang.String VVAR
protected static final java.lang.String RVAR
protected static final java.lang.String LP
protected static final java.lang.String RP
protected static final java.lang.String SPACE
protected static final java.lang.String LOG_TRUE
protected static final java.lang.String LOG_FALSE
public static final java.util.List<java.lang.String> LOGICAL_OPERATORS
public static final java.util.List<java.lang.String> DOC_PREDICATES
protected java.lang.String sourceFile
public int startLine
public int endLine
public long endFilePosition
public java.util.ArrayList<java.lang.String> errors
public java.lang.String theFormula
public static final java.lang.String termMentionSuffix
public static final java.lang.String classSymbolSuffix
public static final java.lang.String termSymbolPrefix
public static final java.lang.String termVariablePrefix
public java.util.ArrayList<java.lang.String> theTptpFormulas
protected static final int MAX_PREDICATE_ARITY
public Formula(Formula f)
public Formula()
public Formula(java.lang.String f)
public java.lang.String getLineSeparator()
public java.lang.String getSourceFile()
public void setSourceFile(java.lang.String filename)
public java.util.ArrayList<java.lang.String> getErrors()
public boolean getIsComputed()
public void setIsComputed(boolean val)
public java.util.ArrayList<java.lang.String> getTheTptpFormulas()
public void clearTheTptpFormulas()
public java.util.ArrayList getTheClausalForm()
public void clearTheClausalForm()
public java.util.ArrayList getClauses()
public java.util.HashMap getVarMap()
public void read(java.lang.String s)
public static java.lang.String integerToPaddedString(int i, int digits)
public java.lang.String createID()
public Formula copy()
public Formula deepCopy()
public int compareTo(java.lang.Object f) throws java.lang.ClassCastException
compareTo
in interface java.lang.Comparable
java.lang.ClassCastException
public boolean isBalancedList()
public java.lang.String car()
public java.lang.String cdr()
public Formula cons(java.lang.String obj)
obj
- The String object that will become the 'car' (or
head) of the resulting Formula (list).public Formula cons(Formula f)
public Formula cdrAsFormula()
public Formula carAsFormula()
public java.lang.String cadr()
public java.lang.String cddr()
public Formula cddrAsFormula()
public java.lang.String caddr()
public Formula append(Formula f)
public static boolean atom(java.lang.String s)
public boolean atom()
public boolean empty()
public static boolean empty(java.lang.String s)
public boolean listP()
public static boolean listP(java.lang.String s)
public java.lang.String validArgs(java.lang.String filename, java.lang.Integer lineNo)
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.public java.lang.String validArgs()
public java.lang.String badQuantification()
public boolean logicallyEquals(java.lang.String s)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public boolean equals(java.lang.String s)
public boolean logicallyEquals(Formula f)
public boolean unifyWith(Formula f)
public static java.util.List<java.util.Set<com.articulate.sigma.Formula.VariableMapping>> mapFormulaVariables(Formula f1, Formula f2, KB kb, java.util.HashMap<FormulaUtil.FormulaMatchMemoMapKey,java.util.List<java.util.Set<com.articulate.sigma.Formula.VariableMapping>>> memoMap)
public boolean deepEquals(Formula f)
public java.lang.String getArgument(int argnum)
public int listLength()
public java.util.ArrayList<java.lang.String> argumentsToArrayList(int start)
public java.util.ArrayList<java.lang.String> complexArgumentsToArrayList(int start)
public java.util.ArrayList<java.util.ArrayList<java.lang.String>> collectVariables()
public java.util.ArrayList<java.util.ArrayList<java.lang.String>> collectQuantifiedUnquantifiedVariables()
public void collectQuantifiedUnquantifiedVariablesRecurse(Formula f, java.util.HashMap<java.lang.String,java.lang.Boolean> varFlag, java.util.HashSet<java.lang.String> unquantifiedVariables, java.util.HashSet<java.lang.String> quantifiedVariables)
public java.util.Set<java.lang.String> collectAllVariables()
public java.util.ArrayList<java.lang.String> collectExistentiallyQuantifiedVariables()
public java.util.ArrayList<java.lang.String> collectQuantifiedVariables()
public java.util.ArrayList<java.lang.String> collectUnquantifiedVariables()
public java.util.Set<java.lang.String> collectTerms()
public Formula substituteVariables(java.util.Map<java.lang.String,java.lang.String> m)
public java.lang.String makeQuantifiersExplicit(boolean query)
query
- controls whether to add universal or existential
quantification. If true, add existential.protected Formula renameVariableArityRelations(KB kb, java.util.TreeMap<java.lang.String,java.lang.String> relationMap)
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.public java.util.HashMap<java.lang.String,java.util.ArrayList> gatherRelationsWithArgTypes(KB kb)
public java.util.HashSet<java.lang.String> gatherRelationConstants()
public boolean isFunctionalTerm()
public static boolean isFunctionalTerm(java.lang.String s)
public boolean isHigherOrder()
public static boolean isVariable(java.lang.String term)
public boolean isVariable()
public boolean isCached()
public boolean isRule()
public boolean isHorn()
public static boolean isQuantifierList(java.lang.String listPred, java.lang.String previousPred)
public boolean isSimpleClause()
public boolean isSimpleNegatedClause()
public static boolean isQuantifier(java.lang.String pred)
public boolean isExistentiallyQuantified()
public boolean isUniversallyQuantified()
public static boolean isCommutative(java.lang.String obj)
obj
- Any object, but should be a String.protected static java.lang.String getDualOperator(java.lang.String op)
op
- A String, assumed to be a SUO-KIF logical operatorpublic static boolean isLogicalOperator(java.lang.String term)
term
- A String, assumed to be an atomic SUO-KIF term.public static boolean isTerm(java.lang.String term)
term
- A String, assumed to be an atomic SUO-KIF term.public static boolean isComparisonOperator(java.lang.String term)
term
- A String.public static boolean isMathFunction(java.lang.String term)
term
- A String.public static boolean isGround(java.lang.String form)
public boolean isGround()
public static boolean isFunction(java.lang.String term)
term
- A String.public static boolean isSkolemTerm(java.lang.String term)
term
- A String.public java.util.ArrayList<java.lang.String> literalToArrayList()
public Formula replaceVar(java.lang.String v, java.lang.String term)
public Formula replaceQuantifierVars(java.lang.String quantifier, java.util.List<java.lang.String> vars) throws java.lang.Exception
java.lang.Exception
public static boolean isQuery(java.lang.String query, java.lang.String formula)
public static boolean isNegatedQuery(java.lang.String query, java.lang.String formulaString)
public static java.lang.String postProcess(java.lang.String s)
public java.lang.String format(java.lang.String hyperlink, java.lang.String indentChars, java.lang.String eolChars)
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.public static java.lang.String textFormat(java.lang.String input)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String htmlFormat(java.lang.String html)
public java.lang.String htmlFormat(KB kb)
public java.lang.String toProlog()
public Formula rename(java.lang.String term2, java.lang.String term1)
public static void testClausifier(java.lang.String[] args)
public static void testCollectVariables()
public static void testIsSimpleClause()
public static void testReplaceVar()
public static void testComplexArgs()
public static void testBigArgs()
public static void main(java.lang.String[] args)