use of org.apache.uima.collection.CollectionException in project webanno by webanno.
the class TcfReader method getNext.
@Override
public void getNext(JCas aJCas) throws IOException, CollectionException {
Resource res = nextFile();
initCas(aJCas, res);
InputStream is = null;
try {
is = new BufferedInputStream(res.getInputStream());
WLData wLData = WLDObjector.read(is);
TextCorpus aCorpusData = wLData.getTextCorpus();
convertToCas(aJCas, aCorpusData);
} catch (WLFormatException e) {
throw new CollectionException(e);
} finally {
closeQuietly(is);
}
}
use of org.apache.uima.collection.CollectionException in project webanno by webanno.
the class TeiReader method getNext.
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
initCas(aCAS, currentResource);
InputStream is = null;
try {
JCas jcas = aCAS.getJCas();
// Create handler
Handler handler = newSaxHandler();
handler.setJCas(jcas);
handler.setLogger(getLogger());
// Parse TEI text
SAXWriter writer = new SAXWriter(handler);
writer.write(currentTeiElement);
handler.endDocument();
} catch (CASException e) {
throw new CollectionException(e);
} catch (SAXException e) {
throw new IOException(e);
} catch (Exception e) {
throw new IOException("This is not a valid WebAnno CPH TEI file");
} finally {
closeQuietly(is);
}
// Move currentTeiElement to the next text
nextTeiElement();
}
use of org.apache.uima.collection.CollectionException in project webanno by webanno.
the class TeiReader method initialize.
@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
super.initialize(aContext);
if (writePOS && !writeTokens) {
throw new ResourceInitializationException(new IllegalArgumentException("Setting writePOS to 'true' requires writeToken to be 'true' too."));
}
try {
// Init with an empty iterator
teiElementIterator = asList(new Element[0]).iterator();
// Make sure we know about the first element;
nextTeiElement();
} catch (CollectionException | IOException e) {
throw new ResourceInitializationException(e);
}
}
use of org.apache.uima.collection.CollectionException in project dkpro-tc by dkpro.
the class BrownCorpusReader method getNext.
@Override
public void getNext(CAS cas) throws IOException, CollectionException {
super.getNext(cas);
JCas jcas;
try {
jcas = cas.getJCas();
} catch (CASException e) {
throw new CollectionException(e);
}
for (Sentence sentence : JCasUtil.select(jcas, Sentence.class)) {
TextClassificationSequence sequence = new TextClassificationSequence(jcas, sentence.getBegin(), sentence.getEnd());
sequence.addToIndexes();
for (Token token : JCasUtil.selectCovered(jcas, Token.class, sentence)) {
TextClassificationTarget unit = new TextClassificationTarget(jcas, token.getBegin(), token.getEnd());
// will add the token content as a suffix to the ID of this unit
unit.setSuffix(token.getCoveredText());
unit.addToIndexes();
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas, token.getBegin(), token.getEnd());
outcome.setOutcome(getTextClassificationOutcome(jcas, unit));
outcome.addToIndexes();
}
}
}
use of org.apache.uima.collection.CollectionException in project dkpro-tc by dkpro.
the class ReutersCorpusReader method getNext.
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
super.getNext(aCAS);
JCas jcas;
try {
jcas = aCAS.getJCas();
} catch (CASException e) {
throw new CollectionException();
}
for (String outcomeValue : getTextClassificationOutcomes(jcas)) {
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(outcomeValue);
outcome.addToIndexes();
}
}
Aggregations