org.dkpro.tc.api.features.Feature类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中org.dkpro.tc.api.features.Feature类的一些代码示例,展示了Feature类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Feature类的具体详情如下:
包路径:org.dkpro.tc.api.features.Feature
类名称:Feature

Feature介绍

[英]Internal representation of a feature.
[中]特征的内部表示。

代码示例

代码示例来源:origin: org.dkpro.tc/dkpro-tc-io-libsvm

private boolean sanityCheckValue(Feature f)
{
  if (f.getValue() instanceof Number) {
    return true;
  }
  if (f.getName().equals(Constants.ID_FEATURE_NAME)) {
    return false;
  }
  try {
    Double.valueOf((String) f.getValue());
  }
  catch (Exception e) {
    throw new IllegalArgumentException(
        "Feature [" + f.getName() + "] has a non-numeric value [" + f.getValue() + "]",
        e);
  }
  return false;
}

代码示例来源:origin: dkpro/dkpro-tc

@Override
public Set<Feature> extract(JCas view1, JCas view2) throws TextClassificationException
{
  return new Feature("BaselineFeature", 0, FeatureType.NUMERIC).asSet();
}

代码示例来源:origin: dkpro/dkpro-tc

public void collectMetaData(List<Instance> instances)
{
  featureNames = new TreeSet<>();
  for (Feature f : instances.get(0).getFeatures()) {
    featureNames.add(f.getName());
    if (!featDesc.containsKey(f.getName())) {
      featDesc.put(f.getName(), f.getType());
    }
    if (f.getType() == FeatureType.NOMINAL) {
      enumFeatureName.put(f.getName(), f.getValue().getClass().getName());
    }
  }
  didCollect = true;
}

代码示例来源:origin: de.unidue.ltl.flextag/flextag-features

public Set<Feature> extract(JCas aView, TextClassificationTarget aTarget)
  throws TextClassificationException
{
  Feature feature = new Feature(FEATURE_NAME, aTarget.getCoveredText().contains(
      ".") ? 1 : 0);
  Set<Feature> features = new HashSet<Feature>();
  features.add(feature);
  return features;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-api-features

@Override
public int compareTo(Feature o)
{
  return this.getName().compareTo(o.getName());
}

代码示例来源:origin: dkpro/dkpro-tc

private String getValue(Feature feature) {
  if (feature.getType().equals(FeatureType.STRING) || feature.getType().equals(FeatureType.NOMINAL)) {
    String value = feature.getValue().toString();
    String idx = stringToIntegerMap.get(value);
    if (idx == null) {
      stringToIntegerMap.put(value, "" + maxStringId++);
      idx = stringToIntegerMap.get(value);
    }
    return idx.toString();
  }
  return feature.getValue().toString();
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-core

@Override
public Set<Feature> extract(JCas jcas, TextClassificationTarget unit)
  throws TextClassificationException
{
  try {
    String idString = (String) InstanceIdFeature.retrieve(jcas, unit).getValue();
    ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
    if (DocumentMetaData.get(jcas).getIsLastSegment() == true) {
      bw.close();
    }
  }
  catch (IOException e) {
    throw new TextClassificationException(e);
  }
  return new HashSet<Feature>();
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-core

private Set<Feature> getSparse(JCas aJCas, TextClassificationTarget aTarget,
    FeatureExtractorResource_ImplBase aFeatExtractor)
  throws TextClassificationException
{
  Set<Feature> features = ((FeatureExtractor) aFeatExtractor).extract(aJCas, aTarget);
  Set<Feature> filtered = new HashSet<>();
  for (Feature f : features) {
    if (!f.isDefaultValue()) {
      filtered.add(f);
    }
  }
  return filtered;
}

代码示例来源:origin: de.unidue.ltl.flextag/flextag-features

public Set<Feature> extract(JCas aView, TextClassificationTarget aTarget)
    throws TextClassificationException
  {

    Feature feature = new Feature(FEATURE_NAME, aTarget.getCoveredText().contains(
        "-") ? 1 : 0);
    Set<Feature> features = new HashSet<Feature>();
    features.add(feature);
    return features;
  }
}

代码示例来源:origin: dkpro/dkpro-tc

@Override
public int compareTo(Feature o)
{
  return this.getName().compareTo(o.getName());
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-core

@Override
  public void process(JCas jcas) throws AnalysisEngineProcessException
  {

    Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas,
        TextClassificationSequence.class);
    for (TextClassificationSequence seq : sequences) {
      int id = seq.getId();
      for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas,
          TextClassificationTarget.class, seq)) {
        String idString;
        try {
          idString = (String) InstanceIdFeature.retrieve(jcas, unit, id).getValue();
          ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
        }
        catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }
  }
}

