edu.northwestern.at.morphadorner.corpuslinguistics.inputter

## Class XMLTextInputter

- java.lang.Object
- - edu.northwestern.at.utils.IsCloseableObject
  - - edu.northwestern.at.morphadorner.corpuslinguistics.inputter.XMLTextInputter

- All Implemented Interfaces:
    TextInputter
  Direct Known Subclasses:
    CompressedXMLTextInputter, DiskBasedXMLTextInputter, SimpleXMLTextInputter

      public class XMLTextInputter
      extends IsCloseableObject
      implements TextInputter

  Text inputter which reads text from a TEI or EEBO XML file.

  The XML file can be divided into smaller sections which are stored in a map. MorphAdorner uses a modified XGTagger interface to adorn each section of text separately, and then merge the results to produce the final adorned XML output.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.jdom2.Document` | `document` The document text object.
    `protected java.lang.String` | `encoding` Text encoding.
    `protected boolean` | `fixGaps` True to fix elements.
    `protected boolean` | `fixOrigs` True to fix elements.
    `protected boolean` | `fixSplitWords` True to fix selected split words.
    `protected java.util.List<PatternReplacer>` | `fixSplitWordsPatternReplacers` Pattern replacers for fixing split words.
    `protected java.util.Map<java.lang.String,java.lang.Object>` | `segmentMap` Map which holds segmented XML text.
    `protected java.util.List<java.lang.String>` | `segmentNames` Segment names.
    `protected boolean` | `splitText` True to split text body into segments.
    `protected boolean` | `storesSegmentFiles` True if segment files are stored in the segment map instead of segment text.
    `protected java.lang.String` | `teiHeaderPattern` TEI header element pattern.
    `protected int` | `textID` Text ID number for generated XML segments.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XMLTextInputter()` Create XML text inputter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close inputter.
    `protected void` | `doLoadDocument(org.jdom2.Document document, java.lang.String schemaURI, java.lang.String docPath)` Loads text from a document into a map.
    `protected void` | `doLoadText(java.net.URL url, java.lang.String encoding, java.lang.String schemaURI)` Loads text from a URL into a map.
    `void` | `enableGapFixer(boolean fixGaps)` Enable gap element fixer.
    `void` | `enableOrigFixer(boolean fixOrigs)` Enable orig element fixer.
    `void` | `enableSplitWordsFixer(boolean fixSplitWords, java.util.List<PatternReplacer> patternReplacers)` Enable split words fixer.
    `void` | `finalize()` Finalize,
    `org.jdom2.Element` | `findChild(org.jdom2.Element parent, java.lang.String namePat)` Find child node name matching regular expression.
    `protected int` | `getNextTextID()` Get next text ID.
    `protected java.lang.String` | `getSegment(java.lang.String segmentName)` Get segment text.
    `int` | `getSegmentCount()` Returns number of text segments.
    `java.lang.String` | `getSegmentName(int segmentNumber)` Returns name of specified segment.
    `java.lang.String` | `getSegmentText(int segmentNumber)` Returns specified segment of loaded text.
    `java.lang.String` | `getSegmentText(java.lang.String segmentName)` Returns specified segment of loaded text.
    `void` | `loadText(java.lang.String str)` Reads text from a String.
    `void` | `loadText(java.lang.String str, java.lang.String xmlSchemaURI)` Reads text from a string using a specified XML schema.
    `void` | `loadText(java.net.URL url, java.lang.String encoding)` Reads text from a URL into a string.
    `void` | `loadText(java.net.URL url, java.lang.String encoding, java.lang.String xmlSchemaURI)` Reads text from a URL using a specified XML schema.
    `protected void` | `putSegment(java.lang.String segmentName, java.lang.String segmentText)` Save segment text.
    `void` | `setSegmentText(int segmentNumber, java.io.File segmentTextFile)` Updates specified segment of loaded text from file.
    `void` | `setSegmentText(int segmentNumber, java.lang.String segmentText)` Updates specified segment of loaded text.
    `void` | `setSegmentText(java.lang.String segmentName, java.io.File segmentTextFile)` Updates specified segment of loaded text from file.
    `void` | `setSegmentText(java.lang.String segmentName, java.lang.String segmentText)` Updates specified segment of loaded text.
    `boolean` | `usesSegmentFiles()` Does inputter use segment files?
    `protected void` | `writeChildren(org.jdom2.Element element, java.lang.String baseFileName, boolean splitText)` Store children of a DOM element.

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

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

