本文整理汇总了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);
}
示例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);
}
}
}
}