laser.regularlanguage.regularexpression.util
Class AbstractRegularExpressions<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.regularexpression.util.AbstractRegularExpressions<L>
Type Parameters:
L - The type of Label associated with the REs.
Direct Known Subclasses:
RegularExpressions

public abstract class AbstractRegularExpressions<L extends LabelInterface>
extends java.lang.Object

The AbstractRegularExpressions class contains various methods for manipulating regular expressions (REs).

The methods in this class all throw an IllegalArgumentException if the specified RE is null or not well-formed.

Define the alphabet of RE R to be Σ(R) the set of all labels used by RE R.

Define the language of RE R to be L(R) the set of all input strings accepted by RE R.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)
See Also:
AlphabetInterface, LabelInterface, RE

Field Summary
protected  AlphabetFactoryInterface<L> alphabetFactory_
          The AlphabetFactoryInterface to be used to create new alphabets
static java.lang.String DESCRIPTION_PREFIX
          The description prefix
static java.lang.String DESCRIPTION_SEPARATOR
          The description separator
static java.lang.String DESCRIPTION_SUFFIX
          The description suffix
static java.lang.String NAME_SEPARATOR
          The name separator
protected  REFactory<L> reFactory_
          The REFactory to be used to create new REs
 
Constructor Summary
protected AbstractRegularExpressions(REFactory<L> reFactory)
          Creates a new AbstractRegularExpressions class.
 
Method Summary
protected abstract  void checkClass(RE<L> theRE)
          Checks that the RE's class is supported.
protected  void checkPreconditions(RE<L> theRE)
          Checks the preconditions on the given RE.
 RE<L> concatenation(RE<L> re1, RE<L> re2)
          Returns an RE that is the concatenation of the given REs.
 RE<L> convertExtendedREtoRE(RE<L> theExtendedRE)
          Converts from the given extended RE to the corresponding basic RE.
 RE<L> empty(AlphabetInterface<L> alphabet, java.lang.Object... args)
          Returns an RE that specifies the empty language.
 RE<L> epsilon(AlphabetInterface<L> alphabet, java.lang.Object... args)
          Returns an RE that specifies the empty string.
 REFactory<L> getREFactory()
          Gets the REFactory being used to create new REs.
 RE<L> label(L label, AlphabetInterface<L> alphabet, java.lang.Object... args)
          Returns an RE that specifies the given label.
protected  REPair<L> normalize(RE<L> re1, RE<L> re2)
          Normalizes the given REs before a binary operation occurs.
 RE<L> read(java.io.File inFile)
          Reads in the RE from the given input File.
abstract  RE<L> read(java.io.Reader in)
          Reads in the RE from the given input Reader.
protected  void setREAttributes(RE<L> oldRE1, RE<L> oldRE2, RE<L> newRE, java.lang.String binaryOp)
          Sets the attributes of the new RE based on the attributes of the old REs and the given binary operation.
protected  void setREAttributes(RE<L> oldRE, RE<L> newRE, java.lang.String unaryOp)
          Sets the attributes of the new RE based on the attributes of the old RE and the given unary operation.
 RE<L> simplify(RE<L> theRE)
          Simplifies the given RE by using identies to remove terms.
 RE<L> star(RE<L> re)
          Returns an RE that is the star of the given RE.
 RE<L> union(RE<L> re1, RE<L> re2)
          Returns an RE that is the union of the given REs.
 void write(RE<L> theRE, java.io.File outFile)
          Writes out the given RE to the specified output File.
abstract  void write(RE<L> theRE, java.io.Writer out)
          Writes out the given RE to the specified output Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_SEPARATOR

public static final java.lang.String NAME_SEPARATOR
The name separator

See Also:
Constant Field Values

DESCRIPTION_PREFIX

public static final java.lang.String DESCRIPTION_PREFIX
The description prefix

See Also:
Constant Field Values

DESCRIPTION_SEPARATOR

public static final java.lang.String DESCRIPTION_SEPARATOR
The description separator

See Also:
Constant Field Values

DESCRIPTION_SUFFIX

public static final java.lang.String DESCRIPTION_SUFFIX
The description suffix

See Also:
Constant Field Values

reFactory_

protected final REFactory<L extends LabelInterface> reFactory_
The REFactory to be used to create new REs


alphabetFactory_

protected final AlphabetFactoryInterface<L extends LabelInterface> alphabetFactory_
The AlphabetFactoryInterface to be used to create new alphabets

Constructor Detail

AbstractRegularExpressions

protected AbstractRegularExpressions(REFactory<L> reFactory)
Creates a new AbstractRegularExpressions class.

Parameters:
reFactory - The REFactory to be used to create new REs (non-null)
Method Detail

checkClass

protected abstract void checkClass(RE<L> theRE)
Checks that the RE's class is supported.

Parameters:
theRE - The RE to be checked

checkPreconditions

protected void checkPreconditions(RE<L> theRE)
Checks the preconditions on the given RE.

Parameters:
theRE - the RE to be checked

getREFactory

public REFactory<L> getREFactory()
Gets the REFactory being used to create new REs.

Returns:
The REFactory being used to create new REs

normalize

