@Override public List<Feature> apply(@Nullable Feature input) { String featureName = Feature.createName(DEFAULT_NAME, input.getName()); Object featureValue = input.getValue(); if(featureValue instanceof String){ return Collections.singletonList(new Feature(featureName, word2class.containsKey(featureValue) ? word2class.get(featureValue) : "NoCluster")); } return Collections.emptyList(); }
public List<Feature> extract(JCas view, T focusAnnotation) throws CleartkExtractorException { List<Feature> features = subExtractor.extract(view, focusAnnotation); for (Feature feature : features) { feature.setName(Feature.createName(name, feature.getName())); } return features; }
public static Feature createFeature(String namePrefix, Feature feature) { return new Feature(createName(namePrefix, feature.name), feature.value); }
@Override public FeatureNode[] encodeAll(Iterable<Feature> features) throws CleartkEncoderException { FeatureNode[] encoded = encoder.encodeAll(features); for(Feature feature : features){ String name; if(feature.getValue() instanceof Number) { name = feature.getName(); } else { name = Feature.createName(new String[]{feature.getName(), feature.getValue().toString()}); } featureNames.add(name); } return encoded; }
public static List<Feature> getCharFeatures(char ch, String prefix){ List<Feature> feats = new ArrayList<>(); feats.add(new Feature(prefix+"_Id", ch == '\n' ? "<LF>" : ch)); feats.add(new Feature(prefix+"_Upper", Character.isUpperCase(ch))); feats.add(new Feature(prefix+"_Lower", Character.isLowerCase(ch))); feats.add(new Feature(prefix+"_Digit", Character.isDigit(ch))); feats.add(new Feature(prefix+"_Space", Character.isWhitespace(ch))); feats.add(new Feature(prefix+"_Type"+Character.getType(ch), true)); return feats; }
public ContextFeature(String baseName, int position, int oobPosition, String featureName) { this.feature = new Feature(featureName, String.format(Locale.ROOT, "OOB%d", oobPosition)); this.setName(Feature.createName(baseName, String.valueOf(position), featureName)); this.setValue(this.feature.getValue()); }
public boolean encodes(Feature feature) { return feature.getValue() instanceof Boolean; }
public List<NameNumber> encode(Feature feature) { List<NameNumber> fves = new ArrayList<NameNumber>(); Counts frequencies = (Counts) feature.getValue(); String prefix = frequencies.getFeatureName(); for (Object key : frequencies.getValues()) { String name = Feature.createName(prefix, key.toString()); NameNumber fve = new NameNumber(name, frequencies.getCount(key)); fves.add(fve); } normalizer.normalize(fves); return fves; }
public SubCategorizationExtractor(String name) { this.featureName = Feature.createName(name, "SubCategorization"); }
protected boolean isTransformable(Feature feature) { return feature instanceof TransformableFeature && this.name.equals(feature.getName()); }
private String createName(boolean specialCasePP, Feature subFeature) { StringBuffer buffer = new StringBuffer(); if (specialCasePP) buffer.append("PP"); buffer.append("HeadWord"); return Feature.createName(buffer.toString(), subFeature.getName()); } }
/** * @param outcome * the outcome of the returned instance * @param featureData * space delimited features. Here the features only have names (no values) corresponding * to the space delimited strings. * @return a single instance with the provided outcome and name-only string features found in the * provided featureData */ public static <T> Instance<T> createInstance(T outcome, String featureData) { Instance<T> instance = new Instance<T>(outcome); String[] columns = featureData.split(" "); for (int i = 0; i < columns.length; i++) { Feature feature = new Feature(); feature.setName(columns[i]); instance.add(feature); } return instance; }
List<Feature> extractNode(JCas jCas, TreebankNode node, boolean specialCasePP) throws CleartkExtractorException { List<Feature> features = subExtractor.extract(jCas, node); for (Feature feature : features) { feature.setName(createName(specialCasePP, feature)); } return features; }
@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; } }
public ContextFeature(String baseName, Feature feature) { this.feature = feature; this.setName(Feature.createName(baseName, feature.getName())); this.setValue(this.feature.getValue()); }
public static List<Feature> getCharFeatures(char ch, String prefix){ List<Feature> feats = new ArrayList<>(); feats.add(new Feature(prefix+"_Id", ch == '\n' ? "<LF>" : ch)); feats.add(new Feature(prefix+"_Upper", Character.isUpperCase(ch))); feats.add(new Feature(prefix+"_Lower", Character.isLowerCase(ch))); feats.add(new Feature(prefix+"_Digit", Character.isDigit(ch))); feats.add(new Feature(prefix+"_Space", Character.isWhitespace(ch))); feats.add(new Feature(prefix+"_Type"+Character.getType(ch), true)); return feats; }