int engineState; try { engineState = engine.canEnhance(job.getContentItem()); } catch (EngineException e) { exception = e; log.trace("++ w: {}: {}","start sync execution", engine.getName()); job.getLock().writeLock().lock(); log.trace(">> w: {}: {}","start sync execution", engine.getName()); try { engine.computeEnhancements(job.getContentItem()); job.setCompleted(execution); } catch (EngineException e){ job.setFailed(execution, engine, e); } finally{ log.trace("<< w: {}: {}","finished sync execution", engine.getName()); job.getLock().writeLock().unlock(); log.trace("++ n: start async execution of Engine {}",engine.getName()); engine.computeEnhancements(job.getContentItem()); log.trace("++ n: finished async execution of Engine {}",engine.getName()); job.setCompleted(execution); } catch (EngineException e) {
@Override public void enhanceContent(ContentItem ci) throws EngineException { log.debug("enhanceContent({}), {} engines available", ci, sortedEngineList.size()); Iterator<EnhancementEngine> engines; //changes in the sortedEngineList do creates new Lists. Therefore we need //only sync the creation of the Iterator. Calls to the iterator will //not trigger ConcurrentModificationExceptions //however the remove Method will not have any affect if the list was //changed. synchronized (sortedEngineList) { engines = sortedEngineList.iterator(); } long start = System.currentTimeMillis(); while (engines.hasNext()) { EnhancementEngine engine = engines.next(); long startEngine = System.currentTimeMillis(); if (engine.canEnhance(ci) == EnhancementEngine.CANNOT_ENHANCE) { log.debug("[{}] cannot be enhanced by engine [{}], skipping", ci.getUri().getUnicodeString(), engine); } else { // TODO should handle sync/async enhancing. All sync for now. engine.computeEnhancements(ci); log.debug("ContentItem [{}] enhanced by engine [{}] in {}ms", new Object[]{ci.getUri().getUnicodeString(), engine,System.currentTimeMillis()-startEngine}); } } log.debug("ContentItem [{}] enhanced in {}ms",ci.getUri().getUnicodeString(),(System.currentTimeMillis()-start)); }
@Override public Set<String> getEngines() throws ChainException { return Collections.singleton(engine.getName()); }
@Override public Set<String> getEngines() throws ChainException { return Collections.singleton(engine.getName()); }
/** * Used in {@link #canEnhance(ContentItem)} to check if a {@link ContentItem} * should be processed based on the language configuration of this engine. * @param engine the {@link EnhancementEngine} calling this method * @param languageConfiguration the language configuration * @param language the language * @param exception <code>false</code> id used in {@link #canEnhance(ContentItem)} * and <code>true</code> when called from {@link #computeEnhancements(ContentItem)} * @return the state * @throws IllegalStateException if exception is <code>true</code> and the * language is not configured as beeing processed. */ public static boolean isLangaugeConfigured(EnhancementEngine engine, LanguageConfiguration languageConfiguration, String language, boolean exception){ boolean state = languageConfiguration.isLanguage(language); if(!state && exception){ throw new IllegalStateException("Language "+language+" is not included " + "by the LanguageConfiguration of this engine (name "+ engine.getName() + "). As this is also checked in canEnhancer this may indicate an Bug in the " + "used EnhancementJobManager!"); } else { return state; } }
/** * Used in {@link #canEnhance(ContentItem)} to check if a {@link ContentItem} * should be processed based on the language configuration of this engine. * @param engine the {@link EnhancementEngine} calling this method * @param languageConfiguration the language configuration * @param language the language * @param exception <code>false</code> id used in {@link #canEnhance(ContentItem)} * and <code>true</code> when called from {@link #computeEnhancements(ContentItem)} * @return the state * @throws IllegalStateException if exception is <code>true</code> and the * language is not configured as beeing processed. */ public static boolean isLangaugeConfigured(EnhancementEngine engine, LanguageConfiguration languageConfiguration, String language, boolean exception){ boolean state = languageConfiguration.isLanguage(language); if(!state && exception){ throw new IllegalStateException("Language "+language+" is not included " + "by the LanguageConfiguration of this engine (name "+ engine.getName() + "). As this is also checked in canEnhancer this may indicate an Bug in the " + "used EnhancementJobManager!"); } else { return state; } }
/** * Getter for the language of the content * @param ci the ContentItem * @param exception <code>false</code> id used in {@link #canEnhance(ContentItem)} * and <code>true</code> when called from {@link #computeEnhancements(ContentItem)} * @return the AnalysedText or <code>null</code> if not found. * @throws IllegalStateException if exception is <code>true</code> and the * language could not be retrieved from the parsed {@link ContentItem}. */ public static String getLanguage(EnhancementEngine engine, ContentItem ci, boolean exception) { String language = EnhancementEngineHelper.getLanguage(ci); if(language != null) { return language; } if(exception){ throw new IllegalStateException("Unable to retrieve the detected language for ContentItem " + ci+". As this is also checked in canEnhancer this may indicate an Bug in the " + "used EnhancementJobManager!"); } else { log.warn("The Enhancement Engine '{} (impl: {})' CAN NOT enhance " + "ContentItem {} because the langauge of " + "this ContentItem is unknown. Users might want to add a " + "Language Identification EnhancementEngine to the current " + "EnhancementChain!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci}); return null; } } /**
/** * Getter for the language of the content * @param ci the ContentItem * @param exception <code>false</code> id used in {@link #canEnhance(ContentItem)} * and <code>true</code> when called from {@link #computeEnhancements(ContentItem)} * @return the AnalysedText or <code>null</code> if not found. * @throws IllegalStateException if exception is <code>true</code> and the * language could not be retrieved from the parsed {@link ContentItem}. */ public static String getLanguage(EnhancementEngine engine, ContentItem ci, boolean exception) { String language = EnhancementEngineHelper.getLanguage(ci); if(language != null) { return language; } if(exception){ throw new IllegalStateException("Unable to retrieve the detected language for ContentItem " + ci+". As this is also checked in canEnhancer this may indicate an Bug in the " + "used EnhancementJobManager!"); } else { log.warn("The Enhancement Engine '{} (impl: {})' CAN NOT enhance " + "ContentItem {} because the langauge of " + "this ContentItem is unknown. Users might want to add a " + "Language Identification EnhancementEngine to the current " + "EnhancementChain!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci}); return null; } } /**
+ "creates the AnalysedText ContentPart such as the " + "POSTaggingEngine (o.a.stanbol.enhancer.engines.opennlp.pos)!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci}); return null;
+ "creates the AnalysedText ContentPart such as the " + "POSTaggingEngine (o.a.stanbol.enhancer.engines.opennlp.pos)!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci}); return null;
+ "that supports the conversion of '{}' files to plain text " + "to the current EnhancementChain!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci,ci.getMimeType()}); return null;
+ "that supports the conversion of '{}' files to plain text " + "to the current EnhancementChain!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci,ci.getMimeType()}); return null;
+ "that supports the conversion of '{}' files to plain text " + "to the current EnhancementChain!", new Object[]{engine.getName(), engine.getClass().getSimpleName(),ci,ci.getMimeType()}); return null;
/** * Creates a {@link Chain} for a single {@link EnhancementEngine} including * optional chain scoped enhancement properties * @param engine the engine * @param enhProps chain scoped enhancement properties or <code>null</code> * if none. * @since 0.12.1 */ public SingleEngineChain(EnhancementEngine engine, Map<String,Object> enhProps){ if(engine == null){ throw new IllegalArgumentException("The parsed EnhancementEngine MUST NOT be NULL!"); } this.engine = engine; this.name = engine.getName()+"Chain"; Graph graph = new IndexedGraph(); writeExecutionNode(graph, createExecutionPlan(graph, name, null), engine.getName(), false, null, enhProps); executionPlan = graph.getImmutableGraph(); }
/** * Creates a {@link Chain} for a single {@link EnhancementEngine} including * optional chain scoped enhancement properties * @param engine the engine * @param enhProps chain scoped enhancement properties or <code>null</code> * if none. * @since 0.12.1 */ public SingleEngineChain(EnhancementEngine engine, Map<String,Object> enhProps){ if(engine == null){ throw new IllegalArgumentException("The parsed EnhancementEngine MUST NOT be NULL!"); } this.engine = engine; this.name = engine.getName()+"Chain"; Graph graph = new IndexedGraph(); writeExecutionNode(graph, createExecutionPlan(graph, name, null), engine.getName(), false, null, enhProps); executionPlan = graph.getImmutableGraph(); }
String name = engine.getName(); Integer order = getEngineOrder(engine); if(prevOrder == null || !prevOrder.equals(order)){