upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / Token.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;
12
13 /**
14  * Contains a parsed token from a Tokenizer.
15  */
16 public class Token {
17
18     private String token = null;
19     private String whitespace = null;
20     private String prepunctuation = null;
21     private String postpunctuation = null;
22     private int position = 0;  // position in the original input text
23     private int lineNumber = 0;   
24
25     /**
26      * Returns the whitespace characters of this Token.
27      *
28      * @return the whitespace characters of this Token;
29      *   null if this Token does not use whitespace characters
30      */
31     public String getWhitespace() {
32         return whitespace;
33     }
34
35     /**
36      * Returns the prepunctuation characters of this Token.
37      *
38      * @return the prepunctuation characters of this Token;
39      *   null if this Token does not use prepunctuation characters
40      */
41     public String getPrepunctuation() {
42         return prepunctuation;
43     }
44
45     /**
46      * Returns the postpunctuation characters of this Token.
47      *
48      * @return the postpunctuation characters of this Token;
49      *   null if this Token does not use postpunctuation characters
50      */
51     public String getPostpunctuation() {
52         return postpunctuation;
53     }
54
55     /**
56      * Returns the position of this token in the original input text.
57      *
58      * @return the position of this token in the original input text
59      */
60     public int getPosition() {
61         return position;
62     }
63
64     /**
65      * Returns the line of this token in the original text.
66      *
67      * @return the line of this token in the original text
68      */
69     public int getLineNumber() {
70         return lineNumber;
71     }
72
73     /**
74      * Sets the whitespace characters of this Token.
75      *
76      * @param whitespace the whitespace character for this token
77      */
78     public void setWhitespace(String whitespace) {
79         this.whitespace = whitespace;
80     }
81
82     /**
83      * Sets the prepunctuation characters of this Token.
84      *
85      * @param prepunctuation the prepunctuation characters
86      */
87     public void setPrepunctuation(String prepunctuation) {
88         this.prepunctuation = prepunctuation;
89     }
90
91     /**
92      * Sets the postpunctuation characters of this Token.
93      *
94      * @param postpunctuation the postpunctuation characters
95      */
96     public void setPostpunctuation(String postpunctuation) {
97         this.postpunctuation = postpunctuation;
98     }
99
100     /**
101      * Sets the position of the token in the original input text.
102      *
103      * @param position the position of the input text
104      */
105     public void setPosition(int position) {
106         this.position = position;
107     }
108
109     /**
110      * Set the line of this token in the original text.
111      *
112      * @param lineNumber the line of this token in the original text
113      */
114     public void setLineNumber(int lineNumber) {
115         this.lineNumber = lineNumber;
116     }
117     
118     /**
119      * Returns the string associated with this token.
120      *
121      * @return  the token if it exists; otherwise null
122      */
123     public String getWord() {
124         return token;
125     }
126     
127     /**
128      * Sets the string of this Token.
129      *
130      * @param word the word for this token
131      */
132     public void setWord(String word) {
133         token = word;
134     }
135
136     /**
137      * Converts this token to a string.
138      *
139      * @return the string representation of this object
140      */
141     public String toString() {
142         StringBuffer fullToken = new StringBuffer();
143         
144         if (whitespace != null) {
145             fullToken.append(whitespace);
146         }
147         if (prepunctuation != null) {
148             fullToken.append(prepunctuation);
149         }
150         if (token != null) {
151             fullToken.append(token);
152         }
153         if (postpunctuation != null) {
154             fullToken.append(postpunctuation);
155         }
156         return fullToken.toString();
157     }
158 }
159