org.symcomp.openmath
Class OpenMathBase

java.lang.Object
  extended by org.symcomp.openmath.OpenMathBase

public abstract class OpenMathBase
extends java.lang.Object

Base class of all OpenMath Objects OpenMathBase and its subclasses are used to store OpenMath expressions. They offer a 1:1-correspondence to the XML-Tree. A tree of OpenMath-Objects can either be constructed programmatically by calling the constructors and stacking the resulting objects together, or by parsing an xml-string. Note that there are no classes for representing attributions and bound variables, the functionality is integrated into all classes and OMBind respectively.


Nested Class Summary
static class OpenMathBase.ENCODINGS
          constants
 
Field Summary
protected  java.util.Map<java.lang.String,OpenMathBase[]> attributions
          an assoziative array that contains the OMATTR attributes of the node
protected  java.lang.String cdbase
          the cdbase of the node, if set
protected  java.lang.String id
          the id of the node, if set
 
Constructor Summary
OpenMathBase()
           
 
Method Summary
 OpenMathBase $plus(OpenMathBase that)
          used to override operators for use from Scala
 org.symcomp.openmath.OMApply apply(OpenMathBase... params)
          Creates an application where this is head and params are the params
 org.symcomp.openmath.OMBind bind(org.symcomp.openmath.OMVariable[] bvars, OpenMathBase param)
          Creates a binding where this is head and params are the params
 OpenMathBase deOMObject()
          Removes the OMObject wrapping if present, otherwise return the unmodified object.
abstract  boolean equals(java.lang.Object that)
          Decide whether two nodes are identical.
 org.symcomp.openmath.OMError error(OpenMathBase[] params)
          Creates an application where this is head and params are the params
 OpenMathBase getAt(OpenMathBase key)
          Get an OMATTR attribute.
 java.util.Map<java.lang.String,OpenMathBase[]> getAttributions()
          Get the attributions.
 java.lang.String getCdbase()
          Get the value of the xml-attribute cdbase
 java.lang.String getId()
          Get the value of the xml-attribute id
 boolean isApplication()
          Check whether this is an OMA
 boolean isApplication(org.symcomp.openmath.OMSymbol oms)
          Check whether this is an application of oms
 boolean isApplication(java.lang.String cd, java.lang.String name)
          Check whether this is an application of with the given cd and name
 boolean isAttributed()
          Find out whether the Object is attributed
 boolean isBinary()
          Check whether this is an OMB
 boolean isBinding()
          Check whether this is an OMBIND
 boolean isBinding(org.symcomp.openmath.OMSymbol oms)
          Check whether this is a binding of oms
 boolean isBinding(java.lang.String cd, java.lang.String name)
          Check whether this is a binding of with the given cd and name
 boolean isError()
          Check whether this is an OME
 boolean isError(org.symcomp.openmath.OMSymbol oms)
          Check whether this is an application of oms
 boolean isError(java.lang.String cd, java.lang.String name)
          Check whether this is an application of with the given cd and name
 boolean isFloat()
          Check whether this is an OMF
 boolean isFloat(double f)
          Check whether this is an OMF and has value f
 boolean isForeign()
          Check whether this is an OMFOREIGN
 boolean isInteger()
          Check whether this is an OMI
 boolean isInteger(java.math.BigInteger i)
          Check whether this is an OMI with value i
 boolean isInteger(java.lang.Integer i)
          Check whether this is an OMI with value i
 boolean isObject()
          Check whether this is an OMOBJ
 boolean isReference()
          Check whether this is an OMR
 boolean isReference(java.lang.String href)
          Check whether this is an OMR whith given href
 boolean isString()
          Check whether this is an OMSTR
 boolean isString(java.lang.String s)
          Check whether this is an OMSTR with given value
 boolean isSymbol()
          Check whether this is an OMS
 boolean isSymbol(java.lang.String cd, java.lang.String name)
          Check whether this is an OMS with given cd and name
 boolean isVariable()
          Check whether this is an OMV
 boolean isVariable(java.lang.String name)
          Check whether this is an OMV of the given name
