|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--moses.controlState.Term
The LGI control state is a Prolog-like bag of terms. The Term class is designed to store such a term, and the control state itself is represented through a Term object. The terms have a tree-like structure: a certain term can be composed of other (sub)terms.
A Term object contains:
Structurally, a term object is composed of a type field, a number of value fields, and a vector field. The type field determines how the value fields and vector fields are to be interpreted.
The following types are available:
Term lt = Term.parse("[role(chair,ceo),department(3),active]");
if(lt.has("role(chair,%B)")) {
//true if the first role is "chair"; the second role is neutral
....
}
UnifyResult dep = lt.find("department(%N)");
Term dept = dep.getTerm(); //returns the whole department term
Term depno = dep.getTVar("N"); //returns the number of the department
The example above shows the usage of the high-level API for this object. The low-level API is to be used in application where performance is a concern.
| Field Summary | |
static int |
CType
Non-atomic compound type term. |
static int |
FType
Atomic float type term. |
java.lang.String |
functor
This field has double purpose: in the case of SType terms, it holds the value of this term. |
float |
FValue
This field maintains the float value of a FType term. |
static int |
IType
Atomic integer type term. |
int |
IValue
This field maintains the integer value of a IType term. |
static int |
LType
Non-atomic list type term. |
static int |
SType
Atomic String type term. |
int |
type
This field maintains the type of this Term. |
java.util.Vector |
VValue
This field maintains the sub terms of this term in the case of CType and LType terms. |
| Constructor Summary | |
Term(double dvalue)
Constructor that builds an FType term out of a double value. |
|
Term(float fvalue)
Constructor that builds an FType term out of a float value. |
|
Term(int ivalue)
Constructor that builds an IType term out of an int value. |
|
Term(java.lang.String svalue)
Constructor that builds an SType term out of a String value. |
|
Term(java.lang.String functor,
int type)
Constructor that builds a term object given a functor and its type. |
|
| Method Summary | |
moses.controlState.Term |
addST(moses.controlState.Term term)
This method adds a (sub) term to the VValue vector. |
void |
addSubTerm(moses.controlState.Term term)
This method adds a (sub) term to the VValue vector. |
void |
appToStringBuff(java.lang.StringBuffer sbuf)
Helper method, not intended to be used directly. |
moses.controlState.Term |
deep_clone()
Deep cloning method: creates a deep copy of this object and returns it. |
boolean |
deep_equals(java.lang.Object obj)
Deep implementation of the equals() method. |
boolean |
deep_equals1(java.lang.Object obj)
The same method as deep_equal, except that each operand is transformed to a string then the comparison is made using String.equals() method (see the mishaps pointed out before, though) Performance wise, it seems more than 5 times slower than the previous implementation. |
int |
fetchInt(java.lang.String functor)
This method searches in this compound or list term for a term with a functor that equals the argument, and whose only sub term is an integer. |
moses.controlState.UnifyResult |
find(java.lang.String sterm)
This method is the same method as findST(Term t) above, overloaded with String argument. |
moses.controlState.UnifyResult |
find(moses.controlState.Term t)
This method is the same method as findST(Term t) above, overloaded with a more suggestive name. It tries to find a sub term of this compound term (CType or LType) that matches (unifies) the argument. |
moses.controlState.UnifyResult |
findST(moses.controlState.Term t)
This method tries to find a sub term of this compound term (CType or LType) that matches (unifies) the argument. |
moses.controlState.Term |
findT(java.lang.String sterm)
Finds a term or a pattern of a term in a compound term or a list, and returns it. |
moses.controlState.Term |
findT(moses.controlState.Term t)
This method is the same as above findT(String sterm), except it is overloaded with a Term type argument. |
moses.controlState.Term |
get(int index)
This method retrieves the sub term in VValue vector at position index. |
int |
getArity()
This method returns the arity of this compound or list-type term. |
static moses.controlState.Term |
getATerm(java.lang.String afunctor)
This method creates a atomic Term out of a given string argument. |
float |
getFloat()
Getter method, it retrieves the FValue of this term. |
java.lang.String |
getFunctor()
Getter method, it retrieves the functor of this term. |
int |
getInteger()
Getter method, it retrieves the IValue field of this term. |
moses.controlState.Term |
getSubTerm(int index)
This method retrieves the sub term in VValue vector at position index. |
static moses.controlState.Term |
getTerm(java.lang.String sTerm)
This method parses a string into a term. |
int |
getType()
Getter method, it retrieves the type of this term. |
java.util.Vector |
getVector()
Getter method, it retrieves the VValue vector in this term. |
boolean |
has(java.lang.String st)
This method searches for the pattern argument within this term. |
boolean |
has(moses.controlState.Term t)
The same as above, except that it is overloaded with a term type argument. |
boolean |
incrementable()
This method verifies that a term is of incrementable form (of compound type, with exactly one sub term, which is of type IType or FType). |
static void |
main(java.lang.String[] args)
|
static moses.controlState.Term |
parse(java.lang.String sTerm)
This method is the same as getTerm(String sTerm), overloaded with a friendlier, more suggestive name. |
void |
setFloat(float fvalue)
This method sets the FValue field of this object directly. |
void |
setFunctor(java.lang.String functor)
This method sets the functor field of this object directly. |
void |
setInteger(int ivalue)
This method sets the IValue field of this object directly. |
void |
setSubTerm(int index,
moses.controlState.Term term)
This method sets (replaces) the component at position index of the VValue field to the term argument. |
java.lang.String |
toString()
This method transforms a Term object into its string representation. |
java.lang.String |
toString1()
Testing/helper method: it transforms this term into a string representation. |
moses.controlState.UnifyResult |
unify(moses.controlState.Term t1)
Method that unifies this term with a given argument. |
boolean |
unify(moses.controlState.Term t1,
java.util.Hashtable symbols)
Helper method. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public int type
public java.lang.String functor
public int IValue
public float FValue
public java.util.Vector VValue
public static final int SType
public static final int IType
public static final int FType
public static final int LType
public static final int CType
| Constructor Detail |
public Term(int ivalue)
ivalue - represents the integer value of this termpublic Term(float fvalue)
fvalue - represents the float value of this termpublic Term(double dvalue)
dvalue - represents the value (truncated to float) of this termpublic Term(java.lang.String svalue)
svalue - represents the String value of this term
public Term(java.lang.String functor,
int type)
Note that in the last case, the constructor leaves the object in a somehow incomplete state, since a compound term usually (and normally) requires at least one sub term.
functor - represents the value of this term according to the above rules.type - represents the type of the term.| Method Detail |
public void setFunctor(java.lang.String functor)
functor - represents the new value of the functor.public void setInteger(int ivalue)
ivalue - represents the new value of the IValue field.public void setFloat(float fvalue)
fvalue - represents the new value of the field.public void addSubTerm(moses.controlState.Term term)
term - represents the term to add as a sub term to VValue.addST(Term term)public moses.controlState.Term addST(moses.controlState.Term term)
term - represents the term to add as a sub term to VValue.addSubTerm(Term term)
public void setSubTerm(int index,
moses.controlState.Term term)
index - represents the position in VValue to replace.term - represents the term to replace in VValue field.public int getType()
public java.lang.String getFunctor()
public int getInteger()
public float getFloat()
public moses.controlState.Term getSubTerm(int index)
index - represents the position of the sub term to retrieve.
get(int index)public moses.controlState.Term get(int index)
index - represents the position of the sub term to retrieve.
getSubTerm(int index)public int getArity()
public java.util.Vector getVector()
public static moses.controlState.Term getATerm(java.lang.String afunctor)
Since exception handling is expensive, in order to avoid parsing exceptions, the method is optimized as follows: if the first character is a number, try to parse it to an integer. If the parsing fails, try a parsing to a float. If none of the parsing works or the first character is not a number, store the term as string.
afunctor - represents the value of the atomic term to be parsed.
public java.lang.String toString1()
public void appToStringBuff(java.lang.StringBuffer sbuf)
sbuf - represents the StringBuffer destination where to append this term.public java.lang.String toString()
toString in class java.lang.Objectparse(String sTerm)public boolean deep_equals(java.lang.Object obj)
obj - represents a Term type object that is to be compared to this term.
public boolean deep_equals1(java.lang.Object obj)
When a term is to be compared to a String, the deep_equals methods are to be avoided. Instead, it is more efficient to transform the term into a string and then compare the strings, rather than parse the string into a term then deep compare the terms. Parse methods are way slower than toString methods.
obj - represents a Term type object that is to be compared to this term.
deep_equals(Object obj)public moses.controlState.Term deep_clone()
public moses.controlState.UnifyResult unify(moses.controlState.Term t1)
Example:
t1(t2(3),t4) will unify with t1(%A,%B) and the bindings will be %A is t2(3)
and %B is t4. The variables will be denominated by % symbol followed by the variable name
(case insensitive), where "%" symbol is defined in UnifyResult class.
If this term contains VAR("%") variables, then they will be treated as legitimate
symbols from the term, and no binding attempt will be made against them.
The method is robust with respect to argument t1 (the method verifies whether the
argument is null).
t1 - represents a pattern to match this term against. This pattern is a term that has so-called
variables instead of sub terms. The variables are denominated by a '%' symbol preceding the name
of the variable.
public boolean unify(moses.controlState.Term t1,
java.util.Hashtable symbols)
The recursive unification function. It takes as argument the
term against whom this term is compared with, and a hashtable with
symbols already bound to proper terms.
If the argument is a
string-type argument and it is a VAR("%") symbol, the
binding is saved in the hashtable argument (unless a binding
for that symbol already existed and it is not a match - in
which case the method nicely fails ).
Otherwise, if the term
is an atomic term (string int float), a deep comparison is
attempted against this term.
If the argument is a compound
type (Ctype or list), a matching of the functor is attempted
and after that, this method is called recursively on each
of the sub terms of this term, with the args each of the
sub terms of the arg term and the same hashtable.
t1 - the term containing the pattern to compare against.symbols - represents a hashtable containing variable to value bindings
that have been matched so far.
unify(Term t1)public moses.controlState.UnifyResult findST(moses.controlState.Term t)
t - represents the term containing the pattern to be searched inside this term.
public moses.controlState.UnifyResult find(java.lang.String sterm)
sterm - represents the string containing the pattern to be searched inside this term.
findST(Term t)public moses.controlState.UnifyResult find(moses.controlState.Term t)
t - represents the term containing the pattern to be searched inside this term.
findST(Term t)public static moses.controlState.Term getTerm(java.lang.String sTerm)
sTerm - represents the string to be parsed into a term.
public static moses.controlState.Term parse(java.lang.String sTerm)
sTerm - represents the string to be parsed into a term.
getTerm(String sTerm)public boolean has(java.lang.String st)
st - represents the string containing the pattern to be searched for.
has(Term t)public boolean has(moses.controlState.Term t)
t - represents the term containing the pattern to be searched for.
has(String st)public moses.controlState.Term findT(java.lang.String sterm)
sterm - represents the string containing the pattern to be searched for.
findT(Term t),
has(String st)public moses.controlState.Term findT(moses.controlState.Term t)
t - represents the term containing the pattern to be searched for.
findT(String sterm),
has(Term t)public int fetchInt(java.lang.String functor)
functor - represents the functor to be searched for.
public boolean incrementable()
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||