Search in sources :

Example 1 with UIMASimpleServletClient

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);
}
Also used : UIMASimpleServletClient(org.apache.stanbol.enhancer.engines.uimaremote.tools.UIMASimpleServletClient) HashSet(java.util.HashSet)

Example 2 with UIMASimpleServletClient

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();
        }
    }
}
Also used : FeatureStructure(org.apache.stanbol.commons.caslight.FeatureStructure) IRI(org.apache.clerezza.commons.rdf.IRI) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) InvalidContentException(org.apache.stanbol.enhancer.servicesapi.InvalidContentException) UIMASimpleServletClient(org.apache.stanbol.enhancer.engines.uimaremote.tools.UIMASimpleServletClient) FeatureStructureListHolder(org.apache.stanbol.commons.caslight.FeatureStructureListHolder) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) IOException(java.io.IOException)

Aggregations

UIMASimpleServletClient (org.apache.stanbol.enhancer.engines.uimaremote.tools.UIMASimpleServletClient)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 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 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)1 NoSuchPartException (org.apache.stanbol.enhancer.servicesapi.NoSuchPartException)1