static OpenMathBase parse(java.io.Reader r)
          Parse the content from the given Reader to an OpenMathBase tree The encoding is guessed by the first byte (using sniffEncoding)
static OpenMathBase parse(java.lang.String text)
          Parse the given OpenMath string to an OpenMathBase tree.
static OpenMathBase parseBinary(java.io.Reader r)
          Parse the given OpenMath binary encoded string to an OpenMathBase tree
static OpenMathBase parseBinary(java.lang.String s)
          Parse the given OpenMath binary encoded string to an OpenMathBase tree
static OpenMathBase parsePopcorn(java.io.InputStream istream)
          Parse a string containing POPCORN code to an OpenMath tree.
static OpenMathBase parsePopcorn(java.io.Reader r)
          Parse a string containing POPCORN code to an OpenMath tree.
static OpenMathBase parsePopcorn(java.lang.String popcode)
          Parse a string containing POPCORN code to an OpenMath tree.
static OpenMathBase parseXml(java.io.Reader r)
          Parse the given OpenMath XML encoded string to an OpenMathBase tree
static OpenMathBase parseXml(java.lang.String s)
          Parse the given OpenMath XML encoded string to an OpenMathBase tree
 void putAt(OpenMathBase key, OpenMathBase val)
          Set an OMATTR attribute.
protected  boolean sameAttributes(OpenMathBase that)
          Decide whether two nodes have the same OMATTR attributes, necessary for equality testing
 void setAttributions(java.util.Map<java.lang.String,OpenMathBase[]> attributions)
          Set the attributions.
 void setCdbase(java.lang.String cdbase)
          Set the value for the xml-attribute cdbase
 void setId(java.lang.String id)
          Set the value for the xml-attribute id
static java.lang.Object[] sniffEncoding(java.io.Reader r)
          Guesses the encoding of the OpenMath object in the given Reader by the first byte.
 char[] toBinary()
          Render whole tree to the binary representation
 void toBinary(java.io.Writer out)
          Render whole tree to the binary representation
 java.lang.String toBinaryAsString()
          Render whole tree to the binary representation.
 java.lang.String toLatex()
          Convert the given OpenMath tree to a string containing a LaTeX representation.
 void toLatex(java.io.Writer out)
          Convert the given OpenMath tree to a string containing a LaTeX representation.
 org.symcomp.openmath.OMObject toOMObject()
          Wraps the OpenMathBase object in an OMOBject is it is not already an OMOBject
 java.lang.String toPopcorn()
          Convert the given OpenMath tree to a string containing a POPCORN representation.
 void toPopcorn(java.io.Writer out)
          Convert the given OpenMath tree to a string containing a POPCORN representation.
 java.lang.String toXml()
          Render whole tree to an XML-string w/o namespace w/o dereferencing
 void toXml(java.io.Writer out)
          Render whole tree to an XML-string w/o namespace w/o dereferencing
 OpenMathBase traverse(OpenMathVisitor visitor)
          Traverse the Object-tree with the visitor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected java.lang.String id
the id of the node, if set


cdbase

protected java.lang.String cdbase
the cdbase of the node, if set


attributions

protected java.util.Map<java.lang.String,OpenMathBase[]> attributions
an assoziative array that contains the OMATTR attributes of the node

Constructor Detail

OpenMathBase

public OpenMathBase()
Method Detail

getId

public java.lang.String getId()
Get the value of the xml-attribute id

Returns:
value of the xml-attribute id

setId

public void setId(java.lang.String id)
Set the value for the xml-attribute id

Parameters:
id - The new id.

getCdbase

public java.lang.String getCdbase()
Get the value of the xml-attribute cdbase

Returns:
value of the xml-attribute cdbase

setCdbase

public void setCdbase(java.lang.String cdbase)
Set the value for the xml-attribute cdbase

Parameters:
cdbase - The new cdbase.

getAttributions

