nick.syllable
Class DictionarySyllabilizer

java.lang.Object
  extended by nick.syllable.DictionarySyllabilizer

public class DictionarySyllabilizer
extends java.lang.Object

This class loads a specified dictionary file into memory. This class was designed to work with the Carnegie Mellon Pronouncing Dictionary version cmudict.0.6d. The dictionary contains about 130,000 words. This project would not be possible without their work.

The expected file format is as follows:

WORD PRONOUNCIATION_INFO

Where 'WORD' is a single word in the dictionary and 'PRONOUNCIATION_INFO' is a string that contains numerical values indicating lexical stress. Each syllable has a numerical value indicating no stress, primary stress or secondary stress. This class ignores all information besides the number of times these values appear.

For example:

STEWARDESSES S T UW1 ER0 D AH0 S IH0 Z

The word is stewardesses and its pronunciation information contains the digits 1,0,0,0. These values occur four times and therefore the word has four syllables. Case is is ignored by this class.

This class is very basic and provides efficient access and lookups. The basic accessor methods randomWord(), wordInDictionary(), getSyllables() and dictionarySize() run in expected O(1) time.

Version:
April 7th, 2009
Author:
Nick Aschenbach (nick.aschenbach@gmail.com)

Constructor Summary
DictionarySyllabilizer(java.lang.String file_name)
          Construct a Dictionary Syllabilizer object
 
Method Summary
 java.lang.String[] dictionary()
           
 int dictionarySize()
           
 int getSyllables(java.lang.String key)
          Provide the number of syllables for a given word.
 java.lang.String randomWord()
           
 boolean wordInDictionary(java.lang.String key)
          Find out if a given word is in the dictionary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DictionarySyllabilizer

public DictionarySyllabilizer(java.lang.String file_name)
                       throws java.io.IOException
Construct a Dictionary Syllabilizer object

Parameters:
file_name - The name of the file to load.
Throws:
java.io.IOException
Method Detail

getSyllables

public int getSyllables(java.lang.String key)
Provide the number of syllables for a given word.

Parameters:
key - The word to search.
Returns:
The number of syllables in the given word.

randomWord

public java.lang.String randomWord()
Returns:
A random word from the dictionary.

wordInDictionary

public boolean wordInDictionary(java.lang.String key)
Find out if a given word is in the dictionary.

Parameters:
key - The word to check.
Returns:
True if the word is in the dictionary and false otherwise.

dictionarySize

public int dictionarySize()
Returns:
The size of the dictionary.

dictionary

public java.lang.String[] dictionary()
Returns:
All of the keys on this dictionary.