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.context;
23  
24  import de.fu_berlin.ties.classify.feature.FeatureVector;
25  import de.fu_berlin.ties.combi.CombinationState;
26  import de.fu_berlin.ties.text.TokenDetails;
27  
28  /***
29   * Extends the {@link de.fu_berlin.ties.text.TokenDetails} class by also storing
30   * the context of a token. Instances of this class are immutable and thus
31   * thread-safe.
32   * 
33   * @author Christian Siefkes
34   * @version $Revision: 1.9 $, $Date: 2006/10/21 16:04:03 $, $Author: siefkes $
35   */
36  public class ContextDetails extends TokenDetails {
37  
38      /***
39       * A feature vector representing the context of the token.
40       */
41      private final FeatureVector context;
42  
43      /***
44       * Whether or not this context is relevant for classification.
45       */
46      private final boolean relevant;
47  
48      /***
49       * The combination state returned by the used
50       * {@link de.fu_berlin.ties.combi.CombinationStrategy} for this token.
51       */
52      private final CombinationState state;
53  
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       * @param features a feature vector representing the context of the token;
67       * actually, only the {@linkplain
68       * FeatureVector#lastTransformation(FeatureVector) last transformation}
69       * of this vector is stored
70       * @param combiState the combination state returned by the used
71       * {@link de.fu_berlin.ties.combi.CombinationStrategy} for this token
72       * @param isRelevant whether or not this context is relevant for
73       * classification
74       */
75      public ContextDetails(final String theToken, final int tokenRep,
76              final int tokenIndex, final boolean wsBefore,
77              final FeatureVector features, final CombinationState combiState,
78              final boolean isRelevant) {
79          super(theToken, tokenRep, tokenIndex, wsBefore);
80          context = FeatureVector.lastTransformation(features);
81          state = combiState;
82          relevant = isRelevant;
83      }
84  
85      /***
86       * Creates a new instance, re-using field values from a {@link TokenDetails}
87       * instance.
88       *
89       * @param orgDetails an instance of the parent class whose member fields
90       * are re-used to initialize this instance
91       * @param features a feature vector representing the context of the token;
92       * actually, only the {@linkplain
93       * FeatureVector#lastTransformation(FeatureVector) last transformation}
94       * of this vector is stored
95       * @param combiState the combination state returned by the used
96       * {@link de.fu_berlin.ties.combi.CombinationStrategy} for this token
97       * @param isRelevant whether or not this context is relevant for
98       * classification
99       */
100     public ContextDetails(final TokenDetails orgDetails,
101             final FeatureVector features, final CombinationState combiState,
102             final boolean isRelevant) {
103         this(orgDetails.getToken(), orgDetails.getRep(), orgDetails.getIndex(),
104                 orgDetails.isWhitespaceBefore(), features, combiState,
105                 isRelevant);
106     }
107 
108 
109     /***
110      * Returns a feature vector representing the context of the token.
111      * @return the value of the attribute
112      */
113     public FeatureVector getContext() {
114         return context;
115     }
116 
117     /***
118      * Returns the combination state returned by the used
119      * {@link de.fu_berlin.ties.combi.CombinationStrategy} for this token.
120      *
121      * @return the value of the attribute
122      */
123     public CombinationState getState() {
124         return state;
125     }
126 
127     /***
128      * Whether or not this context is relevant for classification.
129      * 
130      * @return the value of the attribute
131      */
132     public boolean isRelevant() {
133         return relevant;
134     }
135 
136 }