Search in sources :

Example 1 with AnalysisEngineProcessException

use of org.apache.uima.analysis_engine.AnalysisEngineProcessException in project deeplearning4j by deeplearning4j.

the class UimaResource method process.

/**
     * Use the given analysis engine and process the given text
     * You must release the return cas yourself
     * @param text the text to process
     * @return the processed cas
     */
public CAS process(String text) {
    CAS cas = retrieve();
    if (cas == null)
        return null;
    cas.setDocumentText(text);
    try {
        analysisEngine.process(cas);
    } catch (AnalysisEngineProcessException e) {
        log.warn("Unable to process text " + text, e);
    }
    return cas;
}
Also used : CAS(org.apache.uima.cas.CAS) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 2 with AnalysisEngineProcessException

use of org.apache.uima.analysis_engine.AnalysisEngineProcessException in project lucene-solr by apache.

the class UIMAAnnotationsTokenizer method initializeIterator.

@Override
protected void initializeIterator() throws IOException {
    try {
        analyzeInput();
    } catch (AnalysisEngineProcessException | ResourceInitializationException e) {
        throw new IOException(e);
    }
    finalOffset = correctOffset(cas.getDocumentText().length());
    Type tokenType = cas.getTypeSystem().getType(tokenTypeString);
    iterator = cas.getAnnotationIndex(tokenType).iterator();
}
Also used : Type(org.apache.uima.cas.Type) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 3 with AnalysisEngineProcessException

use of org.apache.uima.analysis_engine.AnalysisEngineProcessException in project lucene-solr by apache.

the class UIMATypeAwareAnnotationsTokenizer method initializeIterator.

@Override
protected void initializeIterator() throws IOException {
    try {
        analyzeInput();
    } catch (AnalysisEngineProcessException | ResourceInitializationException e) {
        throw new IOException(e);
    }
    featurePath = cas.createFeaturePath();
    try {
        featurePath.initialize(typeAttributeFeaturePath);
    } catch (CASException e) {
        featurePath = null;
        throw new IOException(e);
    }
    finalOffset = correctOffset(cas.getDocumentText().length());
    Type tokenType = cas.getTypeSystem().getType(tokenTypeString);
    iterator = cas.getAnnotationIndex(tokenType).iterator();
}
Also used : Type(org.apache.uima.cas.Type) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) CASException(org.apache.uima.cas.CASException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException)

Example 4 with AnalysisEngineProcessException

use of org.apache.uima.analysis_engine.AnalysisEngineProcessException in project stanbol by apache.

the class UIMALocal method computeEnhancements.

@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
    Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES);
    if (contentPart == null) {
        throw new IllegalStateException("No ContentPart with an supported Mimetype '" + SUPPORTED_MIMETYPES + "' found for ContentItem " + ci.getUri() + ": This is also checked in the canEnhance method! -> This " + "indicated an Bug in the implementation of the " + "EnhancementJobManager!");
    }
    String text;
    try {
        text = ContentItemHelper.getText(contentPart.getValue());
    } catch (IOException e) {
        throw new InvalidContentException(this, ci, e);
    }
    JCas jcas;
    try {
        logger.info("Processing text with UIMA AE...");
        jcas = processText(text);
    } catch (ResourceInitializationException ex) {
        logger.error("Error initializing UIMA AE", ex);
        throw new EngineException("Error initializing UIMA AE", ex);
    } catch (AnalysisEngineProcessException ex) {
        logger.error("Error running UIMA AE", ex);
        throw new EngineException("Error running UIMA AE", ex);
    }
    //just for being sure
    if (jcas == null) {
        return;
    }
    for (String typeName : uimaTypeNames) {
        List<FeatureStructure> featureSetList = concertToCasLight(jcas, typeName);
        IRI uimaIRI = new IRI(uimaUri);
        FeatureStructureListHolder holder;
        ci.getLock().writeLock().lock();
        try {
            holder = ci.getPart(uimaIRI, FeatureStructureListHolder.class);
        } catch (NoSuchPartException e) {
            holder = new FeatureStructureListHolder();
            logger.info("Adding FeatureSet List Holder content part with uri:" + uimaUri);
            ci.addPart(uimaIRI, holder);
            logger.info(uimaUri + " content part added.");
        } finally {
            ci.getLock().writeLock().unlock();
        }
        ci.getLock().writeLock().lock();
        try {
            holder.addFeatureStructureList(uimaSourceName, featureSetList);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) JCas(org.apache.uima.jcas.JCas) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) IOException(java.io.IOException) AnalysisEngineProcessException(org.apache.uima.analysis_engine.AnalysisEngineProcessException) FeatureStructure(org.apache.stanbol.commons.caslight.FeatureStructure) InvalidContentException(org.apache.stanbol.enhancer.servicesapi.InvalidContentException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) FeatureStructureListHolder(org.apache.stanbol.commons.caslight.FeatureStructureListHolder)

Aggregations

AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)4 IOException (java.io.IOException)3 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)3 Type (org.apache.uima.cas.Type)2 IRI (org.apache.clerezza.commons.rdf.IRI)1 FeatureStructure (org.apache.stanbol.commons.caslight.FeatureStructure)1 FeatureStructureListHolder (org.apache.stanbol.commons.caslight.FeatureStructureListHolder)1 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)1 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)1 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)1 NoSuchPartException (org.apache.stanbol.enhancer.servicesapi.NoSuchPartException)1 CAS (org.apache.uima.cas.CAS)1 CASException (org.apache.uima.cas.CASException)1 JCas (org.apache.uima.jcas.JCas)1