public abstract class Feature extends Object implements Cloneable, Comparable, Serializable
Classifier
's decision.Modifier and Type | Field and Description |
---|---|
protected String |
containingPackage
The Java
package containing the classifier that produced this feature. |
protected String |
generatingClassifier
The name of the LBJava classifier that produced this feature.
|
Modifier | Constructor and Description |
---|---|
protected |
Feature()
For internal use only.
|
|
Feature(String p,
String c)
Initializing constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
childLexiconLookup(ChildLexicon lex,
int label)
Does a feature-type-specific lookup of this feature in the given
ChildLexicon . |
boolean |
classEquivalent(Feature f)
Some features are functionally equivalent, differing only in the encoding of their values;
this method will return
true iff the class of this feature and f
are different, but they differ only because they encode their values differently. |
Object |
clone()
Returns a shallow clone of this
Feature . |
int |
compareNameStrings(Object o)
Compares only the run-time types, packages, classifier names, and identifiers of the
features.
|
abstract int |
compareTo(Object o)
Used to sort features into an order that is convenient both to page through and for the
lexicon to read off disk.
|
abstract Feature |
conjunction(Feature f,
Classifier c)
Create a feature representing the conjunction of this feature with the given argument
feature.
|
protected Feature |
conjunctWith(DiscreteFeature f,
Classifier c)
Create a feature representing the conjunction of this feature with the given argument
feature.
|
protected Feature |
conjunctWith(RealFeature f,
Classifier c)
Create a feature representing the conjunction of this feature with the given argument
feature.
|
int |
depth()
The depth of a feature is one more than the maximum depth of any of its children, or 0 if it
has no children.
|
abstract Feature |
encode(String e)
Returns a feature object in which any strings that are being used to represent an identifier
or value have been encoded in byte strings.
|
boolean |
equals(Object o)
Two
Feature s are equal when their packages and generating classifiers are
equivalent. |
boolean |
fromArray()
Determines if this feature comes from an array.
|
abstract ByteString |
getByteStringIdentifier()
Retrieves this feature's identifier as a byte string.
|
abstract ByteString |
getByteStringValue()
Gives a string representation of the value of this feature.
|
Feature |
getFeatureKey(Lexicon lexicon)
Return the feature that should be used to index this feature into a lexicon.
|
abstract Feature |
getFeatureKey(Lexicon lexicon,
boolean training,
int label)
Return the feature that should be used to index this feature into a lexicon.
|
String |
getGeneratingClassifier()
Retrieves the name of the classifier that produced this feature.
|
String |
getPackage()
Retrieves this feature's package.
|
abstract double |
getStrength()
Returns the strength of this feature if it were to be placed in a mathematical vector space.
|
abstract String |
getStringIdentifier()
Retrieves this feature's identifier as a string.
|
abstract String |
getStringValue()
Gives a string representation of the value of this feature.
|
short |
getValueIndex()
Returns the index in the generating classifier's value list of this feature's value.
|
boolean |
hasByteStringIdentifier()
Determines if this feature contains a byte string identifier field.
|
int |
hashCode()
The hash code of a
Feature is a function of the hash codes of
containingPackage and generatingClassifier . |
boolean |
hasStringIdentifier()
Determines if this feature contains a string identifier field.
|
boolean |
isConjunctive()
Determines if this feature is conjunctive.
|
abstract boolean |
isDiscrete()
Determines if this feature is discrete.
|
boolean |
isPrimitive()
Determines if this feature is primitive.
|
boolean |
isReferrer()
Determines if this feature is a referring feature.
|
void |
lexRead(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in,
Lexicon lex,
String p,
String g,
String si,
ByteString bi)
Reads the representation of a feature with this object's run-time type as stored by a
lexicon, overwriting the data in this object.
|
static Feature |
lexReadFeature(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in,
Lexicon lex,
Class c,
String p,
String g,
String si,
ByteString bi)
Reads the representation of a feature of any type as stored by a lexicon, omitting redundant
information.
|
String |
lexWrite(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out,
Lexicon lex,
String c,
String p,
String g,
String si,
ByteString bi)
Writes a binary representation of the feature intended for use by a lexicon, omitting
redundant information when possible.
|
abstract RealFeature |
makeReal()
Returns a
RealFeature whose value is the strength of the current feature, and whose
identifier field contains all the information necessary to distinguish this
feature from other features. |
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the representation of a feature with this object's run-time type from the given stream,
overwriting the data in this object.
|
static Feature |
readFeature(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a feature of any type from the given stream.
|
void |
removeFromChildLexicon(ChildLexicon lex)
Takes care of any feature-type-specific tasks that need to be taken care of when removing a
feature of this type from a
ChildLexicon , in particular updating parent counts and
removing children of this feature if necessary. |
void |
setArrayLength(int l)
If this feature is an array feature, call this method to set its array length; otherwise,
this method has no effect.
|
String |
toString()
Returns a string representation of this
Feature . |
String |
toStringNoPackage()
Returns a string representation of this
Feature omitting the package. |
short |
totalValues()
Returns the total number of values this feature might possibly be set to.
|
abstract boolean |
valueEquals(String v)
Determines whether or not the parameter is equivalent to the string representation of the
value of this feature.
|
abstract Feature |
withStrength(double s)
Returns a new feature object that's identical to this feature except its strength is given by
s . |
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes a complete binary representation of the feature.
|
abstract void |
write(StringBuffer buffer)
Writes a string representation of this
Feature to the specified buffer. |
void |
writeNameString(StringBuffer buffer)
Writes a string representation of this
Feature 's package, generating classifier,
and sometimes identifier information to the specified buffer. |
void |
writeNoPackage(StringBuffer buffer)
Writes a string representation of this
Feature to the specified buffer, omitting
the package name. |
protected String containingPackage
package
containing the classifier that produced this feature.protected String generatingClassifier
protected Feature()
readFeature(ExceptionlessInputStream)
public String getPackage()
public String getGeneratingClassifier()
public abstract String getStringIdentifier()
public abstract ByteString getByteStringIdentifier()
public abstract String getStringValue()
public abstract ByteString getByteStringValue()
public abstract boolean valueEquals(String v)
v
- The string to compare against.true
iff the parameter is equivalent to the string representation of the
value of this feature.public abstract boolean isDiscrete()
true
iff this is discrete.public boolean hasByteStringIdentifier()
true
iff this feature contains a byte string identifier field.public boolean hasStringIdentifier()
true
iff this feature contains a string identifier field.public boolean isPrimitive()
true
iff this is primitive.public boolean isConjunctive()
true
iff this feature is conjunctive.public boolean isReferrer()
true
iff this feature is a referring feature.public boolean fromArray()
true
iff this feature comes from an array.public int depth()
public short getValueIndex()
public short totalValues()
public void setArrayLength(int l)
l
- The new length.public abstract double getStrength()
public Feature getFeatureKey(Lexicon lexicon)
getFeatureKey(lexicon, true,
-1)
.lexicon
- The lexicon into which this feature will be indexed.getFeatureKey(Lexicon,boolean,int)
public abstract Feature getFeatureKey(Lexicon lexicon, boolean training, int label)
lexicon
- The lexicon into which this feature will be indexed.training
- Whether or not the learner is currently training.label
- The label of the example containing this feature, or -1 if we aren't doing per
class feature counting.public abstract RealFeature makeReal()
RealFeature
whose value is the strength of the current feature, and whose
identifier
field contains all the information necessary to distinguish this
feature from other features. When defining this method, RealFeature
s may simply
return themselves.public abstract Feature conjunction(Feature f, Classifier c)
f
- The feature to conjunct with.c
- The classifier producing the resulting feature.f
.protected Feature conjunctWith(DiscreteFeature f, Classifier c)
f
- The feature to conjunct with.c
- The classifier producing the resulting feature.f
.protected Feature conjunctWith(RealFeature f, Classifier c)
f
- The feature to conjunct with.c
- The classifier producing the resulting feature.f
.public abstract Feature withStrength(double s)
s
.s
- The strength of the new feature.null
if this feature cannot take the
specified strength.public abstract Feature encode(String e)
e
- The encoding to use.public void removeFromChildLexicon(ChildLexicon lex)
ChildLexicon
, in particular updating parent counts and
removing children of this feature if necessary.lex
- The child lexicon this feature is being removed from.public int childLexiconLookup(ChildLexicon lex, int label)
ChildLexicon
.lex
- The child lexicon this feature is being looked up in.label
- The label of the example containing this feature, or -1 if we aren't doing per
class feature counting.f
in this lexicon.public int hashCode()
Feature
is a function of the hash codes of
containingPackage
and generatingClassifier
.public boolean equals(Object o)
Feature
s are equal when their packages and generating classifiers are
equivalent.public boolean classEquivalent(Feature f)
true
iff the class of this feature and f
are different, but they differ only because they encode their values differently. This method
does not compare the values themselves, however.f
- Another feature.public abstract int compareTo(Object o)
compareTo
in interface Comparable
o
- An object to compare with.public int compareNameStrings(Object o)
o
- An object to compare with.public abstract void write(StringBuffer buffer)
Feature
to the specified buffer.buffer
- The buffer to write to.public void writeNameString(StringBuffer buffer)
Feature
's package, generating classifier,
and sometimes identifier information to the specified buffer. This method will need to be
overridden to write the identifier information, but at least the overriding method will have
the convenience of calling this method to accomplish most of the work first.buffer
- The buffer to write to.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
out
- The output stream.public void writeNoPackage(StringBuffer buffer)
Feature
to the specified buffer, omitting
the package name.buffer
- The buffer to write to.public String lexWrite(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out, Lexicon lex, String c, String p, String g, String si, ByteString bi)
out
- The output stream.lex
- The lexicon out of which this feature is being written.c
- The fully qualified name of the assumed class. The runtime class of this feature
won't be written if it's equivalent to c
.p
- The assumed package string. This feature's package string won't be written if it's
equivalent to p
.g
- The assumed classifier name string. This feature's classifier name string won't be
written if it's equivalent to g
.si
- The assumed identifier as a string. If this feature has a string identifier, it
won't be written if it's equivalent to si
.bi
- The assumed identifier as a byte string. If this feature has a byte string
identifier, it won't be written if it's equivalent to bi
.public static Feature readFeature(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
-1
appears instead, this method returns
null
.
This method is appropriate for reading features as written by
write(ExceptionlessOutputStream)
.
in
- The input stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
This method is appropriate for reading features as written by
write(ExceptionlessOutputStream)
.
in
- The input stream.public static Feature lexReadFeature(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in, Lexicon lex, Class c, String p, String g, String si, ByteString bi)
This method is appropriate for reading features as written by
lexWrite(ExceptionlessOutputStream,Lexicon,String,String,String,String,ByteString)
.
in
- The input stream.lex
- The lexicon we are reading in to.c
- The assumed class. If no class name is given in the input stream, a feature of this
type is instantiated.p
- The assumed package string. If no package name is given in the input stream, the
instantiated feature is given this package.g
- The assumed classifier name string. If no classifier name is given in the input
stream, the instantiated feature is given this classifier name.si
- The assumed identifier as a string. If the feature being read has a string
identifier field and no identifier is given in the input stream, the feature is given
this identifier.bi
- The assumed identifier as a byte string. If the feature being read has a byte
string identifier field and no identifier is given in the input stream, the feature is
given this identifier.public void lexRead(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in, Lexicon lex, String p, String g, String si, ByteString bi)
This method is appropriate for reading features as written by
lexWrite(ExceptionlessOutputStream,Lexicon,String,String,String,String,ByteString)
.
in
- The input stream.lex
- The lexicon we are reading in to.p
- The assumed package string. If no package name is given in the input stream, the
instantiated feature is given this package.g
- The assumed classifier name string. If no classifier name is given in the input
stream, the instantiated feature is given this classifier name.si
- The assumed identifier as a string. If the feature being read has a string
identifier field and no identifier is given in the input stream, the feature is given
this identifier.bi
- The assumed identifier as a byte string. If the feature being read has a byte
string identifier field and no identifier is given in the input stream, the feature is
given this identifier.public String toString()
Feature
.public String toStringNoPackage()
Feature
omitting the package.Copyright © 2016. All rights reserved.