public class EnglishSyllableCounter extends java.lang.Object implements SyllableCounter
This syllable counter uses a two-stage process for counting syllables in a word.
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.
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 and Description |
---|
EnglishSyllableCounter()
Create an English syllable counter.
|
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.
|
protected static java.lang.String syllableCountFileName
protected java.util.Map<java.lang.String,java.lang.Integer> syllableCountMap
protected static final java.util.regex.Pattern[] SubtractSyllables
protected static final java.util.regex.Pattern[] AddSyllables
public EnglishSyllableCounter()
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
mapURL
- URL for map file.separator
- Field separator.qualifier
- Quote character.encoding
- Character encoding for the file.java.io.FileNotFoundException
- If input file does not exist.java.io.IOException
- If input file cannot be opened.public java.util.Map<java.lang.String,java.lang.Integer> getSyllableCountMap()
public int countSyllables(java.lang.String word)
countSyllables
in interface SyllableCounter
word
- The word whose syllable count is desired.