protected REPair<L> normalize(RE<L> re1,
                              RE<L> re2)
Normalizes the given REs before a binary operation occurs.

Parameters:
re1 - The first RE
re2 - The second RE
Returns:
The normalized REs

setREAttributes

protected void setREAttributes(RE<L> oldRE,
                               RE<L> newRE,
                               java.lang.String unaryOp)
Sets the attributes of the new RE based on the attributes of the old RE and the given unary operation.

Parameters:
oldRE - The old RE
newRE - The new RE
unaryOp - The unary operation

setREAttributes

protected void setREAttributes(RE<L> oldRE1,
                               RE<L> oldRE2,
                               RE<L> newRE,
                               java.lang.String binaryOp)
Sets the attributes of the new RE based on the attributes of the old REs and the given binary operation.

Parameters:
oldRE1 - The first old RE
oldRE2 - The second old RE
newRE - The new FSA
binaryOp - The binary operation

concatenation

public RE<L> concatenation(RE<L> re1,
                           RE<L> re2)
Returns an RE that is the concatenation of the given REs. Call the returned RE concatRE. Formally, Σ(concatRE) is Σ(re1) ∪ Σ(re2) and L(concatRE) is L(re1) ⋅ L(re2).

L(concatRE) = { x ⋅ y | x ∈ L(re1) and y ∈ L(re2) }

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
re1 - The first RE
re2 - The second RE
Returns:
An RE that is the concatenation of the given REs

empty

public RE<L> empty(AlphabetInterface<L> alphabet,
                   java.lang.Object... args)
Returns an RE that specifies the empty language.

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
alphabet - The alphabet for the RE
args - The createRE method arguments (optional)
Returns:
An empty RE

epsilon

public RE<L> epsilon(AlphabetInterface<L> alphabet,
                     java.lang.Object... args)
Returns an RE that specifies the empty string.

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
alphabet - The alphabet for the RE
args - The createRE method arguments (optional)
Returns:
An epsilon RE

label

public RE<L> label(L label,
                   AlphabetInterface<L> alphabet,
                   java.lang.Object... args)
Returns an RE that specifies the given label.

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
label - The label of interest
alphabet - The alphabet for the RE
args - The createRE method arguments (optional)
Returns:
A label RE

star

public RE<L> star(RE<L> re)
Returns an RE that is the star of the given RE. Call the returned RE starRE. Formally, Σ(starRE) is Σ(re) and L(starRE) is L(re)*.

L(starRE) = {x_1, x_2, ..., x_k | k >= 0 and each x_i ∈ L(re) }

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
re - The RE
Returns:
An RE that is the star of the given RE

union

public RE<L> union(RE<L> re1,
                   RE<L> re2)
Returns an RE that is the union of the given REs. Call the returned RE unionRE. Formally, Σ(unionRE) is Σ(re1) ∪ Σ(re2) and L(unionRE) is L(re1) ∪ L(re2).

L(unionRE) = { x | x ∈ L(re1) or x ∈ L(re2) }

NOTE: This is a regular operation.

PRECONDITIONS:

Parameters:
re1 - The first RE
re2 - The second RE
Returns:
An RE that is the union of the given REs

convertExtendedREtoRE

public RE<L> convertExtendedREtoRE(RE<L> theExtendedRE)
                                                   throws REException
Converts from the given extended RE to the corresponding basic RE.

PRECONDITIONS:

Parameters:
theExtendedRE - The extended RE to be converted
Returns:
The corresponding basic RE
Throws:
REException - if an RE related error occurs
See Also:
RE.isExtendedRE()

simplify

public RE<L> simplify(RE<L> theRE)
                                      throws REException
Simplifies the given RE by using identies to remove terms.

PRECONDITIONS:

Parameters:
theRE - The RE to be simplified
Returns:
The simplified RE
Throws:
REException - if an RE related error occurs

read

public RE<L> read(java.io.File inFile)
                                  throws java.io.IOException,
                                         REException
Reads in the RE from the given input File.

Parameters:
inFile - The File to be used as input (non-null)
Returns:
The corresponding RE
Throws:
java.io.IOException - if an I/O related error occurs
REException - if an RE related error occurs

read

public abstract RE<L> read(java.io.Reader in)
                                           throws java.io.IOException,
                                                  REException
Reads in the RE from the given input Reader.

Parameters:
in - The Reader to be used as input (non-null)
Returns:
The corresponding RE
Throws:
java.io.IOException - if an I/O related error occurs
REException - if an RE related error occurs

write

public void write(RE<L> theRE,
                  java.io.File outFile)
           throws java.io.IOException,
                  REException
Writes out the given RE to the specified output File.

PRECONDITIONS:

Parameters:
theRE - The RE to be written out
outFile - The File to be used as output
Throws:
java.io.IOException - if an I/O related error occurs
REException - if an RE related error occurs

write

public abstract void write(RE<L> theRE,
                           java.io.Writer out)
                    throws java.io.IOException,
                           REException
Writes out the given RE to the specified output Writer.

PRECONDITIONS:

Parameters:
theRE - The RE to be written out
out - The Writer to be used as output
Throws:
java.io.IOException - if an I/O related error occurs
REException - if an RE related error occurs