本文整理汇总了Java中org.apache.uima.collection.CollectionException类的典型用法代码示例。如果您正苦于以下问题:Java CollectionException类的具体用法?Java CollectionException怎么用?Java CollectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollectionException类属于org.apache.uima.collection包,在下文中一共展示了CollectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void getNext(CAS aCAS)
throws IOException, CollectionException
{
// nextTarEntry cannot be null here!
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int size = IOUtils.copy(tarArchiveInputStream, buffer);
String entryName = nextTarEntry.getName();
getLogger().debug("Loaded " + size + " bytes from " + entryName);
// and move forward
fastForwardToNextValidEntry();
// and now create JCas
InputStream inputStream = new ByteArrayInputStream(buffer.toByteArray());
try {
XmiCasDeserializer.deserialize(inputStream, aCAS, lenient);
}
catch (SAXException e) {
throw new IOException(e);
}
}
示例2: closeReaderOpenNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
private boolean closeReaderOpenNext()
throws CollectionException, IOException
{
try {
bfs.get(currentReader).close();
}
catch (IOException e) {
e.printStackTrace();
}
if (currentReader + 1 < bfs.size()) {
currentReader++;
return hasNext();
}
return false;
}
示例3: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void getNext(CAS aCAS)
throws IOException, CollectionException
{
super.getNext(aCAS);
JCas jcas;
try {
jcas = aCAS.getJCas();
JCasId id = new JCasId(jcas);
id.setId(jcasId++);
id.addToIndexes();
}
catch (CASException e) {
throw new CollectionException();
}
TextClassificationOutcome outcome = new TextClassificationOutcome(jcas);
outcome.setOutcome(getTextClassificationOutcome(jcas));
outcome.addToIndexes();
if (!suppress) {
new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
}
}
示例4: hasNextDocument
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public boolean hasNextDocument() throws IOException, CollectionException {
if (nextDocument == null) {
String line = reader.readLine();
while (line != null && nextDocument == null) {
nextDocument = documentExtractor.extractDocument(line);
if (nextDocument != null)
break;
line = reader.readLine();
}
if (nextDocument != null)
return true;
return false;
}
return true;
}
示例5: hasNextDocument
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
protected boolean hasNextDocument() throws IOException, CollectionException {
if (nextDocument == null) {
if (documentIndex++ < documentPaths.size()) {
String documentPath = documentPaths.get(documentIndex - 1);
String documentId = documentPath.substring(documentPath.lastIndexOf(StringConstants.FORWARD_SLASH) + 1);
if (FileArchiveUtil.isZippedFile(new File(documentId)))
documentId = FileArchiveUtil.getUnzippedFileName(documentId);
String documentText = getTextFromClasspathResource(documentPath);
nextDocument = new GenericDocument(documentId);
nextDocument.setDocumentText(documentText);
return true;
}
return false;
}
return true;
}
示例6: getNextDocument
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
protected GenericDocument getNextDocument() throws CollectionException, IOException {
File file = fileIterator.next();
String filePath = file.getAbsolutePath();
String documentId = file.getName();
BufferedReader gzreader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filePath))));
String text = "";
for(String line; (line = gzreader.readLine()) != null; ) {
if(text.equals("")) {
text = line;
} else {
text = text + " " + line;
}
}
//String text = FileUtil.copyToString(file, this.encoding);
GenericDocument gd = new GenericDocument(documentId);
gd.setDocumentText(text);
return gd;
}
示例7: hasNextDocument
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
protected boolean hasNextDocument() throws IOException, CollectionException {
if (nextDocument == null) {
while (medlineXmlDeserializer.hasNext() && nextDocument == null) {
Object next = medlineXmlDeserializer.next();
if (next instanceof MedlineCitation) {
MedlineCitation nextCitation = (MedlineCitation) next;
StringBuffer documentText = new StringBuffer();
documentText.append(nextCitation.getArticle().getArticleTitle());
for (AbstractText abstractText : nextCitation.getArticle().getTheAbstract().getAbstractTexts())
documentText.append(StringConstants.NEW_LINE + abstractText.getAbstractText());
nextDocument = new GenericDocument(nextCitation.getPmid().getPmid());
nextDocument.setDocumentText(documentText.toString());
}
}
if (nextDocument != null)
return true;
return false;
}
return true;
}
示例8: hasNextDocument
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
protected boolean hasNextDocument() throws IOException, CollectionException {
if (nextDocument == null) {
if (pubmedXmlDeserializer.hasNext()) {
PubmedArticleBase nextArticle = pubmedXmlDeserializer.next();
StringBuffer documentText = new StringBuffer();
documentText.append(nextArticle.getArticleTitle());
String abstractText = nextArticle.getArticleAbstractText();
if (abstractText != null) {
documentText.append(StringConstants.NEW_LINE + StringConstants.NEW_LINE + abstractText);
}
nextDocument = new GenericDocument(nextArticle.getPubmedId().getPmid());
nextDocument.addOtherDocumentID("year", nextArticle.getDate());
nextDocument.setDocumentText(documentText.toString());
return true;
}
return false;
}
return true;
}
示例9: adaptFile
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void adaptFile(CAS cas, Path path) throws CollectionException {
LOGGER.info("Deserializing an input stream into a cas");
try (InputStream inputStream = Files.newInputStream(path)) {
XmiCasDeserializer.deserialize(inputStream, cas,
!(failOnUnknownType == null || failOnUnknownType));
} catch (SAXException | IOException e) {
LOGGER.error("Failed on document: {}", path);
throw new CollectionException(e);
}
if (addDocumentId != null && addDocumentId) {
CAS metadata = cas.getView("metadata");
Type idType = metadata.getTypeSystem()
.getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
Feature idFeat = idType.getFeatureByBaseName("documentId");
FeatureStructure fs = metadata.createFS(idType);
fs.setStringValue(idFeat, path.getFileName().toString());
metadata.addFsToIndexes(fs);
}
}
示例10: adaptFile
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void adaptFile(CAS cas, Path path) throws CollectionException, IOException {
LOGGER.debug("Reading text into a CAS view.");
CAS targetView = cas.createView(viewName);
byte[] bytes = Files.readAllBytes(path);
String documentText = new String(bytes,
Objects.requireNonNull(encoding,
"Encoding must not be null"));
targetView.setDocumentText(documentText);
String fileName = path.getFileName().toString();
int period = fileName.lastIndexOf('.');
if (period == -1) {
period = fileName.length();
}
String documentId = fileName.substring(0, period);
UimaAdapters.createDocument(cas, null, documentId);
}
示例11: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
if (!hasNext()) {
throw new CollectionException(new NoSuchElementException());
}
final int curFileIdx = lastReadFileIdx + 1;
File file = files.get(curFileIdx);
lastReadFileIdx = curFileIdx;
//
String fileContent = FileUtils.readFileToString(file, encoding);
aCAS.setDocumentText(fileContent);
try {
DocumentMetadata docMeta = new DocumentMetadata(aCAS.getJCas());
docMeta.setSourceUri(getURIForMetadata(file).toString());
docMeta.addToIndexes();
} catch (CASException e) {
throw new IllegalStateException(e);
}
}
示例12: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void getNext(CAS cas) throws IOException, CollectionException {
if (!dbIterator.hasNext()) {
throw new NoSuchElementException();
}
DbTuple tuple = dbIterator.next();
consumedCount++;
cas.setDocumentText(tuple.text);
try {
DocumentMetadata docMeta = new DocumentMetadata(cas.getJCas());
docMeta.setSourceUri(tuple.url);
docMeta.addToIndexes();
} catch (CASException e) {
throw new CollectionException(e);
}
}
示例13: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void getNext(CAS aCAS) throws IOException, CollectionException {
UriAnnotatorPair pair = uriAnnotatorPairsIterator.next();
try {
corpusDAO
.getDocumentCas(pair.getUri(), pair.getAnnotatorId(), aCAS);
} catch (SAXException e) {
getLogger().error(
String.format("Exception at %s annotated by %s.",
pair.getUri(), pair.getAnnotatorId()));
e.printStackTrace();
throw new CollectionException();
}
addSourceDocumentInformation(aCAS, pair);
mCurrentIndex++;
}
示例14: getNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
public void getNext(JCas aJcas) throws IOException, CollectionException {
File f = documents.get(i);
LineIterator it = FileUtils.lineIterator(f);
int start =0;
int inds=0;
StringBuffer sb = new StringBuffer();
while(it.hasNext()){
String line = it.nextLine();
Sentence sent = new Sentence(aJcas, start, start+line.length());
sent.addToIndexes();
start = start + line.length() + 1;
sb.append(line+"\n");
if (inds%10000==0)
System.out.println("R"+inds);
}
aJcas.setDocumentText(sb.toString());
//had to add english as default language, one could also add another configuration parameter
aJcas.setDocumentLanguage("en");
i++;
}
示例15: doGetNext
import org.apache.uima.collection.CollectionException; //导入依赖的package包/类
@Override
protected void doGetNext(final JCas jCas) throws IOException, CollectionException {
final String source = String.join(".", activeMQ.getResourceName(), endpoint);
try {
final Message msg = this.consumer.receive();
if (msg instanceof TextMessage) {
final String text = ((TextMessage) msg).getText();
final InputStream is = IOUtils.toInputStream(text);
this.extractor.processStream(is, source, jCas);
} else {
throw new IOException(String.format("Unexpected message type for message with id %1 from source %2",
msg.getJMSMessageID(), source));
}
} catch (final JMSException e) {
throw new CollectionException(e);
}
}