public class ParseTree
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ParseTree.RPNStep
Stores backreference information in "packed" and "compressed" formats.
|
Constructor and Description |
---|
ParseTree()
Constructor - default, creates empty ParseTree.
|
ParseTree(ParseNode root)
Constructor - creates ParseTree using a ParseNode root.
|
ParseTree(ParseTree.RPNStep[] rpn)
Build a ParseTree from an RPN Stmt array.
|
Modifier and Type | Method and Description |
---|---|
ParseTree.RPNStep[] |
convertToRPN() |
ParseTree.RPNStep[] |
convertToRPN(boolean pressLeaf) |
ParseTree.RPNStep[] |
convertToRPNExpanded()
Convert ParseTree to RPN Stmt array.
|
int |
countParseNodes(boolean expanded)
Count parse nodes in a ParseTree.
|
ParseTree |
deepClone()
(Deep) Clone a ParseTree.
|
ParseTree |
deepCloneApplyingAssrtSubst(Hyp[] assrtHypArray,
ParseNode[] assrtSubst)
(Deep) Clone a ParseTree while substituting a set of VarHyp substitutions
specified by a parallel Hyp array.
|
ParseTree |
deepCloneApplyingAssrtSubst(Hyp[] assrtHypArray,
ParseNode[] assrtSubst,
java.util.List<WorkVar> workVarList)
(Deep) Clone a ParseTree while substituting a set of VarHyp substitutions
specified by a parallel Hyp array and keeping count of the number of
dummy VarHyp substitutions.
|
ParseTree |
deepCloneApplyingWorkVarUpdates()
(Deep) Clone a ParseTree while substituting a set of Work Var updates.
|
ParseTree |
deepCloneWNodeSub(ParseNode matchNode,
ParseNode substNode)
(Deep) Clone a ParseTree while substituting a given node with another.
|
ParseNode |
findChildVarHypNode(int childIndex)
Finds first VarHyp within parseTree.root.child[i].
|
java.lang.String |
getLevelOneTwo()
Computes the levelOneTwo string (key) value after calculating it if the
answer is not already known.
|
int |
getMaxDepth()
Gets the maximum depth of the tree after calculating it if the answer is
not already known.
|
ParseNode |
getRoot()
Return root of tree.
|
boolean |
isDup(int parseCount,
ParseTree[] parseTreeArray)
Check ParseTree array for duplicates.
|
boolean |
isDup(ParseTree parseTree)
Check another ParseTree for duplication.
|
void |
resetLevelOneTwo()
Resets the levelOneTwo string key value to the default value;
|
void |
resetMaxDepth()
Resets the maximum depth of the tree to the initial value.
|
static Serializer<ParseTree> |
serializer(java.util.Map<java.lang.String,Stmt> stmtTbl) |
void |
setRoot(ParseNode root)
Set root of tree.
|
ParseTree |
squishTree()
Compresses ("squishes") the tree to re-use repeated subtrees.
|
java.lang.String |
toString()
Converts a ParseTree to a String consisting of Stmt labels in RPN order.
|
public ParseTree()
public ParseTree(ParseNode root)
root
- the root nodepublic ParseTree(ParseTree.RPNStep[] rpn)
Note: A Metamath proof may contain a "?" to indicate a missing step. Missing steps are stored in mmj.lang.Theorem.proof[] as a "null" stmt reference. --> if rpn[i] == null, throw IllegalArgumentException
rpn
- Stmt array, may be parse or proof RPN.java.lang.IllegalArgumentException
- if ParseTree cannot be built from the
RPN (null statment or RPN incomplete.)public ParseNode getRoot()
public void setRoot(ParseNode root)
root
- of tree.public boolean isDup(int parseCount, ParseTree[] parseTreeArray)
No longer used, except in BottomUpParser.
parseCount
- number of trees in array.parseTreeArray
- array of trees.public boolean isDup(ParseTree parseTree)
No longer used, except in BottomUpParser.
parseTree
- tree to compare.public ParseTree deepClone()
public ParseTree deepCloneWNodeSub(ParseNode matchNode, ParseNode substNode)
matchNode
- node to replace.substNode
- new node to substitute.public ParseTree deepCloneApplyingAssrtSubst(Hyp[] assrtHypArray, ParseNode[] assrtSubst, java.util.List<WorkVar> workVarList)
This function is a helper for mmj.pa.ProofUnifier.
assrtHypArray
- parallel array for assrtSubstassrtSubst
- array of ParseNode sub-tree roots specifying hyp
substitutions.workVarList
- arrayList of WorkVar updated to contain set of Work
Vars used in the subtree. substituted into the output.public ParseTree deepCloneApplyingAssrtSubst(Hyp[] assrtHypArray, ParseNode[] assrtSubst)
assrtHypArray
- parallel array for assrtSubstassrtSubst
- array of ParseNode sub-tree roots specifying hyp
substitutions.public ParseTree deepCloneApplyingWorkVarUpdates()
This function is a helper for mmj.pa.ProofUnifier.
public ParseNode findChildVarHypNode(int childIndex)
This feat is useful for GrammarRule parse trees, which contain at most one VarHyp per root.child[i].
childIndex
- index into ParseNode.child array.public ParseTree.RPNStep[] convertToRPNExpanded()
Notes on algorithm:
public ParseTree squishTree()
public ParseTree.RPNStep[] convertToRPN()
public ParseTree.RPNStep[] convertToRPN(boolean pressLeaf)
public int countParseNodes(boolean expanded)
If root is null, count = zero.
expanded
- true to count repeated subtrees multiple times, false to
count them as size 1 stubs in subsequent occurrencespublic int getMaxDepth()
public void resetMaxDepth()
public java.lang.String getLevelOneTwo()
public void resetLevelOneTwo()
public java.lang.String toString()
Note: this can fail if the ParseTree is invalid. Intended for testing/diagnostic use.
toString
in class java.lang.Object
public static Serializer<ParseTree> serializer(java.util.Map<java.lang.String,Stmt> stmtTbl)