public class Formula extends Object implements Comparable
| Modifier and Type | Field and Description |
|---|---|
protected static String |
AND |
static String |
classSymbolSuffix |
protected static String |
DIVIDEFN |
static List<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 String |
EQUAL |
static String |
EQUANT |
ArrayList<String> |
errors |
protected static String |
FN_SUFF |
protected static String |
GT |
protected static String |
GTET |
protected static String |
IF |
protected static String |
IFF |
protected static String |
KAPPAFN |
protected static String |
LOG_FALSE |
protected static String |
LOG_TRUE |
static List<String> |
LOGICAL_OPERATORS
The SUO-KIF logical operators.
|
protected static String |
LP |
protected static String |
LT |
protected static String |
LTET |
protected static int |
MAX_PREDICATE_ARITY
This constant indicates the maximum predicate arity supported
by the current implementation of Sigma.
|
protected static String |
MINUSFN |
protected static String |
NOT |
protected static String |
OR |
protected static String |
PLUSFN |
protected static String |
R_PREF |
protected static String |
RP |
protected static String |
RVAR |
protected static String |
SK_PREF |
protected static String |
SKFN |
protected String |
sourceFile
The source file in which the formula appears.
|
protected static String |
SPACE |
int |
startLine
The line in the file on which the formula starts.
|
static String |
termMentionSuffix |
static String |
termSymbolPrefix |
static String |
termVariablePrefix |
String |
theFormula
The formula.
|
ArrayList<String> |
theTptpFormulas
A list of TPTP formulas (Strings) that together constitute the
translation of theFormula.
|
protected static String |
TIMESFN |
static String |
UQUANT |
protected static String |
V_PREF |
protected static String |
VVAR |
protected static String |
VX |
| Constructor and Description |
|---|
Formula() |
Formula(Formula f) |
Formula(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.
|
ArrayList<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(String s)
Test whether the String is a LISP atom.
|
String |
badQuantification()
Not yet implemented! Test whether the Formula has variables that are not properly
quantified.
|
String |
caddr()
Returns the LISP 'caddr' of the formula, which is the third
list element of the formula.
|
String |
cadr()
Returns the LISP 'cadr' (the second list element) of the
formula.
|
String |
car() |
Formula |
carAsFormula()
Returns the LISP 'car' of the formula as a new Formula, if
possible, else returns null.
|
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.
|
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.
|
Set<String> |
collectAllVariables()
Collects all variables in this Formula.
|
ArrayList<String> |
collectExistentiallyQuantifiedVariables()
Collects all quantified variables in this Formula.
|
ArrayList<ArrayList<String>> |
collectQuantifiedUnquantifiedVariables()
A new method to collect all quantified and unquantified variables
in this Formula.
|
void |
collectQuantifiedUnquantifiedVariablesRecurse(Formula f,
HashMap<String,Boolean> varFlag,
HashSet<String> unquantifiedVariables,
HashSet<String> quantifiedVariables)
Collect quantified and unquantified variables recursively
|
ArrayList<String> |
collectQuantifiedVariables()
Collects all quantified variables in this Formula.
|
Set<String> |
collectTerms()
Collect all the terms in a formula
|
ArrayList<String> |
collectUnquantifiedVariables()
Collect all the unquantified variables in a formula
|
ArrayList<ArrayList<String>> |
collectVariables()
Collects all variables in this Formula.
|
int |
compareTo(Object f)
Implement the Comparable interface by defining the compareTo
method.
|
ArrayList<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(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.
|
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(String s)
Test whether the String is an empty formula.
|
boolean |
equals(Object o)
Test if the contents of the formula are equal to the
argument.
|
boolean |
equals(String s)
Test if the contents of the formula are equal to the String argument.
|
String |
format(String hyperlink,
String indentChars,
String eolChars)
Format a formula for either text or HTML presentation by inserting
the proper hyperlink code, characters for indentation and end of line.
|
HashSet<String> |
gatherRelationConstants()
Returns a HashSet of all atomic KIF Relation constants that
occur as Predicates or Functions (argument 0 terms) in this
Formula.
|
HashMap<String,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.
|
String |
getArgument(int argnum)
Return the numbered argument of the given formula.
|
ArrayList |
getClauses()
Returns a List of List objects.
|
protected static String |
getDualOperator(String op)
Returns the dual logical operator of op, or null if op is not
an operator or has no dual.
|
ArrayList<String> |
getErrors() |
boolean |
getIsComputed()
Should return false if this Formula occurs in and was loaded
from sourceFile.
|
String |
getLineSeparator()
Returns the platform-specific line separator String
|
String |
getSourceFile() |
ArrayList |
getTheClausalForm()
Returns a List of the clauses that together constitute the
resolution form of this Formula.
|
ArrayList<String> |
getTheTptpFormulas()
Returns an ArrayList of the TPTP formulas (Strings) that
together constitute the TPTP translation of theFormula.
|
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.
|
String |
htmlFormat(KB kb)
Format a formula for HTML presentation.
|
String |
htmlFormat(String html)
Format a formula for HTML presentation.
|
static 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(String obj)
A static utility method.
|
static boolean |
isComparisonOperator(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(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(String s)
Test whether a Formula is a functional term
|
boolean |
isGround()
Returns true if formula has variable, else returns false.
|
static boolean |
isGround(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(String term)
Returns true if term is a standard FOL logical operator, else
returns false.
|
static boolean |
isMathFunction(String term)
Returns true if term is a SUO-KIF mathematical function, else
returns false.
|
static boolean |
isNegatedQuery(String query,
String formulaString)
Compare the given formula to the negated query and return whether
they are the same (minus the negation).
|
static boolean |
isQuantifier(String pred)
Test whether a predicate is a logical quantifier
|
static boolean |
isQuantifierList(String listPred,
String previousPred)
Test whether a list with a predicate is a quantifier list
|
static boolean |
isQuery(String query,
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(String term)
Returns true if term is a SUO-KIF Skolem term, else returns false.
|
static boolean |
isTerm(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(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(String s)
Test whether the String is a list.
|
ArrayList<String> |
literalToArrayList() |
boolean |
logicallyEquals(Formula f)
Tests if this is logically equal with the parameter formula.
|
boolean |
logicallyEquals(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(String[] args)
A test method.
|
String |
makeQuantifiersExplicit(boolean query)
Makes implicit quantification explicit.
|
static List<Set<com.articulate.sigma.Formula.VariableMapping>> |
mapFormulaVariables(Formula f1,
Formula f2,
KB kb,
HashMap<FormulaUtil.FormulaMatchMemoMapKey,List<Set<com.articulate.sigma.Formula.VariableMapping>>> memoMap)
Compares two formulae by recursively traversing its predicate structure and by building possible variable maps
between the variables of the two formulae.
|
Formula |
negate() |
static String |
postProcess(String s)
Remove the 'holds' prefix wherever it appears.
|
void |
read(String s)
Read a String into the variable 'theFormula'.
|
Formula |
rename(String term2,
String term1)
Replace term2 with term1
|
protected Formula |
renameVariableArityRelations(KB kb,
TreeMap<String,String> relationMap) |
Formula |
replaceQuantifierVars(String quantifier,
List<String> vars) |
Formula |
replaceVar(String v,
String term)
Replace v with term.
|
void |
setIsComputed(boolean val)
Sets the value of isComputed to val.
|
void |
setSourceFile(String filename) |
Formula |
substituteVariables(Map<String,String> m)
Replace variables with a value as given by the map argument
|
static void |
testBigArgs()
A test method.
|
static void |
testClausifier(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 String |
textFormat(String input)
Format a formula for text presentation.
|
String |
toProlog()
Format a formula as a prolog statement.
|
String |
toString()
Format a formula for text presentation.
|
boolean |
unifyWith(Formula f)
Compares this formula with the parameter by trying to compare the predicate structure of th two and logically
unify their variables.
|
String |
validArgs()
Test whether the Formula uses logical operators and predicates
with the correct number of arguments.
|
String |
validArgs(String filename,
Integer lineNo)
Test whether the Formula uses logical operators and predicates
with the correct number of arguments.
|
protected static final String AND
protected static final String OR
protected static final String NOT
protected static final String IF
protected static final String IFF
public static final String UQUANT
public static final String EQUANT
protected static final String EQUAL
protected static final String GT
protected static final String GTET
protected static final String LT
protected static final String LTET
protected static final String KAPPAFN
protected static final String PLUSFN
protected static final String MINUSFN
protected static final String TIMESFN
protected static final String DIVIDEFN
protected static final String SKFN
protected static final String SK_PREF
protected static final String FN_SUFF
protected static final String V_PREF
protected static final String R_PREF
protected static final String VX
protected static final String VVAR
protected static final String RVAR
protected static final String LP
protected static final String RP
protected static final String SPACE
protected static final String LOG_TRUE
protected static final String LOG_FALSE
protected String sourceFile
public int startLine
public int endLine
public long endFilePosition
public String theFormula
public static final String termMentionSuffix
public static final String classSymbolSuffix
public static final String termSymbolPrefix
public static final String termVariablePrefix
public ArrayList<String> theTptpFormulas
protected static final int MAX_PREDICATE_ARITY
public Formula(Formula f)
public Formula()
public Formula(String f)
public String getLineSeparator()
public String getSourceFile()
public void setSourceFile(String filename)
public boolean getIsComputed()
public void setIsComputed(boolean val)
public ArrayList<String> getTheTptpFormulas()
public void clearTheTptpFormulas()
public ArrayList getTheClausalForm()
public void clearTheClausalForm()
public ArrayList getClauses()
public HashMap getVarMap()
public void read(String s)
public static String integerToPaddedString(int i, int digits)
public String createID()
public Formula copy()
public Formula deepCopy()
public int compareTo(Object f) throws ClassCastException
compareTo in interface ComparableClassCastExceptionpublic boolean isBalancedList()
public String car()
public String cdr()
public Formula cons(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 String cadr()
public String cddr()
public Formula cddrAsFormula()
public String caddr()
public Formula append(Formula f)
public static boolean atom(String s)
public boolean atom()
public boolean empty()
public static boolean empty(String s)
public boolean listP()
public static boolean listP(String s)
public String validArgs(String filename, 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 String validArgs()
public String badQuantification()
public boolean logicallyEquals(String s)
public int hashCode()
public boolean equals(Object o)
public boolean equals(String s)
public boolean logicallyEquals(Formula f)
f - public boolean unifyWith(Formula f)
f - public static List<Set<com.articulate.sigma.Formula.VariableMapping>> mapFormulaVariables(Formula f1, Formula f2, KB kb, HashMap<FormulaUtil.FormulaMatchMemoMapKey,List<Set<com.articulate.sigma.Formula.VariableMapping>>> memoMap)
f1 - f2 - kb - memoMap - a memo-ization mechanism designed to reduce the number of recursive calls in "dynamic programming"
fashionpublic boolean deepEquals(Formula f)
public String getArgument(int argnum)
public int listLength()
public ArrayList<String> argumentsToArrayList(int start)
public ArrayList<String> complexArgumentsToArrayList(int start)
public ArrayList<ArrayList<String>> collectVariables()
public ArrayList<ArrayList<String>> collectQuantifiedUnquantifiedVariables()
public void collectQuantifiedUnquantifiedVariablesRecurse(Formula f, HashMap<String,Boolean> varFlag, HashSet<String> unquantifiedVariables, HashSet<String> quantifiedVariables)
public Set<String> collectAllVariables()
public ArrayList<String> collectExistentiallyQuantifiedVariables()
public ArrayList<String> collectQuantifiedVariables()
public ArrayList<String> collectUnquantifiedVariables()
public Formula substituteVariables(Map<String,String> m)
public String makeQuantifiersExplicit(boolean query)
query - controls whether to add universal or existential
quantification. If true, add existential.protected Formula renameVariableArityRelations(KB kb, TreeMap<String,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 HashMap<String,ArrayList> gatherRelationsWithArgTypes(KB kb)
public HashSet<String> gatherRelationConstants()
public boolean isFunctionalTerm()
public static boolean isFunctionalTerm(String s)
public boolean isHigherOrder()
public static boolean isVariable(String term)
public boolean isVariable()
public boolean isCached()
public boolean isRule()
public boolean isHorn()
public static boolean isQuantifierList(String listPred, String previousPred)
public boolean isSimpleClause()
public boolean isSimpleNegatedClause()
public static boolean isQuantifier(String pred)
public boolean isExistentiallyQuantified()
public boolean isUniversallyQuantified()
public static boolean isCommutative(String obj)
obj - Any object, but should be a String.protected static String getDualOperator(String op)
op - A String, assumed to be a SUO-KIF logical operatorpublic static boolean isLogicalOperator(String term)
term - A String, assumed to be an atomic SUO-KIF term.public static boolean isTerm(String term)
term - A String, assumed to be an atomic SUO-KIF term.public static boolean isComparisonOperator(String term)
term - A String.public static boolean isMathFunction(String term)
term - A String.public static boolean isGround(String form)
public boolean isGround()
public static boolean isFunction(String term)
term - A String.public static boolean isSkolemTerm(String term)
term - A String.public ArrayList<String> literalToArrayList()
public Formula replaceVar(String v, String term)
public Formula replaceQuantifierVars(String quantifier, List<String> vars) throws Exception
Exceptionpublic static boolean isQuery(String query, String formula)
public static boolean isNegatedQuery(String query, String formulaString)
public static String postProcess(String s)
public String format(String hyperlink, String indentChars, 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 String toString()
public String toProlog()
public static void testClausifier(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(String[] args)
public Formula negate()
Copyright © 2015. All rights reserved.