Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class chomps.Chompy

java.lang.Object
  |
  +--chomps.Chompy

public class Chompy
extends java.lang.Object
Chompy is a general purpose recursive language parser. Using a set of rules which form the Chompy world, Chompy will evaluate and generate grammatical sentential structures. Chompy requires the use of the Tool class in the package tools which must be present in the CLASSPATH.

Version:
1.0
Author:
Copyright Neil Blue (1998)
See Also:
Chomp, Parser

Field Summary
java.lang.String[] heads
          After a call to update() heads holds an array of rule heads for quick reference.
int ruleCount
          ruleCount holds the number of rules at the last call to update().
java.lang.String[][] tails
          After a call to update() tails holds an array of string arrays representing the atoms of the rule tails for quick reference.
 
Method Summary
void addRule(java.lang.String head, java.lang.String tail)
          Adds a rule to the Chompy world.
void clearAdded()
          Resets the number of rules added since the last call to getAdded() or clearAdded() to zero.
void delete()
          Deletes all the rules in the Chompy world.
void delete(int index)
          Deletes the rule with the given index.
int getAdded()
          Gets the number of rules added since the last call to getAdded() or clearAdded().
java.lang.String getRule(int index)
          Gets the rule with the given index.
int getRuleCount()
          Gets the number of rules in the Chompy world.
java.lang.String[] getRuleList()
          Gets a formatted list of all the rules in the Chompy world.
boolean isa(java.lang.String source, java.lang.String target)
          Parses the source String to see if it is of the form of the target String.
void save(java.lang.String filename)
          Saves all the rules in the Chompy world to the given filename.
java.lang.String toString()
          Returns a string describing the current Chompy object.
void update()
          Updates the list of rule heads and tails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

heads

public java.lang.String[] heads
After a call to update() heads holds an array of rule heads for quick reference.
See Also:
update()

tails

public java.lang.String[][] tails
After a call to update() tails holds an array of string arrays representing the atoms of the rule tails for quick reference.
See Also:
update()

ruleCount

public int ruleCount
ruleCount holds the number of rules at the last call to update().
See Also:
update()
Method Detail

addRule

public void addRule(java.lang.String head,
                    java.lang.String tail)
            throws InvalidRuleException
Adds a rule to the Chompy world. The formatted structure of rules in Chompy is as follows:
     head = tail1 + tail2 + ... + tailn
Where there must be one or more tail arguments. The head must always be a single atom (i.e. a string of ASCII characters with no spaces). Each tail is also a single atom. The tail is passed to addRule as a String of atoms separated by spaces e.g.:
     chompy.addRule("Sentence", "NP VP");
Which would evaluate to:
     SENTENCE = NP + VP
Each rule is counted when it is added, and this count is reset when getAdded() or clearAdded() are called.
Parameters:
head - A string representing the head of the rule.
tail - A string of atoms separated by spaces.
Throws:
InvalidRuleException - if an invalid rule has been passed.
See Also:
getAdded(), clearAdded(), getRuleCount(), delete(), delete(int index)

getAdded

public int getAdded()
Gets the number of rules added since the last call to getAdded() or clearAdded().
Returns:
The number of rules added.
See Also:
addRule(String head, String tail), clearAdded()

clearAdded

public void clearAdded()
Resets the number of rules added since the last call to getAdded() or clearAdded() to zero.
See Also:
addRule(String head, String tail), getAdded()

getRuleList

public java.lang.String[] getRuleList()
Gets a formatted list of all the rules in the Chompy world. They are formatted in the form:
     (index) head = tail1 + tail2 + ... + tailn
The list of formatted output is returned as a String array.
Returns:
A formatted list of all the ruled in the Chompy world.
See Also:
getRule(int index)

getRule

public java.lang.String getRule(int index)
                        throws java.lang.IndexOutOfBoundsException
Gets the rule with the given index. The rule is not formatted and is returned in the form:
     head tail1 tail2 ... tailn
e.g.
     SENTENCE NP VP
Parameters:
index - The index of the rule to get.
Returns:
The rule with the given index.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of bounds.
See Also:
getRuleList()

getRuleCount

public int getRuleCount()
Gets the number of rules in the Chompy world.
Returns:
The number of rule in the Chompy world.
See Also:
addRule(String head, String tail), delete(), delete(int index)

delete

public void delete()
Deletes all the rules in the Chompy world.
See Also:
addRule(String head, String tail), delete(int index), getRuleCount()

delete

public void delete(int index)
           throws java.lang.IndexOutOfBoundsException
Deletes the rule with the given index.
Parameters:
index - The index of the rule to delete.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of bounds.
See Also:
addRule(String head, String tail), delete(), getRuleCount()

save

public void save(java.lang.String filename)
         throws java.io.IOException
Saves all the rules in the Chompy world to the given filename. If the filename does not exist then it is created.
Parameters:
filename - The filename to save the world to.
Throws:
java.io.IOException - If there is an error writing to the file.

isa

public boolean isa(java.lang.String source,
                   java.lang.String target)
Parses the source String to see if it is of the form of the target String. This is command checks the source string recursively using the rules in the Chompy world. See Chomp help file for more details.
Parameters:
source - The source String to check.
target - The target String to look for.

update

public void update()
Updates the list of rule heads and tails.
See Also:
heads, tails, ruleCount

toString

public java.lang.String toString()
Returns a string describing the current Chompy object.
Returns:
A descriptive string.
Overrides:
toString in class java.lang.Object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD