public class DiscreteArrayFeature extends DiscretePrimitiveFeature
Modifier and Type | Field and Description |
---|---|
protected int |
arrayIndex
The feature's index in the returned array it is contained in.
|
protected int |
arrayLength
The size of the returned array this feature is contained in.
|
identifier, value
BooleanValues, totalValues, valueIndex
containingPackage, generatingClassifier
Modifier | Constructor and Description |
---|---|
protected |
DiscreteArrayFeature()
For internal use only.
|
|
DiscreteArrayFeature(String p,
String c,
ByteString id,
ByteString v,
int i,
int l)
Sets the identifier, value, array index, and size of the containing array.
|
|
DiscreteArrayFeature(String p,
String c,
ByteString id,
ByteString v,
short vi,
short t,
int i,
int l)
Sets all member variables.
|
Modifier and Type | Method and Description |
---|---|
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. |
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.
|
boolean |
equals(Object o)
Two
DiscreteArrayFeature s are equivalent when their containing packages,
identifiers, indices, and values are equivalent. |
boolean |
fromArray()
Determines if this feature comes from an array.
|
int |
getArrayIndex()
Returns the array index of this feature.
|
int |
getArrayLength()
Returns the length of the feature array that this feature comes from.
|
Feature |
getFeatureKey(Lexicon lexicon,
boolean training,
int label)
Return the feature that should be used to index this feature into a lexicon.
|
int |
hashCode()
The hash code of a
DiscreteArrayFeature is the sum of the hash codes of the
containing package, the identifier, the value and the array index. |
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.
|
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.
|
RealFeature |
makeReal()
Returns a
RealArrayFeature whose value field is
set to the strength of the current feature, and whose DiscretePrimitiveFeature.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 feaeture with this object's run-time type from the given
stream, overwriting the data in this object.
|
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.
|
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.
|
void |
write(StringBuffer buffer)
Writes a string representation of this
Feature to the specified buffer. |
encode, getByteStringIdentifier, getByteStringValue, getStringIdentifier, getStringValue, hasByteStringIdentifier, isPrimitive, valueEquals, writeNameString
conjunction, conjunctWith, getStrength, getValueIndex, isDiscrete, totalValues
childLexiconLookup, clone, compareNameStrings, conjunctWith, depth, getFeatureKey, getGeneratingClassifier, getPackage, hasStringIdentifier, isConjunctive, isReferrer, lexReadFeature, readFeature, removeFromChildLexicon, toString, toStringNoPackage, writeNoPackage
protected int arrayIndex
protected int arrayLength
protected DiscreteArrayFeature()
public DiscreteArrayFeature(String p, String c, ByteString id, ByteString v, int i, int l)
p
- The new discrete feature's package.c
- The name of the classifier that produced this feature.id
- The new discrete feature's identifier.v
- The new discrete feature's value.i
- The index of this feature in the returned array.l
- The length of the array this feature is contained in.public DiscreteArrayFeature(String p, String c, ByteString id, ByteString v, short vi, short t, int i, int l)
p
- The new discrete feature's package.c
- The name of the classifier that produced this feature.id
- The new discrete feature's identifier.v
- The new discrete feature's value.vi
- The index corresponding to the value.t
- The total allowable values for this feature.i
- The index of this feature in the returned array.l
- The length of the array this feature is contained in.public int getArrayIndex()
public int getArrayLength()
public boolean fromArray()
public void setArrayLength(int l)
setArrayLength
in class Feature
l
- The new length.public Feature getFeatureKey(Lexicon lexicon, boolean training, int label)
getFeatureKey
in class DiscretePrimitiveFeature
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 RealFeature makeReal()
RealArrayFeature
whose value
field is
set to the strength of the current feature, and whose DiscretePrimitiveFeature.identifier
field contains all
the information necessary to distinguish this feature from other features.makeReal
in class DiscretePrimitiveFeature
public Feature withStrength(double s)
s
.withStrength
in class DiscretePrimitiveFeature
s
- The strength of the new feature.null
if this feature cannot take the
specified strength.public int hashCode()
DiscreteArrayFeature
is the sum of the hash codes of the
containing package, the identifier, the value and the array index.hashCode
in class DiscretePrimitiveFeature
Feature
.public boolean equals(Object o)
DiscreteArrayFeature
s are equivalent when their containing packages,
identifiers, indices, and values are equivalent.equals
in class DiscretePrimitiveFeature
o
- The object with which to compare this Feature
.Feature
.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.classEquivalent
in class DiscretePrimitiveFeature
f
- Another feature.public int compareTo(Object o)
compareTo
in interface Comparable
compareTo
in class DiscretePrimitiveFeature
o
- An object to compare with.public void write(StringBuffer buffer)
Feature
to the specified buffer.write
in class DiscretePrimitiveFeature
buffer
- The buffer to write to.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
write
in class DiscretePrimitiveFeature
out
- The output stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
read
in class DiscretePrimitiveFeature
in
- The input stream.public String lexWrite(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out, Lexicon lex, String c, String p, String g, String si, ByteString bi)
lexWrite
in class DiscretePrimitiveFeature
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 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)
.
lexRead
in class DiscretePrimitiveFeature
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.Copyright © 2016. All rights reserved.