use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class IdfPairMetaCollector method getNgramsFD.
@Override
protected FrequencyDistribution<String> getNgramsFD(JCas jcas) throws TextClassificationException {
TextClassificationTarget aTarget = JCasUtil.selectSingle(jcas, TextClassificationTarget.class);
FrequencyDistribution<String> toReturn = NGramUtils.getDocumentNgrams(jcas, aTarget, true, false, 1, 1, stopwords, ngramAnnotationType);
return toReturn;
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class TestTargetSurfaceFormContextFeature method setUp.
private Object[] setUp() throws Exception {
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("It is raining all day");
DocumentMetaData dmd = new DocumentMetaData(jcas);
dmd.setDocumentId("1");
dmd.addToIndexes();
AnalysisEngine engine = createEngine(BreakIteratorSegmenter.class);
engine.process(jcas.getCas());
ArrayList<Token> arrayList = new ArrayList<Token>(JCasUtil.select(jcas, Token.class));
Token bb = arrayList.get(0);
TextClassificationTarget tcbb = new TextClassificationTarget(jcas, bb.getBegin(), bb.getEnd());
tcbb.addToIndexes();
Token b = arrayList.get(1);
TextClassificationTarget tcb = new TextClassificationTarget(jcas, b.getBegin(), b.getEnd());
tcb.addToIndexes();
Token c = arrayList.get(2);
TextClassificationTarget tcu = new TextClassificationTarget(jcas, c.getBegin(), c.getEnd());
tcu.addToIndexes();
Token n = arrayList.get(3);
TextClassificationTarget tcn = new TextClassificationTarget(jcas, n.getBegin(), n.getEnd());
tcn.addToIndexes();
Token nn = arrayList.get(4);
TextClassificationTarget tcnn = new TextClassificationTarget(jcas, nn.getBegin(), nn.getEnd());
tcnn.addToIndexes();
return new Object[] { jcas, tcu };
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class NumberOfHashTagsTest method numberOfHashTagsFeatureExtractorTest.
@Test
public void numberOfHashTagsFeatureExtractorTest() throws Exception {
AnalysisEngineDescription desc = createEngineDescription(NoOpAnnotator.class);
AnalysisEngine engine = createEngine(desc);
JCas jcas = engine.newJCas();
jcas.setDocumentLanguage("en");
jcas.setDocumentText("This is a very #emotional tweet ;-) #icouldcry #ILoveHashTags");
engine.process(jcas);
TextClassificationTarget aTarget = new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length());
aTarget.addToIndexes();
NumberOfHashTags extractor = new NumberOfHashTags();
List<Feature> features = new ArrayList<Feature>(extractor.extract(jcas, aTarget));
Assert.assertEquals(1, features.size());
for (Feature feature : features) {
assertFeature(NumberOfHashTags.class.getSimpleName(), 3, feature);
}
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class SequenceOutcomeReader method setTextClassificationTarget.
protected void setTextClassificationTarget(JCas aJCas, String token, int begin, int end) {
TextClassificationTarget aTarget = new TextClassificationTarget(aJCas, begin, end);
// This improves readability of the id2outcome report
aTarget.setSuffix(token);
aTarget.addToIndexes();
}
use of org.dkpro.tc.api.type.TextClassificationTarget in project dkpro-tc by dkpro.
the class CrfSuiteLoadModelConnector method getInstancesInSequence.
private List<Instance> getInstancesInSequence(FeatureExtractorResource_ImplBase[] featureExtractors, JCas jcas, TextClassificationSequence sequence, boolean addInstanceId, int sequenceId) throws Exception {
List<Instance> instances = new ArrayList<Instance>();
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, sequence);
for (TextClassificationTarget aTarget : seqTargets) {
Instance instance = new Instance();
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
}
// execute feature extractors and add features to instance
try {
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
instance.addFeatures(((FeatureExtractor) featExt).extract(jcas, aTarget));
}
} catch (TextClassificationException e) {
throw new AnalysisEngineProcessException(e);
}
// set and write outcome label(s)
instance.setOutcomes(getOutcomes(jcas, aTarget));
instance.setJcasId(jcasId);
instance.setSequenceId(sequenceId);
instance.setSequencePosition(aTarget.getId());
instances.add(instance);
}
return instances;
}
Aggregations