View Javadoc

1   /*
2    * Copyright (C) 2004 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 library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   *
12   * This library 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 GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, visit
19   * http://www.gnu.org/licenses/lgpl.html or write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21   */
22  package de.fu_berlin.ties.extract.amend;
23  
24  import de.fu_berlin.ties.classify.feature.FeatureVector;
25  import de.fu_berlin.ties.text.TokenDetails;
26  
27  /***
28   * Extends the {@link de.fu_berlin.ties.text.TokenDetails} class by also storing
29   * the context of a token. Instances of this class are immutable and thus
30   * thread-safe.
31   * 
32   * @author Christian Siefkes
33   * @version $Revision: 1.2 $, $Date: 2004/11/19 14:04:51 $, $Author: siefkes $
34   */
35  public class ContextDetails extends TokenDetails {
36  
37      /***
38       * A feature vector representing the context of the token.
39       */
40      private final FeatureVector context;
41  
42  
43      /***
44       * Creates a new instance.
45       *
46       * @param theToken the token to represent
47       * @param tokenRep the repetition of the token in the document (counting
48       * starts with 0, as the first occurrence is the "0th repetition")
49       * @param tokenIndex the index of the token in the document (counting
50       * starts with 0 for the very first token)
51       * @param wsBefore whether there is whitespace before the main
52       * <code>token</code> (either at the end of <code>left</code> or in the
53       * preceding element)
54       * @param features a feature vector representing the context of the token
55       */
56      public ContextDetails(final String theToken, final int tokenRep,
57              final int tokenIndex, final boolean wsBefore,
58              final FeatureVector features) {
59          super(theToken, tokenRep, tokenIndex, wsBefore);
60          context = features;
61      }
62  
63      /***
64       * Creates a new instance, re-using field values from a {@link TokenDetails}
65       * instance.
66       *
67       * @param orgDetails an instance of the parent class whose member fields
68       * are re-used to initialize this instance
69       * @param features a feature vector representing the context of the token
70       */
71      public ContextDetails(final TokenDetails orgDetails,
72              final FeatureVector features) {
73          this(orgDetails.getToken(), orgDetails.getRep(), orgDetails.getIndex(),
74                  orgDetails.isWhitespaceBefore(), features);
75      }
76  
77  
78      /***
79       * Returns a feature vector representing the context of the token.
80       * @return the value of the attribute
81       */
82      public FeatureVector getContext() {
83          return context;
84      }
85  
86  }