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