public class Rule extends Object implements Serializable, Comparable<Rule>
A rule consists of a parent state, a label (or terminal symbol),
an array of child states, and a weight. The states and labels are
represented as int values for efficiency reasons; they can be
resolved to human-readable values by looking them up using
TreeAutomaton.getStateForId(int)
(for states) or
Signature.resolveSymbolId(int)
using the tree
automaton's signature (for labels).
In order to create new rule objects, do not instantiate
Rules directly. Instead, call TreeAutomaton.createRule(java.lang.Object, java.lang.String, java.util.List)
or one of its variants. This gives the containing TreeAutomaton
a chance to update its internal data structures if necessary.
If it is not specified, the weight is set to 1.0. You can
destructively modify a rule's weight; this is useful, for instance,
in implementing the EM algorithm. As a consequence, equals(java.lang.Object)
and hashCode()
ignore the weight, i.e. a rule remains equals
to itself after you change the weight.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Rule o) |
boolean |
equals(Object obj)
Compares two rules for equality.
|
static Collection<Integer> |
extractParentStates(Collection<Rule> rules) |
int |
getArity() |
int[] |
getChildren() |
Object |
getExtra()
Retrieves the auxiliary information from this rule.
|
int |
getLabel() |
String |
getLabel(TreeAutomaton auto) |
int |
getParent() |
double |
getWeight() |
int |
hashCode() |
boolean |
isLoop() |
static List<String> |
rulesToStrings(Collection<Rule> rules,
TreeAutomaton auto) |
void |
setExtra(Object extra)
Stores auxiliary information within this rule.
|
void |
setWeight(double weight) |
String |
toString() |
String |
toString(TreeAutomaton auto) |
String |
toString(TreeAutomaton auto,
boolean parentIsFinal) |
public int[] getChildren()
public int getLabel()
public String getLabel(TreeAutomaton auto)
public int getParent()
public double getWeight()
public void setWeight(double weight)
public Object getExtra()
setExtra(java.lang.Object)
public void setExtra(Object extra)
extra
- public int getArity()
public String toString(TreeAutomaton auto)
public String toString(TreeAutomaton auto, boolean parentIsFinal)
public static List<String> rulesToStrings(Collection<Rule> rules, TreeAutomaton auto)
public boolean equals(Object obj)
public int compareTo(Rule o)
compareTo
in interface Comparable<Rule>
public static Collection<Integer> extractParentStates(Collection<Rule> rules)
public boolean isLoop()
Copyright © 2017. All rights reserved.