- - ### Field Detail

    - #### segmentMap

          protected java.util.Map<java.lang.String,java.lang.Object> segmentMap

      Map which holds segmented XML text.

      The key is the segment name. The value is the segment data. The value may be something else in subclasses.

    - #### textID

          protected int textID

      Text ID number for generated XML segments.

    - #### segmentNames

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

      Segment names.

    - #### encoding

          protected java.lang.String encoding

      Text encoding.

    - #### splitText

          protected boolean splitText

      True to split text body into segments.

    - #### fixGaps

          protected boolean fixGaps

      True to fix elements.

    - #### fixOrigs

          protected boolean fixOrigs

      True to fix elements.

    - #### fixSplitWords

          protected boolean fixSplitWords

      True to fix selected split words.

    - #### fixSplitWordsPatternReplacers

          protected java.util.List<PatternReplacer> fixSplitWordsPatternReplacers

      Pattern replacers for fixing split words.

    - #### teiHeaderPattern

          protected final java.lang.String teiHeaderPattern

      TEI header element pattern.
      See Also:
        Constant Field Values

    - #### document

          protected org.jdom2.Document document

      The document text object.

    - #### storesSegmentFiles

          protected boolean storesSegmentFiles

      True if segment files are stored in the segment map instead of segment text.

  - ### Constructor Detail

    - #### XMLTextInputter

          public XMLTextInputter()

      Create XML text inputter.

  - ### Method Detail

    - #### doLoadDocument

          protected void doLoadDocument(org.jdom2.Document document,
                            java.lang.String schemaURI,
                            java.lang.String docPath)
                                 throws org.jdom2.JDOMException,
                                        java.io.IOException,
                                        java.net.URISyntaxException,
                                        org.xml.sax.SAXException

      Loads text from a document into a map.
      Parameters:
        `document` - Document from which to read text.
        `schemaURI` - XML schema URI. Null if none.
        `docPath` - Path for original document.
      Throws:
        `java.io.IOException` - If an I/O error occurs.
        `org.jdom2.JDOMException`
        `java.net.URISyntaxException`
        `org.xml.sax.SAXException`

    - #### doLoadText

          protected void doLoadText(java.net.URL url,
                        java.lang.String encoding,
                        java.lang.String schemaURI)
                             throws org.jdom2.JDOMException,
                                    java.io.IOException,
                                    java.net.URISyntaxException,
                                    org.xml.sax.SAXException

      Loads text from a URL into a map.
      Parameters:
        `url` - URL from which to read text.
        `encoding` - Text encoding.
        `schemaURI` - XML schema URI. Null if none.
      Throws:
        `java.io.IOException` - If an I/O error occurs.
        `org.jdom2.JDOMException`
        `java.net.URISyntaxException`
        `org.xml.sax.SAXException`

    - #### findChild

          public org.jdom2.Element findChild(org.jdom2.Element parent,
                                    java.lang.String namePat)

      Find child node name matching regular expression.
      Parameters:
        `parent` - Node whose child we want.
        `namePat` - Regular expression for child name.
      Returns:
        The first child whose name matches the specified namePat, or null if none matches.

    - #### loadText

          public void loadText(java.net.URL url,
                      java.lang.String encoding)
                        throws java.lang.Exception

      Reads text from a URL into a string.
      Specified by:
        `loadText` in interface `TextInputter`
      Parameters:
        `url` - URL from which to read text.
        `encoding` - Text encoding.
      Throws:
        `java.lang.Exception` - If an error occurs.

    - #### loadText

          public void loadText(java.net.URL url,
                      java.lang.String encoding,
                      java.lang.String xmlSchemaURI)
                        throws java.lang.Exception

      Reads text from a URL using a specified XML schema.
      Specified by:
        `loadText` in interface `TextInputter`
      Parameters:
        `url` - URL from which to read text.
        `encoding` - Text encoding.
        `xmlSchemaURI` - String URI specifying XML schema.
      Throws:
        `java.lang.Exception` - If an error occurs.

        The schema and schema type should be ignored when the input is not an XML file.

    - #### loadText

          public void loadText(java.lang.String str)
                        throws java.lang.Exception

      Reads text from a String.
      Specified by:
        `loadText` in interface `TextInputter`
      Parameters:
        `str` - String from which to read text.
      Throws:
        `java.io.IOException` - If an error occurs.
        `java.lang.Exception`

    - #### loadText

          public void loadText(java.lang.String str,
                      java.lang.String xmlSchemaURI)
                        throws java.lang.Exception

      Reads text from a string using a specified XML schema.
      Specified by:
        `loadText` in interface `TextInputter`
      Parameters:
        `str` - String from which to read text.
        `xmlSchemaURI` - String URI specifying Xml schema.
      Throws:
        `java.lang.Exception` - If an error occurs.

        The schema and schema type should be ignored when the input is not an XML file.

    - #### getSegmentCount

          public int getSegmentCount()

      Returns number of text segments.
      Specified by:
        `getSegmentCount` in interface `TextInputter`
      Returns:
        Number of text segments.

    - #### getSegmentName

          public java.lang.String getSegmentName(int segmentNumber)

      Returns name of specified segment.
      Specified by:
        `getSegmentName` in interface `TextInputter`
      Parameters:
        `segmentNumber` - The segment number (starts at 0).
      Returns:
        The name for the specified segment number, or null if the segment number is invalid.

    - #### getSegmentText

          public java.lang.String getSegmentText(int segmentNumber)

      Returns specified segment of loaded text.
      Specified by:
        `getSegmentText` in interface `TextInputter`
      Parameters:
        `segmentNumber` - The segment number (starts at 0).
      Returns:
        The text for for the specified segment number, or null if the segment number is invalid. The returned text may be an empty string if the segment number is valid but the segment contains no text.

    - #### getSegmentText

          public java.lang.String getSegmentText(java.lang.String segmentName)

      Returns specified segment of loaded text.
      Specified by:
        `getSegmentText` in interface `TextInputter`
      Parameters:
        `segmentName` - The segment name.
      Returns:
        The text for for the specified segment name, or null if the segment name is invalid. The returned text may be an empty string if the segment name is valid but the segment contains no text.

    - #### setSegmentText

          public void setSegmentText(int segmentNumber,
                            java.lang.String segmentText)

      Updates specified segment of loaded text.
      Specified by:
        `setSegmentText` in interface `TextInputter`
      Parameters:
        `segmentNumber` - The segment number (starts at 0).
        `segmentText` - The updated segment text.

    - #### setSegmentText

          public void setSegmentText(java.lang.String segmentName,
                            java.lang.String segmentText)

      Updates specified segment of loaded text.
      Specified by:
        `setSegmentText` in interface `TextInputter`
      Parameters:
        `segmentName` - The segment name.
        `segmentText` - The updated segment text.

    - #### setSegmentText

          public void setSegmentText(int segmentNumber,
                            java.io.File segmentTextFile)

      Updates specified segment of loaded text from file.
      Specified by:
        `setSegmentText` in interface `TextInputter`
      Parameters:
        `segmentNumber` - The segment number (starts at 0).
        `segmentTextFile` - The file containing the updated segment text.

    - #### setSegmentText

          public void setSegmentText(java.lang.String segmentName,
                            java.io.File segmentTextFile)

      Updates specified segment of loaded text from file.
      Specified by:
        `setSegmentText` in interface `TextInputter`
      Parameters:
        `segmentName` - The segment name.
        `segmentTextFile` - The file containing the updated segment text.

    - #### getNextTextID

          protected int getNextTextID()

      Get next text ID.
      Returns:
        The next text ID.

    - #### writeChildren

          protected void writeChildren(org.jdom2.Element element,
                           java.lang.String baseFileName,
                           boolean splitText)

      Store children of a DOM element.
      Parameters:
        `element` - The DOM element to store.
        `baseFileName` - The base file name for entry names generated from the DOM element.
        `splitText` - True to split body text into segments.

    - #### getSegment

          protected java.lang.String getSegment(java.lang.String segmentName)

      Get segment text.
      Parameters:
        `segmentName` - Segment name.
      Returns:
        Segment text.

    - #### putSegment

          protected void putSegment(java.lang.String segmentName,
                        java.lang.String segmentText)

      Save segment text.
      Parameters:
        `segmentName` - Segment name.
        `segmentText` - Segment text.

    - #### enableGapFixer

          public void enableGapFixer(boolean fixGaps)

      Enable gap element fixer.
      Specified by:
        `enableGapFixer` in interface `TextInputter`
      Parameters:
        `fixGaps` - true to fix gap tags.

    - #### enableOrigFixer

          public void enableOrigFixer(boolean fixOrigs)

      Enable orig element fixer.
      Specified by:
        `enableOrigFixer` in interface `TextInputter`
      Parameters:
        `fixOrigs` - true to fix orig tags.

    - #### enableSplitWordsFixer

          public void enableSplitWordsFixer(boolean fixSplitWords,
                                   java.util.List<PatternReplacer> patternReplacers)

      Enable split words fixer.
      Specified by:
        `enableSplitWordsFixer` in interface `TextInputter`
      Parameters:
        `fixSplitWords` - true to fix selected split words.
        `patternReplacers` - Patterns for fixing split words.

    - #### usesSegmentFiles

          public boolean usesSegmentFiles()

      Does inputter use segment files?
      Specified by:
        `usesSegmentFiles` in interface `TextInputter`
      Returns:
        true if inputter uses segment files.

    - #### close

          public void close()

      Close inputter.
      Overrides:
        `close` in class `IsCloseableObject`

    - #### finalize

          public void finalize()
                        throws java.lang.Throwable

      Finalize,
      Overrides:
        `finalize` in class `java.lang.Object`
      Throws:
        `java.lang.Throwable`