use of org.apache.stanbol.enhancer.engines.uimaremote.tools.UIMASimpleServletClient in project stanbol by apache.
the class UIMARemoteClient method activate.
@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
Dictionary<String, Object> props = ctx.getProperties();
if (props.get(UIMA_SUPPORTED_MIMETYPES) instanceof String[]) {
SUPPORTED_MIMETYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList((String[]) props.get(UIMA_SUPPORTED_MIMETYPES))));
} else {
logger.warn("Got String: '" + props.get(UIMA_SUPPORTED_MIMETYPES) + "' instead of String[] from Felix for param:" + UIMA_SUPPORTED_MIMETYPES);
SUPPORTED_MIMETYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(new String[] { (String) props.get(UIMA_SUPPORTED_MIMETYPES) })));
}
String[] endpointsA;
if (props.get(UIMA_ENDPOINTS) instanceof String[]) {
endpointsA = (String[]) props.get(UIMA_ENDPOINTS);
} else {
logger.warn("Got String: '" + props.get(UIMA_ENDPOINTS) + "' instead of String[] from Felix for param:" + UIMA_ENDPOINTS);
endpointsA = new String[] { (String) props.get(UIMA_ENDPOINTS) };
}
usscList = new ArrayList<UIMASimpleServletClient>();
for (String endpoint : endpointsA) {
String[] parts = endpoint.split(";", 2);
if (parts.length == 2) {
UIMASimpleServletClient ussc = new UIMASimpleServletClient();
ussc.setSourceName(parts[0]);
ussc.setUri(parts[1]);
usscList.add(ussc);
} else {
logger.error("Enpoint '" + endpoint + "' cannot be configured. Proper format: <sourcename>;<uri>");
}
}
this.uimaUri = (String) props.get(UIMA_CONTENTPART_URIREF);
}
use of org.apache.stanbol.enhancer.engines.uimaremote.tools.UIMASimpleServletClient in project stanbol by apache.
the class UIMARemoteClient 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);
}
for (UIMASimpleServletClient ussc : usscList) {
logger.info("Accessing uima source:" + ussc.getSourceName() + " endpoint:" + ussc.getUri());
List<FeatureStructure> featureSetList = ussc.process(text);
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(ussc.getSourceName(), featureSetList);
} finally {
ci.getLock().writeLock().unlock();
}
}
}
Aggregations