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);
}
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);
}
}
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();
}
}
}
Aggregations