代码示例来源:origin: dkpro/dkpro-tc

private Set<Feature> getSparse(JCas aJCas, TextClassificationTarget aTarget,
    FeatureExtractorResource_ImplBase aFeatExtractor)
  throws TextClassificationException
{
  Set<Feature> features = ((FeatureExtractor) aFeatExtractor).extract(aJCas, aTarget);
  Set<Feature> filtered = new HashSet<>();
  for (Feature f : features) {
    if (!f.isDefaultValue()) {
      filtered.add(f);
    }
  }
  return filtered;
}

代码示例来源:origin: dkpro/dkpro-tc

protected boolean sanityCheckValue(Feature f)
{
  if (f.getValue() instanceof Number) {
    return true;
  }
  if (f.getName().equals(Constants.ID_FEATURE_NAME)) {
    return false;
  }
  try {
    Double.valueOf((String) f.getValue());
  }
  catch (Exception e) {
    throw new IllegalArgumentException(
        "Feature [" + f.getName() + "] has a non-numeric value [" + f.getValue() + "]",
        e);
  }
  return false;
}

代码示例来源:origin: dkpro/dkpro-tc

@Override
  public Set<Feature> extract(JCas jcas, TextClassificationTarget classificationUnit)
    throws TextClassificationException
  {

    Collection<Token> tokens = JCasUtil.select(jcas, Token.class);
    if (tokens.size() > 150) {
      return new Feature(FEATURE_NAME, LengthEnum.LONG, FeatureType.NOMINAL).asSet();
    }
    else if (tokens.size() > 100) {
      return new Feature(FEATURE_NAME, LengthEnum.MIDDLE, FeatureType.NOMINAL).asSet();
    }
    else {
      return new Feature(FEATURE_NAME, LengthEnum.SHORT, FeatureType.NOMINAL).asSet();
    }
  }
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-core

public void collectMetaData(List<Instance> instances)
{
  featureNames = new TreeSet<>();
  for (Feature f : instances.get(0).getFeatures()) {
    featureNames.add(f.getName());
    if (!featDesc.containsKey(f.getName())) {
      featDesc.put(f.getName(), f.getType());
    }
    if (f.getType() == FeatureType.NOMINAL) {
      enumFeatureName.put(f.getName(), f.getValue().getClass().getName());
    }
  }
  didCollect = true;
}

代码示例来源:origin: de.unidue.ltl.flextag/flextag-features

public Set<Feature> extract(JCas aView, TextClassificationTarget aTarget)
  throws TextClassificationException
{
  Feature feature = new Feature(FEATURE_NAME, aTarget.getCoveredText().contains(
      "_") ? 1 : 0);
  Set<Feature> features = new HashSet<Feature>();
  features.add(feature);
  return features;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-core

private List<Instance> enforceMatchingFeatures(List<Instance> instances)
{
  if (!isTesting) {
    return instances;
  }
  List<Instance> out = new ArrayList<>();
  for (Instance i : instances) {
    List<Feature> newFeatures = new ArrayList<>();
    for (Feature feat : i.getFeatures()) {
      if (!featureMeta.getFeatureNames().contains(feat.getName())) {
        continue;
      }
      newFeatures.add(feat);
    }
    i.setFeatures(newFeatures);
    out.add(i);
  }
  return out;
}

代码示例来源:origin: dkpro/dkpro-tc

@Override
  public void process(JCas jcas) throws AnalysisEngineProcessException
  {

    Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas,
        TextClassificationSequence.class);
    for (TextClassificationSequence seq : sequences) {
      int id = seq.getId();
      for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas,
          TextClassificationTarget.class, seq)) {
        String idString;
        try {
          idString = (String) InstanceIdFeature.retrieve(jcas, unit, id).getValue();
          ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
        }
        catch (Exception e) {
          throw new AnalysisEngineProcessException(e);
        }
      }
    }
  }
}

代码示例来源:origin: dkpro/dkpro-tc

Set<Feature> features = ((FeatureExtractor) featExt).extract(aJCas, aTarget);
features.forEach(x -> {
  if (!x.isDefaultValue()) {
    instance.addFeature(x);

代码示例来源:origin: dkpro/dkpro-tc

private void recordInstanceId(Instance instance, int i, Map<String, String> index2instanceId) {
  Collection<Feature> features = instance.getFeatures();
  for (Feature f : features) {
    if (f.getName().equals(Constants.ID_FEATURE_NAME)) {
      index2instanceId.put(i + "", f.getValue() + "");
      return;
    }
  }
}

相关文章