rita.support
Class RiLexiconImpl

java.lang.Object
  extended by rita.support.RiLexiconImpl
All Implemented Interfaces:
com.sun.speech.freetts.lexicon.Lexicon, RiLexiconIF

public class RiLexiconImpl
extends java.lang.Object
implements RiLexiconIF

Provides an implementation of a user-customizable Lexicon using CMU-style pronunciation tags and Penn-style part-of-speech tags.

Note: this is a support class, public access is provided through rita.RiLexicon.

The implementation also allows users to define their own addenda that will be addenda, it values will be added to the system addenda, overriding any existing elements in the system addenda.


Field Summary
static java.lang.String DATA_DELIM
           
 
Method Summary
 void addAddendum(java.lang.String word, java.lang.String pos, java.lang.String[] phones)
          returns a '0' (no-stress) or 1 (stressed) for each phoneme public String[] getRawStresses(String word) { String phones = lookupPhonemesAndStresses(word); if (phones == null) return null; String[] p = phones.split(Featured.PHONEME_BOUNDARY); for (int i = 0; i < p .length; i++) { String s = p[i]; char c = s.charAt(s.length()-1); System.err.println("Checking: "+s+"/"+c); if (c == RiLexicon.STRESSED) p[i] = "1"; else p[i] = "0"; } return p; } static final char[] STRESS_MARKS = { RiLexicon.STRESSED, RiLexicon.UNSTRESSED };
 int getAddendaCount()
          Returns the number of user addenda items added to the lexicon
 java.util.Map getFeatures(java.lang.String word)
           
static RiLexiconImpl getInstance()
          Deprecated.  
static RiLexiconImpl getInstance(processing.core.PApplet p)
          Creates, loads and returns the singleton lexicon instance.
static RiLexiconImpl getInstance(processing.core.PApplet p, java.lang.String pathToLexicon)
          Creates, loads and returns the singleton lexicon instance.
 java.util.Map getLexicalData()
          Returns the raw data (as a Map) used in the lexicon.
 java.lang.String[] getPhonemeArr(java.lang.String word, boolean useLTS)
          Gets the phoneme list for a given word, either via lookup or, if not found, (and useLTS is true), generated via the letter-to-sound engine, else null.
 java.lang.String getPhonemes(java.lang.String word, boolean useLTS)
          Gets the phoneme list for a given word, either via lookup or, if not found, (and useLTS is true), generated via the letter-to-sound engine, else null.
 java.lang.String[] getPhones(java.lang.String word, java.lang.String partOfSpeech)
          Gets the phone list (+ stresses) for a given word.
 java.lang.String[] getPhones(java.lang.String word, java.lang.String partOfSpeech, boolean useLTS)
          Gets the phone list (+ stresses) for a given word.
 java.lang.String[] getPosArr(java.lang.String word)
           
 java.lang.String getPosStr(java.lang.String word)
           
 java.lang.String getPosStrOld(java.lang.String word)
           
 java.lang.String getRawPhones(java.lang.String word)
           
 java.lang.String getRawPhones(java.lang.String word, boolean useLTS)
           
 java.util.Set getWords()
           
 java.util.Set getWords(java.lang.String regex)
           
 java.util.Set getWordsWithPos(java.lang.String pos)
           
static boolean isCaching()
           
 boolean isLoaded()
          Determines if this lexicon is loaded.
 boolean isSyllableBoundary(java.util.List syllablePhones, java.lang.String[] wordPhones, int currentWordPhone)
          Determines if the currentPhone represents a new syllable boundary.
 java.util.Iterator iterator()
           
 java.util.Set keySet()
           
 void load()
          Loads the data into this lexicon.
 java.lang.String lookupRaw(java.lang.String word)
           
static void main(java.lang.String[] args)
           
 java.util.Iterator posIterator(java.lang.String pos)
           
 void preloadFeatures()
           
 java.util.Iterator randomIterator()
           
 java.util.Iterator randomPosIterator(java.lang.String pos)
           
 void removeAddendum(java.lang.String word, java.lang.String partOfSpeech)
          Removes a word from the lexicon.
 void setLexicalData(java.util.Map lexicalData)
          Sets the raw data (a Map) used in the lexicon, replacing all default words and features.
 int size()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_DELIM

public static final java.lang.String DATA_DELIM
See Also:
Constant Field Values
Method Detail

getInstance

public static RiLexiconImpl getInstance()
Deprecated. 

Invisible:

getInstance

public static RiLexiconImpl getInstance(processing.core.PApplet p)
Creates, loads and returns the singleton lexicon instance.


getInstance

public static RiLexiconImpl getInstance(processing.core.PApplet p,
                                        java.lang.String pathToLexicon)
Creates, loads and returns the singleton lexicon instance.


getLexicalData

public java.util.Map getLexicalData()
Returns the raw data (as a Map) used in the lexicon. Modifications to this Map will be immediately reflected in the lexicon.


