1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties.text;
23
24 import org.apache.commons.lang.builder.ToStringBuilder;
25
26 /***
27 * Stores details on a token in a document. Instances of this class are
28 * immutable and thus thread-safe.
29 *
30 * @author Christian Siefkes
31 * @version $Revision: 1.3 $, $Date: 2004/11/17 15:25:11 $, $Author: siefkes $
32 */
33 public class TokenDetails {
34
35 /***
36 * The token itself.
37 */
38 private final String token;
39
40 /***
41 * The repetition of the token in the original text (counting starts with 0,
42 * as the first occurrence is the "0th repetition").
43 */
44 private final int rep;
45
46 /***
47 * The index of the token in the original text (indexing starts with 0).
48 */
49 private final int index;
50
51 /***
52 * Whether there is whitespace before the token.
53 */
54 private final boolean whitespaceBefore;
55
56 /***
57 * Creates a new instance.
58 *
59 * @param theToken the token to represent
60 * @param tokenRep the repetition of the token in the document (counting
61 * starts with 0, as the first occurrence is the "0th repetition")
62 * @param tokenIndex the index of the token in the document (counting
63 * starts with 0 for the very first token)
64 * @param wsBefore whether there is whitespace before the main
65 * <code>token</code> (either at the end of <code>left</code> or in the
66 * preceding element)
67 */
68 public TokenDetails(final String theToken, final int tokenRep,
69 final int tokenIndex, final boolean wsBefore) {
70 super();
71 token = theToken;
72 rep = tokenRep;
73 index = tokenIndex;
74 whitespaceBefore = wsBefore;
75 }
76
77 /***
78 * Returns the index of the token in the original text (indexing starts
79 * with 0).
80 *
81 * @return the value of the attribute
82 */
83 public int getIndex() {
84 return index;
85 }
86
87 /***
88 * Returns the repetition of the token in the original text (counting starts
89 * with 0, as the first occurrence is the "0th repetition").
90 *
91 * @return the value of the attribute
92 */
93 public int getRep() {
94 return rep;
95 }
96
97 /***
98 * Returns the token itself.
99 * @return the value of the attribute
100 */
101 public String getToken() {
102 return token;
103 }
104
105 /***
106 * Whether there is whitespace before the token.
107 * @return the value of the attribute
108 */
109 public boolean isWhitespaceBefore() {
110 return whitespaceBefore;
111 }
112
113 /***
114 * Returns a string representation of this object.
115 *
116 * @return a textual representation
117 */
118 public String toString() {
119 return new ToStringBuilder(this)
120 .append("token", token)
121 .append("repetition", rep)
122 .append("index", index)
123 .append("whitespace before", whitespaceBefore)
124 .toString();
125 }
126
127 }