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.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.3 $, $Date: 2004/05/31 19:13:49 $, $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, setting the strength to 1.0.
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 this(rep, myComment, 1.0f);
67 }
68
69 /***
70 * Creates a new instance.
71 *
72 * @param rep the representation of this feature; or <code>null</code> to
73 * create a comment-only feature
74 * @param myComment a comment on this feature or the features to follow;
75 * might be <code>null</code>
76 * @param myStrength The strenght of this feature -- higher values might
77 * indicate more important or more frequent features
78 */
79 public DefaultFeature(final String rep, final String myComment,
80 final float myStrength) {
81 super(myComment);
82 representation = rep;
83 strength = myStrength;
84 }
85
86 /***
87 * Returns the representation of this feature, to be used for
88 * classification.
89 *
90 * @return the feature representation, or <code>null</code> if this feature
91 * contains only a comment
92 */
93 public String getRepresentation() {
94 return representation;
95 }
96
97 /***
98 * Returns a strength value for this feature.
99 *
100 * <p>This method is non-public because it should only be accessed through
101 * {@link FeatureVector#strength(Feature)} to allow feature vectors to
102 * modify the strenghts of the stored features.
103 *
104 * @return a strength value for this feature
105 */
106 public float getStrength() {
107 return strength;
108 }
109
110 /***
111 * Returns a string representation of this object.
112 *
113 * @return a textual representation
114 */
115 public String toString() {
116 return new ToStringBuilder(this)
117 .appendSuper(super.toString())
118 .append("representation", representation)
119 .append("strength", strength)
120 .toString();
121 }
122
123 }