edu.northwestern.at.morphadorner.corpuslinguistics.syllablecounter

## Class EnglishSyllableCounter

- java.lang.Object
- - edu.northwestern.at.morphadorner.corpuslinguistics.syllablecounter.EnglishSyllableCounter

- All Implemented Interfaces:
    SyllableCounter
  Direct Known Subclasses:
    DefaultSyllableCounter

      public class EnglishSyllableCounter
      extends java.lang.Object
      implements SyllableCounter

  EnglishSyllableCounter: Counts syllables in English words.

  This syllable counter uses a two-stage process for counting syllables in a word.

  1. The word is first looked up in a dictionary which maps words to their syllable counts. When the word is found in the dictionary, the associated syllable count is returned.
  2. When the word does not appear in the dictionary, the syllable count is computed from the number of vowel groups in the word. Adjustments are made for silent final "e"s and certain other letter groups.

  Most of the data used to construct the dictionary of syllable counts comes from a pronunciation dictionary provided by Carnegie-Mellon University.

  The code used to compute syllable counts for words not found in the syllable counts dictionary is based upon that written by Greg Fast in Perl and Larry Ogrodnek in Java. Their methods provide the correct syllable count about 85-90% of the time. Rarely is the syllable count wrong by more than one.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static java.util.regex.Pattern[]` | `AddSyllables`
    `protected static java.util.regex.Pattern[]` | `SubtractSyllables`
    `protected static java.lang.String` | `syllableCountFileName` Path to map from spellings to syllable counts.
    `protected java.util.Map<java.lang.String,java.lang.Integer>` | `syllableCountMap` Map of spellings to syllable counts.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EnglishSyllableCounter()` Create an English syllable counter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `countSyllables(java.lang.String word)` Find number of syllables in a single English word.
    `java.util.Map<java.lang.String,java.lang.Integer>` | `getSyllableCountMap()` Get syllable count map.
    `java.util.Map<java.lang.String,java.lang.Integer>` | `loadSyllableCountMap(java.net.URL mapURL, java.lang.String separator, java.lang.String qualifier, java.lang.String encoding)` Load syllable counts map from a URL.

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

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

- - ### Field Detail

    - #### syllableCountFileName

          protected static java.lang.String syllableCountFileName

      Path to map from spellings to syllable counts.

    - #### syllableCountMap

          protected java.util.Map<java.lang.String,java.lang.Integer> syllableCountMap

      Map of spellings to syllable counts.

    - #### SubtractSyllables

          protected static final java.util.regex.Pattern[] SubtractSyllables

    - #### AddSyllables

          protected static final java.util.regex.Pattern[] AddSyllables

  - ### Constructor Detail

    - #### EnglishSyllableCounter

          public EnglishSyllableCounter()

      Create an English syllable counter.

  - ### Method Detail

    - #### loadSyllableCountMap

          public java.util.Map<java.lang.String,java.lang.Integer> loadSyllableCountMap(java.net.URL mapURL,
                                                                               java.lang.String separator,
                                                                               java.lang.String qualifier,
                                                                               java.lang.String encoding)
                                                                                 throws java.io.IOException,
                                                                                        java.io.FileNotFoundException

      Load syllable counts map from a URL.
      Parameters:
        `mapURL` - URL for map file.
        `separator` - Field separator.
        `qualifier` - Quote character.
        `encoding` - Character encoding for the file.
      Returns:
        Map with values read from file.
      Throws:
        `java.io.FileNotFoundException` - If input file does not exist.
        `java.io.IOException` - If input file cannot be opened.

    - #### getSyllableCountMap

          public java.util.Map<java.lang.String,java.lang.Integer> getSyllableCountMap()

      Get syllable count map.
      Returns:
        The syllable count map. Keys are words, values are integer syllable counts.

    - #### countSyllables

          public int countSyllables(java.lang.String word)

      Find number of syllables in a single English word.
      Specified by:
        `countSyllables` in interface `SyllableCounter`
      Parameters:
        `word` - The word whose syllable count is desired.
      Returns:
        The number of syllables in the word.