Search in sources :

Example 6 with ResourceInitializationException

use of org.apache.uima.resource.ResourceInitializationException in project lucene-solr by apache.

the class BasicAEProvider method getAE.

@Override
public AnalysisEngine getAE() throws ResourceInitializationException {
    synchronized (this) {
        if (cachedDescription == null) {
            XMLInputSource in = null;
            boolean success = false;
            try {
                // get Resource Specifier from XML file
                in = getInputSource();
                // get AE description
                cachedDescription = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
                configureDescription(cachedDescription);
                success = true;
            } catch (Exception e) {
                throw new ResourceInitializationException(e);
            } finally {
                if (success) {
                    try {
                        IOUtils.close(in.getInputStream());
                    } catch (IOException e) {
                        throw new ResourceInitializationException(e);
                    }
                } else if (in != null) {
                    IOUtils.closeWhileHandlingException(in.getInputStream());
                }
            }
        }
    }
    return UIMAFramework.produceAnalysisEngine(cachedDescription);
}
Also used : XMLInputSource(org.apache.uima.util.XMLInputSource) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) IOException(java.io.IOException) IOException(java.io.IOException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException)

Example 7 with ResourceInitializationException

use of org.apache.uima.resource.ResourceInitializationException in project stanbol by apache.

the class UIMALocal method activate.

@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
    super.activate(ctx);
    Dictionary<String, Object> props = ctx.getProperties();
    this.uimaUri = (String) props.get(UIMA_CONTENTPART_URIREF);
    this.uimaSourceName = (String) props.get(UIMA_SOURCENAME);
    this.uimaDescriptorPath = (String) props.get(UIMA_DESCRIPTOR_PATH);
    SUPPORTED_MIMETYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList((String[]) props.get(UIMA_SUPPORTED_MIMETYPES))));
    aeProvider = AEProviderFactory.getInstance().getAEProvider(uimaSourceName, uimaDescriptorPath, new HashMap<String, Object>());
    try {
        AnalysisEngine ae = aeProvider.getAE();
        TypeDescription[] aeTypes = ae.getAnalysisEngineMetaData().getTypeSystem().getTypes();
        uimaTypeNames = new ArrayList<String>();
        for (TypeDescription aeType : aeTypes) {
            String aeTypeName = aeType.getName();
            logger.info("Configuring Analysis Engine Type:" + aeTypeName);
            uimaTypeNames.add(aeTypeName);
        }
    } catch (ResourceInitializationException ex) {
        logger.error("Cannot retrieve AE from AEProvider. ", ex);
        throw new ConfigurationException(uimaDescriptorPath, "Cannot retreive AE from AEProvider", ex);
    }
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.osgi.service.cm.ConfigurationException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) HashSet(java.util.HashSet) AnalysisEngine(org.apache.uima.analysis_engine.AnalysisEngine)

Example 8 with ResourceInitializationException

use of org.apache.uima.resource.ResourceInitializationException 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

ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)8 IOException (java.io.IOException)4 AnalysisEngineProcessException (org.apache.uima.analysis_engine.AnalysisEngineProcessException)3 Type (org.apache.uima.cas.Type)2 ResourceAccessException (org.apache.uima.resource.ResourceAccessException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 POSModel (opennlp.tools.postag.POSModel)1 POSTaggerME (opennlp.tools.postag.POSTaggerME)1 TokenizerME (opennlp.tools.tokenize.TokenizerME)1 TokenizerModel (opennlp.tools.tokenize.TokenizerModel)1 POSModelResource (opennlp.uima.postag.POSModelResource)1 TokenizerModelResource (opennlp.uima.tokenize.TokenizerModelResource)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 AEProvider (org.apache.lucene.analysis.uima.ae.AEProvider)1 SolrException (org.apache.solr.common.SolrException)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