setLexicalData

public void setLexicalData(java.util.Map lexicalData)
Sets the raw data (a Map) used in the lexicon, replacing all default words and features.


getAddendaCount

public int getAddendaCount()
Returns the number of user addenda items added to the lexicon


isLoaded

public boolean isLoaded()
Determines if this lexicon is loaded.

Specified by:
isLoaded in interface com.sun.speech.freetts.lexicon.Lexicon
Returns:
true if the lexicon is loaded

load

public void load()
          throws java.io.IOException
Loads the data into this lexicon. If the

Specified by:
load in interface com.sun.speech.freetts.lexicon.Lexicon
Throws:
java.io.IOException - if errors occur during loading

getPhones

public java.lang.String[] getPhones(java.lang.String word,
                                    java.lang.String partOfSpeech)
Gets the phone list (+ stresses) for a given word. If a phone list cannot be found, returns null. The partOfSpeech is optional, but null always matches.

Specified by:
getPhones in interface com.sun.speech.freetts.lexicon.Lexicon

getPhones

public java.lang.String[] getPhones(java.lang.String word,
                                    java.lang.String partOfSpeech,
                                    boolean useLTS)
Gets the phone list (+ stresses) for a given word. If a phone list cannot be found, null is returned. The partOfSpeech is optional, but null always matches.

Specified by:
getPhones in interface com.sun.speech.freetts.lexicon.Lexicon

getPhonemes

public java.lang.String getPhonemes(java.lang.String word,
                                    boolean useLTS)
Gets the phoneme list for a given word, either via lookup or, if not found, (and useLTS is true), generated via the letter-to-sound engine, else null.


getPhonemeArr

public java.lang.String[] getPhonemeArr(java.lang.String word,
                                        boolean useLTS)
Gets the phoneme list for a given word, either via lookup or, if not found, (and useLTS is true), generated via the letter-to-sound engine, else null.


removeAddendum

public void removeAddendum(java.lang.String word,
                           java.lang.String partOfSpeech)
Removes a word from the lexicon.

Specified by:
removeAddendum in interface com.sun.speech.freetts.lexicon.Lexicon
Parameters:
word - the word to remove
partOfSpeech - the part of speech

size

public int size()

getWords

public java.util.Set getWords()

lookupRaw

public java.lang.String lookupRaw(java.lang.String word)
Invisible:

iterator

public java.util.Iterator iterator()
Invisible:

randomIterator

public java.util.Iterator randomIterator()

randomPosIterator

public java.util.Iterator randomPosIterator(java.lang.String pos)

posIterator

public java.util.Iterator posIterator(java.lang.String pos)

keySet

public java.util.Set keySet()

getWords

public java.util.Set getWords(java.lang.String regex)

getWordsWithPos

public java.util.Set getWordsWithPos(java.lang.String pos)

getFeatures

public java.util.Map getFeatures(java.lang.String word)

addAddendum

public void addAddendum(java.lang.String word,
                        java.lang.String pos,
                        java.lang.String[] phones)
returns a '0' (no-stress) or 1 (stressed) for each phoneme public String[] getRawStresses(String word) { String phones = lookupPhonemesAndStresses(word); if (phones == null) return null; String[] p = phones.split(Featured.PHONEME_BOUNDARY); for (int i = 0; i < p .length; i++) { String s = p[i]; char c = s.charAt(s.length()-1); System.err.println("Checking: "+s+"/"+c); if (c == RiLexicon.STRESSED) p[i] = "1"; else p[i] = "0"; } return p; } static final char[] STRESS_MARKS = { RiLexicon.STRESSED, RiLexicon.UNSTRESSED };

Specified by:
addAddendum in interface com.sun.speech.freetts.lexicon.Lexicon

isSyllableBoundary

public boolean isSyllableBoundary(java.util.List syllablePhones,
                                  java.lang.String[] wordPhones,
                                  int currentWordPhone)
Determines if the currentPhone represents a new syllable boundary.

Specified by:
isSyllableBoundary in interface com.sun.speech.freetts.lexicon.Lexicon
Parameters:
syllablePhones - the phones in the current syllable so far
wordPhones - the phones for the whole word
currentWordPhone - the word phone in question
Returns:
true if the word phone in question is on a syllable boundary; otherwise false.

isCaching

public static boolean isCaching()

preloadFeatures

public void preloadFeatures()

getRawPhones

public java.lang.String getRawPhones(java.lang.String word)

getRawPhones

public java.lang.String getRawPhones(java.lang.String word,
                                     boolean useLTS)

getPosStr

public java.lang.String getPosStr(java.lang.String word)

getPosStrOld

public java.lang.String getPosStrOld(java.lang.String word)

getPosArr

public java.lang.String[] getPosArr(java.lang.String word)
Specified by:
getPosArr in interface RiLexiconIF

main

public static void main(java.lang.String[] args)