ua.gradsoft.termware
Class AttributedTerm

java.lang.Object
  extended by ua.gradsoft.termware.Term
      extended by ua.gradsoft.termware.AttributedTerm
All Implemented Interfaces:
Serializable, Cloneable, Attributed

public class AttributedTerm
extends Term
implements Attributed

Term with attributes.

Author:
Ruslan Shevchenko
See Also:
Serialized Form

Constructor Summary
AttributedTerm(Term t)
           
AttributedTerm(Term term, Map<String,Term> attributes)
           
 
Method Summary
 boolean boundEquals(Term x)
          equality, when propositional variables are already bounded.
 boolean boundUnify(Term t, Substitution s)
          unification when we already have s and when same propositional variables means same things
 PartialOrderingResult concreteOrder(Term x, Substitution s)
          compare for 'more concrete' relation.
 Term createSame(Term[] newBody)
          create term, with same name but new body.
 boolean emptyFv()
          true, if term does not contains free propositional variables.
 int findSubtermIndexBoundEqualsTo(Term x)
           
 boolean freeEquals(Term x)
          Equality when all propositional variables are equal
 boolean freeUnify(Term t, Substitution s)
          do unification of this and t and store in s substitution.
 int getArity()
          get arity (i.
 BigDecimal getAsBigDecimal(TermWareInstance instance)
          get BigDecimal value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException
 BigInteger getAsBigInteger(TermWareInstance instance)
          get BigInteger value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException
 boolean getAsBoolean(TermWareInstance instance)
          get boolean value, if this term can be converted to boolean
 byte getAsByte(TermWareInstance instance)
          get Byte value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException
 char getAsChar(TermWareInstance instance)
          get char value.
 double getAsDouble(TermWareInstance instance)
          get double value, if this term represent some number, otherwise throw ConversionException
 float getAsFloat(TermWareInstance instance)
          get float value, if this term represent some number, otherwise throw ConversionException
 int getAsInt(TermWareInstance instance)
          get integer value, if this term represent some number, otherwise throw ConversionException
 Object getAsJavaObject(TermWareInstance instance)
           
 long getAsLong(TermWareInstance instance)
          get long value, if this term represent some number, otherwise throw ConversionException
 Number getAsNumber(TermWareInstance instance)
           
 short getAsShort(TermWareInstance instance)
          get short value, if this term represent some number, otherwise throw ConversionException
 Term getAttribute(String attribute)
          get attribute with name name .
 Map<String,Term> getAttributes()
          return map, where keys are attribute names, value - values of attributes.
 BigDecimal getBigDecimal()
          get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException
 BigInteger getBigInteger()
          get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException
 boolean getBoolean()
          get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException
 byte getByte()
          get byte value, if this term represent byte, otherwise throw UnsupportedOperationException
 char getChar()
          get char value, if this term represent char, otherwise throw UnsupportedOperationException
 double getDouble()
          get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.
 float getFloat()
          get float value, if this term represent float, otherwise throw UnsupportedOperationException.
 int getInt()
          get integer value, if this term represent integer, otherwise throw UnsupportedOperationException
 Object getJavaObject()
           
 long getLong()
          get long value, if this term represent long, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to long.
 String getName()
          get name of functional symbol.
 Object getNameIndex()
          get index of name in instance symbol table.
 Number getNumber()
          get numeric value, if this term represent number, otherwise throw UnsupportedOperationException
 String getPatternName()
          return name of pattern, for which unification is applicable.
 Object getPatternNameIndex()
          return index of pattern name.
 int getPrimaryType0()
          return code of level-0 primary type
 short getShort()
          get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short.
 String getString()
          get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException
 Term getSubtermAt(int i)
          get subterm of current term.
 Term getTerm()
          get term.
 int getXIndex()
          if this variable is a propositional variable, return index of one.
 boolean isAtom()
          is term is atom ?
 boolean isBigDecimal()
          true, if this term is BigDecimal
 boolean isBigInteger()
          true, if this term is BigInteger
 boolean isBoolean()
          is term is booleam ?
 boolean isByte()
          true, if this term is Byte
 boolean isChar()
          is term is char ?
 boolean isComplexTerm()
          true, if this term have subterms
 boolean isDouble()
          is Term is double ?
 boolean isFloat()
          is Term is float ?
 boolean isInt()
          is term is Int ?
 boolean isJavaObject()
          if this term is Java Object ?
 boolean isLong()
          is Term is long ?
 boolean isNil()
          is term is nil ?
 boolean isNumber()
          is term is Number ?
 boolean isShort()
          is Term is short ?
 boolean isString()
          is Term is string ?
 boolean isX()
          true if this term is propositional variable.
 int maxFv()
          get maximum index of free propositional variable in term
 int minFv()
          get minimal index of free propositional variable in term.
 void print(PrintWriter out)
          print term on out
 void setAttribute(String attribute, Term value)
          set attribute with name name and value value .
 void setSubtermAt(int i, Term t)
          set i-th subterm to t when i < arity then throw IndexOutOfBoundsException
 void shiftFv(int newMinFv)
          renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv
 Term subst(Substitution s)
          receive new term, which is sibstution of current term and s
 boolean substInside(Substitution s)
          apply substitution s to current term.
 Term termClone()
          deep clone of term.
 int termCompare(Term x)
          compare functions.
 Term unAttribute()
           
 
Methods inherited from class ua.gradsoft.termware.Term
containsSubtermBoundEqualsTo, getAsString, getPrimaryType1, print, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributedTerm

public AttributedTerm(Term term,
                      Map<String,Term> attributes)

AttributedTerm

public AttributedTerm(Term t)
Method Detail

boundEquals

public boolean boundEquals(Term x)
                    throws TermWareException
Description copied from class: Term
equality, when propositional variables are already bounded.

Specified by:
boundEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are bound-equals.
Throws:
TermWareException

boundUnify

public boolean boundUnify(Term t,
                          Substitution s)
                   throws TermWareException
Description copied from class: Term
unification when we already have s and when same propositional variables means same things

Specified by:
boundUnify in class Term
Throws:
TermWareException

createSame

public Term createSame(Term[] newBody)
                throws TermWareException
Description copied from class: Term
create term, with same name but new body. If this term have arity 0, or other than original - throws exception.

Specified by:
createSame in class Term
Throws:
TermWareException

emptyFv

public boolean emptyFv()
Description copied from class: Term
true, if term does not contains free propositional variables. (fv-set for this term is empty.)

Specified by:
emptyFv in class Term
Returns:
true, if fv_set does not contains free proporsitional variables.

freeEquals

public boolean freeEquals(Term x)
                   throws TermWareException
Description copied from class: Term
Equality when all propositional variables are equal

Specified by:
freeEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are free-equals.
Throws:
TermWareException

freeUnify

public boolean freeUnify(Term t,
                         Substitution s)
                  throws TermWareException
Description copied from class: Term
do unification of this and t and store in s substitution.

Specified by:
freeUnify in class Term
Returns:
true, if unification was succesfull.
Throws:
TermWareException

getArity

public int getArity()
Description copied from class: Term
get arity (i. e. number of subterms)

Specified by:
getArity in class Term
Returns:
arity of term.

getBigDecimal

public BigDecimal getBigDecimal()
                         throws UnsupportedOperationException
Description copied from class: Term
get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException

Specified by:
getBigDecimal in class Term
Returns:
number value
Throws:
UnsupportedOperationException - raised if this term does not represent BigDecimal value.

getAsBigDecimal

public BigDecimal getAsBigDecimal(TermWareInstance instance)
                           throws ConversionException
Description copied from class: Term
get BigDecimal value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Overrides:
getAsBigDecimal in class Term
Returns:
number value
Throws:
ConversionException - is conversion is not possible.

getBigInteger

public BigInteger getBigInteger()
                         throws UnsupportedOperationException
Description copied from class: Term
get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException

Specified by:
getBigInteger in class Term
Returns:
value
Throws:
UnsupportedOperationException - raised if this term does not represent BigInteger value.

getAsBigInteger

public BigInteger getAsBigInteger(TermWareInstance instance)
                           throws ConversionException
Description copied from class: Term
get BigInteger value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Overrides:
getAsBigInteger in class Term
Returns:
number value
Throws:
ConversionException - raised if conversion is impossible.

getBoolean

public boolean getBoolean()
Description copied from class: Term
get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException

Specified by:
getBoolean in class Term
Returns:
boolean value

getAsBoolean

public boolean getAsBoolean(TermWareInstance instance)
                     throws ConversionException
Description copied from class: Term
get boolean value, if this term can be converted to boolean

Overrides:
getAsBoolean in class Term
Throws:
ConversionException

getByte

public byte getByte()
Description copied from class: Term
get byte value, if this term represent byte, otherwise throw UnsupportedOperationException

Specified by:
getByte in class Term
Returns:
value

getAsByte

public byte getAsByte(TermWareInstance instance)
               throws ConversionException
Description copied from class: Term
get Byte value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Overrides:
getAsByte in class Term
Returns:
number value
Throws:
ConversionException - if conversion to byte is impossible.

getChar

public char getChar()
Description copied from class: Term
get char value, if this term represent char, otherwise throw UnsupportedOperationException

Specified by:
getChar in class Term
Returns:
char value

getAsChar

public char getAsChar(TermWareInstance instance)
               throws ConversionException
Description copied from class: Term
get char value. If this term does not represet char then try to transform one to char use instance type conversion routines.

Overrides:
getAsChar in class Term
Throws:
ConversionException

getDouble

public double getDouble()
Description copied from class: Term
get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.

Specified by:
getDouble in class Term
Returns:
double value

getAsDouble

public double getAsDouble(TermWareInstance instance)
                   throws ConversionException
Description copied from class: Term
get double value, if this term represent some number, otherwise throw ConversionException

Overrides:
getAsDouble in class Term
Returns:
double value
Throws:
ConversionException - if conversion is impossible.

getFloat

public float getFloat()
Description copied from class: Term
get float value, if this term represent float, otherwise throw UnsupportedOperationException. Note, that getFloat does not provide conversion of other numeric types (such as double) to float. For this use getAsFloat(ITerm t);

Specified by:
getFloat in class Term
Returns:
float value

getAsFloat

public float getAsFloat(TermWareInstance instance)
                 throws ConversionException
Description copied from class: Term
get float value, if this term represent some number, otherwise throw ConversionException

Overrides:
getAsFloat in class Term
Returns:
float value
Throws:
ConversionException - if conversion is impossible.

getInt

public int getInt()
Description copied from class: Term
get integer value, if this term represent integer, otherwise throw UnsupportedOperationException

Specified by:
getInt in class Term
Returns:
int value

getAsInt

public int getAsInt(TermWareInstance instance)
             throws ConversionException
Description copied from class: Term
get integer value, if this term represent some number, otherwise throw ConversionException

Overrides:
getAsInt in class Term
Returns:
int value
Throws:
ConversionException - if conversion is impossible.

getJavaObject

public Object getJavaObject()
Specified by:
getJavaObject in class Term
Returns:
Java Object, if this term holds opaque Java Object, otherwise throw UnsupportedOperationException

getAsJavaObject

public Object getAsJavaObject(TermWareInstance instance)
                       throws ConversionException
Overrides:
getAsJavaObject in class Term
Throws:
ConversionException

getLong

public long getLong()
Description copied from class: Term
get long value, if this term represent long, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to long. Use getAsLong(TermWareInstance instance) for this purpose.

Specified by:
getLong in class Term
Returns:
short value

getAsLong

public long getAsLong(TermWareInstance instance)
               throws ConversionException
Description copied from class: Term
get long value, if this term represent some number, otherwise throw ConversionException

Overrides:
getAsLong in class Term
Returns:
long value
Throws:
ConversionException - if conversion is impossible.

getName

public String getName()
Description copied from class: Term
get name of functional symbol.

Specified by:
getName in class Term
Returns:
name

getNameIndex

public Object getNameIndex()
Description copied from class: Term
get index of name in instance symbol table. If name is not inde (during unifications names are compared by indexes. This allows to speedup unification process)

Specified by:
getNameIndex in class Term

getPatternName

public String getPatternName()
Description copied from class: Term
return name of pattern, for which unification is applicable. (i. e. if x.getPatternName()="q", than unification is applicable to pattern-name. used for implementing of pattern mathing: for example { x : y } is a pattern for set, where x - element from set, y - rest of set). Name of this term is set_pattern , but pattern name is set

Overrides:
getPatternName in class Term

getPatternNameIndex

public Object getPatternNameIndex()
Description copied from class: Term
return index of pattern name. (If term is adopted to current instance - index in instance symbol table, or just name)

Overrides:
getPatternNameIndex in class Term

getNumber

public Number getNumber()
Description copied from class: Term
get numeric value, if this term represent number, otherwise throw UnsupportedOperationException

Specified by:
getNumber in class Term
Returns:
number value

getAsNumber

public Number getAsNumber(TermWareInstance instance)
                   throws ConversionException
Overrides:
getAsNumber in class Term
Throws:
ConversionException

getPrimaryType0

public int getPrimaryType0()
Description copied from class: Term
return code of level-0 primary type

Specified by:
getPrimaryType0 in class Term
Returns:
code of primary type
See Also:
PrimaryTypes

getShort

public short getShort()
               throws UnsupportedOperationException
Description copied from class: Term
get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short. Use ITermHelper.getAsShort(ITerm t, TermWareInstance instance) for this purpose.

Specified by:
getShort in class Term
Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getAsShort

public short getAsShort(TermWareInstance instance)
                 throws ConversionException
Description copied from class: Term
get short value, if this term represent some number, otherwise throw ConversionException

Overrides:
getAsShort in class Term
Parameters:
instance - instance of runtime environment.
Returns:
short value
Throws:
ConversionException - if conversion is impossible.

getString

public String getString()
Description copied from class: Term
get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException

Specified by:
getString in class Term
Returns:
string value

getSubtermAt

public Term getSubtermAt(int i)
Description copied from class: Term
get subterm of current term. when i < arity then throw TermIndexOutOfBoundsException

Specified by:
getSubtermAt in class Term
Parameters:
i - - index of subterm, starting from 0
Returns:
i-th subterm of current term.

getTerm

public Term getTerm()
Description copied from class: Term
get term. Semantics is "return this term". Non-trivial implementations are used for deallocating proxy terms.

Specified by:
getTerm in class Term

getXIndex

public int getXIndex()
Description copied from class: Term
if this variable is a propositional variable, return index of one. Otherwise throw UnsupportedOperationException

Specified by:
getXIndex in class Term

isAtom

public boolean isAtom()
Description copied from class: Term
is term is atom ?

Specified by:
isAtom in class Term
Returns:
true if this term is atom

isBigDecimal

public boolean isBigDecimal()
Description copied from class: Term
true, if this term is BigDecimal

Specified by:
isBigDecimal in class Term

isBigInteger

public boolean isBigInteger()
Description copied from class: Term
true, if this term is BigInteger

Specified by:
isBigInteger in class Term

isBoolean

public boolean isBoolean()
Description copied from class: Term
is term is booleam ?

Specified by:
isBoolean in class Term
Returns:
true if this term is boolean

isByte

public boolean isByte()
Description copied from class: Term
true, if this term is Byte

Specified by:
isByte in class Term

isChar

public boolean isChar()
Description copied from class: Term
is term is char ?

Specified by:
isChar in class Term
Returns:
true if this term is char

isComplexTerm

public boolean isComplexTerm()
Description copied from class: Term
true, if this term have subterms

Specified by:
isComplexTerm in class Term
Returns:
true if this term have subterms.

isDouble

public boolean isDouble()
Description copied from class: Term
is Term is double ?

Specified by:
isDouble in class Term
Returns:
true if term represents double value.

isFloat

public boolean isFloat()
Description copied from class: Term
is Term is float ?

Specified by:
isFloat in class Term
Returns:
true if term represents float value.

isInt

public boolean isInt()
Description copied from class: Term
is term is Int ?

Specified by:
isInt in class Term
Returns:
true if term represents integer value.

isJavaObject

public boolean isJavaObject()
Description copied from class: Term
if this term is Java Object ?

Specified by:
isJavaObject in class Term

isLong

public boolean isLong()
Description copied from class: Term
is Term is long ?

Specified by:
isLong in class Term
Returns:
true if term represents long value.

isNil

public boolean isNil()
Description copied from class: Term
is term is nil ?

Specified by:
isNil in class Term
Returns:
true if this term is Nil

isNumber

public boolean isNumber()
Description copied from class: Term
is term is Number ?

Specified by:
isNumber in class Term
Returns:
true if term represents number value.

isShort

public boolean isShort()
Description copied from class: Term
is Term is short ?

Specified by:
isShort in class Term
Returns:
true if term represents short value.

isString

public boolean isString()
Description copied from class: Term
is Term is string ?

Specified by:
isString in class Term
Returns:
true if term represents string value.

isX

public boolean isX()
Description copied from class: Term
true if this term is propositional variable.

Specified by:
isX in class Term
Returns:
true if this term is propositional variable

maxFv

public int maxFv()
          throws TermWareException
Description copied from class: Term
get maximum index of free propositional variable in term

Specified by:
maxFv in class Term
Returns:
index of propositional variable with maximal index.
Throws:
TermWareException

minFv

public int minFv()
          throws TermWareException
Description copied from class: Term
get minimal index of free propositional variable in term.

Specified by:
minFv in class Term
Returns:
index of propositional variable with minimal index.
Throws:
TermWareException

print

public void print(PrintWriter out)
Description copied from class: Term
print term on out

Specified by:
print in class Term
Parameters:
out - - PrintWriter, where to print term.

setSubtermAt

public void setSubtermAt(int i,
                         Term t)
                  throws TermWareException
Description copied from class: Term
set i-th subterm to t when i < arity then throw IndexOutOfBoundsException

Specified by:
setSubtermAt in class Term
Parameters:
i - - index of subterm to set.
t - - subterm to set.
Throws:
TermWareException

shiftFv

public void shiftFv(int newMinFv)
             throws TermWareException
Description copied from class: Term
renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv

Specified by:
shiftFv in class Term
Throws:
TermWareException

subst

public Term subst(Substitution s)
           throws TermWareException
Description copied from class: Term
receive new term, which is sibstution of current term and s

Specified by:
subst in class Term
Throws:
TermWareException

substInside

public boolean substInside(Substitution s)
                    throws TermWareException
Description copied from class: Term
apply substitution s to current term.

Specified by:
substInside in class Term
Throws:
TermWareException

termClone

public Term termClone()
               throws TermWareException
Description copied from class: Term
deep clone of term. (only immunitable terms are not cloned)

Specified by:
termClone in class Term
Throws:
TermWareException

termCompare

public int termCompare(Term x)
Description copied from class: Term
compare functions. define ordering on set of terms. Note, that ordering is not the same as Java build-in compare.

Specified by:
termCompare in class Term
Parameters:
x - - term to compare

concreteOrder

public PartialOrderingResult concreteOrder(Term x,
                                           Substitution s)
                                    throws TermWareException
Description copied from class: Term
compare for 'more concrete' relation. i. e. x.<(concrete)<(y) means, that for each substitution of free variables sx exists substituion sy : x[sx] = y[sy] .
Substitution s store previously matched variables.

Specified by:
concreteOrder in class Term
Throws:
TermWareException

findSubtermIndexBoundEqualsTo

public int findSubtermIndexBoundEqualsTo(Term x)
                                  throws TermWareException
Specified by:
findSubtermIndexBoundEqualsTo in class Term
Throws:
TermWareException

unAttribute

public Term unAttribute()

setAttribute

public void setAttribute(String attribute,
                         Term value)
Description copied from interface: Attributed
set attribute with name name and value value . If value is NIL, then attribute is erased from set.

Specified by:
setAttribute in interface Attributed

getAttribute

public Term getAttribute(String attribute)
Description copied from interface: Attributed
get attribute with name name . When such attribute does not exists -- return NIL.

Specified by:
getAttribute in interface Attributed

getAttributes

public Map<String,Term> getAttributes()
Description copied from interface: Attributed
return map, where keys are attribute names, value - values of attributes.

Specified by:
getAttributes in interface Attributed