org.jscience.ml.openmath
Class OMBinding

java.lang.Object
  extended by org.jscience.ml.openmath.OMObject
      extended by org.jscience.ml.openmath.OMBinding
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class OMBinding
extends OMObject

Models an OpenMath binding object.

See Also:
"The OpenMath standard 2.0, 2.1.3", Serialized Form

Field Summary
protected  OMObject binder
          Stores the binder.
protected  OMObject body
          Stores the body.
protected  java.util.Vector variables
          Stores the variables.
 
Fields inherited from class org.jscience.ml.openmath.OMObject
attributes
 
Constructor Summary
OMBinding()
          Constructor.
OMBinding(OMObject newBinder, java.util.Vector newVariables, OMObject newBody)
          Constructor.
 
Method Summary
 void addVariable(OMObject object)
          Add variable.
 OMObject alphaConvert(OMObject source, OMObject dest)
          Perform Alpha conversion on the binding and its children.
 OMObject betaReduce(OMObject var, OMObject reduction)
          Performs light-weight Beta reduction.
 java.lang.Object clone()
          Clones the object (shallow copy).
 java.lang.Object copy()
          Copies the object (full copy).
 OMObject firstVariable()
          Get the first variable.
 OMObject getBinder()
          Get the binder.
 OMObject getBody()
          Get the body.
 java.lang.String getType()
          Gets the type.
 OMObject getVariableAt(int index)
          Get variable at i-place.
 java.util.Vector getVariables()
          Get the variables.
 void insertVariableAt(OMObject object, int index)
          Insert variable at i-place.
 boolean isAtom()
          Are we an atom object.
 boolean isComposite()
          Are we a composite object.
 boolean isSame(OMObject object)
          Determines if this is the same object.
 boolean isValid()
          Determines if this is a valid object.
 OMObject lastVariable()
          Get the last variable.
 void removeAllVariables()
          Remove all variables.
 boolean removeVariable(OMObject object)
          Remove variable.
 void removeVariableAt(int index)
          Remove variable at i-place.
 OMObject replace(OMObject source, OMObject dest)
          Replace any occurrence of source to destination.
 void setBinder(OMObject newBinder)
          Sets the binder.
 void setBody(OMObject newBody)
          Set the body.
 void setVariableAt(OMObject object, int index)
          Set variable at i-place.
 void setVariables(java.util.Vector newVariables)
          Set the variables.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class org.jscience.ml.openmath.OMObject
getAttribute, getAttributes, removeAttribute, setAttribute, setAttributes
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

binder

protected OMObject binder
Stores the binder.


variables

protected java.util.Vector variables
Stores the variables.


body

protected OMObject body
Stores the body.

Constructor Detail

OMBinding

public OMBinding()
Constructor.


OMBinding

public OMBinding(OMObject newBinder,
                 java.util.Vector newVariables,
                 OMObject newBody)
Constructor.

Parameters:
newBinder - the binder.
newVariables - a Vector with the bound variables.
newBody - the body.
Method Detail

getType

public java.lang.String getType()
Gets the type.

Specified by:
getType in class OMObject
Returns:
the type of the OMObject.

getBinder

public OMObject getBinder()
Get the binder.

Returns:
the binder, or null if not set.

setBinder

public void setBinder(OMObject newBinder)
Sets the binder.

Parameters:
newBinder - sets the binder.

getVariables

public java.util.Vector getVariables()
Get the variables.

Returns:
the variables, or null if not set.

setVariables

public void setVariables(java.util.Vector newVariables)
Set the variables.

Parameters:
newVariables - the variables.

getBody

public OMObject getBody()
Get the body.

Returns:
the body, or null if not set.

setBody

public void setBody(OMObject newBody)
Set the body.

Parameters:
newBody - the body

getVariableAt

public OMObject getVariableAt(int index)
Get variable at i-place.

Parameters:
index - the index of the variable.
Returns:
the variable.

setVariableAt

public void setVariableAt(OMObject object,
                          int index)
Set variable at i-place.

Parameters:
object - the object to set.
index - the index to set at.

insertVariableAt

public void insertVariableAt(OMObject object,
                             int index)
Insert variable at i-place.

Parameters:
object - the object to insert.
index - the index to insert at.

removeVariableAt

public void removeVariableAt(int index)
Remove variable at i-place.

Parameters:
index - the index to remove from.

addVariable

public void addVariable(OMObject object)
Add variable.

Parameters:
object - adds a variable (at the end).

removeVariable

public boolean removeVariable(OMObject object)
Remove variable.

Note: This removes the first occurence of the given variable. If you want to remove all the references to the given object, continue remove until this returns false.

Parameters:
object - the variable to remove.
Returns:
true if there are more occurrences, false if not.

removeAllVariables

public void removeAllVariables()
Remove all variables.


firstVariable

public OMObject firstVariable()
Get the first variable.

Returns:
the first variable.

lastVariable

public OMObject lastVariable()
Get the last variable.

Returns:
the last variable.

toString

public java.lang.String toString()
Returns a string representation of the object.

Specified by:
toString in class OMObject
Returns:
the string representation.

clone

public java.lang.Object clone()
Clones the object (shallow copy).

Specified by:
clone in class OMObject
Returns:
a copy of the object.

copy

public java.lang.Object copy()
Copies the object (full copy).

Specified by:
copy in class OMObject
Returns:
a deep copy of the object.

isComposite

public boolean isComposite()
Are we a composite object.

Specified by:
isComposite in class OMObject
Returns:
true if it is composite, false if it is not.

isAtom

public boolean isAtom()
Are we an atom object.

Specified by:
isAtom in class OMObject
Returns:
true if it is an atom, false if it is not.

isSame

public boolean isSame(OMObject object)
Determines if this is the same object.

Specified by:
isSame in class OMObject
Parameters:
object - the object to test against.
Returns:
true if it is the same, false if it is not.

isValid

public boolean isValid()
Determines if this is a valid object.

Specified by:
isValid in class OMObject
Returns:
true if it is valid, false if it is not.

replace

public OMObject replace(OMObject source,
                        OMObject dest)
Replace any occurrence of source to destination.

Note: this method will not replace bound variables inside a binding. This will be the responsibility of the alphaConvert method. So if the given source is a bound variable the replacing will NOT occur, use the alphaConvert method instead!

Parameters:
source - the source object.
dest - the destination object.
Returns:
the application with the replacing.

betaReduce

public OMObject betaReduce(OMObject var,
                           OMObject reduction)
Performs light-weight Beta reduction.

Note: While reducing name-capturing might occur. This method does NOT do alpha conversion to avoid this problem. So consider this to be light-weight Beta reduction.

Parameters:
var - the variable to reduce.
reduction - the object to reduce it to.
Returns:
the beta reduced object.

alphaConvert

public OMObject alphaConvert(OMObject source,
                             OMObject dest)
Perform Alpha conversion on the binding and its children.

Note: the renaming is done by means of the replace method, this will ensure that any bound variable lower in the tree with the same name as the variable in this binding will not be replaced .

Parameters:
source - the source object
dest - the destination object
Returns:
the converted object