当前位置: 首页>>代码示例>>Java>>正文


Java Instances类代码示例

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


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

示例1: test

import org.cleartk.ml.Instances; //导入依赖的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

示例2: process

import org.cleartk.ml.Instances; //导入依赖的package包/类
public void process(JCas jCas) throws AnalysisEngineProcessException {
  // for each sentence in the document, generate training/classification instances
  for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
    List<List<Feature>> tokenFeatureLists = new ArrayList<List<Feature>>();
    List<String> tokenOutcomes = new ArrayList<String>();

    // for each token, extract features and the outcome
    List<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, sentence);
    for (Token token : tokens) {

      // apply the two feature extractors
      List<Feature> tokenFeatures = new ArrayList<Feature>();
      tokenFeatures.addAll(this.tokenFeatureExtractor.extract(jCas, token));
      tokenFeatures.addAll(this.contextFeatureExtractor.extractWithin(jCas, token, sentence));
      tokenFeatureLists.add(tokenFeatures);

      // add the expected token label from the part of speech
      if (this.isTraining()) {
        tokenOutcomes.add(token.getPos());
      }
    }

    // for training, write instances to the data write
    if (this.isTraining()) {
      this.dataWriter.write(Instances.toInstances(tokenOutcomes, tokenFeatureLists));
    }

    // for classification, set the token part of speech tags from the classifier outcomes.
    else {
      List<String> outcomes = this.classifier.classify(tokenFeatureLists);
      Iterator<Token> tokensIter = tokens.iterator();
      for (String outcome : outcomes) {
        tokensIter.next().setPos(outcome);
      }
    }
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:38,代码来源:ExamplePosAnnotator.java


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