public java.util.Map<java.lang.String,OpenMathBase[]> getAttributions()
Get the attributions. Note that the Format of the map is: Key - String representation of the OMATTR-key, Value - an OpenMathBase[], where [0] is the OMATTR key and [1] is the OMATTR value.

Returns:
the attributions

setAttributions

public void setAttributions(java.util.Map<java.lang.String,OpenMathBase[]> attributions)
Set the attributions. Note that the Format of the map is: Key - String representation of the OMATTR-key, Value - an OpenMathBase[], where [0] is the OMATTR key and [1] is the OMATTR value.

Parameters:
attributions - The new attributions.

putAt

public void putAt(OpenMathBase key,
                  OpenMathBase val)
Set an OMATTR attribute. In groovy, this can syntactically be done using the []-operator

Parameters:
key - the OMATTR key
val - the OMATTR value

getAt

public OpenMathBase getAt(OpenMathBase key)
Get an OMATTR attribute. In groovy, this can syntactically be done using the []-operator

Parameters:
key - the key for which to fetch a value
Returns:
the value if available or null if none is set

isAttributed

public boolean isAttributed()
Find out whether the Object is attributed

Returns:
true if the object is attributed

equals

public abstract boolean equals(java.lang.Object that)
Decide whether two nodes are identical. To return true, the nodes need to have the same class, id, cdbase, attributes and childs (recursively). This is -- of course -- only a syntactical check.

Overrides:
equals in class java.lang.Object

apply

public org.symcomp.openmath.OMApply apply(OpenMathBase... params)
Creates an application where this is head and params are the params

Parameters:
params - the parameters
Returns:
the application of this

error

public org.symcomp.openmath.OMError error(OpenMathBase[] params)
Creates an application where this is head and params are the params

Parameters:
params - the parameters
Returns:
the application of this

bind

public org.symcomp.openmath.OMBind bind(org.symcomp.openmath.OMVariable[] bvars,
                                        OpenMathBase param)
Creates a binding where this is head and params are the params

Parameters:
bvars - the variables to bind
param - the expression to bind
Returns:
the binding of this

isApplication

public boolean isApplication()
Check whether this is an OMA

Returns:
true if this is an OMA

isApplication

public boolean isApplication(org.symcomp.openmath.OMSymbol oms)
Check whether this is an application of oms

Parameters:
oms - the possible head
Returns:
true if this is an application of oms

isApplication

public boolean isApplication(java.lang.String cd,
                             java.lang.String name)
Check whether this is an application of with the given cd and name

Parameters:
cd - the cd of the OMS
name - the name of the OMS
Returns:
true if this is an application of OMS with the given name and cd

isBinary

public boolean isBinary()
Check whether this is an OMB

Returns:
true if this is an OMB

isBinding

public boolean isBinding()
Check whether this is an OMBIND

Returns:
true if this is an OMBIND

isBinding

public boolean isBinding(org.symcomp.openmath.OMSymbol oms)
Check whether this is a binding of oms

Parameters:
oms - the possible head
Returns:
true if this is a binding of oms

isBinding

public boolean isBinding(java.lang.String cd,
                         java.lang.String name)
Check whether this is a binding of with the given cd and name

Parameters:
cd - the cd of the OMS
name - the name of the OMS
Returns:
true if this is a binding of OMS with the given name and cd

isError

public boolean isError()
Check whether this is an OME

Returns:
true if this is an OME

isError

public boolean isError(org.symcomp.openmath.OMSymbol oms)
Check whether this is an application of oms

Parameters:
oms - the possible head
Returns:
true if this is an application of oms

isError

public boolean isError(java.lang.String cd,
                       java.lang.String name)
Check whether this is an application of with the given cd and name

Parameters:
cd - the cd of the OMS
name - the name of the OMS
Returns:
true if this is an application of OMS with the given name and cd

isFloat

public boolean isFloat()
Check whether this is an OMF

Returns:
true if this is an OMF

isFloat

