• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Feature类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.cleartk.ml.Feature的典型用法代码示例。如果您正苦于以下问题:Java Feature类的具体用法?Java Feature怎么用?Java Feature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Feature类属于org.cleartk.ml包,在下文中一共展示了Feature类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: process

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
	for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
		List<Feature> features = extractor.extract(jcas, figure);
		features.addAll(contextExtractor.extract(jcas, figure, null, Token.class, tokenExtractor));
		if (this.isTraining()) {
			String outcome = figure.getGender();
			if (outcome != null)
				this.dataWriter.write(new Instance<String>(outcome, features));
		} else {
			String category = this.classifier.classify(features);
			figure.setGender(category);
		}

	}

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:18,代码来源:ClearTkGenderAnnotator.java


示例2: createExtractor

import org.cleartk.ml.Feature; //导入依赖的package包/类
public static <T extends Annotation> NamedFeatureExtractor1<T> createExtractor(
    PatternType patternType) {
  final CharacterCategoryPatternFunction<T> ccpf = new CharacterCategoryPatternFunction<T>(
      patternType);
  return new NamedFeatureExtractor1<T>() {

    @Override
    public List<Feature> extract(JCas view, Annotation focusAnnotation)
        throws CleartkExtractorException {
      String text = focusAnnotation.getCoveredText();
      return ccpf.apply(new Feature(null, text));
    }

    @Override
    public String getFeatureName() {
      return ccpf.getFeatureName();
    }
  };
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:CharacterCategoryPatternFunction.java


示例3: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, Annotation annotation1, Annotation annotation2) {
  Annotation firstAnnotation, secondAnnotation;

  if (annotation1.getBegin() <= annotation2.getBegin()) {
    firstAnnotation = annotation1;
    secondAnnotation = annotation2;
  } else {
    firstAnnotation = annotation2;
    secondAnnotation = annotation1;
  }

  String featureName = Feature.createName(this.name, "Distance", this.unitClass.getSimpleName());
  int featureValue;
  if (secondAnnotation.getBegin() <= firstAnnotation.getEnd()) {
    featureValue = 0;
  } else {
    List<? extends Annotation> annotations = JCasUtil.selectCovered(
        jCas,
        unitClass,
        firstAnnotation.getEnd(),
        secondAnnotation.getBegin());
    featureValue = annotations.size();
  }

  return Collections.singletonList(new Feature(featureName, featureValue));
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:DistanceExtractor.java


示例4: process

import org.cleartk.ml.Feature; //导入依赖的package包/类
public void process(JCas cas) throws AnalysisEngineProcessException {
  List<Feature> features = Arrays.asList(
      new Feature("pos", "NN"),
      new Feature("distance", 3.0),
      new Feature("precision", 1.234));
  Instance<String> instance = new Instance<String>("A", features);
  this.dataWriter.write(instance);

  features = Arrays.asList(new Feature("name", "2PO"), new Feature("p's", 2));
  instance = new Instance<String>("B", features);
  this.dataWriter.write(instance);

  instance = new Instance<String>("Z");
  this.dataWriter.write(instance);

  features = Arrays.asList(new Feature("A_B", "AB"));
  instance = new Instance<String>("A", features);
  this.dataWriter.write(instance);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:MalletStringOutcomeDataWriterTest.java


示例5: generateBooleanInstances

import org.cleartk.ml.Feature; //导入依赖的package包/类
private static List<Instance<Boolean>> generateBooleanInstances(int n) {
  Random random = new Random(42);
  List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
  for (int i = 0; i < n; i++) {
    Instance<Boolean> instance = new Instance<Boolean>();
    if (random.nextInt(2) == 0) {
      instance.setOutcome(true);
      instance.add(new TreeFeature("TK_tree1", "(S (NP I) (VB ran) (. .))"));
      instance.add(new Feature("hello", random.nextInt(100) + 1000));
      instance.add(new Feature("goodbye", 500));
    } else {
      instance.setOutcome(false);
      instance.add(new TreeFeature("TK_tree1", "(S (VB I) (NP ran) (. .))"));
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", 500));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:21,代码来源:RunTkLibSvmTest.java


示例6: LTCharacterNgramFeatureFunction

import org.cleartk.ml.Feature; //导入依赖的package包/类
/**
 * This feature function serves up character n-grams based on StringValued features. For example,
 * if you wanted trigram suffixes (e.g. 'ion' of 'emotion') for words that are of length 7 or more
 * you could call the constructor with the following:
 * CharacterNGramFeatureFunction(Orientation.RIGHT_TO_LEFT, 0, 3, 7, false)
 *
 * @param featureName
 *          a user-specified name for the feature function, to be included in all feature names.
 * @param orientation
 *          must be one of LEFT_TO_RIGHT or RIGHT_TO_LEFT. The orientation determines whether
 *          index 0 corresponds to the first character of the string value or the last. The
 *          orientation does not affect the ordering of the characters in the n-gram which are
 *          always returned in left-to-right order.
 * @param start
 *          the start of the n-gram (typically 0 for both orientations)
 * @param end
 *          the end of the n-gram (typically n for both orientations)
 * @param minimumValueLength
 *          This parameter allows you to skip string values that are too short. It must be greater
 *          than or equal to end.
 * @param lowerCase
 *          if true than the n-gram used as the feature value will be lowercased.
 */
public LTCharacterNgramFeatureFunction(
    String featureName,
    Orientation orientation,
    int start,
    int end,
    int minimumValueLength,
    boolean lowerCase) {
  name = Feature.createName(
      "NGram",
      orientation == Orientation.RIGHT_TO_LEFT ? "Right" : "Left",
      String.valueOf(start),
      String.valueOf(end),
      String.valueOf(minimumValueLength),
      lowerCase ? "lower" : null,
      featureName);
  if (minimumValueLength < end) {
    throw new IllegalArgumentException(
        "minimumValueLength must be greater than or equal to the parameter end.");
  }
  this.orientation = orientation;
  this.start = start;
  this.end = end;
  this.minimumValueLength = minimumValueLength;
  this.lowerCase = lowerCase;
}
 
开发者ID:tudarmstadt-lt,项目名称:GermaNER,代码行数:49,代码来源:LTCharacterNgramFeatureFunction.java


示例7: getScoredOutcomes

import org.cleartk.ml.Feature; //导入依赖的package包/类
private Map<OUTCOME_TYPE, Double> getScoredOutcomes(List<Feature> features, Path path)
    throws CleartkProcessingException {

  // add the features from preceding outcomes
  features = Lists.newArrayList(features);
  if (path != null) {
    List<Object> previousOutcomes = new ArrayList<Object>(path.outcomes);
    for (OutcomeFeatureExtractor outcomeFeatureExtractor : this.outcomeFeatureExtractors) {
      features.addAll(outcomeFeatureExtractor.extractFeatures(previousOutcomes));
    }
  }

  // get the scored outcomes for this instance
  Map<OUTCOME_TYPE, Double> scoredOutcomes = this.delegatedClassifier.score(features);
  if (scoredOutcomes.isEmpty()) {
    throw new IllegalStateException("expected at least one scored outcome, found "
        + scoredOutcomes);
  }
  return scoredOutcomes;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:21,代码来源:ViterbiClassifier.java


示例8: createExtractor

import org.cleartk.ml.Feature; //导入依赖的package包/类
public static <T extends Annotation> NamedFeatureExtractor1<T> createExtractor(
        PatternType patternType)
{
    final LTCharacterCategoryPatternFunction<T> ccpf = new LTCharacterCategoryPatternFunction<T>(
            patternType);
    return new NamedFeatureExtractor1<T>()
    {

        @Override
        public List<Feature> extract(JCas view, Annotation focusAnnotation)
            throws CleartkExtractorException
        {
            String text = focusAnnotation.getCoveredText();
            return ccpf.apply(new Feature(null, text));
        }

        @Override
        public String getFeatureName()
        {
            return ccpf.getFeatureName();
        }
    };
}
 
开发者ID:tudarmstadt-lt,项目名称:GermaNER,代码行数:24,代码来源:LTCharacterCategoryPatternFunction.java


示例9: test

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Test
public void test() {
  List<String> outcomes = Arrays.asList("X", "Y", "Z");
  List<Feature> features1 = Arrays.asList(new Feature("foo", 42), new Feature("bar", "a"));
  List<Feature> features2 = Arrays.asList(new Feature("foo", -1), new Feature("bar", "b"));
  List<Feature> features3 = Arrays.asList(new Feature("foo", 13), new Feature("bar", "c"));
  List<List<Feature>> featureLists = new ArrayList<List<Feature>>();
  featureLists.add(features1);
  featureLists.add(features2);
  featureLists.add(features3);

  List<Instance<String>> expected = new ArrayList<Instance<String>>();
  expected.add(new Instance<String>("X", features1));
  expected.add(new Instance<String>("Y", features2));
  expected.add(new Instance<String>("Z", features3));

  List<Instance<String>> actual = Instances.toInstances(outcomes, featureLists);
  Assert.assertEquals(expected, actual);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:InstancesTest.java


示例10: generateBooleanInstances

import org.cleartk.ml.Feature; //导入依赖的package包/类
public static List<Instance<Boolean>> generateBooleanInstances(int n) {
  Random random = new Random(42);
  List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
  for (int i = 0; i < n; i++) {
    Instance<Boolean> instance = new Instance<Boolean>();
    if (random.nextInt(2) == 0) {
      instance.setOutcome(true);
      instance.add(new Feature("hello", random.nextInt(100) + 1000));
      instance.add(new Feature("goodbye", 500));
    } else {
      instance.setOutcome(false);
      instance.add(new Feature("goodbye", 500));
      instance.add(new Feature("hello", random.nextInt(100)));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:19,代码来源:ExampleInstanceFactory.java


示例11: apply

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public List<Feature> apply(Feature feature)
{
    Object featureValue = feature.getValue();
    try {
        if (featureValue == null) {
            return Collections.singletonList(new Feature("ClarkPOS", "ClarkPOS_null"));
        }

        return Collections.singletonList(new Feature("ClarkPOS", ClarkPosInduction.posInduction
                .get(featureValue.toString())));
    }
    catch (Exception e) {
        return Collections.singletonList(new Feature("ClarkPOS", "ClarkPOS_null"));
    }
}
 
开发者ID:tudarmstadt-lt,项目名称:GermaNER,代码行数:17,代码来源:ClarkPosInductionFeatureExtractor.java


示例12: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public List<Feature> extract(JCas view, FOCUS_T focusAnnotation) throws CleartkExtractorException {

  List<Feature> extracted = this.subExtractor.extract(view, focusAnnotation);
  List<Feature> result = new ArrayList<Feature>();
  if (this.isTrained) {
    // We have trained / loaded a centroid tf*idf model, so now compute
    // a cosine similarity for the extracted values
    Map<String, Double> extractedFeatureMap = this.featuresToFeatureMap(extracted);
    result.add(new Feature(name, this.simFunction.distance(extractedFeatureMap, centroidMap)));

  } else {
    // We haven't trained this extractor yet, so just mark the existing features
    // for future modification, by creating one mega container feature
    result.add(new TransformableFeature(this.name, extracted));
  }

  return result;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:CentroidTfidfSimilarityExtractor.java


示例13: classify

import org.cleartk.ml.Feature; //导入依赖的package包/类
public String classify(List<Feature> features) throws CleartkProcessingException {
  FeatureVector featureVector = this.featuresEncoder.encodeAll(features);

  int maxScoredIndex = 0;
  double maxScore = 0;
  boolean first = true;
  for (int i : models.keySet()) {
    double score = score(featureVector, i);
    if (first || score > maxScore) {
      first = false;
      maxScore = score;
      maxScoredIndex = i;
    }
  }

  return outcomeEncoder.decode(maxScoredIndex);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:18,代码来源:SvmLightStringOutcomeClassifier.java


示例14: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, TreebankNode node)
    throws CleartkExtractorException {
  TreebankNode parent = node.getParent();

  if (parent == null)
    return Collections.emptyList();

  List<TreebankNode> children = Lists.newArrayList(JCasUtil.select(
      parent.getChildren(),
      TreebankNode.class));
  int index = children.indexOf(node);
  int siblingIndex = index + offset;

  if (siblingIndex < 0 || siblingIndex >= children.size())
    return Collections.emptyList();

  TreebankNode sibling = children.get(siblingIndex);

  List<Feature> features = subExtractor.extract(jCas, sibling);
  for (Feature feature : features) {
    feature.setName(Feature.createName(name, feature.getName()));
  }

  return features;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:26,代码来源:SiblingExtractor.java


示例15: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, TreebankNode constituent)
    throws CleartkExtractorException {

  TreebankNode headNode = findHead(constituent);
  List<Feature> features = new ArrayList<Feature>(extractNode(jCas, headNode, false));

  if (includePPHead && constituent.getNodeType().equals("PP")) {
    for (int i = 0; i < constituent.getChildren().size(); i++) {
      TreebankNode child = constituent.getChildren(i);

      if (child.getNodeType().equals("NP")) {
        features = new ArrayList<Feature>(features);
        features.addAll(extractNode(jCas, findHead(child), true));
        break;
      }
    }
  }

  return features;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:21,代码来源:HeadWordExtractor.java


示例16: testTreeFeatures

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Test
public void testTreeFeatures() throws Exception {
  TreeFeatureVectorFeaturesEncoder encoder = new TreeFeatureVectorFeaturesEncoder();
  encoder.addEncoder(new NumberEncoder());
  encoder.addEncoder(new BooleanEncoder());
  encoder.addEncoder(new StringEncoder());
  
  Feature feat = new Feature("Feature1");
  List<Feature> singletonList = Lists.newArrayList();
  singletonList.add(feat);
  
  // test that the encoder can handle features without names
  try{
    encoder.encodeAll(singletonList);
  }catch(Exception e){
      Assert.assertTrue(false);
  }
  
  List<Instance<Boolean>> instances = generateTreeFeatureInstances(100);
  for(Instance<Boolean> instance : instances){
    TreeFeatureVector features = encoder.encodeAll(instance.getFeatures());
    Map<String,TreeFeature> treeFeatures = features.getTrees();
    Assert.assertTrue(treeFeatures.size() > 0);
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:26,代码来源:RunTkSvmLightTest.java


示例17: generateBooleanInstances

import org.cleartk.ml.Feature; //导入依赖的package包/类
private static List<Instance<Boolean>> generateBooleanInstances(int n) {
  Random random = new Random(42);
  List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
  for (int i = 0; i < n; i++) {
    Instance<Boolean> instance = new Instance<Boolean>();
    if (random.nextInt(2) == 0) {
      instance.setOutcome(true);
      instance.add(new Feature("TK_tree", "(S (NP I) (VB ran) (. .))"));
      instance.add(new Feature("hello", random.nextInt(100) + 1000));
      instance.add(new Feature("goodbye", 500));
    } else {
      instance.setOutcome(false);
      instance.add(new Feature("TK_tree", "(S (VB I) (NP ran) (. .))"));
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", 500));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:21,代码来源:RunTkSvmLightTest.java


示例18: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas jCas, TreebankNode node)
    throws UnsupportedOperationException {

  TreebankNode parent = node.getParent();
  if (parent == null)
    return new ArrayList<Feature>();

  StringBuffer buffer = new StringBuffer();
  buffer.append(parent.getNodeType() + "->");
  boolean first = true;
  for (TreebankNode child : JCasUtil.select(parent.getChildren(), TreebankNode.class)) {
    if (!first)
      buffer.append("-");
    buffer.append(child.getNodeType());
    first = false;
  }

  return Collections.singletonList(new Feature(this.featureName, buffer));
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:SubCategorizationExtractor.java


示例19: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
@Override
public <SEARCH_T extends Annotation> List<Feature> extract(
    JCas jCas,
    Annotation focusAnnotation,
    Bounds bounds,
    Class<SEARCH_T> annotationClass,
    FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException {
  List<Feature> features = new ArrayList<Feature>();
  int pos = 0;
  for (SEARCH_T ann : JCasUtil.selectCovered(jCas, annotationClass, focusAnnotation)) {
    for (Feature feature : extractor.extract(jCas, ann)) {
      features.add(new ContextFeature(this.getName(), pos, feature));
    }
    pos += 1;
  }
  return features;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:18,代码来源:CleartkExtractor.java


示例20: extract

import org.cleartk.ml.Feature; //导入依赖的package包/类
public List<Feature> extract(JCas view, T focusAnnotation) {
  String text = focusAnnotation.getCoveredText();
  int startOffset = this.start;
  if (startOffset < 0) {
    startOffset += text.length();
  }
  if (startOffset < 0) {
    startOffset = 0;
  }
  int stopOffset = this.stop;
  if (stopOffset < 0) {
    stopOffset += text.length();
  }
  if (stopOffset > text.length()) {
    stopOffset = text.length();
  }
  text = text.substring(startOffset, stopOffset);
  return Collections.singletonList(new Feature(this.featureName, text));
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:20,代码来源:TextSliceExtractor.java



注:本文中的org.cleartk.ml.Feature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TearDownStack类代码示例发布时间:2022-05-22
下一篇:
Java TestPortProvider类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap