edu.northwestern.at.morphadorner.tools

## Class ExtendedAdornedWordFilter

- java.lang.Object
- - org.xml.sax.helpers.XMLFilterImpl
  - - edu.northwestern.at.utils.xml.ExtendedXMLFilterImpl
    - - edu.northwestern.at.morphadorner.tools.ExtendedAdornedWordFilter

- All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

      public class ExtendedAdornedWordFilter
      extends ExtendedXMLFilterImpl

  Filter to extract XML word information during XML parsing.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `(package private) class` | `ExtendedAdornedWordFilter.MainFront` Holds main/front information.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected QueueStack<java.lang.String>` | `divStack` Div tag stack.
    `protected java.lang.String` | `firstWordID` First word ID found in text.
    `protected int` | `gapCount` Gap count for generating IDs.
    `protected boolean` | `generateGapWords` Generate words for gaps.
    `protected java.util.List<java.lang.String>` | `idList` List of String word IDs.
    `protected java.util.Map<java.lang.String,ExtendedAdornedWord>` | `idToWordInfo` Map word ID to list of adorned word information objects.
    `protected java.lang.String` | `lastElementName` Last element name encountered.
    `protected java.lang.String` | `lastID` Last word ID.
    `protected ExtendedAdornedWord` | `lastWordInfo` Last word encountered.
    `protected java.util.List<ExtendedAdornedWord>` | `lastWordList` List of current last word for a text section.
    `protected ExtendedAdornedWord` | `lastWordPartInfo` Last word part encountered for a split word.
    `protected java.util.List<ExtendedAdornedWord>` | `lastWordPartList` List of current last word part for a text section.
    `protected java.util.Map<java.lang.String,ExtendedAdornedWord>` | `leadingGapWords` Gap words which appear before first real word.
    `protected int` | `pageNumber` Running page number.
    `protected XMLTagClassifier` | `tagClassifier` XML tag classes.
    `protected java.util.List<java.lang.String>` | `tagList` List of tags for determining node ancestry of each word.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader)` Create adorned word info filter.
    `ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader, boolean generateGapWords)` Create adorned word info filter.
    `ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader, XMLTagClassifier tagClassifier, boolean generateGapWords)` Create adorned word info filter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addWordOrdinals()` Generate missing word ordinals.
    `void` | `characters(char[] ch, int start, int length)` Handle character data.
    `void` | `endDocument()` End of document found.
    `void` | `endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)` Handle end of an element.
    `java.util.List<java.lang.String>` | `findWordsByMatchingLeadingPath(java.lang.String pattern)` Find words whose paths start with a given string.
    `java.util.List<java.lang.String>` | `findWordsByMatchingPath(java.lang.String pattern)` Find words matching a specified path regular expression pattern.
    `protected void` | `fixLeadingGapWords()` Correct IDs for leading gap words.
    `protected void` | `generateMissingExtendedAdornedWordInformation()` Generate missing adorned word information.
    `java.util.List<java.lang.String>` | `getAdornedWordIDs()` Return list of adorned word IDs.
    `java.util.List<java.lang.String>` | `getAdornedWordIDsInReadingContextOrder()` Get adorned word IDs in reading context order.
    `int` | `getAdornedWordIndexByID(java.lang.String id)` Get index for a word ID.
    `protected java.lang.String` | `getDivType()` Get nearest ancestral div type for word.
    `ExtendedAdornedWord` | `getExtendedAdornedWord(int index)` Get adorned word information for a word index.
    `ExtendedAdornedWord` | `getExtendedAdornedWord(java.lang.String id)` Get adorned word information for a word ID.
    `protected boolean` | `getInJumpTag()` Get in jump tag flag.
    `protected ExtendedAdornedWordFilter.MainFront` | `getMainFront()` Get main/side and front/main/back text divisions.
    `int` | `getNumberOfWords()` Get number of words read.
    `java.util.List<java.lang.String>` | `getRelatedSplitWordIDs(java.lang.String wordID)` Get related adorned word IDs for a word ID of a split word.
    `java.util.List<ExtendedAdornedWord>` | `getRelatedSplitWords(ExtendedAdornedWord adornedWordInfo)` Get related adorned words.
    `protected java.util.List<java.lang.String>` | `getSelectedWordIDs(java.lang.String startingWordID, java.lang.String endingWordID)` Get list of selected word IDs from specified ID range.
    `java.util.List<java.util.List<ExtendedAdornedWord>>` | `getSentences()` Get adorned words as a list of sentences.
    `protected java.util.List<java.util.List<ExtendedAdornedWord>>` | `getSentencesFromEOS()` Get adorned words as a list of sentences using EOS attributes.
    `protected java.util.List<java.util.List<ExtendedAdornedWord>>` | `getSentencesFromSentenceNumbers()` Get adorned words as a list of sentences using sentence numbers.
    `java.util.List<java.lang.String>` | `getSiblingWordIDs(java.lang.String wordID)` Get sibling words.
    `protected boolean` | `getSpoken()` Get spoken/not spoken word flag.
    `protected boolean` | `getUnclear()` Get unclear word flag.
    `protected boolean` | `getVerse()` Get verse flag.
    `protected java.lang.String` | `getWordText(ExtendedAdornedWord adornedWord)` Get word text for an extended adorned word.
    `void` | `ignorableWhitespace(char[] ch, int start, int length)` Handle whitespace.
    `java.lang.String[]` | `splitPath(java.lang.String path)` Split word path into separate tags.
    `java.lang.String[]` | `splitPathFull(java.lang.String path)` Split word path into separate tags.
    `void` | `startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)` Handle start of an XML element.
    `java.lang.String` | `trimTag(java.lang.String tag)` Trim tag number from XML tag.
    `java.lang.String` | `trimTrailingSoftTags(java.lang.String path)` Remove trailing soft tags from a path.

    - ### Methods inherited from class edu.northwestern.at.utils.xml.ExtendedXMLFilterImpl

      `removeAttribute, setAttributeValue, setAttributeValue, setAttributeValue`

    - ### Methods inherited from class org.xml.sax.helpers.XMLFilterImpl

      `endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, parse, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### idToWordInfo

          protected java.util.Map<java.lang.String,ExtendedAdornedWord> idToWordInfo

      Map word ID to list of adorned word information objects.

    - #### idList

          protected java.util.List<java.lang.String> idList

      List of String word IDs.

    - #### tagList

          protected java.util.List<java.lang.String> tagList

      List of tags for determining node ancestry of each word.

    - #### divStack

          protected QueueStack<java.lang.String> divStack

      Div tag stack.

    - #### lastWordList

          protected java.util.List<ExtendedAdornedWord> lastWordList

      List of current last word for a text section.

    - #### lastWordPartList

          protected java.util.List<ExtendedAdornedWord> lastWordPartList

      List of current last word part for a text section.

    - #### lastWordInfo

          protected ExtendedAdornedWord lastWordInfo

      Last word encountered. Reset for each hard/jump tag.

    - #### lastWordPartInfo

          protected ExtendedAdornedWord lastWordPartInfo

      Last word part encountered for a split word.

    - #### tagClassifier

          protected XMLTagClassifier tagClassifier

      XML tag classes.

    - #### generateGapWords

          protected boolean generateGapWords

      Generate words for gaps.

    - #### lastID

          protected java.lang.String lastID

      Last word ID.

    - #### gapCount

          protected int gapCount

      Gap count for generating IDs.

    - #### pageNumber

          protected int pageNumber

      Running page number. Starts at 0.

    - #### leadingGapWords

          protected java.util.Map<java.lang.String,ExtendedAdornedWord> leadingGapWords

      Gap words which appear before first real word.

    - #### firstWordID

          protected java.lang.String firstWordID

      First word ID found in text.

    - #### lastElementName

          protected java.lang.String lastElementName

      Last element name encountered.

  - ### Constructor Detail

    - #### ExtendedAdornedWordFilter

          public ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader)

      Create adorned word info filter.
      Parameters:
        `reader` - XML input reader to which this filter applies.

    - #### ExtendedAdornedWordFilter

          public ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader,
                                   boolean generateGapWords)

      Create adorned word info filter.
      Parameters:
        `reader` - XML input reader to which this filter applies.
        `generateGapWords` - true to generate "words" for elements.

    - #### ExtendedAdornedWordFilter

          public ExtendedAdornedWordFilter(org.xml.sax.XMLReader reader,
                                   XMLTagClassifier tagClassifier,
                                   boolean generateGapWords)

      Create adorned word info filter.
      Parameters:
        `reader` - XML input reader to which this filter applies.
        `tagClassifier` - XML tag class.
        `generateGapWords` - true to generate "words" for elements.

  - ### Method Detail

    - #### startElement

          public void startElement(java.lang.String uri,
                          java.lang.String localName,
                          java.lang.String qName,
                          org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException

      Handle start of an XML element.
      Specified by:
        `startElement` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `startElement` in class `org.xml.sax.helpers.XMLFilterImpl`
      Parameters:
        `uri` - The XML element's URI.
        `localName` - The XML element's local name.
        `qName` - The XML element's qname.
        `atts` - The XML element's attributes.
      Throws:
        `org.xml.sax.SAXException`

    - #### characters

          public void characters(char[] ch,
                        int start,
                        int length)
                          throws org.xml.sax.SAXException

      Handle character data.
      Specified by:
        `characters` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `characters` in class `org.xml.sax.helpers.XMLFilterImpl`
      Parameters:
        `ch` - Array of characters.
        `start` - The starting position in the array.
        `length` - The number of characters.
      Throws:
        `org.xml.sax.SAXException` - If there is an error.

    - #### ignorableWhitespace

          public void ignorableWhitespace(char[] ch,
                                 int start,
                                 int length)
                                   throws org.xml.sax.SAXException

      Handle whitespace.
      Specified by:
        `ignorableWhitespace` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `ignorableWhitespace` in class `org.xml.sax.helpers.XMLFilterImpl`
      Parameters:
        `ch` - Array of characters.
        `start` - The starting position in the array.
        `length` - The number of characters.
      Throws:
        `org.xml.sax.SAXException` - If there is an error.

    - #### endElement

          public void endElement(java.lang.String uri,
                        java.lang.String localName,
                        java.lang.String qName)
                          throws org.xml.sax.SAXException

      Handle end of an element.
      Specified by:
        `endElement` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `endElement` in class `org.xml.sax.helpers.XMLFilterImpl`
      Parameters:
        `uri` - The XML element's URI.
        `localName` - The XML element's local name.
        `qName` - The XML element's qname.
      Throws:
        `org.xml.sax.SAXException`

    - #### endDocument

          public void endDocument()
                           throws org.xml.sax.SAXException

      End of document found.
      Specified by:
        `endDocument` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `endDocument` in class `org.xml.sax.helpers.XMLFilterImpl`
      Throws:
        `SaxException`
        `org.xml.sax.SAXException`

    - #### getMainFront

          protected ExtendedAdornedWordFilter.MainFront getMainFront()

      Get main/side and front/main/back text divisions.
      Returns:
        MainFront object with main/side and front/middle/back entries.

    - #### getNumberOfWords

          public int getNumberOfWords()

      Get number of words read.
      Returns:
        Number of words read.

    - #### getSpoken

          protected boolean getSpoken()

      Get spoken/not spoken word flag.
      Returns:
        true if word appears as descendant of or <> tag, false otherwise.

    - #### getVerse

          protected boolean getVerse()

      Get verse flag.
      Returns:
        true if word appears as descendant of tag, false otherwise.

    - #### getUnclear

          protected boolean getUnclear()

      Get unclear word flag.
      Returns:
        true if word appears as descendant of tag, false otherwise.

    - #### getInJumpTag

          protected boolean getInJumpTag()

      Get in jump tag flag.
      Returns:
        true if word appears as descendant of a jump tag, false otherwise.

    - #### getDivType

          protected java.lang.String getDivType()

      Get nearest ancestral div type for word.
      Returns:
        Nearest ancestral div type for word.

    - #### getAdornedWordIDs

          public java.util.List<java.lang.String> getAdornedWordIDs()

      Return list of adorned word IDs.
      Returns:
        List of String adorned word IDs.

    - #### getExtendedAdornedWord

          public ExtendedAdornedWord getExtendedAdornedWord(java.lang.String id)

      Get adorned word information for a word ID.
      Parameters:
        `id` - The String word ID.
      Returns:
        ExtendedAdornedWord for the specified ID. Returns null if ID not found.

    - #### getExtendedAdornedWord

          public ExtendedAdornedWord getExtendedAdornedWord(int index)

      Get adorned word information for a word index.
      Parameters:
        `index` - The word index.
      Returns:
        ExtendedAdornedWord for the specified index. Returns null if index not found.

    - #### getAdornedWordIndexByID

          public int getAdornedWordIndexByID(java.lang.String id)

      Get index for a word ID.
      Parameters:
        `id` - The String word ID.
      Returns:
        Index of word in adorned words list. Returns -1 ID not found.

    - #### getAdornedWordIDsInReadingContextOrder

          public java.util.List<java.lang.String> getAdornedWordIDsInReadingContextOrder()

      Get adorned word IDs in reading context order.
      Returns:
        List of word IDs in reading context order.

    - #### getSentences

          public java.util.List<java.util.List<ExtendedAdornedWord>> getSentences()

      Get adorned words as a list of sentences.
      Returns:
        List of sentences. Each sentence is a list of ExtendedAdornedWord entries. Sentences are returned in reading context order. Only one ExtendedAdornedWord entry is returned for split words.

        This method tries to return sentences in as close to their order of appearance in the text as possible. Sentences from intrusive jump tags will generally appear after the text section into which they intrude, and so may be dislodged an arbitrary distance from their actual position in the text.

    - #### getSentencesFromEOS

          protected java.util.List<java.util.List<ExtendedAdornedWord>> getSentencesFromEOS()

      Get adorned words as a list of sentences using EOS attributes.
      Returns:
        List of sentences. Each sentence is a list of ExtendedAdornedWord entries. Sentences are returned in reading context order. Only one ExtendedAdornedWord entry is returned for split words.

        This method tries to return sentences in as close to their order of appearance in the text as possible. Sentences from intrusive jump tags will generally appear after the text section into which they intrude, and so may be dislodged an arbitrary distance from their actual position in the text.

    - #### getSentencesFromSentenceNumbers

          protected java.util.List<java.util.List<ExtendedAdornedWord>> getSentencesFromSentenceNumbers()

      Get adorned words as a list of sentences using sentence numbers.
      Returns:
        List of sentences. Each sentence is a list of ExtendedAdornedWord entries. Sentences are returned in reading context order. Only one ExtendedAdornedWord entry is returned for split words.

        This method tries to return sentences in as close to their order of appearance in the text as possible. Sentences from intrusive jump tags will generally appear after the text section into which they intrude, and so may be dislodged an arbitrary distance from their actual position in the text.

    - #### getRelatedSplitWordIDs

          public java.util.List<java.lang.String> getRelatedSplitWordIDs(java.lang.String wordID)

      Get related adorned word IDs for a word ID of a split word.
      Parameters:
        `wordID` - Word ID for which related IDs are wanted.
      Returns:
        List of related word IDs.

        Related word IDs are the word IDs for the other parts of a split word. The returned list includes the given wordID.

        For unsplit words, the single given wordID is returned in the list.

        Null is returned when the wordID does not exist.

    - #### getRelatedSplitWords

          public java.util.List<ExtendedAdornedWord> getRelatedSplitWords(ExtendedAdornedWord adornedWordInfo)

      Get related adorned words.
      Parameters:
        `adornedWordInfo` - Adorned word for which related words are wanted.
      Returns:
        List of related adorned words.

        Related words are those corresponding to the parts of a split word. The returned list includes the given word.

        For unsplit words, the single given adorned word is returned in the list.

    - #### trimTag

          public java.lang.String trimTag(java.lang.String tag)

      Trim tag number from XML tag.
      Parameters:
        `tag` - XML tag to trim.
      Returns:
        Trimmed tag.

    - #### splitPathFull

          public java.lang.String[] splitPathFull(java.lang.String path)

      Split word path into separate tags.
      Parameters:
        `path` - The word path.
      Returns:
        String array of split XML tags. The trailing "w[]" element is removed.

    - #### splitPath

          public java.lang.String[] splitPath(java.lang.String path)

      Split word path into separate tags.
      Parameters:
        `path` - The word path.
      Returns:
        String array of split XML tags. Both the leading document name tag and the trailing word (w[]) tag are removed.

    - #### trimTrailingSoftTags

          public java.lang.String trimTrailingSoftTags(java.lang.String path)

      Remove trailing soft tags from a path.
      Parameters:
        `path` - Path from which to remove trailing soft tags.
      Returns:
        Path with trailing soft tags removed.

    - #### getSiblingWordIDs

          public java.util.List<java.lang.String> getSiblingWordIDs(java.lang.String wordID)

      Get sibling words.
      Parameters:
        `wordID` - The word ID of the word for which to find siblings.
      Returns:
        String list of sibling word IDs. Empty list if no siblings found.

        Sibling words have the same parent hard or jump tag.

    - #### findWordsByMatchingPath

          public java.util.List<java.lang.String> findWordsByMatchingPath(java.lang.String pattern)

      Find words matching a specified path regular expression pattern.
      Parameters:
        `pattern` - The regular expression pattern to match.
      Returns:
        String list of words matching the pattern. Empty if no words match.

    - #### findWordsByMatchingLeadingPath

          public java.util.List<java.lang.String> findWordsByMatchingLeadingPath(java.lang.String pattern)

      Find words whose paths start with a given string.
      Parameters:
        `pattern` - The pattern to match.
      Returns:
        String list of words matching the pattern. Empty if no words match.

    - #### getSelectedWordIDs

          protected java.util.List<java.lang.String> getSelectedWordIDs(java.lang.String startingWordID,
                                                            java.lang.String endingWordID)

      Get list of selected word IDs from specified ID range.
      Parameters:
        `startingWordID` - Starting word ID.
        `endingWordID` - Ending word ID.
      Returns:
        String list of selected word IDs.

    - #### addWordOrdinals

          protected void addWordOrdinals()

      Generate missing word ordinals.

    - #### fixLeadingGapWords

          protected void fixLeadingGapWords()

      Correct IDs for leading gap words.

    - #### generateMissingExtendedAdornedWordInformation

          protected void generateMissingExtendedAdornedWordInformation()

      Generate missing adorned word information.

      Generates any missing word and sentence numbers, end of sentence flags, word paths, gap IDs, etc.

    - #### getWordText

          protected java.lang.String getWordText(ExtendedAdornedWord adornedWord)

      Get word text for an extended adorned word.
      Parameters:
        `adornedWord` - The extended adorned word.

        The word text for an unsplit word is just the word's text. The word text for a split word is the joined text for all word parts, in order of appearance of the parts.