ua.gradsoft.termware
Class Term

java.lang.Object
  extended by ua.gradsoft.termware.Term
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AbstractComplexTerm, AbstractPrimitiveTerm, AttributedTerm, JTerm, NodeTerm, NTerm, XTerm

public abstract class Term
extends Object
implements Serializable, Cloneable

Basic class for Term - universal representation of term (elementary TermWare object).

See Also:
Serialized Form

Constructor Summary
Term()
           
 
Method Summary
abstract  boolean boundEquals(Term x)
          equality, when propositional variables are already bounded.
abstract  boolean boundUnify(Term t, Substitution s)
          unification when we already have s and when same propositional variables means same things
abstract  PartialOrderingResult concreteOrder(Term x, Substitution s)
          compare for 'more concrete' relation.
 boolean containsSubtermBoundEqualsTo(Term x)
           
abstract  Term createSame(Term[] newBody)
          create term, with same name but new body.
abstract  boolean emptyFv()
          true, if term does not contains free propositional variables.
abstract  int findSubtermIndexBoundEqualsTo(Term x)
           
abstract  boolean freeEquals(Term x)
          Equality when all propositional variables are equal
abstract  boolean freeUnify(Term t, Substitution s)
          do unification of this and t and store in s substitution.
abstract  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
 String getAsString(TermWareInstance instance)
          get string value, if this term represent sring, otherwise throw ConversionException
abstract  BigDecimal getBigDecimal()
          get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException
abstract  BigInteger getBigInteger()
          get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException
abstract  boolean getBoolean()
          get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException
abstract  byte getByte()
          get byte value, if this term represent byte, otherwise throw UnsupportedOperationException
abstract  char getChar()
          get char value, if this term represent char, otherwise throw UnsupportedOperationException
abstract  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.
abstract  float getFloat()
          get float value, if this term represent float, otherwise throw UnsupportedOperationException.
abstract  int getInt()
          get integer value, if this term represent integer, otherwise throw UnsupportedOperationException
abstract  Object getJavaObject()
           
abstract  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.
abstract  String getName()
          get name of functional symbol.
abstract  Object getNameIndex()
          get index of name in instance symbol table.
abstract  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.
abstract  int getPrimaryType0()
          return code of level-0 primary type
 int getPrimaryType1()
          return code of level-1 primary type
abstract  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.
abstract  String getString()
          get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException
abstract  Term getSubtermAt(int i)
          get subterm of current term.
abstract  Term getTerm()
          get term.
abstract  int getXIndex()
          if this variable is a propositional variable, return index of one.
abstract  boolean isAtom()
          is term is atom ?
abstract  boolean isBigDecimal()
          true, if this term is BigDecimal
abstract  boolean isBigInteger()
          true, if this term is BigInteger
abstract  boolean isBoolean()
          is term is booleam ?
abstract  boolean isByte()
          true, if this term is Byte
abstract  boolean isChar()
          is term is char ?
abstract  boolean isComplexTerm()
          true, if this term have subterms
abstract  boolean isDouble()
          is Term is double ?
abstract  boolean isFloat()
          is Term is float ?
abstract  boolean isInt()
          is term is Int ?
abstract  boolean isJavaObject()
          if this term is Java Object ?
abstract  boolean isLong()
          is Term is long ?
abstract  boolean isNil()
          is term is nil ?
abstract  boolean isNumber()
          is term is Number ?
abstract  boolean isShort()
          is Term is short ?
abstract  boolean isString()
          is Term is string ?
abstract  boolean isX()
          true if this term is propositional variable.
abstract  int maxFv()
          get maximum index of free propositional variable in term
abstract  int minFv()
          get minimal index of free propositional variable in term.
 void print(PrintStream out)
          print term on out
abstract  void print(PrintWriter out)
          print term on out
 void println(PrintStream out)
          println term on out .
 void println(PrintWriter out)
          println term on out .
abstract  void setSubtermAt(int i, Term t)
          set i-th subterm to t when i < arity then throw IndexOutOfBoundsException
abstract  void shiftFv(int newMinFv)
          renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv
abstract  Term subst(Substitution s)
          receive new term, which is sibstution of current term and s
abstract  boolean substInside(Substitution s)
          apply substitution s to current term.
abstract  Term termClone()
          deep clone of term.
abstract  int termCompare(Term x)
          compare functions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Term

public Term()
Method Detail

getPrimaryType0

public abstract int getPrimaryType0()
return code of level-0 primary type

Returns:
code of primary type
See Also:
PrimaryTypes

getPrimaryType1

public final int getPrimaryType1()
return code of level-1 primary type


isNil

public abstract boolean isNil()
is term is nil ?

Returns:
true if this term is Nil

isAtom

public abstract boolean isAtom()
is term is atom ?

Returns:
true if this term is atom

isBoolean

public abstract boolean isBoolean()
is term is booleam ?

Returns:
true if this term is boolean

getBoolean

public abstract boolean getBoolean()
get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException

Returns:
boolean value
Throws:
UnsupportedOperationException - raised if this term does not represent boolean value.

getAsBoolean

public boolean getAsBoolean(TermWareInstance instance)
                     throws ConversionException
get boolean value, if this term can be converted to boolean

Throws:
ConversionException

isChar

public abstract boolean isChar()
is term is char ?

Returns:
true if this term is char

getChar

public abstract char getChar()
get char value, if this term represent char, otherwise throw UnsupportedOperationException

Returns:
char value
Throws:
UnsupportedOperationException - raised if this term does not represent boolean value.

getAsChar

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

Throws:
ConversionException

isNumber

public abstract boolean isNumber()
is term is Number ?

Returns:
true if term represents number value.

getNumber

public abstract Number getNumber()
get numeric value, if this term represent number, otherwise throw UnsupportedOperationException

Returns:
number value
Throws:
UnsupportedOperationException - raised if this term does not represent numeric value.

getAsNumber

public Number getAsNumber(TermWareInstance instance)
                   throws ConversionException
Throws:
ConversionException

isBigDecimal

public abstract boolean isBigDecimal()
true, if this term is BigDecimal


getBigDecimal

public abstract BigDecimal getBigDecimal()
                                  throws UnsupportedOperationException
get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException

Returns:
number value
Throws:
UnsupportedOperationException - raised if this term does not represent BigDecimal value.

getAsBigDecimal

public BigDecimal getAsBigDecimal(TermWareInstance instance)
                           throws ConversionException
get BigDecimal value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Returns:
number value
Throws:
UnsupportedOperationException - raised if this term does not represent Number value.
ConversionException - is conversion is not possible.

isBigInteger

public abstract boolean isBigInteger()
true, if this term is BigInteger


getBigInteger

public abstract BigInteger getBigInteger()
                                  throws UnsupportedOperationException
get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException

Returns:
value
Throws:
UnsupportedOperationException - raised if this term does not represent BigInteger value.

getAsBigInteger

public BigInteger getAsBigInteger(TermWareInstance instance)
                           throws ConversionException
get BigInteger value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Returns:
number value
Throws:
ConversionException - raised if conversion is impossible.
UnsupportedOperationException - raised if this term does not represent Number value.

isByte

public abstract boolean isByte()
true, if this term is Byte


getByte

public abstract byte getByte()
get byte value, if this term represent byte, otherwise throw UnsupportedOperationException

Returns:
value
Throws:
UnsupportedOperationException - raised if this term does not represent byte value.

getAsByte

public byte getAsByte(TermWareInstance instance)
               throws ConversionException
get Byte value, if this term represent some Numeric value, otherwise throw UnsupportedOperationException

Returns:
number value
Throws:
ConversionException - if conversion to byte is impossible.

isInt

public abstract boolean isInt()
is term is Int ?

Returns:
true if term represents integer value.

getInt

public abstract int getInt()
                    throws UnsupportedOperationException
get integer value, if this term represent integer, otherwise throw UnsupportedOperationException

Returns:
int value
Throws:
InvalidPrimitiveTypeException - raised if this term does not represent integer value.
UnsupportedOperationException

getAsInt

public int getAsInt(TermWareInstance instance)
             throws ConversionException
get integer value, if this term represent some number, otherwise throw ConversionException

Returns:
int value
Throws:
ConversionException - if conversion is impossible.

isFloat

public abstract boolean isFloat()
is Term is float ?

Returns:
true if term represents float value.

getFloat

public abstract float getFloat()
                        throws UnsupportedOperationException
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);

Returns:
float value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getAsFloat

public float getAsFloat(TermWareInstance instance)
                 throws ConversionException
get float value, if this term represent some number, otherwise throw ConversionException

Returns:
float value
Throws:
ConversionException - if conversion is impossible.

isDouble

public abstract boolean isDouble()
is Term is double ?

Returns:
true if term represents double value.

getDouble

public abstract double getDouble()
                          throws UnsupportedOperationException
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.

Returns:
double value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getAsDouble

public double getAsDouble(TermWareInstance instance)
                   throws ConversionException
get double value, if this term represent some number, otherwise throw ConversionException

Returns:
double value
Throws:
ConversionException - if conversion is impossible.

isLong

public abstract boolean isLong()
is Term is long ?

Returns:
true if term represents long value.

getLong

public abstract long getLong()
                      throws UnsupportedOperationException
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.

Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getAsLong

public long getAsLong(TermWareInstance instance)
               throws ConversionException
get long value, if this term represent some number, otherwise throw ConversionException

Returns:
long value
Throws:
ConversionException - if conversion is impossible.

isShort

public abstract boolean isShort()
is Term is short ?

Returns:
true if term represents short value.

getShort

public abstract short getShort()
                        throws UnsupportedOperationException
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.

Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getAsShort

public short getAsShort(TermWareInstance instance)
                 throws ConversionException
get short value, if this term represent some number, otherwise throw ConversionException

Parameters:
instance - instance of runtime environment.
Returns:
short value
Throws:
ConversionException - if conversion is impossible.

isString

public abstract boolean isString()
is Term is string ?

Returns:
true if term represents string value.

getString

public abstract String getString()
get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException

Returns:
string value
Throws:
UnsupportedOperationException - raised if this term does not represent string value.

getAsString

public String getAsString(TermWareInstance instance)
                   throws ConversionException
get string value, if this term represent sring, otherwise throw ConversionException

Parameters:
instance - instance of runtime environment.
Returns:
string value
Throws:
ConversionException - if conversion is impossible.

isX

public abstract boolean isX()
true if this term is propositional variable.

Returns:
true if this term is propositional variable

getXIndex

public abstract int getXIndex()
if this variable is a propositional variable, return index of one. Otherwise throw UnsupportedOperationException


isComplexTerm

public abstract boolean isComplexTerm()
true, if this term have subterms

Returns:
true if this term have subterms.

getName

public abstract String getName()
get name of functional symbol.

Returns:
name

getNameIndex

public abstract Object getNameIndex()
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)


isJavaObject

public abstract boolean isJavaObject()
if this term is Java Object ?


getJavaObject

public abstract Object getJavaObject()
Returns:
Java Object, if this term holds opaque Java Object, otherwise throw UnsupportedOperationException

getAsJavaObject

public Object getAsJavaObject(TermWareInstance instance)
                       throws ConversionException
Throws:
ConversionException

getArity

public abstract int getArity()
get arity (i. e. number of subterms)

Returns:
arity of term.

getTerm

public abstract Term getTerm()
get term. Semantics is "return this term". Non-trivial implementations are used for deallocating proxy terms.


getSubtermAt

public abstract Term getSubtermAt(int i)
get subterm of current term. when i < arity then throw TermIndexOutOfBoundsException

Parameters:
i - - index of subterm, starting from 0
Returns:
i-th subterm of current term.

setSubtermAt

public abstract void setSubtermAt(int i,
                                  Term t)
                           throws TermWareException
set i-th subterm to t when i < arity then throw IndexOutOfBoundsException

Parameters:
i - - index of subterm to set.
t - - subterm to set.
Throws:
TermWareException

getPatternName

public String getPatternName()
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


getPatternNameIndex

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


freeUnify

public abstract boolean freeUnify(Term t,
                                  Substitution s)
                           throws TermWareException
do unification of this and t and store in s substitution.

Returns:
true, if unification was succesfull.
Throws:
TermWareException

boundUnify

public abstract boolean boundUnify(Term t,
                                   Substitution s)
                            throws TermWareException
unification when we already have s and when same propositional variables means same things

Throws:
TermWareException

substInside

public abstract boolean substInside(Substitution s)
                             throws TermWareException
apply substitution s to current term.

Throws:
TermWareException

subst

public abstract Term subst(Substitution s)
                    throws TermWareException
receive new term, which is sibstution of current term and s

Throws:
TermWareException

freeEquals

public abstract boolean freeEquals(Term x)
                            throws TermWareException
Equality when all propositional variables are equal

Parameters:
x - - term to compare.
Returns:
true, if terms are free-equals.
Throws:
TermWareException

boundEquals

public abstract boolean boundEquals(Term x)
                             throws TermWareException
equality, when propositional variables are already bounded.

Parameters:
x - - term to compare.
Returns:
true, if terms are bound-equals.
Throws:
TermWareException

containsSubtermBoundEqualsTo

public boolean containsSubtermBoundEqualsTo(Term x)
                                     throws TermWareException
Throws:
TermWareException

findSubtermIndexBoundEqualsTo

public abstract int findSubtermIndexBoundEqualsTo(Term x)
                                           throws TermWareException
Throws:
TermWareException

termClone

public abstract Term termClone()
                        throws TermWareException
deep clone of term. (only immunitable terms are not cloned)

Throws:
TermWareException

termCompare

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

Parameters:
x - - term to compare

concreteOrder

public abstract PartialOrderingResult concreteOrder(Term x,
                                                    Substitution s)
                                             throws TermWareException
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.

Throws:
TermWareException

createSame

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

Throws:
TermWareException

minFv

public abstract int minFv()
                   throws TermWareException
get minimal index of free propositional variable in term.

Returns:
index of propositional variable with minimal index.
Throws:
TermWareException

maxFv

public abstract int maxFv()
                   throws TermWareException
get maximum index of free propositional variable in term

Returns:
index of propositional variable with maximal index.
Throws:
TermWareException

shiftFv

public abstract void shiftFv(int newMinFv)
                      throws TermWareException
renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv

Throws:
TermWareException

emptyFv

public abstract boolean emptyFv()
true, if term does not contains free propositional variables. (fv-set for this term is empty.)

Returns:
true, if fv_set does not contains free proporsitional variables.

print

public void print(PrintStream out)
print term on out

Parameters:
out - - PrintStream, where to print term.

print

public abstract void print(PrintWriter out)
print term on out

Parameters:
out - - PrintWriter, where to print term.

println

public final void println(PrintStream out)
println term on out . (i. e. effect of t.println(out) is equals to:
 t.print(out);
 out.println();


println

public final void println(PrintWriter out)
println term on out . (i. e. effect of t.println(out) is equals to:
 t.print(out);
 out.println();