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.us;
13 import com.sun.speech.freetts.FeatureSet;
14 import com.sun.speech.freetts.FeatureSetImpl;
15 import com.sun.speech.freetts.Item;
16 import com.sun.speech.freetts.Relation;
17 import com.sun.speech.freetts.Utterance;
20 * Helper class to add words and breaks into a Relation object.
22 public class WordRelation {
24 private Relation relation;
25 private TokenToWords tokenToWords;
28 private WordRelation(Relation parentRelation, TokenToWords tokenToWords) {
29 this.relation = parentRelation;
30 this.tokenToWords = tokenToWords;
35 * Creates a WordRelation object with the given utterance and
38 * @param utterance the Utterance from which to create a Relation
39 * @param tokenToWords the TokenToWords object to use
41 * @return a WordRelation object
43 public static WordRelation createWordRelation(Utterance utterance,
44 TokenToWords tokenToWords) {
45 Relation relation = utterance.createRelation(Relation.WORD);
46 return new WordRelation(relation, tokenToWords);
51 * Adds a break as a feature to the last item in the list.
53 public void addBreak() {
54 Item wordItem = (Item) relation.getTail();
55 if (wordItem != null) {
56 FeatureSet featureSet = wordItem.getFeatures();
57 featureSet.setString("break", "1");
63 * Adds a word as an Item to this WordRelation object.
65 * @param word the word to add
67 public void addWord(String word) {
68 Item tokenItem = tokenToWords.getTokenItem();
69 Item wordItem = tokenItem.createDaughter();
70 FeatureSet featureSet = wordItem.getFeatures();
71 featureSet.setString("name", word);
72 relation.appendItem(wordItem);
77 * Sets the last Item in this WordRelation to the given word.
79 * @param word the word to set
81 public void setLastWord(String word) {
82 Item lastItem = relation.getTail();
83 FeatureSet featureSet = lastItem.getFeatures();
84 featureSet.setString("name", word);
89 * Returns the last item in this WordRelation.
91 * @return the last item
93 public Item getTail() {
94 return relation.getTail();