public abstract class Algebra<E> extends Object implements Serializable
A concrete implementation of this abstract base class must provide two
methods, evaluate(java.lang.String, java.util.List)
and parseString(java.lang.String)
. The evaluate method interprets
its first argument (a string) as a function symbol of the algebra, and
applies it to the given arguments. The parseString method translates a string
representation of a value of this algebra into the value itself. The Algebra
class then implements a default implementation of the method
evaluate(de.up.ling.tree.Tree)
, which evaluates an entire term of
the algebra. You may override the evaluate-term method with a specialized
implementation if this is more efficient.
The Algebra class also provides a default implementation of decomposition automata for this class. Decomposition automata are needed for parsing. The default implementation uses values of the algebra as its states, and only provides bottom-up rules which simply evaluate the terminal symbol on the child "states". This default implementation will allow you to get started with parsing quickly, but if you want to achieve reasonably parsing efficiency, you will almost certainly want to implement your own optimized decompose method eventually.
Constructor and Description |
---|
Algebra()
Constructs a new instance which is based on a newly created Signature.
|
Modifier and Type | Method and Description |
---|---|
TreeAutomaton |
decompose(E value)
Computes a decomposition automaton for the given value.
|
E |
evaluate(Tree<String> t)
Evaluates a term over the algebra's signature into an algebra object.
|
static Iterator<Class> |
getAllAlgebraClasses()
Returns an iterator over all subclasses of Algebra.
|
Class |
getClassOfValues()
Returns the class of the elements of this algebra.
|
Signature |
getSignature()
Returns the signature of this algebra.
|
boolean |
hasOptions()
Returns true if the algebra implementation has options that would make
sense to be set using
setOptions(java.lang.String) . |
abstract E |
parseString(String representation)
Resolves the string representation of some element of the algebra's
domain to this element.
|
void |
readOptions(Reader optionReader)
Sets the options of the algebra implementation.
|
String |
representAsString(E object)
Returns a string representation of this object.
|
void |
setOptions(String string)
Sets the options of the algebra implementation from a string.
|
JComponent |
visualize(E object)
Returns a Swing component that visualizes an object of this algebra.
|
void |
writeOptions(Writer optionWriter)
Writes the options of the current algebra object to a Writer.
|
public Algebra()
public E evaluate(Tree<String> t)
t
- a term (= tree whose nodes are labeled with algebra operation
symbols)public Signature getSignature()
public TreeAutomaton decompose(E value)
value
- public abstract E parseString(String representation) throws ParserException
TreeAlgebra.parseString(java.lang.String)
resolves the string "f(a,b)" into a tree with three nodes.It is the job of an algebra class to keep track of the signature of the algebra. Many algebras have a potentially infinite domain (e.g. the string algebra can be used with arbitrary alphabets), so the algebra class should keep track of the symbols that were actually used in the current run of the program. The best practice is to update the signature each time the parseString method is called. The rest of the IRTG tool code takes care to call parseString of the respective algebra to obtain objects of type E, so this ensures that the signature is always up-to-date.
representation
- ParserException
public void readOptions(Reader optionReader) throws Exception
SetAlgebra
for an example.optionReader
- Exception
public void setOptions(String string) throws Exception
readOptions(java.io.Reader)
.string
- Exception
readOptions(java.io.Reader)
public void writeOptions(Writer optionWriter) throws Exception
optionWriter
- Exception
readOptions(java.io.Reader)
public boolean hasOptions()
setOptions(java.lang.String)
.public JComponent visualize(E object)
object
- public String representAsString(E object)
Object.toString()
method. Concrete algebras may overwrite this implementation for
algebra-specific string representations. Whenever Alto knows to which
algebra an object belongs, it will attempt to call this method instead of
the generic toString to produce algebra-specific string representations.object
- public Class getClassOfValues()
Object
; you may override this with
the actual class of the objects of your algebra.
This method is used in some places throughout Alto to figure out what
OutputCodec
s are appropriate for encoding objects of the algebra.
By overriding the method to return more specific classes than Object, you
make more output codecs available in those places.
Copyright © 2017. All rights reserved.