Class AugmentedLexiconFileHandler

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byLexiconFileHandler
          extended byAugmentedLexiconFileHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class AugmentedLexiconFileHandler
extends LexiconFileHandler

An AugmentedLexiconFileHandler reads lexicon files whose constitents are AugmentedConstituents.

The BNF grammar we are trying to parse is something like the following:

    Lexicon <- START("Lexicon") Description? Word* END("Lexicon")
    Description <- START("Description") characters END("Description")
    Word <- START("Word" id=) Sense+ END("Word")
    Sense <- START("Sense") Feature+ END("Sense")
    Feature <- START(FEATNAME) characters END(FEATNAME)
 
where FEATNAME is a feature name (such as "category", "root", etc.). The value of the feature is parsed as a Symbol or Variable (possibly constrained), although this syntax isn't described in XML.


Field Summary
(package private)  Symbol feature
           
(package private)  FeatureSet features
           
(package private) static int STATE_FEATURE
           
 
Fields inherited from class LexiconFileHandler
cat, description, lexicon, locator, state, STATE_CATEGORY, STATE_DESCRIPTION, STATE_FILE, STATE_LEXICON, STATE_SENSE, STATE_WORD, textBuffer, word
 
Constructor Summary
AugmentedLexiconFileHandler(AugmentedLexicon l)
          Create a new AugmentedLexiconFileHandler to read into the given AugmentedLexicon.
 
Method Summary
 void characters(char[] buf, int offset, int len)
          Called by the SAX parsing engine when characters are read outside of any element tag.
 void endElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName)
          SAX ContentHandler method called when an end-element tag is encountered.
static void main(java.lang.String[] argv)
          Test the LexiconFileHandler.
 void startElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName, org.xml.sax.Attributes attrs)
          SAX ContentHandler method called when a start-element tag is encountered.
 
Methods inherited from class LexiconFileHandler
consumeText, error, ERROR, fatalError, readFile, setDocumentLocator, warning
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_FEATURE

static final int STATE_FEATURE
See Also:
Constant Field Values

feature

Symbol feature

features

FeatureSet features
Constructor Detail

AugmentedLexiconFileHandler

public AugmentedLexiconFileHandler(AugmentedLexicon l)
Create a new AugmentedLexiconFileHandler to read into the given AugmentedLexicon.

Method Detail

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String sName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Description copied from class: LexiconFileHandler
SAX ContentHandler method called when a start-element tag is encountered.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class LexiconFileHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String sName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Description copied from class: LexiconFileHandler
SAX ContentHandler method called when an end-element tag is encountered.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class LexiconFileHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws org.xml.sax.SAXException
Description copied from class: LexiconFileHandler
Called by the SAX parsing engine when characters are read outside of any element tag. This can be called multiple times, such as when the text spans multiple lines (depends on whitespace treatment, whether the parser is validating, etc.). So the safe thing to do is just hold onto the text for later use when an end-element tag is reached (assuming we don't care about the actual form of the original text, but just its content, which is the case for us). We could be more careful, saving the text in states where we're expecting text and otherwise indicating a state-specific error, but frankly I don't care that much.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class LexiconFileHandler
Throws:
org.xml.sax.SAXException

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException
Description copied from class: LexiconFileHandler
Test the LexiconFileHandler.

Throws:
java.io.IOException