001/** 002 * Portions Copyright 2001 Sun Microsystems, Inc. 003 * Portions Copyright 1999-2001 Language Technologies Institute, 004 * Carnegie Mellon University. 005 * All Rights Reserved. Use is subject to license terms. 006 * 007 * See the file "license.terms" for information on usage and 008 * redistribution of this file, and for a DISCLAIMER OF ALL 009 * WARRANTIES. 010 */ 011package com.sun.speech.freetts; 012 013/** 014 * Contains a parsed token from a Tokenizer. 015 */ 016public class Token { 017 018 private String token = null; 019 private String whitespace = null; 020 private String prepunctuation = null; 021 private String postpunctuation = null; 022 private int position = 0; // position in the original input text 023 private int lineNumber = 0; 024 025 /** 026 * Returns the whitespace characters of this Token. 027 * 028 * @return the whitespace characters of this Token; 029 * null if this Token does not use whitespace characters 030 */ 031 public String getWhitespace() { 032 return whitespace; 033 } 034 035 /** 036 * Returns the prepunctuation characters of this Token. 037 * 038 * @return the prepunctuation characters of this Token; 039 * null if this Token does not use prepunctuation characters 040 */ 041 public String getPrepunctuation() { 042 return prepunctuation; 043 } 044 045 /** 046 * Returns the postpunctuation characters of this Token. 047 * 048 * @return the postpunctuation characters of this Token; 049 * null if this Token does not use postpunctuation characters 050 */ 051 public String getPostpunctuation() { 052 return postpunctuation; 053 } 054 055 /** 056 * Returns the position of this token in the original input text. 057 * 058 * @return the position of this token in the original input text 059 */ 060 public int getPosition() { 061 return position; 062 } 063 064 /** 065 * Returns the line of this token in the original text. 066 * 067 * @return the line of this token in the original text 068 */ 069 public int getLineNumber() { 070 return lineNumber; 071 } 072 073 /** 074 * Sets the whitespace characters of this Token. 075 * 076 * @param whitespace the whitespace character for this token 077 */ 078 public void setWhitespace(String whitespace) { 079 this.whitespace = whitespace; 080 } 081 082 /** 083 * Sets the prepunctuation characters of this Token. 084 * 085 * @param prepunctuation the prepunctuation characters 086 */ 087 public void setPrepunctuation(String prepunctuation) { 088 this.prepunctuation = prepunctuation; 089 } 090 091 /** 092 * Sets the postpunctuation characters of this Token. 093 * 094 * @param postpunctuation the postpunctuation characters 095 */ 096 public void setPostpunctuation(String postpunctuation) { 097 this.postpunctuation = postpunctuation; 098 } 099 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