本文整理汇总了Java中org.cleartk.ml.Feature.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Feature.getName方法的具体用法?Java Feature.getName怎么用?Java Feature.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.cleartk.ml.Feature
的用法示例。
在下文中一共展示了Feature.getName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
public List<NameNumber> encode(Feature feature) {
StringBuffer buffer = new StringBuffer();
String name = feature.getName();
Object value = feature.getValue();
if (name != null) {
buffer.append(name);
}
if (value != null) {
if (name != null) {
buffer.append("_");
}
buffer.append(value.toString());
}
NameNumber fve = new NameNumber(buffer.toString(), 1.0);
return Collections.singletonList(fve);
}
示例2: encodeAll
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
public TreeFeatureVector encodeAll(Iterable<Feature> features) throws CleartkEncoderException {
List<Feature> fves = new ArrayList<Feature>();
LinkedHashMap<String, TreeFeature> trs = new LinkedHashMap<String, TreeFeature>();
for (Feature feature : features) {
if (feature instanceof TreeFeature){
trs.put(feature.getName(), (TreeFeature) feature);
} else if (feature.getName() != null && feature.getName().matches("^TK.*")) {
TreeFeature tf = new TreeFeature(feature.getName(), feature.getValue());
trs.put(feature.getName(), tf);
} else {
fves.add(feature);
}
}
FeatureVector f = nameNumberEncoder.encodeAll(fves);
TreeFeatureVector tfv = new TreeFeatureVector();
tfv.setFeatures(f);
tfv.setTrees(trs);
return tfv;
}
示例3: encode
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
public List<String> encode(Feature feature) throws CleartkEncoderException {
StringBuilder sb = new StringBuilder();
if (feature.getName() != null) {
sb.append(feature.getName()).append(VALUE_DELIMITER);
}
sb.append(feature.getValue());
return ImmutableList.of(sb.toString());
}
示例4: featureToAttribute
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
/**
* @param feature
* @return
*/
private Attribute featureToAttribute(Feature feature) {
String name = feature.getName();
Attribute attribute = attributeMap.get(name);
if (attribute == null) {
attribute = featureToAttribute(feature, attributes.size());
attributes.add(attribute);
attributeMap.put(name, attribute);
}
return attribute;
}
示例5: transform
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
protected Feature transform(Feature feature) {
String featureName = feature.getName();
MeanStddevTuple stats = this.meanStddevMap.get(featureName);
double value = ((Number) feature.getValue()).doubleValue();
double zmus = 0.0d;
if (stats != null && stats.stddev > 0) {
zmus = (value - stats.mean) / stats.stddev;
return new Feature("ZMUS_" + featureName, zmus);
} else {
return null;
}
}
示例6: featuresToFeatureMap
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
public Map<String, Double> featuresToFeatureMap(List<Feature> features) {
Map<String, Double> featureMap = new HashMap<String, Double>();
for (Feature feature : features) {
String termName = feature.getName();
int tf = (Integer) feature.getValue();
featureMap.put(termName, tf * this.idfMap.getIDF(termName));
}
return featureMap;
}
示例7: computeCentroid
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
protected Map<String, Double> computeCentroid(Iterable<Instance<OUTCOME_T>> instances, IDFMap idfs) {
// Now compute centroid of all applicable terms (features) in all instances
int numDocuments = idfs.getTotalDocumentCount();
Map<String, Double> newCentroidMap = new HashMap<String, Double>();
for (Instance<OUTCOME_T> instance : instances) {
// Grab the matching tf*idf features from the set of all features in an instance
for (Feature feature : instance.getFeatures()) {
if (this.isTransformable(feature)) {
// tf*idf features contain a list of features, these are actually what get added
// to our document frequency map
for (Feature untransformedFeature : ((TransformableFeature) feature).getFeatures()) {
String termName = untransformedFeature.getName();
int tf = (Integer) untransformedFeature.getValue();
double tfidf = tf * idfs.getIDF(termName);
double sumTfidf = (newCentroidMap.containsKey(termName))
? sumTfidf = newCentroidMap.get(termName)
: 0.0;
newCentroidMap.put(termName, sumTfidf + tfidf);
}
}
}
}
for (Map.Entry<String, Double> entry : newCentroidMap.entrySet()) {
double mean = entry.getValue() / numDocuments;
newCentroidMap.put(entry.getKey(), mean);
}
return newCentroidMap;
}
示例8: transform
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
protected Feature transform(Feature feature) {
String featureName = feature.getName();
MinMaxPair stats = this.minMaxMap.get(featureName);
double mmn = 0.5d; // this is the default value we will return if we've never seen the feature
// before
double value = ((Number) feature.getValue()).doubleValue();
// this is the typical case
if (stats != null && stats.min < stats.max) {
mmn = (value - stats.min) / (stats.max - stats.min);
}
// this is an edge case that could happen when the value is always the same
if (stats != null && stats.min == stats.max) {
if (value == stats.min) {
mmn = 0.5d;
} else {
mmn = value < stats.min ? 0 : 1;
}
}
mmn = Math.max(0, mmn); // if mmn is negative, then return zero (this would happen if the
// feature value was a the smallest value yet seen)
mmn = Math.min(1, mmn); // if mmn is more than one, then return 1 (this would happen if the
// feature value was the largest value yet seen)
return new Feature("MINMAX_NORMED_" + featureName, mmn);
}
示例9: encodeAll
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
public ContextValues encodeAll(Iterable<Feature> featuresIterable) throws CleartkEncoderException {
// this is not guaranteed to work, however with normal use of ClearTK, it will
Collection<Feature> features = (Collection<Feature>) featuresIterable;
// populate context array and values array from the features
String[] context = new String[features.size()];
float[] values = new float[features.size()];
int i = -1;
for (Feature feature : features) {
++i;
// convert features to a String name and a float value
if (feature.getValue() instanceof Number) {
context[i] = feature.getName();
values[i] = ((Number) feature.getValue()).floatValue();
} else if (feature.getValue() instanceof Boolean) {
context[i] = feature.getName();
values[i] = (Boolean) feature.getValue() ? 1.0f : 0.0f;
} else {
Object value = feature.getValue();
context[i] = Feature.createName(feature.getName(), value == null ? null : value.toString());
values[i] = 1.0f;
}
}
return new ContextValues(context, values);
}
示例10: encode
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
public List<NameNumber> encode(Feature feature) {
String name = feature.getName();
Number number = (Number) feature.getValue();
return Collections.singletonList(new NameNumber(name, number));
}
示例11: encode
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
public List<NameNumber> encode(Feature feature) {
String name = feature.getName();
Number number = ((Boolean) feature.getValue()).booleanValue() ? 1.0 : 0.0;
return Collections.singletonList(new NameNumber(name, number));
}
示例12: transform
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
@Override
protected Feature transform(Feature feature) {
int tf = (Integer) feature.getValue();
double tfidf = tf * this.idfMap.getIDF(feature.getName());
return new Feature("TF-IDF_" + feature.getName(), tfidf);
}
示例13: nameFeature
import org.cleartk.ml.Feature; //导入方法依赖的package包/类
public String nameFeature(Feature feature) {
return (feature.getValue() instanceof Number)
? feature.getName()
: feature.getName() + ":" + feature.getValue();
}