Search in sources :

Example 1 with CeliMorphoFeatures

use of org.apache.stanbol.enhancer.engines.celi.CeliMorphoFeatures in project stanbol by apache.

the class CeliLemmatizerEnhancementEngine method addMorphoAnalysisEnhancement.

private void addMorphoAnalysisEnhancement(ContentItem ci, String text, String language, Graph g) throws EngineException {
    // clerezza language for PlainLiterals
    Language lang = new Language(language);
    List<LexicalEntry> terms;
    try {
        terms = this.client.performMorfologicalAnalysis(text, language);
    } catch (IOException e) {
        throw new EngineException("Error while calling the CELI Lemmatizer" + " service (configured URL: " + serviceURL + ")!", e);
    } catch (SOAPException e) {
        throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI lemmatizer service!", e);
    }
    // get a write lock before writing the enhancements
    ci.getLock().writeLock().lock();
    try {
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        for (LexicalEntry le : terms) {
            List<CeliMorphoFeatures> mFeatures = this.convertLexicalEntryToMorphFeatures(le, language);
            for (CeliMorphoFeatures feat : mFeatures) {
                // Create a text annotation for each interpretation produced by the morphological analyzer
                IRI textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
                g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT, new PlainLiteralImpl(le.getWordForm(), lang)));
                if (le.from >= 0 && le.to > 0) {
                    g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(le.from)));
                    g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(le.to)));
                    g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT, new PlainLiteralImpl(getSelectionContext(text, le.getWordForm(), le.from), lang)));
                }
                g.addAll(feat.featuresAsTriples(textAnnotation, lang));
            }
        }
    } finally {
        ci.getLock().writeLock().unlock();
    }
}
Also used : CeliMorphoFeatures(org.apache.stanbol.enhancer.engines.celi.CeliMorphoFeatures) IRI(org.apache.clerezza.commons.rdf.IRI) Language(org.apache.clerezza.commons.rdf.Language) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) SOAPException(javax.xml.soap.SOAPException) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) IOException(java.io.IOException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory)

Aggregations

IOException (java.io.IOException)1 SOAPException (javax.xml.soap.SOAPException)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 Language (org.apache.clerezza.commons.rdf.Language)1 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)1 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)1 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)1 CeliMorphoFeatures (org.apache.stanbol.enhancer.engines.celi.CeliMorphoFeatures)1 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)1