View Javadoc

1   /*
2    * Copyright (C) 2003-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.classify.feature;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  
26  /***
27   * Default implementation of the
28   * {@link de.fu_berlin.ties.classify.feature.Feature} class. Instances of this
29   * class are immutable and thus thread-safe.
30   *
31   * @author Christian Siefkes
32   * @version $Revision: 1.7 $, $Date: 2006/10/21 16:03:57 $, $Author: siefkes $
33   */
34  public class DefaultFeature extends Feature {
35  
36      /***
37       * The strenght of this feature -- higher values might indicate more
38       * important or more frequent features.
39       */
40  //    private final float strength;
41  
42      /***
43       * The representation of this feature, to be used for classification.
44       */
45      private final String representation;
46  
47      /***
48       * Creates a new instance, without storing a comment.
49       *
50       * @param rep the representation of this feature; or <code>null</code> to
51       * create a comment-only feature
52       */
53      public DefaultFeature(final String rep) {
54          this(rep, null);
55      }
56  
57      /***
58       * Creates a new instance.
59       *
60       * @param rep the representation of this feature; or <code>null</code> to
61       * create a comment-only feature
62       * @param myComment a comment on this feature or the features to follow;
63       * might be <code>null</code>
64       */
65      public DefaultFeature(final String rep, final String myComment) {
66          super(myComment);
67          representation = rep;
68  //        this(rep, myComment, 1.0f);
69      }
70  
71      /***
72       * Creates a new instance.
73       *
74       * @param rep the representation of this feature; or <code>null</code> to
75       * create a comment-only feature
76       * @param myComment a comment on this feature or the features to follow;
77       * might be <code>null</code>
78       * @param myStrength The strenght of this feature -- higher values might
79       * indicate more important or more frequent features
80       */
81  /*    public DefaultFeature(final String rep, final String myComment,
82                            final float myStrength) {
83          super(myComment);
84          representation = rep;
85          strength = myStrength;
86      } */
87  
88      /***
89       * Returns the representation of this feature, to be used for
90       * classification.
91       *
92       * @return the feature representation, or <code>null</code> if this feature
93       * contains only a comment
94       */
95      public String getRepresentation() {
96          return representation;
97      }
98  
99      /***
100      * Returns a strength value for this feature.
101      *
102      * <p>This method is non-public because it should only be accessed through
103      * {@link FeatureVector#strength(Feature)} to allow feature vectors to
104      * modify the strenghts of the stored features.
105      *
106      * @return a strength value for this feature
107      */
108 /*    public float getStrength() {
109         return strength;
110     } */
111 
112     /***
113      * Returns a string representation of this object.
114      *
115      * @return a textual representation
116      */
117     public String toString() {
118         return new ToStringBuilder(this)
119             .appendSuper(super.toString())
120             .append("representation", representation)
121 //            .append("strength", strength)
122             .toString();
123     }
124 
125 }