本文整理汇总了Java中org.cleartk.ml.Instance.setOutcome方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.setOutcome方法的具体用法?Java Instance.setOutcome怎么用?Java Instance.setOutcome使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.cleartk.ml.Instance
的用法示例。
在下文中一共展示了Instance.setOutcome方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: generateTreeFeatureInstances
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
private static List<Instance<Boolean>> generateTreeFeatureInstances(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("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 TreeFeature("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;
}
示例10: process
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
for (Sentence sentence : select(jCas, Sentence.class)) {
List<Instance<String>> instances = new ArrayList<>();
List<Token> tokens = selectCovered(jCas, Token.class, sentence);
for (Token token : tokens) {
Instance<String> instance = new Instance<>();
for (FeatureExtractor1<Token> extractor : this.featureExtractors) {
if (extractor instanceof CleartkExtractor) {
instance.addAll((((CleartkExtractor) extractor).extractWithin(jCas, token, sentence)));
}
else {
instance.addAll(extractor.extract(jCas, token));
}
}
try {
instance.setOutcome(selectCovered(jCas, GoldAspectTarget.class, token).get(0).getAspectTargetType());
} catch (IndexOutOfBoundsException e) {
//e.printStackTrace();
}
instances.add(instance);
}
if (this.isTraining()) {
this.dataWriter.write(instances);
} else {
List<String> labels = this.classify(instances);
Iterator<Token> tokensIter = tokens.iterator();
for (String label : labels) {
Token t = tokensIter.next();
AspectTarget target = new AspectTarget(jCas, t.getBegin(), t.getEnd());
target.setAspectTargetType(label);
target.addToIndexes();
}
}
}
}
示例11: createInstances
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
public List<Instance<String>> createInstances(int n, String featureName, String outcome) {
Instance<String> instance = new Instance<String>();
instance.add(new Feature(featureName));
instance.setOutcome(outcome);
List<Instance<String>> instances = Lists.newArrayList();
for (int i = 0; i < n; i++) {
instances.add(instance);
}
return instances;
}
示例12: testLabel
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
@Test
public void testLabel() {
Instance<Double> instance = new Instance<Double>();
// test an instance with no label
Assert.assertEquals(null, instance.getOutcome());
// test setting and retrieving the label
instance.setOutcome(3.14);
Assert.assertEquals(3.14d, instance.getOutcome().doubleValue(), 0.01d);
}
示例13: createInstance
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
private static Instance<String> createInstance(String data) {
Instance<String> instance = new Instance<String>();
String[] columns = data.split(" ");
instance.setOutcome(columns[0]);
for (int i = 1; i < columns.length; i++) {
instance.add(new Feature(columns[i]));
}
return instance;
}
示例14: 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 TreeFeature("Tree", "(S (NP I) (VB ran) (. .))"));
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 TreeFeature("Tree", "(S (TT going) (ZZ gone) (. .))"));
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 TreeFeature("Tree", "(S (DET The) (PP Fox) (. .))"));
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;
}
示例15: generateStringMultiKernelInstances
import org.cleartk.ml.Instance; //导入方法依赖的package包/类
private static List<Instance<String>> generateStringMultiKernelInstances(int n) {
SubsetTreeKernel sst = new SubsetTreeKernel(0.4, true);
DescendingPathKernel dpk = new DescendingPathKernel(0.4, false);
PartialTreeKernel ptk = new PartialTreeKernel(0.4, 0.5, true);
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 TreeFeature("Tree", "(S (NP I) (VB ran) (. .))", sst));
instance.add(new TreeFeature("Tree", "(S (NP I) (VB ran) (. .))", dpk));
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 if (c == 1) {
instance.setOutcome("B");
instance.add(new TreeFeature("Tree", "(S (TT going) (ZZ gone) (. .))", sst));
instance.add(new TreeFeature("Tree", "(S (TT going) (ZZ gone) (. .))", dpk));
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)));
} else {
instance.setOutcome("C");
instance.add(new TreeFeature("Tree", "(S (DET The) (PP Fox) (. .))", sst));
instance.add(new TreeFeature("Tree", "(S (DET The) (PP Fox) (. .))", dpk));
instance.add(new TreeFeature("DepTree", "(ROOT (dep (Fox (det The) (punct .))))", ptk));
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;
}