当前位置: 首页>>代码示例>>Java>>正文


Java CollectionException类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:24,代码来源:CompressedXmiReader.java

示例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;
}
 
开发者ID:Horsmann,项目名称:FlexTag,代码行数:17,代码来源:LineTokenTagReader.java

示例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();
    }
}
 
开发者ID:Horsmann,项目名称:FlexTag,代码行数:26,代码来源:TestReaderSingleLabel.java

示例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;
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:18,代码来源:DocumentPerLineCollectionReader.java

示例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;
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:18,代码来源:ClasspathCollectionReader.java

示例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;
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:22,代码来源:GzippedFileSystemCollectionReader.java

示例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;
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:22,代码来源:MedlineXmlFileCollectionReader.java

示例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;
}
 
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:21,代码来源:PubmedXmlFileCollectionReader.java

示例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);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:24,代码来源:XmiInputFileAdapter.java

示例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);
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:20,代码来源:PlainTextInputFileAdapter.java

示例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);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:23,代码来源:FileDirectoryCollectionReader.java

示例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);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:20,代码来源:JdbcCollectionReader.java

示例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++;
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:19,代码来源:CorpusDAOCollectionReader.java

示例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++;
}
 
开发者ID:tudarmstadt-lt,项目名称:sentiment,代码行数:22,代码来源:StanfordReader.java

示例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);
	}

}
 
开发者ID:dstl,项目名称:baleen,代码行数:21,代码来源:ActiveMQReader.java


注:本文中的org.apache.uima.collection.CollectionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。