upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / lexicon / Lexicon.java
1 /**
2  * Portions Copyright 2001 Sun Microsystems, Inc.
3  * Portions Copyright 1999-2001 Language Technologies Institute, 
4  * Carnegie Mellon University.
5  * All Rights Reserved.  Use is subject to license terms.
6  * 
7  * See the file "license.terms" for information on usage and
8  * redistribution of this file, and for a DISCLAIMER OF ALL 
9  * WARRANTIES.
10  */
11 package com.sun.speech.freetts.lexicon;
12
13 import java.util.List;
14 import java.io.IOException;
15
16 /**
17  * Provides the phone list for words.  A Lexicon is composed of three
18  * pieces:  an addenda, the compiled form, and the letter to sound
19  * rules.
20  * <ul>
21  *   <li>The addenda either contains Word instances that are not in
22  *   the compiled form, or it contains Word instances that replace
23  *   definitions in the compiled form.  The addenda is meant to be
24  *   relatively small (e.g., 10's of words).
25  *   <li>The compiled form is meant to hold a large number of words
26  *   (e.g., 10's of thousands of words) and provide a very efficient
27  *   means for finding those words.
28  *   <li>The letter to sound rules will attempt to find a definition for
29  *   a word not found in either the addenda or compiled form.
30  * </ul>
31  */
32 public interface Lexicon {
33     /**
34      * Gets the phone list for a given word.  If a phone list cannot
35      * be found, <code>null</code> is returned.  The
36      * <code>partOfSpeech</code> is implementation dependent, but
37      * <code>null</code> always matches.
38      *
39      * @param word the word to find
40      * @param partOfSpeech the part of speech or <code>null</code>
41      *
42      * @return the list of phones for word or null
43      */
44     public String[] getPhones(String word, String partOfSpeech);
45
46     /**
47      * Gets the phone list for a given word.  If a phone list cannot
48      * be found, <code>null</code> is returned.  The
49      * <code>partOfSpeech</code> is implementation dependent, but
50      * <code>null</code> always matches.
51      *
52      * @param word the word to find
53      * @param partOfSpeech the part of speech or <code>null</code>
54      * @param useLTS whether to use the letter-to-sound rules when
55      *        the word is not in the lexicon.
56      *
57      * @return the list of phones for word or null
58      */    
59     public String[] getPhones(String word, String partOfSpeech, boolean useLTS);
60
61     /**
62      * Adds a word to the addenda.  The
63      * part of speech is implementation dependent.
64      *
65      * @param word the word to add
66      * @param partOfSpeech the part of speech or <code>null</code>
67      * 
68      */
69     public void addAddendum(String word, String partOfSpeech, String[] phones);
70
71     /**
72      * Removes a word from the addenda.  Both the part of speech and
73      * word must be an exact match.
74      *
75      * @param word the word to add
76      * @param partOfSpeech the part of speech
77      */
78     public void removeAddendum(String word, String partOfSpeech);
79
80     /**
81      * Determines if the <code>currentWordPhone</code> represents a
82      * new syllable boundary.
83      *
84      * @param syllablePhones the phones in the current syllable so far
85      * @param wordPhones the phones for the whole word
86      * @param currentWordPhone the word phone in question
87      *
88      * @return <code>true</code> if the phone is a new boundary
89      */
90     public boolean isSyllableBoundary(List syllablePhones,
91                                       String[] wordPhones,
92                                       int currentWordPhone);    
93
94     /**
95      * Loads this lexicon.  The loading of a lexicon need not be done
96      * in the constructor.
97      *
98      * @throws IOException if an error occurs while loading
99      */
100     public void load() throws IOException;
101
102
103     /**
104      * Determines if this lexicon is loaded.
105      *
106      * @return <code>true</code> if the lexicon is loaded
107      */
108     public boolean isLoaded();
109 }