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.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
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
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
82
83
84
85
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
109
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
122 .toString();
123 }
124
125 }