asd
Class ASDGrammar

java.lang.Object
  extended by asd.ASDGrammar

public class ASDGrammar
extends java.lang.Object

Instances are ASD grammars in the internal representation used by the ASD Parser.

Author:
James A. Mason

Field Summary
static java.lang.String DUMMYWORD
          The string used in dummy nodes in an ASD grammar.
 
Constructor Summary
ASDGrammar()
          Creates a new empty ASDGrammar.
ASDGrammar(java.lang.String fileName, boolean includeCoords)
          Creates a new ASDGrammar from the character representation stored in a given file.
ASDGrammar(java.lang.String fileName, boolean includeCoords, boolean markIncoming)
          Creates a new ASDGrammar from the character representation stored in a given file.
 
Method Summary
 java.util.HashMap<java.lang.String,java.util.ArrayList<ASDGrammarNode>> lexicon()
          Returns the HashMap used to store the words and lists of instances in the grammar.
 ASDGrammarNode lookupInstance(ASDGrammarSuccessor successor)
          Looks up a word instance in the grammar specified by a given ASDGrammarSuccessor.
 java.util.ArrayList<ASDGrammarNode> lookupWord(java.lang.String word)
          Looks up a given string in the grammar and returns a list of instances for the word.
 void markNodesWithIncomingEdges()
          Marks all ASDGrammarNodes in the grammar that have incoming edges.
 boolean nodesWithIncomingEdgesMarked()
          Indicates whether all ASDGrammarNodes in the grammar that have incoming edges have already been marked.
 java.util.Set<java.lang.String> phraseTypes()
          Returns a Set containing the phrase types recognized by the grammar.
static void setDUMMYWORD(java.lang.String newValue)
          Allows a client to reset the string which is used to represent a "dummy" word in the grammar -- used in the labels on dummy nodes.
 void setNodesWithIncomingEdgesNotMarked()
          Allows a client to reset to false the flag which indicates whether nodes in the grammar with incoming edges have been marked.
 boolean uniqueInstance(java.lang.String word)
          Indicates whether or not a specified word has exactly one instance in the lexicon/grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMMYWORD

public static java.lang.String DUMMYWORD
The string used in dummy nodes in an ASD grammar.

Constructor Detail

ASDGrammar

public ASDGrammar()
Creates a new empty ASDGrammar.


ASDGrammar

public ASDGrammar(java.lang.String fileName,
                  boolean includeCoords)
           throws java.io.IOException,
                  ASDInputException,
                  java.net.MalformedURLException
Creates a new ASDGrammar from the character representation stored in a given file. Throws an IOException if there is no such file, or an ASDInputException if the representation of the grammar in the file is ill-formed.

Parameters:
fileName - the name of the file to be used
includeCoords - indicates whether or not to include pixel coordinates in the grammar loaded, if they are present. They are needed by ASDEditor but not by ASDParser.
Throws:
java.io.IOException
ASDInputException
java.net.MalformedURLException

ASDGrammar

public ASDGrammar(java.lang.String fileName,
                  boolean includeCoords,
                  boolean markIncoming)
           throws java.io.IOException,
                  ASDInputException,
                  java.net.MalformedURLException
Creates a new ASDGrammar from the character representation stored in a given file. Throws an IOException if there is no such file, or an ASDInputException if the representation of the grammar in the file is ill-formed.

Parameters:
fileName - the name of the file to be used
includeCoords - indicates whether or not to include pixel coordinates in the grammar loaded, if they are present. They are needed by ASDEditor but not by ASDParser.
markIncoming - indicates whether or not to mark grammar nodes that have incoming edges, for use by the ASDparser
Throws:
java.io.IOException
ASDInputException
java.net.MalformedURLException
Method Detail

lexicon

public java.util.HashMap<java.lang.String,java.util.ArrayList<ASDGrammarNode>> lexicon()
Returns the HashMap used to store the words and lists of instances in the grammar.


lookupInstance

public ASDGrammarNode lookupInstance(ASDGrammarSuccessor successor)
Looks up a word instance in the grammar specified by a given ASDGrammarSuccessor. If the instance has already been looked up, the ASDGrammarSuccessor will already have a direct reference to it; otherwise that direct reference will be set when the instance is looked up the first time.

Parameters:
successor - an ASDGrammarSuccessor specifying the word instance
Returns:
the ASDGrammarNode representing the word instance; null if not found.

lookupWord

public java.util.ArrayList<ASDGrammarNode> lookupWord(java.lang.String word)
Looks up a given string in the grammar and returns a list of instances for the word. Each instance is an ASDGrammarNode.

Parameters:
word - the "word" string to be looked up
Returns:
an ArrayList of instances for the word; null if the word is not found in the grammar.

markNodesWithIncomingEdges

public void markNodesWithIncomingEdges()
Marks all ASDGrammarNodes in the grammar that have incoming edges. This is needed by ASDParser to detect uniquely-parsed subphrases.


nodesWithIncomingEdgesMarked

public boolean nodesWithIncomingEdgesMarked()
Indicates whether all ASDGrammarNodes in the grammar that have incoming edges have already been marked.


phraseTypes

public java.util.Set<java.lang.String> phraseTypes()
Returns a Set containing the phrase types recognized by the grammar.


setDUMMYWORD

public static void setDUMMYWORD(java.lang.String newValue)
Allows a client to reset the string which is used to represent a "dummy" word in the grammar -- used in the labels on dummy nodes. The default is "$$".


setNodesWithIncomingEdgesNotMarked

public void setNodesWithIncomingEdgesNotMarked()
Allows a client to reset to false the flag which indicates whether nodes in the grammar with incoming edges have been marked. This is needed if the client modifies the grammar but does not invoke the method markNodesWithIncomingEdges before passing the modified grammar to ASDParser.


uniqueInstance

public boolean uniqueInstance(java.lang.String word)
Indicates whether or not a specified word has exactly one instance in the lexicon/grammar.

Parameters:
word - the "word" string to be looked up
Returns:
true if the word has one instance in the grammar, false if not.