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.
28 *
29 * @author Christian Siefkes
30 * @version $Revision: 1.7 $, $Date: 2006/10/21 16:04:25 $, $Author: siefkes $
31 */
32 public class TokenDetails {
33
34 /***
35 * The token itself.
36 */
37 private final String token;
38
39 /***
40 * The repetition of the token in the original text (counting starts with 0,
41 * as the first occurrence is the "0th repetition").
42 */
43 private int rep;
44
45 /***
46 * The index of the token in the original text (indexing starts with 0).
47 */
48 private final int index;
49
50 /***
51 * Whether there is whitespace before the token.
52 */
53 private final boolean whitespaceBefore;
54
55 /***
56 * Creates a new instance.
57 *
58 * @param theToken the token to represent
59 * @param tokenRep the repetition of the token in the document (counting
60 * starts with 0, as the first occurrence is the "0th repetition")
61 * @param tokenIndex the index of the token in the document (counting
62 * starts with 0 for the very first token)
63 * @param wsBefore whether there is whitespace before the main
64 * <code>token</code> (either at the end of <code>left</code> or in the
65 * preceding element)
66 */
67 public TokenDetails(final String theToken, final int tokenRep,
68 final int tokenIndex, final boolean wsBefore) {
69 super();
70 token = theToken;
71 rep = tokenRep;
72 index = tokenIndex;
73 whitespaceBefore = wsBefore;
74 }
75
76 /***
77 * Returns the index of the token in the original text (indexing starts
78 * with 0).
79 *
80 * @return the value of the attribute
81 */
82 public int getIndex() {
83 return index;
84 }
85
86 /***
87 * Returns the repetition of the token in the original text (counting starts
88 * with 0, as the first occurrence is the "0th repetition").
89 *
90 * @return the value of the attribute
91 */
92 public int getRep() {
93 return rep;
94 }
95
96 /***
97 * Returns the token itself.
98 * @return the value of the attribute
99 */
100 public String getToken() {
101 return token;
102 }
103
104 /***
105 * Whether there is whitespace before the token.
106 * @return the value of the attribute
107 */
108 public boolean isWhitespaceBefore() {
109 return whitespaceBefore;
110 }
111
112 /***
113 * Modifies the repetition of the token in the original text (counting
114 * starts with 0, as the first occurrence is the "0th repetition").
115 *
116 * @param newRep the new value of the attribute
117 */
118 public void setRep(final int newRep) {
119 this.rep = newRep;
120 }
121
122 /***
123 * Returns a string representation of this object.
124 *
125 * @return a textual representation
126 */
127 public String toString() {
128 return new ToStringBuilder(this)
129 .append("token", token)
130 .append("repetition", rep)
131 .append("index", index)
132 .append("whitespace before", whitespaceBefore)
133 .toString();
134 }
135
136 }