public class Clausifier
extends java.lang.Object
Constructor and Description |
---|
Clausifier(java.lang.String s) |
Modifier and Type | Method and Description |
---|---|
Formula |
clausify()
This method converts the SUO-KIF Formula to a version of
clausal (resolution, conjunctive normal) form with Skolem
functions, following the procedure described in Logical
Foundations of Artificial Intelligence, by Michael Genesereth
and Nils Nilsson, 1987, pp.
|
static Formula |
clausify(Formula f)
convenience method
|
java.util.ArrayList |
clausifyWithRenameInfo()
Note this returns a List of mixed types! Fixme!
|
static java.util.Set<java.lang.String> |
extractVariables(Formula f)
Extract all variables in a list
|
static java.lang.String |
getOriginalVar(java.lang.String var,
java.util.Map<java.lang.String,java.lang.String> varMap)
This method finds the original variable that corresponds to a new
variable.
|
Formula |
instantiateVariables()
Create constants to fill variables.
|
static void |
main(java.lang.String[] args) |
protected static java.lang.String |
normalizeVariables_1(java.lang.String input,
int[] idxs,
java.util.Map vmap,
boolean replaceSkolemTerms)
An internal helper method for normalizeVariables(String input).
|
static java.lang.String |
normalizeVariables(java.lang.String input)
Returns a String in which all variables and row variables have
been normalized -- renamed, in depth-first order of occurrence,
starting from index 1 -- to support comparison of Formulae for
equality.
|
protected static java.lang.String |
normalizeVariables(java.lang.String input,
boolean replaceSkolemTerms)
Returns a String in which all variables and row variables have
been normalized -- renamed, in depth-first order of occurrence,
starting from index 1 -- to support comparison of Formulae for
equality.
|
Formula |
rename(java.lang.String term2,
java.lang.String term1)
Replace term2 with term1
|
static Formula |
renameVariables(Formula f)
convenience method
|
static Formula |
renameVariables(Formula f,
java.util.Map topLevelVars,
java.util.Map scopedRenames,
java.util.Map allRenames)
convenience method
|
java.util.ArrayList<Formula> |
separateConjunctions()
Turn a conjunction into an ArrayList of separate statements
|
static java.util.ArrayList<Formula> |
separateConjunctions(Formula f)
convenience method
|
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 |
test1()
A test method.
|
static void |
testClausifier(java.lang.String[] args)
A test method.
|
Formula |
toCanonicalClausalForm()
This method converts the SUO-KIF Formula to a canonical version
of clausal (resolution, conjunctive normal) form with Skolem
functions, following the procedure described in Logical
Foundations of Artificial Intelligence, by Michael Genesereth
and Nils Nilsson, 1987, pp.
|
static Formula |
toCanonicalClausalForm(Formula f)
convenience method
|
protected Formula |
toCanonicalKifSpecialForm(boolean preserveSharedVariables)
This method returns a canonical version of this Formula,
assumed to be a KIF "special" form, in which all internal
first-order KIF formulae are replaced by their canonical
versions, and all variables are renamed, in left to right
depth-first order of occurrence, starting from index 1.
|
java.util.ArrayList |
toNegAndPosLitsWithRenameInfo()
TODO: Note mixed types in return List! Fixme!
This method converts the SUO-KIF Formula to an ArrayList of
clauses.
|
static java.util.ArrayList |
toNegAndPosLitsWithRenameInfo(Formula f)
convenience method
|
protected Formula |
toOpenQueryForNegatedDualForm()
This method returns an open Formula that constitutes a KIF
query expression, which is generated from the canonicalized
negation of the original Formula.
|
java.lang.String |
toString() |
static Formula |
universalsOut(Formula f)
convenience method
|
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.ArrayList<Formula> separateConjunctions()
public static java.util.ArrayList<Formula> separateConjunctions(Formula f)
public java.util.ArrayList clausifyWithRenameInfo()
clausify()
,
toNegAndPosLitsWithRenameInfo()
,
toCanonicalClausalForm();
public java.util.ArrayList toNegAndPosLitsWithRenameInfo()
clausify()
,
clausifyWithRenameInfo()
,
toCanonicalClausalForm();
public static java.util.ArrayList toNegAndPosLitsWithRenameInfo(Formula f)
public Formula toCanonicalClausalForm()
clausify()
,
clausifyWithRenameInfo()
,
toNegAndPosLitsWithRenameInfo()
protected Formula toOpenQueryForNegatedDualForm()
This method returns an open Formula that constitutes a KIF query expression, which is generated from the canonicalized negation of the original Formula. The original Formula is assumed to be a "rule", having both positive and negative literals when converted to canonical clausal form. This method returns a query expression that can be used to test the validity of the original Formula. If the query succeeds (evaluates to true, or retrieves variable bindings), then the negation of the original Formula is valid, and the original Formula must be invalid.
Note that this method will work reliably only for standard first order KIF expressions, and probably will not produce expected (or sane) results if used with non-standard KIF.
Formula.toCanonicalClausalForm()
protected Formula toCanonicalKifSpecialForm(boolean preserveSharedVariables)
Formula.toCanonicalClausalForm()
.preserveSharedVariables
- If true, all variable sharing
between embedded expressions will be preserved, even though all
variables will still be renamed as part of the canonicalization
processFormula.toCanonicalClausalForm()
public static java.lang.String normalizeVariables(java.lang.String input)
input
- A String representing a SUO-KIF Formula, possibly
containing variables to be normalizednormalizeVariables_1();
protected static java.lang.String normalizeVariables(java.lang.String input, boolean replaceSkolemTerms)
input
- A String representing a SUO-KIF Formula, possibly
containing variables to be normalizedreplaceSkolemTerms
- If true, all Skolem terms in input
are treated as variables and are replaced with normalized
variable termsnormalizeVariables_1();
protected static java.lang.String normalizeVariables_1(java.lang.String input, int[] idxs, java.util.Map vmap, boolean replaceSkolemTerms)
input
- A String possibly containing variables to be
normalizedidxs
- A two-place int[] in which int[0] is the current
variable index, and int[1] is the current row variable indexvmap
- A Map in which the keys are old variables and the
values are new variablesnormalizeVariables();
public Formula rename(java.lang.String term2, java.lang.String term1)
public Formula substituteVariables(java.util.Map<java.lang.String,java.lang.String> m)
public static java.util.Set<java.lang.String> extractVariables(Formula f)
public Formula instantiateVariables()
public static Formula renameVariables(Formula f, java.util.Map topLevelVars, java.util.Map scopedRenames, java.util.Map allRenames)
public static java.lang.String getOriginalVar(java.lang.String var, java.util.Map<java.lang.String,java.lang.String> varMap)
var
- A SUO-KIF variable (String)varMap
- A Map (graph) of successive new to old variable
correspondences.public Formula clausify()
A literal is an atomic formula. (Note, however, that because SUO-KIF allows higher-order formulae, not all SUO-KIF literals are really atomic.) A clause is a disjunction of literals that share no variable names with literals in any other clause in the KB. Note that even a relatively simple SUO-KIF formula might generate multiple clauses. In such cases, the Formula returned will be a conjunction of clauses. (A KB is understood to be a conjunction of clauses.) In all cases, the Formula returned by this method should be a well-formed SUO-KIF Formula if the input (original formula) is a well-formed SUO-KIF Formula. Rendering the output in true (LISPy) clausal form would require an additional step, the removal of all commutative logical operators, and the result would not be well-formed SUO-KIF.
clausifyWithRenameInfo()
,
toNegAndPosLitsWithRenameInfo()
,
toCanonicalClausalForm();
public static void test1()
public static void testClausifier(java.lang.String[] args)
public static void main(java.lang.String[] args)