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.
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package com.sun.speech.freetts.en;
13 import com.sun.speech.freetts.UtteranceProcessor;
14 import com.sun.speech.freetts.Voice;
15 import com.sun.speech.freetts.Utterance;
16 import com.sun.speech.freetts.Item;
17 import com.sun.speech.freetts.Relation;
18 import com.sun.speech.freetts.ProcessException;
19 import com.sun.speech.freetts.PathExtractorImpl;
20 import com.sun.speech.freetts.PathExtractor;
24 * Annotates the utterance with post lexical information.
26 public class PostLexicalAnalyzer implements UtteranceProcessor {
27 private static final PathExtractor wordPath =
28 new PathExtractorImpl("R:SylStructure.parent.parent.name", true);
29 private static final PathExtractor P_PH_VC =
30 new PathExtractorImpl("p.ph_vc", true);
31 private static final PathExtractor N_PH_VC =
32 new PathExtractorImpl("n.ph_vc", true);
35 * Constructs a PostLexicalAnalyzer
37 public PostLexicalAnalyzer () {
41 * Performs the post lexical processing.
43 * @param utterance the utterance to process
45 * @throws ProcessException if an error occurs while
46 * processing of the utterance
48 public void processUtterance(Utterance utterance) throws ProcessException {
49 fixApostrophe(utterance);
54 * Fixes apostrophe s segments.
56 * @param utterance the utterance to fix
58 private void fixApostrophe(Utterance utterance) {
59 Voice voice = utterance.getVoice();
60 for (Item item = utterance.getRelation(Relation.SEGMENT).getHead();
62 item = item.getNext()) {
63 String word = wordPath.findFeature(item).toString();
65 if (word.equals("'s")) {
67 String pname = item.getPrevious().toString();
70 voice.getPhoneFeature(pname,"ctype")) != -1) &&
72 voice.getPhoneFeature(pname, "cplace")) == -1)) {
74 } else if (voice.getPhoneFeature(pname, "cvox").equals("-")) {
75 item.getFeatures().setString("name", "s");
77 } else if (word.equals("'ve") ||
78 word.equals("'ll") || word.equals("'d")) {
79 if ("-".equals(P_PH_VC.findFeature(item))) {
88 * Prepends a schwa to the given item
90 * @param item the item to prepend the schwa to.
92 private static void prependSchwa(Item item) {
93 Item schwa = item.prependItem(null);
94 schwa.getFeatures().setString("name", "ax");
96 Relation.SYLLABLE_STRUCTURE).prependItem(schwa);
101 * Changes the pronunciation of "the" from 'd ax' to 'd iy' if
102 * the following word starts with a vowel. "The every" is a good
105 * @param utterance the utterance to process
107 private void fixTheIy(Utterance utterance) {
108 Voice voice = utterance.getVoice();
109 for (Item item = utterance.getRelation(Relation.SEGMENT).getHead();
110 item != null; item = item.getNext()) {
112 if ("ax".equals(item.toString())) {
113 String word = wordPath.findFeature(item).toString();
114 if ("the".equals(word) &&
115 ("+".equals(N_PH_VC.findFeature(item)))) {
116 item.getFeatures().setString("name", "iy");
123 * Returns the string representation of the object
125 * @return the string representation of the object
127 public String toString() {
128 return "PostLexicalAnalyzer";