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

Java Instance类代码示例

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

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



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

示例1: process

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

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

  features = Arrays.asList(
      new Feature("A", 2.1),
      new Feature("B", 2.0),
      new Feature("C", 2.234));
  instance = new Instance<String>("no", features);
  this.dataWriter.write(instance);

  features = Arrays.asList(
      new Feature("A", 5.1),
      new Feature("B", 5.0),
      new Feature("C", 5.234));
  instance = new Instance<String>("yes", features);
  this.dataWriter.write(instance);

}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:WekaDataWriterTest.java


示例3: generateStringInstances

import org.cleartk.ml.Instance; //导入依赖的package包/类
public static List<Instance<String>> generateStringInstances(int n) {
  Random random = new Random(42);
  List<Instance<String>> instances = new ArrayList<Instance<String>>();
  for (int i = 0; i < n; i++) {
    Instance<String> instance = new Instance<String>();
    int c = random.nextInt(3);
    if (c == 0) {
      instance.setOutcome("A");
      instance.add(new Feature("hello", random.nextInt(100) + 950));
      instance.add(new Feature("goodbye", random.nextInt(100)));
      instance.add(new Feature("farewell", random.nextInt(100)));
    } else if (c == 1) {
      instance.setOutcome("B");
      instance.add(new Feature("goodbye", random.nextInt(100) + 950));
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("farewell", random.nextInt(100)));
    } else {
      instance.setOutcome("C");
      instance.add(new Feature("farewell", random.nextInt(100) + 950));
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", random.nextInt(100)));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:ExampleInstanceFactory.java


示例4: process

import org.cleartk.ml.Instance; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
  for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) {
    Instance<Boolean> instance = new Instance<Boolean>(false, this.extractor.extract(
        jcas,
        sentence));

    if (this.isTraining()) {
      this.dataWriter.write(instance);
    } else {
      Map<Boolean, Double> scoredOutcomes = this.classifier.score(instance.getFeatures());
      Double trueScore = scoredOutcomes.get(true);
      if (trueScore > 0.0) {
        SummarySentence extractedSentence = new SummarySentence(
            jcas,
            sentence.getBegin(),
            sentence.getEnd());
        extractedSentence.setScore(trueScore);
        extractedSentence.addToIndexes();
      }
    }
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:SumBasicAnnotator.java


示例5: transform

import org.cleartk.ml.Instance; //导入依赖的package包/类
@Override
public Instance<OUTCOME_T> transform(Instance<OUTCOME_T> instance) {
  List<Feature> features = new ArrayList<Feature>();
  List<Feature> featuresToTransform = new ArrayList<Feature>();
  for (Feature feature : instance.getFeatures()) {
    if (this.isTransformable(feature)) {
      // Store off features for later similarity computation
      featuresToTransform.addAll(((TransformableFeature) feature).getFeatures());
    } else {
      // pass through non-transformable features
      features.add(feature);
    }
  }

  // Create centroid similarity feature
  Map<String, Double> featureMap = this.featuresToFeatureMap(featuresToTransform);
  features.add(new Feature(this.name, new Double(this.simFunction.distance(
      featureMap,
      centroidMap))));

  return new Instance<OUTCOME_T>(instance.getOutcome(), features);
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:23,代码来源:CentroidTfidfSimilarityExtractor.java


示例6: createIdfMap

import org.cleartk.ml.Instance; //导入依赖的package包/类
protected IDFMap createIdfMap(Iterable<Instance<OUTCOME_T>> instances) {
  IDFMap newIdfMap = new IDFMap();

  // Add instance's term frequencies to the global counts
  for (Instance<OUTCOME_T> instance : instances) {

    Set<String> featureNames = new HashSet<String>();
    // 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()) {
          featureNames.add(untransformedFeature.getName());
        }
      }
    }

    for (String featureName : featureNames) {
      newIdfMap.add(featureName);
    }
    newIdfMap.incTotalDocumentCount();

  }
  return newIdfMap;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:TfidfExtractor.java


示例7: selectTransformableFeatures

import org.cleartk.ml.Instance; //导入依赖的package包/类
/**
 * Recursively look through all features in an instance to find the features this extractor is
 * responsible for extracting
 */
protected List<TransformableFeature> selectTransformableFeatures(Instance<OUTCOME_T> instance) {

  List<TransformableFeature> features = new ArrayList<TransformableFeature>();
  Stack<Feature> featuresToProcess = new Stack<Feature>();
  featuresToProcess.addAll(instance.getFeatures());

  while (!featuresToProcess.isEmpty()) {
    Feature currFeature = featuresToProcess.pop();
    if (currFeature instanceof TransformableFeature) {
      TransformableFeature transformable = (TransformableFeature) currFeature;
      if (transformable.getName().equals(this.name)) {
        features.add(transformable);
      } else {
        featuresToProcess.addAll(transformable.getFeatures());
      }
    }
  }
  return features;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:TrainableExtractor_ImplBase.java


示例8: train

import org.cleartk.ml.Instance; //导入依赖的package包/类
@Override
public void train(Iterable<Instance<OUTCOME_T>> instances) {
  // aggregate statistics for all features and classes
  this.mutualInfoStats = new MutualInformationStats<OUTCOME_T>(this.smoothingCount);

  for (Instance<OUTCOME_T> instance : instances) {
    OUTCOME_T outcome = instance.getOutcome();
    for (Feature feature : instance.getFeatures()) {
      if (this.isTransformable(feature)) {
        for (Feature untransformedFeature : ((TransformableFeature) feature).getFeatures()) {
          mutualInfoStats.update(this.nameFeature(untransformedFeature), outcome, 1);
        }
      }
    }
  }
  // Compute mutual information score for each feature
  Set<String> featureNames = mutualInfoStats.classConditionalCounts.rowKeySet();

  this.selectedFeatures = Ordering.natural().onResultOf(
      this.mutualInfoStats.getScoreFunction(
          this.combineScoreMethod)).reverse().immutableSortedCopy(featureNames);
  this.isTrained = true;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:MutualInformationFeatureSelectionExtractor.java


示例9: write

import org.cleartk.ml.Instance; //导入依赖的package包/类
public void write(List<Instance<OUTCOME_TYPE>> instances) throws CleartkProcessingException {
  if (this.delegatedDataWriter == null)
    throw new IllegalStateException(
        "delegatedDataWriter must be set before calling writeSequence");

  List<Object> outcomes = new ArrayList<Object>();
  for (Instance<OUTCOME_TYPE> instance : instances) {
    List<Feature> instanceFeatures = instance.getFeatures();
    for (OutcomeFeatureExtractor outcomeFeatureExtractor : outcomeFeatureExtractors) {
      instanceFeatures.addAll(outcomeFeatureExtractor.extractFeatures(outcomes));
    }
    outcomes.add(instance.getOutcome());
    delegatedDataWriter.write(instance);
  }

}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:17,代码来源:ViterbiDataWriter.java


示例10: process

import org.cleartk.ml.Instance; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
  for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
    List<Instance<String>> instances = new ArrayList<Instance<String>>();
    List<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, sentence);
    for (Token token : tokens) {
      Instance<String> instance = new Instance<String>();
      instance.addAll(this.extractor.extract(jCas, token));
      instance.setOutcome(token.getPos());
      instances.add(instance);
    }
    if (this.isTraining()) {
      this.dataWriter.write(instances);
    } else {
      this.classify(instances);
    }
  }
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:19,代码来源:ViterbiDataWriterTest.java


示例11: test

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


示例12: testFeatures

import org.cleartk.ml.Instance; //导入依赖的package包/类
@Test
public void testFeatures() {
  Instance<String> instance = new Instance<String>();

  // test an instance with no features
  Assert.assertEquals(0, instance.getFeatures().size());

  // test the .add() method
  Feature f1 = new Feature("foo", "bar");
  instance.add(f1);
  Assert.assertEquals(1, instance.getFeatures().size());
  Assert.assertEquals(f1, instance.getFeatures().get(0));

  // test the .addAll() method
  Feature f2 = new Feature(true);
  Feature f3 = new Feature("baz", 42.0);
  List<Feature> newFeatures = new ArrayList<Feature>();
  newFeatures.add(f2);
  newFeatures.add(f3);
  instance.addAll(newFeatures);
  Assert.assertEquals(3, instance.getFeatures().size());
  Assert.assertEquals(f1, instance.getFeatures().get(0));
  Assert.assertEquals(f2, instance.getFeatures().get(1));
  Assert.assertEquals(f3, instance.getFeatures().get(2));
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:26,代码来源:InstanceTest.java


示例13: generateStringInstances

import org.cleartk.ml.Instance; //导入依赖的package包/类
/**
 * Create a number of random Instance objects that should be easy to classify. This is primarily
 * useful for testing DataWriter and Classifier implementations.
 * 
 * @param n
 *          The number of instances
 * @return The list of newly-created instances
 */
public static List<Instance<String>> generateStringInstances(int n) {
  List<Instance<String>> instances = new ArrayList<Instance<String>>();
  for (int i = 0; i < n; i++) {
    Instance<String> instance = new Instance<String>();
    switch (ClassifierTestUtil.random.nextInt(3)) {
      case 0:
        instance.setOutcome("A");
        instance.add(new Feature("hello", -1050 + ClassifierTestUtil.random.nextInt(100)));
        break;
      case 1:
        instance.setOutcome("B");
        instance.add(new Feature("hello", -50 + ClassifierTestUtil.random.nextInt(100)));
        break;
      case 2:
        instance.setOutcome("C");
        instance.add(new Feature("hello", 950 + ClassifierTestUtil.random.nextInt(100)));
        break;
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:31,代码来源:ClassifierTestUtil.java


示例14: generateBooleanInstances

import org.cleartk.ml.Instance; //导入依赖的package包/类
/**
 * Create a number of random Instance objects that should be easy to classify. This is primarily
 * useful for testing DataWriter and Classifier implementations.
 * 
 * @param n
 *          The number of instances
 * @return The list of newly-created instances
 */
public static List<Instance<Boolean>> generateBooleanInstances(int n) {
  List<Instance<Boolean>> instances = new ArrayList<Instance<Boolean>>();
  for (int i = 0; i < n; i++) {
    Instance<Boolean> instance = new Instance<Boolean>();
    if (ClassifierTestUtil.random.nextInt(2) == 0) {
      instance.setOutcome(true);
      instance.add(new Feature("hello", ClassifierTestUtil.random.nextInt(1000) + 1000));
    } else {
      instance.setOutcome(false);
      instance.add(new Feature("hello", ClassifierTestUtil.random.nextInt(100)));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:24,代码来源:ClassifierTestUtil.java


示例15: generateBooleanInstances

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


示例16: generateBooleanInstances

import org.cleartk.ml.Instance; //导入依赖的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("hello", random.nextInt(100) + 1000));
      instance.add(new Feature("goodbye", 500));
    } else {
      instance.setOutcome(false);
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", 500));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:19,代码来源:RunSvmLightTest.java


示例17: generateStringInstances

import org.cleartk.ml.Instance; //导入依赖的package包/类
private static List<Instance<String>> generateStringInstances(int n) {
  Random random = new Random(42);
  List<Instance<String>> instances = new ArrayList<Instance<String>>();
  for (int i = 0; i < n; i++) {
    Instance<String> instance = new Instance<String>();
    int c = random.nextInt(3);
    if (c == 0) {
      instance.setOutcome("A");
      instance.add(new Feature("hello", random.nextInt(100) + 950));
      instance.add(new Feature("goodbye", random.nextInt(100)));
      instance.add(new Feature("farewell", random.nextInt(100)));
    } else if (c == 1) {
      instance.setOutcome("B");
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", random.nextInt(100) + 950));
      instance.add(new Feature("farewell", random.nextInt(100)));
    } else {
      instance.setOutcome("C");
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", random.nextInt(100)));
      instance.add(new Feature("farewell", random.nextInt(100) + 950));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:RunSvmLightTest.java


示例18: generateBooleanInstances

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


示例19: generateBooleanMultiKernelInstances

import org.cleartk.ml.Instance; //导入依赖的package包/类
private static List<Instance<Boolean>> generateBooleanMultiKernelInstances(int n){
  SubsetTreeKernel sst = new SubsetTreeKernel(0.4, true);
  PartialTreeKernel ptk = new PartialTreeKernel(0.4, 0.5, true);
  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<>();
    if (random.nextInt(2) == 0) {
      instance.setOutcome(true);
      instance.add(new TreeFeature("Tree", "(S (NP I) (VB ran) (. .))", sst));
      instance.add(new TreeFeature("DepTree", "(ROOT (dep (ran (nsubj i))))", ptk));
      instance.add(new Feature("hello", random.nextInt(100) + 950));
      instance.add(new Feature("goodbye", random.nextInt(100)));
      instance.add(new Feature("farewell", random.nextInt(100)));
    } else {
      instance.setOutcome(false);
      instance.add(new TreeFeature("Tree", "(S (TT going) (ZZ gone) (. .))", sst));
      instance.add(new TreeFeature("DepTree", "(ROOT (dep (gone (nsubj going))))", ptk));
      instance.add(new Feature("hello", random.nextInt(100)));
      instance.add(new Feature("goodbye", random.nextInt(100) + 950));
      instance.add(new Feature("farewell", random.nextInt(100)));
    }
    instances.add(instance);
  }
  return instances;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:27,代码来源:RunTkLibSvmTest.java


示例20: generateBooleanInstances

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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