View Javadoc

1   /*
2    * Copyright (C) 2004-2006 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, visit
19   * http://www.gnu.org/licenses/gpl.html or write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 }