use of org.dkpro.tc.api.type.TextClassificationSequence in project dkpro-tc by dkpro.
the class TcAnnotator method addTCSequenceAnnotation.
private void addTCSequenceAnnotation(JCas jcas) {
Type type = jcas.getCas().getTypeSystem().getType(nameSequence);
Collection<AnnotationFS> sequenceAnnotation = CasUtil.select(jcas.getCas(), type);
for (AnnotationFS seq : sequenceAnnotation) {
TextClassificationSequence tcs = new TextClassificationSequence(jcas, seq.getBegin(), seq.getEnd());
tcs.addToIndexes();
}
}
use of org.dkpro.tc.api.type.TextClassificationSequence in project dkpro-tc by dkpro.
the class TestFoldUtil method setSeq.
private void setSeq(JCas cas, int beg, int end) {
TextClassificationSequence seq = new TextClassificationSequence(cas, beg, end);
seq.addToIndexes();
String[] split = seq.getCoveredText().split(" ");
setUnit(cas, beg, beg + split[0].length());
setUnit(cas, beg + split[0].length() + 1, end);
}
use of org.dkpro.tc.api.type.TextClassificationSequence in project dkpro-tc by dkpro.
the class TestFoldUtil method countNumberOfTextClassificationSequencesAndUnitsPerCas.
private List<List<Integer>> countNumberOfTextClassificationSequencesAndUnitsPerCas(List<File> writtenBins) throws Exception {
List<List<Integer>> arrayList = new ArrayList<>();
List<Integer> units = new ArrayList<>();
List<Integer> seq = new ArrayList<>();
for (File f : writtenBins) {
JCas jcas = JCasFactory.createJCas();
CollectionReader createReader = createReader(jcas, f);
createReader.getNext(jcas.getCas());
Collection<TextClassificationTarget> colUni = JCasUtil.select(jcas, TextClassificationTarget.class);
units.add(colUni.size());
Collection<TextClassificationSequence> colSeq = JCasUtil.select(jcas, TextClassificationSequence.class);
seq.add(colSeq.size());
}
arrayList.add(seq);
arrayList.add(units);
return arrayList;
}
use of org.dkpro.tc.api.type.TextClassificationSequence in project dkpro-tc by dkpro.
the class InstanceExtractor method getSequenceInstances.
public List<Instance> getSequenceInstances(JCas jcas, boolean useSparse) throws TextClassificationException {
List<Instance> instances = new ArrayList<Instance>();
int jcasId = JCasUtil.selectSingle(jcas, JCasId.class).getId();
int sequenceId = 0;
int unitId = 0;
Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
for (TextClassificationSequence seq : sequences) {
unitId = 0;
List<TextClassificationTarget> seqTargets = JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq);
for (TextClassificationTarget aTarget : seqTargets) {
aTarget.setId(unitId++);
Instance instance = new Instance();
if (addInstanceId) {
instance.addFeature(InstanceIdFeature.retrieve(jcas, aTarget, sequenceId));
}
for (FeatureExtractorResource_ImplBase featExt : featureExtractors) {
if (useSparse) {
instance.addFeatures(getSparse(jcas, aTarget, featExt));
} else {
instance.addFeatures(getDense(jcas, aTarget, featExt));
}
}
// set and write outcome label(s)
instance.setOutcomes(getOutcomes(jcas, aTarget));
instance.setWeight(getWeight(jcas, aTarget));
instance.setJcasId(jcasId);
instance.setSequenceId(sequenceId);
instance.setSequencePosition(aTarget.getId());
instances.add(instance);
}
sequenceId++;
}
return instances;
}
use of org.dkpro.tc.api.type.TextClassificationSequence in project dkpro-tc by dkpro.
the class SequenceContextMetaCollector method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Collection<TextClassificationSequence> sequences = JCasUtil.select(jcas, TextClassificationSequence.class);
for (TextClassificationSequence seq : sequences) {
int id = seq.getId();
for (TextClassificationTarget unit : JCasUtil.selectCovered(jcas, TextClassificationTarget.class, seq)) {
String idString;
try {
idString = (String) InstanceIdFeature.retrieve(jcas, unit, id).getValue();
ContextMetaCollectorUtil.addContext(jcas, unit, idString, bw);
} catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
}
}
Aggregations