public boolean isFloat(double f)
Check whether this is an OMF and has value f

Parameters:
f - the value to compare
Returns:
true if this is an OMF of given value

isForeign

public boolean isForeign()
Check whether this is an OMFOREIGN

Returns:
true if this is an OMFOREIGN

isInteger

public boolean isInteger()
Check whether this is an OMI

Returns:
true if this is an OMI

isInteger

public boolean isInteger(java.math.BigInteger i)
Check whether this is an OMI with value i

Parameters:
i - the value to compare
Returns:
true if this is an OMI of given value

isInteger

public boolean isInteger(java.lang.Integer i)
Check whether this is an OMI with value i

Parameters:
i - the value to compare
Returns:
true if this is an OMI of given value

isObject

public boolean isObject()
Check whether this is an OMOBJ

Returns:
true if this is an OMOBJ

toOMObject

public org.symcomp.openmath.OMObject toOMObject()
Wraps the OpenMathBase object in an OMOBject is it is not already an OMOBject

Returns:
the wrapped Object

deOMObject

public OpenMathBase deOMObject()
Removes the OMObject wrapping if present, otherwise return the unmodified object.

Returns:
the OMObject element or the OpenMathBase object itself if it wasn't an OMObject

isReference

public boolean isReference()
Check whether this is an OMR

Returns:
true if this is an OMR

isReference

public boolean isReference(java.lang.String href)
Check whether this is an OMR whith given href

Parameters:
href - the value to compare
Returns:
true if this is an OMR with given href

isString

public boolean isString()
Check whether this is an OMSTR

Returns:
true if this is an OMSTR

isString

public boolean isString(java.lang.String s)
Check whether this is an OMSTR with given value

Parameters:
s - the String to compare to
Returns:
true if this is an OMSTR with given value

isSymbol

public boolean isSymbol()
Check whether this is an OMS

Returns:
true if this is an OMS

isSymbol

public boolean isSymbol(java.lang.String cd,
                        java.lang.String name)
Check whether this is an OMS with given cd and name

Parameters:
cd - the cd to check
name - the name to check
Returns:
true if this is an OMS of given cd and name

isVariable

public boolean isVariable()
Check whether this is an OMV

Returns:
true if this is an OMV

isVariable

public boolean isVariable(java.lang.String name)
Check whether this is an OMV of the given name

Parameters:
name - the name to check
Returns:
true if this is an OMV of given name

sameAttributes

protected boolean sameAttributes(OpenMathBase that)
Decide whether two nodes have the same OMATTR attributes, necessary for equality testing

Parameters:
that - the OpenMathBase Object to test against
Returns:
true if the attributes are the same, false otherwise

traverse

public OpenMathBase traverse(OpenMathVisitor visitor)
Traverse the Object-tree with the visitor.

Parameters:
visitor -
Returns:

sniffEncoding

public static java.lang.Object[] sniffEncoding(java.io.Reader r)
                                        throws OpenMathException
Guesses the encoding of the OpenMath object in the given Reader by the first byte.

Parameters:
r - a reader that delivers an OpenMath stream
Returns:
an Object[] o, o[0] is one of the OpenMathBase.ENCODINGS, o[1] is the reader you should subsequently read from.
Throws:
OpenMathException - if something went wrong

parse

public static OpenMathBase parse(java.io.Reader r)
                          throws OpenMathException
Parse the content from the given Reader to an OpenMathBase tree The encoding is guessed by the first byte (using sniffEncoding)

Parameters:
r - a reader that delivers an OpenMath stream
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parse

public static OpenMathBase parse(java.lang.String text)
                          throws OpenMathException
Parse the given OpenMath string to an OpenMathBase tree. The encoding is guessed by the first byte.

Parameters:
text - an OpenMath XML encoded string
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parseXml

public static OpenMathBase parseXml(java.io.Reader r)
                             throws OpenMathException
Parse the given OpenMath XML encoded string to an OpenMathBase tree

Parameters:
r - a Reader that delivers an OpenMath XML encoded string
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parseXml

public static OpenMathBase parseXml(java.lang.String s)
                             throws OpenMathException
Parse the given OpenMath XML encoded string to an OpenMathBase tree

Parameters:
s - an OpenMath XML encoded string
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parseBinary

public static OpenMathBase parseBinary(java.io.Reader r)
                                throws OpenMathException
Parse the given OpenMath binary encoded string to an OpenMathBase tree

Parameters:
r - a Reader that delivers an OpenMath binary encoded string
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parseBinary

public static OpenMathBase parseBinary(java.lang.String s)
                                throws OpenMathException
Parse the given OpenMath binary encoded string to an OpenMathBase tree

Parameters:
s - an OpenMath binary encoded string
Returns:
the representing OpenMathBase tree
Throws:
OpenMathException - if something went wrong

parsePopcorn

public static OpenMathBase parsePopcorn(java.io.Reader r)
                                 throws OpenMathException
Parse a string containing POPCORN code to an OpenMath tree.

Parameters:
r - a Reader delivering a POPCORN string
Returns:
the represented OpenMathBase tree
Throws:
OpenMathException - if sth went wrong ;)

parsePopcorn

public static OpenMathBase parsePopcorn(java.lang.String popcode)
                                 throws OpenMathException
Parse a string containing POPCORN code to an OpenMath tree.

Parameters:
popcode - a POPCORN string
Returns:
the represented OpenMathBase tree
Throws:
OpenMathException - if sth went wrong ;)

parsePopcorn

public static OpenMathBase parsePopcorn(java.io.InputStream istream)
                                 throws OpenMathException
Parse a string containing POPCORN code to an OpenMath tree.

Parameters:
istream - a stream delivering a POPCORN string
Returns:
the represented OpenMathBase tree
Throws:
OpenMathException - if sth went wrong ;)

toXml

public java.lang.String toXml()
Render whole tree to an XML-string w/o namespace w/o dereferencing

Returns:
a XML string representation of the tree

toXml

public void toXml(java.io.Writer out)
           throws OpenMathException
Render whole tree to an XML-string w/o namespace w/o dereferencing

Parameters:
out - the writer to which to write
Throws:
OpenMathException - if something goes wrong

toBinary

public char[] toBinary()
Render whole tree to the binary representation

Returns:
a char[]

toBinaryAsString

public java.lang.String toBinaryAsString()
Render whole tree to the binary representation.

Returns:
a String

toBinary

public void toBinary(java.io.Writer out)
              throws OpenMathException
Render whole tree to the binary representation

Parameters:
out - the writer to which to write
Throws:
OpenMathException - if something goes wrong

toPopcorn

public java.lang.String toPopcorn()
Convert the given OpenMath tree to a string containing a POPCORN representation. This method uses org.symcomp.openmath.popcorn.PopcornRenderer

Returns:
a string containing the Popcorn representation

toPopcorn

public void toPopcorn(java.io.Writer out)
               throws OpenMathException
Convert the given OpenMath tree to a string containing a POPCORN representation. This method uses org.symcomp.openmath.popcorn.PopcornRenderer

Parameters:
out - a writer to deliver the POPCODE
Throws:
OpenMathException - if something goes wrong

toLatex

public java.lang.String toLatex()
Convert the given OpenMath tree to a string containing a LaTeX representation. This method uses org.symcomp.openmath.latex.LatexRenderer

Returns:
a string containing the LaTeX representation

toLatex

public void toLatex(java.io.Writer out)
             throws OpenMathException
Convert the given OpenMath tree to a string containing a LaTeX representation. This method uses org.symcomp.openmath.latex.LatexRenderer

Parameters:
out - a Writer for the LaTeX representation
Throws:
java.lang.Exception - if something goes wrong
OpenMathException

$plus

public OpenMathBase $plus(OpenMathBase that)
used to override operators for use from Scala

Parameters:
that -
Returns:


Copyright © 2010. All Rights Reserved.