You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2014/05/13 08:26:21 UTC
svn commit: r1594140 [1/2] - in /stanbol/trunk: ./ enhancement-engines/
enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/
enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhan...
Author: rwesten
Date: Tue May 13 06:26:20 2014
New Revision: 1594140
URL: http://svn.apache.org/r1594140
Log:
merged implementations for STANBOL-488 and STANBOL-1287 from the 0.12 branch to trunk. With this commit the EnhancementProperties support for 0.12.1 and 1.0.0 is in sync (merged revisions: 1571146, 1571150, 1572586, 1593490 and 1594134)
Added:
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConfigurationException.java
- copied unchanged from r1571150, stanbol/branches/release-0.12/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConfigurationException.java
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContextFactory.java
- copied unchanged from r1571150, stanbol/branches/release-0.12/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContextFactory.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java
- copied, changed from r1571150, stanbol/branches/release-0.12/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/ParseBackend.java
- copied unchanged from r1571150, stanbol/branches/release-0.12/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/ParseBackend.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EnhancementPropertyException.java
- copied unchanged from r1571146, stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EnhancementPropertyException.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/DictionaryAdapter.java
- copied unchanged from r1593490, stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/DictionaryAdapter.java
stanbol/trunk/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java
- copied unchanged from r1593490, stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java
stanbol/trunk/enhancer/generic/servicesapi/src/test/resources/log4j.properties
- copied unchanged from r1593490, stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/resources/log4j.properties
stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancementPropertiesTest.java
Modified:
stanbol/trunk/ (props changed)
stanbol/trunk/enhancement-engines/ (props changed)
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConstants.java
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContext.java
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineConfig.java
stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java
stanbol/trunk/enhancer/ (props changed)
stanbol/trunk/enhancer/chain/graph/src/main/java/org/apache/stanbol/enhancer/chain/graph/impl/GraphChain.java
stanbol/trunk/enhancer/chain/graph/src/main/resources/OSGI-INF/metatype/metatype.properties
stanbol/trunk/enhancer/chain/list/src/main/java/org/apache/stanbol/enhancer/chain/list/impl/ListChain.java
stanbol/trunk/enhancer/chain/list/src/main/resources/OSGI-INF/metatype/metatype.properties
stanbol/trunk/enhancer/chain/weighted/src/main/java/org/apache/stanbol/enhancer/chain/weighted/impl/WeightedChain.java
stanbol/trunk/enhancer/chain/weighted/src/main/resources/OSGI-INF/metatype/metatype.properties
stanbol/trunk/enhancer/generic/servicesapi/ (props changed)
stanbol/trunk/enhancer/generic/servicesapi/pom.xml
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EngineException.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/InvalidContentException.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ConfigUtils.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionMetadataHelper.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ExecutionPlanHelper.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractChain.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/SingleEngineChain.java
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/NamespaceEnum.java
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java
stanbol/trunk/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java
stanbol/trunk/integration-tests/ (props changed)
stanbol/trunk/parent/pom.xml
Propchange: stanbol/trunk/
------------------------------------------------------------------------------
Merged /stanbol/branches/release-0.12:r1571146,1571150,1572586,1593490,1593899,1594122
Propchange: stanbol/trunk/enhancement-engines/
------------------------------------------------------------------------------
Merged /stanbol/branches/release-0.12/enhancement-engines:r1571150,1572586,1593490
Modified: stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConstants.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConstants.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConstants.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceConstants.java Tue May 13 06:26:20 2014
@@ -116,7 +116,20 @@ public interface DereferenceConstants {
* enhancement results.
*/
String FALLBACK_MODE = "enhancer.engines.dereference.fallback";
-
+ /**
+ * By default {@link #FALLBACK_MODE} is enabled
+ */
boolean DEFAULT_FALLBACK_MODE = true;
+ /**
+ * Parameter allowing users to define a list of languages to be dereferenced.
+ * An empty string is used for literals that do not have an language tag.
+ */
+ String DEREFERENCE_ENTITIES_LANGUAGES = "enhancer.engines.dereference.languages";
+
+ /**
+ * Language key used for configuring literals without language tag
+ */
+ String NO_LANGUAGE_KEY = "none";
+
}
Modified: stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContext.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContext.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContext.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceContext.java Tue May 13 06:26:20 2014
@@ -1,55 +1,294 @@
package org.apache.stanbol.enhancer.engines.dereference;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.DEREFERENCE_ENTITIES_LANGUAGES;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.NO_LANGUAGE_KEY;
+
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import java.util.Set;
-import org.apache.clerezza.rdf.core.Language;
+import org.apache.commons.lang.StringUtils;
import org.apache.stanbol.commons.stanboltools.offline.OfflineMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DereferenceContext {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ protected final static String INTERNAL_CONTENT_LANGUAGES = "internal.dereference.contentlanguages";
+ protected final static String INTERNAL_ACCEPT_LANGUAGES = "internal.dereference.acceptlanguages";
+
+ protected final EntityDereferenceEngine engine;
+
+ protected final Map<String,Object> enhancementProps;
/**
* The {@link OfflineMode} status
*/
- protected final boolean offlineMode;
+ private boolean offlineMode;
/**
- * Read-only set with languages that need to be dereferenced.
+ * Read-only set with literal languages defined in the context.
*/
- private Set<String> languages = new HashSet<String>();
+ private Set<String> contextLanguages;
+ /**
+ * Read-only set with literal languages to be dereferenced. This is the
+ * union over {@link #contextLanguages} and {@link #getConfig()}.
+ * {@link DereferenceEngineConfig#getLanaguages() getLanaguages()}
+ */
+ private Set<String> languages;
+ private List<String> fields;
+ private String program;
+
+
/**
* Create a new DereferenceContext.
* @param offlineMode the {@link OfflineMode} state
+ * @param ep The enhancement properties
+ * @throws DereferenceConfigurationException if the parsed enhancement
+ * propertied contain an invalid configuration
*/
- protected DereferenceContext(boolean offlineMode){
- this.offlineMode = offlineMode;
+ @SuppressWarnings("unchecked")
+ protected DereferenceContext(EntityDereferenceEngine engine, Map<String,Object> ep)
+ throws DereferenceConfigurationException {
+ this.engine = engine;
+ this.enhancementProps = ep;
+ parseLanguages(ep == null ? null : ep.get(DEREFERENCE_ENTITIES_LANGUAGES),
+ ep == null ? null : (Collection<String>)ep.get(INTERNAL_CONTENT_LANGUAGES),
+ ep == null ? null : (Collection<String>)ep.get(INTERNAL_ACCEPT_LANGUAGES));
+ parseFields(ep == null ? null : ep.get(DereferenceConstants.DEREFERENCE_ENTITIES_FIELDS));
+ parseLDPath(ep == null ? null : ep.get(DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH));
+ //call the initialisation callback
+ initialise();
}
+ /**
+ * Parses the {@link DereferenceConstants#DEREFERENCE_ENTITIES_LANGUAGES}
+ * from the parsed value, merges content- and accept-languages and finally
+ * calls {@link #initLiteralLanguages(Set)} with the resulting set
+ * @param value the value of the
+ * {@link DereferenceConstants#DEREFERENCE_ENTITIES_LANGUAGES} key
+ * @param the content languages or <code>null</code> if
+ * {@link DereferenceConstants#FILTER_CONTENT_LANGUAGES} is deactivated
+ * @param the accept languages or <code>null</code> if
+ * {@link DereferenceConstants#FILTER_ACCEPT_LANGUAGES} is deactivated
+ * @throws DereferenceConfigurationException if the parsed value is not a
+ * valid configuration
+ */
+ private void parseLanguages(Object value, Collection<String> contentLanguages,
+ Collection<String> acceptLanguages) throws DereferenceConfigurationException {
+ Set<String> languages;
+ if(value == null){
+ languages = null;
+ } else {
+ languages = new HashSet<String>();
+ if(value instanceof String){
+ String lang = (String) value;
+ addLanguage(languages, lang);
+ } else if(value instanceof Collection<?>){
+ for(Object lang : (Collection<?>)value){
+ if(lang instanceof String){
+ addLanguage(languages, (String)lang);
+ }
+ }
+ }
+ if(languages.isEmpty()){
+ languages = null;
+ }
+ }
+ if(contentLanguages != null && !contentLanguages.isEmpty()){
+ if(languages == null){
+ languages = new HashSet<String>();
+ }
+ languages.addAll(contentLanguages);
+ }
+ if(acceptLanguages != null && !acceptLanguages.isEmpty()){
+ if(languages == null){
+ languages = new HashSet<String>();
+ }
+ languages.addAll(acceptLanguages);
+ }
+ //set the contextLanguages field
+ if(languages == null){
+ this.contextLanguages = Collections.emptySet();
+ } else {
+ this.contextLanguages = Collections.unmodifiableSet(languages);
+ }
+ //merge the languages with those of the config and set the languages field
+ Set<String> merged;
+ Collection<String> configLangs = getConfig().getLanaguages();
+ if(languages == null && configLangs == null){
+ merged = null;
+ } else if(configLangs == null){
+ merged = languages;
+ } else {
+ merged = new HashSet<String>(configLangs);
+ if(languages != null){
+ merged.addAll(languages);
+ }
+ }
+ this.languages = merged;
+ }
/**
- * If the {@link OfflineMode} is active
- * @return the offline mode status
+ * Parsed the language from the language string and adds it to the languages
+ * set. This will convert languages to lower case and also converts empty
+ * values as well as the {@link DereferenceConstants#NO_LANGUAGE_KEY} to
+ * <code>null</code> (indicating labels without any language)
+ * @param languages
+ * @param lang
*/
- public boolean isOfflineMode() {
- return offlineMode;
+ private void addLanguage(Set<String> languages, String lang) {
+ if(StringUtils.isBlank(lang) || NO_LANGUAGE_KEY.equalsIgnoreCase(lang)){
+ languages.add(null);
+ } else {
+ languages.add(lang.toLowerCase(Locale.ROOT));
+ }
}
+
/**
- * Setter for the languages of literals that should be dereferenced
- * @param languages the ContentLanguages
+ * Parsed the {@link DereferenceConstants#DEREFERENCE_ENTITIES_FIELDS}
+ * from the parsed value and calls {@link #initDereferencedFields(List)} with
+ * the parsed value
+ * @param value the value
+ * @throws DereferenceConfigurationException if the parsed value is not a
+ * valid configuration
*/
- protected void setLanguages(Set<String> languages) {
- if(languages == null){
- this.languages = Collections.emptySet();
+ private void parseFields(Object value) throws DereferenceConfigurationException{
+ List<String> fields;
+ if(value instanceof String && !StringUtils.isBlank((String)value)){
+ fields = Collections.singletonList((String)value);
+ } else if(value instanceof Collection<?>){
+ fields = new ArrayList<String>(((Collection<?>)value).size());
+ for(Object field : (Collection<?>)value){
+ if(field != null && field instanceof String &&
+ !StringUtils.isBlank((String)field)){
+ fields.add((String)field);
+ } // else ignore
+ }
} else {
- this.languages = Collections.unmodifiableSet(languages);
+ fields = null;
}
+ this.fields = fields;
+ }
+
+ /**
+ * Parsed the {@link DereferenceConstants#DEREFERENCE_ENTITIES_LDPATH}
+ * from the parsed value and calls {@link #initLdPathProgram(String)} with
+ * the parsed value
+ * @param value the value
+ * @throws DereferenceConfigurationException if the parsed value is not a
+ * valid configuration
+ */
+ private void parseLDPath(Object value) throws DereferenceConfigurationException {
+ String program;
+ if(value instanceof String && !StringUtils.isBlank((String)value)){
+ program = (String)value;
+ } else if(value instanceof Collection<?>){
+ StringBuilder sb = new StringBuilder();
+ for(Object field : (Collection<?>)value){
+ if(field != null && field instanceof String &&
+ !StringUtils.isBlank((String)field)){
+ sb.append((String)field).append('\n');
+ } // else ignore
+ }
+ program = sb.length() > 0 ? sb.toString() : null;
+ } else {
+ program = null;
+ }
+ this.program = program;
+ }
+
+ /**
+ * Allows to set the offline mode state
+ */
+ protected final void setOfflineMode(boolean state){
+ this.offlineMode = state;
+ }
+
+ /**
+ * If the {@link OfflineMode} is active. If active Dereferencers are not
+ * allowed access remote resources for dereferencing Entities.
+ * @return the offline mode status
+ */
+ public final boolean isOfflineMode() {
+ return offlineMode;
+ }
+
+ /**
+ * Context specific DerefernecedField configuration
+ * @return the context specific DereferencedField configuration or
+ * <code>null</code> if none
+ */
+ public final List<String> getFields() {
+ return fields;
+ }
+
+ /**
+ * Initialisation callback for the DereferenceContext. This is called by
+ * the constructor after the {@link #enhancementProps} are set and
+ * {@link #getLanguages()}, {@link #getFields()} and
+ * {@link #getLdPathProgram()} are initialised.<p>
+ * The default implementation is empty.
+ */
+ protected void initialise(){
+
}
/**
+ * Context specific LDPath program
+ * @return the context specific LDPath program or <code>null</code> if none
+ */
+ public final String getLdPathProgram() {
+ return program;
+ }
+
+ /**
* Getter for the languages that should be dereferenced. If
- * empty all languages should be included.
+ * empty all languages should be included. This is the union over
+ * Languages enabled in the context and
+ * {@link #getConfig()}.{@link DereferenceEngineConfig#getLanaguages()
+ * getLanaguages()}
* @return the languages for literals that should be dereferenced.
*/
- public Set<String> getLanguages() {
+ public final Set<String> getLanguages() {
return languages;
}
+
+ /**
+ * Set of languages enabled via the context. This does not include languages
+ * enabled in the {@link DereferenceEngineConfig}
+ * @return the set of languages enabled via the context.
+ */
+ protected final Set<String> getContextLanguages(){
+ return contextLanguages;
+ }
+
+ /**
+ * Getter for the Enhancement Properties for this Context.
+ * @return the Enhancement Properties
+ */
+ protected final Map<String,Object> getEnhancementProps() {
+ return enhancementProps;
+ }
+
+ /**
+ * Getter for the Dereference Engine Configuration
+ * @return the dereference configuration
+ */
+ public final DereferenceEngineConfig getConfig() {
+ return engine.getConfig();
+ }
+
+ /**
+ * The EntityDereferencer this context is built for
+ * @return the entity dereferencer
+ */
+ public final EntityDereferencer getDereferencer(){
+ return engine.getDereferencer();
+ }
+
}
Modified: stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineConfig.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineConfig.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineConfig.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineConfig.java Tue May 13 06:26:20 2014
@@ -1,7 +1,6 @@
package org.apache.stanbol.enhancer.engines.dereference;
-import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.DEREFERENCE_ENTITIES_FIELDS;
-import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.NO_LANGUAGE_KEY;
import static org.apache.stanbol.commons.namespaceprefix.NamespaceMappingUtils.getConfiguredUri;
import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_REFERENCE;
@@ -10,8 +9,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
+import java.util.Locale;
+import java.util.Set;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.commons.lang.StringUtils;
@@ -335,4 +337,51 @@ public class DereferenceEngineConfig imp
}
return values;
}
+ /**
+ * Getter for Literal languages that should be dereferenced.
+ * @return
+ */
+ public Collection<String> getLanaguages(){
+ Object value = config.get(DEREFERENCE_ENTITIES_LANGUAGES);
+ if(value == null){
+ return null;
+ } else {
+ Set<String> languages = new HashSet<String>();
+ if(value instanceof String){
+ addLanguage(languages, (String)value);
+ } else if(value instanceof String[]){
+ for(String lang : (String[])value){
+ addLanguage(languages, lang);
+ }
+ } else if(value instanceof Collection<?>){
+ for(Object lang : (Collection<?>)value){
+ if(lang instanceof String){
+ addLanguage(languages, (String)lang);
+ }
+ }
+ }
+ if(languages.isEmpty()){
+ return null;
+ } else {
+ return languages;
+ }
+ }
+ }
+
+ /**
+ * Parses a language from the parsed languate string and adds it to the
+ * parsed languages set. This converts languages to lower case and also
+ * checks for the {@link DereferenceConstants#NO_LANGUAGE_KEY} value.
+ * @param languages the set holding the languages
+ * @param lang the language
+ */
+ private void addLanguage(Set<String> languages, String lang) {
+ if(!StringUtils.isBlank(lang)){
+ if(NO_LANGUAGE_KEY.equalsIgnoreCase(lang)){
+ languages.add(null);
+ } else {
+ languages.add(lang.toLowerCase(Locale.ROOT));
+ }
+ }
+ }
}
Modified: stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java Tue May 13 06:26:20 2014
@@ -16,7 +16,6 @@
*/
package org.apache.stanbol.enhancer.engines.dereference;
-import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.URI_PATTERN;
import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.DC_LANGUAGE;
import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_REFERENCE;
@@ -37,20 +36,18 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import org.apache.clerezza.rdf.core.Language;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.NonLiteral;
import org.apache.clerezza.rdf.core.Resource;
import org.apache.clerezza.rdf.core.Triple;
import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.commons.lang.StringUtils;
import org.apache.stanbol.commons.stanboltools.offline.OfflineMode;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.apache.stanbol.enhancer.servicesapi.EngineException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementPropertyException;
import org.apache.stanbol.enhancer.servicesapi.ServiceProperties;
import org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper;
-import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,6 +69,8 @@ public class EntityDereferenceEngine imp
protected final DereferenceEngineConfig config;
+ protected final DereferenceContextFactory contextFactory;
+
protected final String name;
protected final boolean filterContentLanguages;
@@ -96,6 +95,10 @@ public class EntityDereferenceEngine imp
private final Map<String,Object> unmodServiceProperties = Collections.unmodifiableMap(serviceProperties);
public EntityDereferenceEngine(EntityDereferencer dereferencer, DereferenceEngineConfig config){
+ this(dereferencer,config,null);
+ }
+ public EntityDereferenceEngine(EntityDereferencer dereferencer, DereferenceEngineConfig config,
+ DereferenceContextFactory contextFactory){
if(config == null){
throw new IllegalArgumentException("The parsed DereferenceEngineConfig MUST NOT be NULL!");
}
@@ -110,6 +113,7 @@ public class EntityDereferenceEngine imp
throw new IllegalArgumentException("The parsed EntityDereferencer MUST NOT be NULL!");
}
this.dereferencer = dereferencer;
+ this.contextFactory = contextFactory != null ? contextFactory : new ContextFactory();
log.debug(" - dereferenced {} (type: {})", dereferencer, dereferencer.getClass().getName());
//init the default ordering
this.fallbackMode = config.isFallbackMode();
@@ -156,11 +160,11 @@ public class EntityDereferenceEngine imp
* of this Engine implementation
* @param mode the offline mode
*/
- public void setOfflineMode(boolean mode){
+ public final void setOfflineMode(boolean mode){
this.offline = mode;
}
- public boolean isOfflineMode(){
+ public final boolean isOfflineMode(){
return offline;
}
/**
@@ -169,12 +173,12 @@ public class EntityDereferenceEngine imp
* @param ordering The ordering or <code>null</code> to set the
* {@value #DEFAULT_ENGINE_ORDERING default} for this engine.
*/
- public void setEngineOrdering(Integer ordering){
+ public final void setEngineOrdering(Integer ordering){
serviceProperties.put(ServiceProperties.ENHANCEMENT_ENGINE_ORDERING,
ordering == null ? DEFAULT_ENGINE_ORDERING : ordering);
}
- public Integer getEngineOrdering(){
+ public final Integer getEngineOrdering(){
return (Integer)serviceProperties.get(ENHANCEMENT_ENGINE_ORDERING);
}
@@ -182,17 +186,21 @@ public class EntityDereferenceEngine imp
* Getter for the config of this engine
* @return the Dereference Engine Configuration
*/
- public DereferenceEngineConfig getConfig() {
+ public final DereferenceEngineConfig getConfig() {
return config;
}
+ public final EntityDereferencer getDereferencer(){
+ return dereferencer;
+ }
+
@Override
- public Map<String,Object> getServiceProperties() {
+ public final Map<String,Object> getServiceProperties() {
return unmodServiceProperties;
}
@Override
- public int canEnhance(ContentItem ci) throws EngineException {
+ public final int canEnhance(ContentItem ci) throws EngineException {
if(offline && !dereferencer.supportsOfflineMode()){
return CANNOT_ENHANCE;
} else {
@@ -201,28 +209,47 @@ public class EntityDereferenceEngine imp
}
@Override
- public void computeEnhancements(ContentItem ci) throws EngineException {
+ public final void computeEnhancements(ContentItem ci) throws EngineException {
if(offline && !dereferencer.supportsOfflineMode()){
//entity dereferencer does no longer support offline mode
return;
}
log.debug("> dereference Entities for ContentItem {}", ci.getUri());
long start = System.nanoTime();
- final DereferenceContext derefContext = new DereferenceContext(offline);
- Set<String> includedLangs = new HashSet<String>();
- //TODO: parse accept languages as soon as Enhancement properties are implemented
+ Map<String,Object> enhancemntProps = EnhancementEngineHelper.getEnhancementProperties(this, ci);
+ final DereferenceContext derefContext;
final MGraph metadata = ci.getMetadata();
Set<UriRef> referencedEntities = new HashSet<UriRef>();
- //(1) read all Entities we need to dereference from the parsed contentItem
ci.getLock().readLock().lock();
try {
- //parse the languages detected for the content
+ //(1) Create the DereferenceContext
if(filterContentLanguages){
+ //parse the languages detected for the content
+ Set<String> contentLanguages = new HashSet<String>();
for(NonLiteral langAnno : EnhancementEngineHelper.getLanguageAnnotations(metadata)){
- includedLangs.add(EnhancementEngineHelper.getString(metadata, langAnno, DC_LANGUAGE));
+ contentLanguages.add(EnhancementEngineHelper.getString(metadata, langAnno, DC_LANGUAGE));
}
+ enhancemntProps.put(DereferenceContext.INTERNAL_CONTENT_LANGUAGES, contentLanguages);
} //no content language filtering - leave contentLanguages empty
+
+ //TODO: parse accept languages as soon as Request headers are available
+ // via Enhancement properties
+
+ //create the dereference context and handle possible configuration exceptions
+ try {
+ derefContext = contextFactory.createContext(this, enhancemntProps);
+ derefContext.setOfflineMode(offline);
+ } catch (DereferenceConfigurationException e){
+ StringBuilder message = new StringBuilder("Unsupported Derefernece Configuarion ");
+ if(e.getProperty() != null){
+ message.append("for property '").append(e.getProperty()).append("' ");
+ }
+ message.append(" parsed via the EnhancementProperties of this request!");
+ throw new EnhancementPropertyException(this, ci, e.getProperty(), message.toString(), e);
+ }
+
//parse the referenced entities from the graph
+ //(2) read all Entities we need to dereference from the parsed contentItem
Set<UriRef> checked = new HashSet<UriRef>();
for(UriRef referenceProperty : config.getEntityReferences()){
Iterator<Triple> entityReferences = metadata.filter(null, referenceProperty, null);
@@ -248,11 +275,6 @@ public class EntityDereferenceEngine imp
ci.getLock().readLock().unlock();
}
long schedule = System.nanoTime();
- if(!includedLangs.isEmpty()){
- includedLangs.add(null); //also include literals without language
- //and set the list to the dereference context
- derefContext.setLanguages(includedLangs);
- } //else no filterLanguages set ... nothing to do
final Lock writeLock = ci.getLock().writeLock();
log.trace(" - scheduled {} Entities for dereferencing",
@@ -406,12 +428,28 @@ public class EntityDereferenceEngine imp
return false; //no match
}
+ /**
+ * {@link DereferenceContextFactory} implementation used if <code>null</code>
+ * is parsed as factory.
+ *
+ * @author Rupert Westenthaler
+ */
+ class ContextFactory implements DereferenceContextFactory {
+
+ @Override
+ public DereferenceContext createContext(EntityDereferenceEngine engine,
+ Map<String,Object> enhancementProperties) {
+ return new DereferenceContext(engine, enhancementProperties);
+ }
+
+ }
+
/**
* Used both as {@link Callable} submitted to the {@link ExecutorService}
* and as object to {@link #await()} the completion of the task.
+ *
* @author Rupert Westenthaler
- *
*/
class DereferenceJob implements Callable<Boolean> {
Copied: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java (from r1571150, stanbol/branches/release-0.12/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java)
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java?p2=stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java&p1=stanbol/branches/release-0.12/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java&r1=1571150&r2=1594140&rev=1594140&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceContext.java Tue May 13 06:26:20 2014
@@ -13,6 +13,9 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.exception.LDPathParseException;
+import org.apache.marmotta.ldpath.model.programs.Program;
import org.apache.stanbol.enhancer.engines.dereference.DereferenceConfigurationException;
import org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants;
import org.apache.stanbol.enhancer.engines.dereference.DereferenceContext;
@@ -25,13 +28,6 @@ import org.apache.stanbol.entityhub.serv
import org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapping;
import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
-import org.slf4j.ILoggerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.exception.LDPathParseException;
-import at.newmedialab.ldpath.model.programs.Program;
public class EntityhubDereferenceContext extends DereferenceContext {
@@ -113,7 +109,7 @@ public class EntityhubDereferenceContext
Program<Object> ldpathProgram;
if(!StringUtils.isBlank(program)){
@SuppressWarnings("rawtypes")
- RDFBackend<Object> parseBackend = new ParseBackend(valueFactory);
+ RDFBackend<Object> parseBackend = new ParseBackend<Object>(valueFactory);
EntityhubLDPath parseLdPath = new EntityhubLDPath(parseBackend, valueFactory);
try {
ldpathProgram = parseLdPath.parseProgram(new StringReader(program));
@@ -126,7 +122,7 @@ public class EntityhubDereferenceContext
//finally validate if all mappings of the program do use a URI as key
//also store used fieldNames as we need them later
Set<String> contextFields = new HashSet<String>();
- for(at.newmedialab.ldpath.model.fields.FieldMapping<?,Object> mapping : ldpathProgram.getFields()) {
+ for(org.apache.marmotta.ldpath.model.fields.FieldMapping<?,Object> mapping : ldpathProgram.getFields()) {
try {
new URI(mapping.getFieldName());
contextFields.add(mapping.getFieldName());
@@ -140,7 +136,7 @@ public class EntityhubDereferenceContext
}
//append the mappings configured for the engine
if(dereferencer.getLdPathProgram() != null){
- for(at.newmedialab.ldpath.model.fields.FieldMapping<?,Object> mapping : dereferencer.getLdPathProgram().getFields()) {
+ for(org.apache.marmotta.ldpath.model.fields.FieldMapping<?,Object> mapping : dereferencer.getLdPathProgram().getFields()) {
if(!contextFields.contains(mapping.getFieldName())){
ldpathProgram.addMapping(mapping);
}//else ignore mappings for fields specified in the context
Modified: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java Tue May 13 06:26:20 2014
@@ -22,6 +22,7 @@ import static org.apache.stanbol.enhance
import static org.osgi.framework.Constants.SERVICE_RANKING;
import java.util.Dictionary;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -35,7 +36,10 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceConfigurationException;
import org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceContext;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceContextFactory;
import org.apache.stanbol.enhancer.engines.dereference.DereferenceEngineConfig;
import org.apache.stanbol.enhancer.engines.dereference.EntityDereferenceEngine;
import org.apache.stanbol.enhancer.engines.dereference.entityhub.shared.SharedDereferenceThreadPool;
@@ -226,7 +230,16 @@ public class EntityhubDereferenceEngine
//now parse dereference field config
entityDereferencer.setDereferencedFields(engineConfig.getDereferenceFields());
entityDereferencer.setLdPath(engineConfig.getLdPathProgram());
- entityDereferenceEngine = new EntityDereferenceEngine(entityDereferencer, engineConfig);
+ entityDereferenceEngine = new EntityDereferenceEngine(entityDereferencer, engineConfig,
+ new DereferenceContextFactory() { //we want to use our own DereferenceContext impl
+
+ @Override
+ public DereferenceContext createContext(EntityDereferenceEngine engine,
+ Map<String,Object> enhancementProperties) throws DereferenceConfigurationException {
+ return new EntityhubDereferenceContext(engine, enhancementProperties);
+ }
+ });
+
//NOTE: registration of this instance as OSGI service is done as soon as the
// entityhub service backing the entityDereferencer is available.
Modified: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java Tue May 13 06:26:20 2014
@@ -49,7 +49,6 @@ import org.apache.stanbol.entityhub.core
import org.apache.stanbol.entityhub.core.mapping.FieldMappingUtils;
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
-import org.apache.stanbol.entityhub.ldpath.backend.AbstractBackend;
import org.apache.stanbol.entityhub.model.clerezza.RdfReference;
import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
@@ -59,8 +58,6 @@ import org.apache.stanbol.entityhub.serv
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
import org.apache.stanbol.entityhub.servicesapi.model.Text;
import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
-import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
-import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
import org.osgi.framework.BundleContext;
@@ -204,24 +201,7 @@ public abstract class TrackingDereferenc
//however we would like to parse/validate the parsed LDPath program
//So we will create a pseudo RDFBackend sufficient to be used with the
//parser
- final RDFBackend<Object> parseBackend = new AbstractBackend() {
- @Override
- protected QueryResultList<String> query(FieldQuery query) throws EntityhubException {
- throw new UnsupportedOperationException("Not expected to be called");
- }
- @Override
- protected ValueFactory getValueFactory() {
- return valueFactory;
- }
- @Override
- protected Representation getRepresentation(String id) throws EntityhubException {
- throw new UnsupportedOperationException("Not expected to be called");
- }
- @Override
- protected FieldQuery createQuery() {
- throw new UnsupportedOperationException("Not expected to be called");
- }
- };
+ final RDFBackend<Object> parseBackend = new ParseBackend<T>(valueFactory);
//NOTE: calling execute(..) an this parseLdPath or even the
//ldpathProgram will result in UnsupportedOperationException
//but parsing is OK
@@ -254,6 +234,28 @@ public abstract class TrackingDereferenc
public Set<String> getDereferencedFields() {
return dereferencedFields;
}
+
+ /**
+ * Getter for the FieldMapper used for the {@link #getDereferencedFields()}
+ * @return the fieldMapper or <code>null</code> of the dereferenced fields
+ * are set
+ */
+ public FieldMapper getFieldMapper(){
+ return fieldMapper;
+ }
+
+ /**
+ * Getter for the LDPath {@link Program} parsed form the
+ * {@link #getLdPath}
+ * @return
+ */
+ public Program<Object> getLdPathProgram(){
+ return ldpathProgram;
+ }
+
+ public ValueFactory getValueFactory(){
+ return valueFactory;
+ }
/**
* Starts the tracking by calling {@link ServiceTracker#open()}
@@ -281,12 +283,13 @@ public abstract class TrackingDereferenc
}
@Override
- public final boolean dereference(UriRef uri, MGraph graph, Lock writeLock, DereferenceContext derefContext) throws DereferenceException {
+ public final boolean dereference(UriRef uri, MGraph graph, Lock writeLock, DereferenceContext dc) throws DereferenceException {
T service = getService();
if(service == null){
throw new DereferenceException(uri, serviceClass.getClass().getSimpleName()
+ "service is currently not available");
}
+ EntityhubDereferenceContext derefContext = (EntityhubDereferenceContext)dc;
Representation rep;
try {
rep = getRepresentation(service, uri.getUnicodeString(), derefContext.isOfflineMode());
@@ -295,18 +298,20 @@ public abstract class TrackingDereferenc
}
//we need the languages as strings
final Set<String> langs = derefContext.getLanguages();
-
+ final FieldMapper fieldMapper = derefContext.getFieldMapper();
+ final Program<Object>ldpathProgram = derefContext.getProgram();
if(rep != null){
- if(fieldMapper == null && ldpathProgram == null && langs.isEmpty()){
+ if(fieldMapper == null && ldpathProgram == null &&
+ (langs == null || langs.isEmpty())){
copyAll(uri, rep, graph, writeLock);
} else { //we need to apply some filters while dereferencing
if(fieldMapper != null || !langs.isEmpty()){
//this considers speficied fields and included languages
- copyMapped(uri, rep, langs, graph, writeLock);
+ copyMapped(uri, rep, fieldMapper, langs, graph, writeLock);
}
if(ldpathProgram != null){
//this executes LDPath statements
- copyLdPath(uri, getRdfBackend(service), langs, graph, writeLock);
+ copyLdPath(uri, getRdfBackend(service), ldpathProgram, langs, graph, writeLock);
}
}
return true;
@@ -319,13 +324,14 @@ public abstract class TrackingDereferenc
* writes the the results to the parsed Graph
* @param uri the context
* @param rdfBackend the RdfBackend the LDPath program is executed on
+ * @param ldpathProgram The {@link Program} parsed via the dereference context
* @param langs the set of languages to dereference
* @param graph the graph to store the results
* @param writeLock the write lock for the graph
* @throws DereferenceException on any {@link EntityhubException} while
* executing the LDPath program
*/
- private void copyLdPath(UriRef uri, RDFBackend<Object> rdfBackend,
+ private void copyLdPath(UriRef uri, RDFBackend<Object> rdfBackend, Program<Object> ldpathProgram,
Set<String> langs, MGraph graph, Lock writeLock) throws DereferenceException {
//A RdfReference needs to be used as context
RdfReference context = valueFactory.createReference(uri);
@@ -394,26 +400,25 @@ public abstract class TrackingDereferenc
* in the graph
* @param uri the uri of the entity to dereference
* @param rep the data for the entity as in the entityhub
+ * @param fieldMapper the {@link FieldMapper} parsed from the dereference context
* @param langs the set of languages to dereference
* @param graph the graph to store the mapping results
* @param writeLock the write lock for the graph
*/
- private void copyMapped(UriRef uri, Representation rep, Set<String> langs,
+ private void copyMapped(UriRef uri, Representation rep, FieldMapper fieldMapper, Set<String> langs,
MGraph graph, Lock writeLock) {
- //init the fieldMapper
- FieldMapper fieldMapper;
- if(!langs.isEmpty()){ //if we need to filter for specific languages
- //we need to modify the field and add a global filter for the
- //languages. NOTE that the field might be null. In that case we
- //need just filter literals by language
- //TODO: maybe cache fieldMappers for sets of languages
- fieldMapper = this.fieldMapper != null ? this.fieldMapper.clone() :
- new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
- fieldMapper.addMapping(new FieldMapping(new TextConstraint(
- (String)null, langs.toArray(new String[graph.size()]))));
- } else { //just use the fieldMapper as parsed in the config
- fieldMapper = this.fieldMapper;
- }
+ //NOTE: The fieldMapper parsed via the context does already have a
+ // filter for the parsed languages. Because of that the old code
+ // adding such a language filter is no longer needed
+// FieldMapper fieldMapper;
+// if(!langs.isEmpty()){ //if we need to filter for specific languages
+// fieldMapper = this.fieldMapper != null ? this.fieldMapper.clone() :
+// new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
+// fieldMapper.addMapping(new FieldMapping(new TextConstraint(
+// (String)null, langs.toArray(new String[langs.size()]))));
+// } else { //just use the fieldMapper as parsed in the config
+// fieldMapper = this.fieldMapper;
+// }
//execute the field mappings
writeLock.lock();
try {
@@ -485,3 +490,4 @@ public abstract class TrackingDereferenc
}
}
+
\ No newline at end of file
Propchange: stanbol/trunk/enhancer/
------------------------------------------------------------------------------
Merged /stanbol/branches/release-0.12/enhancer:r1571146,1571150,1572586,1593490,1593899
Modified: stanbol/trunk/enhancer/chain/graph/src/main/java/org/apache/stanbol/enhancer/chain/graph/impl/GraphChain.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/graph/src/main/java/org/apache/stanbol/enhancer/chain/graph/impl/GraphChain.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/graph/src/main/java/org/apache/stanbol/enhancer/chain/graph/impl/GraphChain.java (original)
+++ stanbol/trunk/enhancer/chain/graph/src/main/java/org/apache/stanbol/enhancer/chain/graph/impl/GraphChain.java Tue May 13 06:26:20 2014
@@ -17,6 +17,7 @@
package org.apache.stanbol.enhancer.chain.graph.impl;
import static org.apache.commons.io.FilenameUtils.getExtension;
+import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getEnhancementProperties;
import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getParameters;
import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getState;
import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getValue;
@@ -84,12 +85,12 @@ import org.slf4j.LoggerFactory;
* empty. Otherwise the {@link #PROPERTY_CHAIN_LIST} will be ignored regardless
* if the graph resource is available or not.
* </ol>
- * TODO: Maybe split this up into two chains - one for each configuration
- * possibility.
+ * <i>NOTE:</i> Since <code>0.12.1</code> this supports EnhancementProperties
+ * as described by <a href="https://issues.apache.org/jira/browse/STANBOL-488"></a>
*
* @author Rupert Westenthaler
*/
-@Component(inherit=true,configurationFactory=true,metatype=true,
+@Component(configurationFactory=true,metatype=true,
policy=ConfigurationPolicy.REQUIRE)
@Service
@Properties(value={
@@ -234,7 +235,7 @@ public class GraphChain extends Abstract
"The configured execution plan MUST at least contain a single " +
"valid execution node!");
}
- internalChain = new ListConfigExecutionPlan(config);
+ internalChain = new ListConfigExecutionPlan(config,getChainProperties());
mode = MODE.LIST;
} else { //both PROPERTY_CHAIN_LIST and PROPERTY_GRAPH_RESOURCE are null
throw new ConfigurationException(PROPERTY_GRAPH_RESOURCE,
@@ -431,7 +432,8 @@ public class GraphChain extends Abstract
* Parses the execution plan form the configuration.
* @param config
*/
- private ListConfigExecutionPlan(Map<String,Map<String,List<String>>> config){
+ private ListConfigExecutionPlan(Map<String,Map<String,List<String>>> config,
+ Map<String,Object> chainProperties){
if(config == null || config.isEmpty()){
throw new IllegalArgumentException("The parsed execution plan " +
"confiuguration MUST NOT be NULL nor empty");
@@ -443,7 +445,7 @@ public class GraphChain extends Abstract
}
engines = Collections.unmodifiableSet(new HashSet<String>(config.keySet()));
MGraph graph = new SimpleMGraph();
- NonLiteral epNode = createExecutionPlan(graph, getName());
+ NonLiteral epNode = createExecutionPlan(graph, getName(), chainProperties);
//caches the String name -> {NonLiteral node, List<Stirng> dependsOn} mappings
Map<String,Object[]> name2nodes = new HashMap<String,Object[]>();
//1. write the nodes (without dependencies)
@@ -454,7 +456,8 @@ public class GraphChain extends Abstract
writeExecutionNode(graph, epNode,
node.getKey(),
getState(node.getValue(), "optional"),
- null),
+ null,
+ getEnhancementProperties(node.getValue())),
node.getValue().get("dependsOn")}); //dependsOn
}
//2. write the dependencies
Modified: stanbol/trunk/enhancer/chain/graph/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/graph/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/graph/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ stanbol/trunk/enhancer/chain/graph/src/main/resources/OSGI-INF/metatype/metatype.properties Tue May 13 06:26:20 2014
@@ -42,3 +42,7 @@ stanbol.enhancer.chain.graph.chainlist.d
of the execution plan with the syntax "<engineName>;[optional];[dependsOn=<engineName1>,<engineName2>]". \
For details and examples please see the documentation. If a Graph Resource is \
configured this property is ignored.
+
+stanbol.enhancer.chain.chainproperties.name=Chain Properties
+stanbol.enhancer.chain.chainproperties.description=Enhancement Properties parsed \
+to all engines of the chain. Syntax: '{property}={value-1},{value-2},..,{value-n}'
\ No newline at end of file
Modified: stanbol/trunk/enhancer/chain/list/src/main/java/org/apache/stanbol/enhancer/chain/list/impl/ListChain.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/list/src/main/java/org/apache/stanbol/enhancer/chain/list/impl/ListChain.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/list/src/main/java/org/apache/stanbol/enhancer/chain/list/impl/ListChain.java (original)
+++ stanbol/trunk/enhancer/chain/list/src/main/java/org/apache/stanbol/enhancer/chain/list/impl/ListChain.java Tue May 13 06:26:20 2014
@@ -16,6 +16,7 @@
*/
package org.apache.stanbol.enhancer.chain.list.impl;
+import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getEnhancementProperties;
import static org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils.getState;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.createExecutionPlan;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.writeExecutionNode;
@@ -75,14 +76,17 @@ import org.slf4j.LoggerFactory;
* engine is not required.
* </ul>
*
+ * <i>NOTE:</i> Since <code>0.12.1</code> this supports EnhancementProperties
+ * as described by <a href="https://issues.apache.org/jira/browse/STANBOL-488"></a>
+ *
* @author Rupert Westenthaler
*
*/
-@Component(inherit=true,configurationFactory=true,metatype=true,
-policy=ConfigurationPolicy.REQUIRE)
+@Component(configurationFactory=true,metatype=true, policy=ConfigurationPolicy.REQUIRE)
@Properties(value={
@Property(name=Chain.PROPERTY_NAME),
@Property(name=ListChain.PROPERTY_ENGINE_LIST, cardinality=1000),
+ @Property(name=AbstractChain.PROPERTY_CHAIN_PROPERTIES,cardinality=1000),
@Property(name=Constants.SERVICE_RANKING, intValue=0)
})
@Service(value=Chain.class)
@@ -94,7 +98,7 @@ public class ListChain extends AbstractC
* The list of Enhancement Engine names used to build the Execution Plan
*/
public static final String PROPERTY_ENGINE_LIST = "stanbol.enhancer.chain.list.enginelist";
-
+
private Set<String> engineNames;
private Graph executionPlan;
@@ -122,7 +126,7 @@ public class ListChain extends AbstractC
Set<String> engineNames = new HashSet<String>(configuredChain.size());
NonLiteral last = null;
MGraph ep = new SimpleMGraph();
- NonLiteral epNode = createExecutionPlan(ep, getName());
+ NonLiteral epNode = createExecutionPlan(ep, getName(), getChainProperties());
log.debug("Parse ListChain config:");
for(String line : configuredChain){
try {
@@ -135,7 +139,8 @@ public class ListChain extends AbstractC
boolean optional = getState(parsed.getValue(), "optional");
log.debug(" > Engine: {} ({})",parsed.getKey(),optional? "optional" : "required");
last = writeExecutionNode(ep, epNode, parsed.getKey(), optional,
- last == null ? null : Collections.singleton(last));
+ last == null ? null : Collections.singleton(last),
+ getEnhancementProperties(parsed.getValue()));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "Unable to parse Chain Configuraiton (message: '"+
e.getMessage()+"')!",e);
Modified: stanbol/trunk/enhancer/chain/list/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/list/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/list/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ stanbol/trunk/enhancer/chain/list/src/main/resources/OSGI-INF/metatype/metatype.properties Tue May 13 06:26:20 2014
@@ -33,4 +33,8 @@ This Chain implementation does not suppo
stanbol.enhancer.chain.list.enginelist.name=Engines
stanbol.enhancer.chain.list.enginelist.description=Defines the Engines in the oder \
-as executed by this Chain. Use "<engineName>;optional" if you want an engine to be optional.
\ No newline at end of file
+as executed by this Chain. Use "<engineName>;optional" if you want an engine to be optional.
+
+stanbol.enhancer.chain.chainproperties.name=Chain Properties
+stanbol.enhancer.chain.chainproperties.description=Enhancement Properties parsed \
+to all engines of the chain. Syntax: '{property}={value-1},{value-2},..,{value-n}'
\ No newline at end of file
Modified: stanbol/trunk/enhancer/chain/weighted/src/main/java/org/apache/stanbol/enhancer/chain/weighted/impl/WeightedChain.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/weighted/src/main/java/org/apache/stanbol/enhancer/chain/weighted/impl/WeightedChain.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/weighted/src/main/java/org/apache/stanbol/enhancer/chain/weighted/impl/WeightedChain.java (original)
+++ stanbol/trunk/enhancer/chain/weighted/src/main/java/org/apache/stanbol/enhancer/chain/weighted/impl/WeightedChain.java Tue May 13 06:26:20 2014
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -39,6 +40,7 @@ import org.apache.felix.scr.annotations.
import org.apache.stanbol.enhancer.servicesapi.Chain;
import org.apache.stanbol.enhancer.servicesapi.ChainException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
+import org.apache.stanbol.enhancer.servicesapi.helper.ConfigUtils;
import org.apache.stanbol.enhancer.servicesapi.impl.AbstractChain;
import org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker;
import org.osgi.framework.Constants;
@@ -76,10 +78,13 @@ import org.slf4j.LoggerFactory;
* engine is not required.
* </ul>
*
+ * <i>NOTE:</i> Since <code>0.12.1</code> this supports EnhancementProperties
+ * as described by <a href="https://issues.apache.org/jira/browse/STANBOL-488"></a>
+ *
* @author Rupert Westenthaler
*
*/
-@Component(inherit=true,configurationFactory=true,metatype=true,
+@Component(configurationFactory=true,metatype=true,
policy=ConfigurationPolicy.REQUIRE)
@Properties(value={
@Property(name=Chain.PROPERTY_NAME),
@@ -96,9 +101,17 @@ public class WeightedChain extends Abstr
* based on there weights.
*/
public static final String PROPERTY_CHAIN = "stanbol.enhancer.chain.weighted.chain";
-
+ /**
+ * the Chain configuration as parsed in the {@link #activate(ComponentContext)} method
+ */
private Map<String,Map<String,List<String>>> chain;
-
+ /**
+ * Do hold chain scope EnhancementProperties of the configured chain.
+ */
+ private Map<String,Map<String,Object>> chainScopedEnhProps;
+ /**
+ * Tracks the engines defined in the {@link #chain}
+ */
private EnginesTracker tracker;
/**
@@ -138,6 +151,17 @@ public class WeightedChain extends Abstr
throw new ConfigurationException(PROPERTY_CHAIN,
"The configured chain MUST at least contain a single valid entry!");
}
+ //init the chain scoped enhancement properties
+ chainScopedEnhProps = new HashMap<String,Map<String,Object>>();
+ if(getChainProperties() != null){
+ chainScopedEnhProps.put(null, getChainProperties());
+ }
+ for(Entry<String,Map<String,List<String>>> entry : chain.entrySet()){
+ Map<String,Object> enhProp = ConfigUtils.getEnhancementProperties(entry.getValue());
+ if(enhProp != null){
+ chainScopedEnhProps.put(entry.getKey(), enhProp);
+ }
+ }
//start tracking the engines of the configured chain
tracker = new EnginesTracker(ctx.getBundleContext(), chain.keySet(),this);
tracker.open();
@@ -147,6 +171,7 @@ public class WeightedChain extends Abstr
protected void deactivate(ComponentContext ctx) {
tracker.close();
tracker = null;
+ chainScopedEnhProps = null;
chain = null;
super.deactivate(ctx);
}
@@ -174,6 +199,10 @@ public class WeightedChain extends Abstr
* configured {@link #chain} is not active.
*/
private Graph createExecutionPlan() throws ChainException {
+ Map<String,Map<String,Object>> chainScopedEnhancementProperties = new HashMap<String,Map<String,Object>>();
+ if(getChainProperties() != null){
+ chainScopedEnhancementProperties.put(null, getChainProperties());
+ }
List<EnhancementEngine> availableEngines = new ArrayList<EnhancementEngine>(chain.size());
Set<String> optionalEngines = new HashSet<String>();
Set<String> missingEngines = new HashSet<String>();
@@ -193,7 +222,8 @@ public class WeightedChain extends Abstr
// throw new ChainException("This Chain is missing the following " +
// "required Engines "+missingEngines);
// }
- return calculateExecutionPlan(getName(),availableEngines,optionalEngines, missingEngines);
+ return calculateExecutionPlan(getName(),availableEngines,optionalEngines,
+ missingEngines,chainScopedEnhancementProperties);
}
@Override
Modified: stanbol/trunk/enhancer/chain/weighted/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/chain/weighted/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/chain/weighted/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ stanbol/trunk/enhancer/chain/weighted/src/main/resources/OSGI-INF/metatype/metatype.properties Tue May 13 06:26:20 2014
@@ -33,4 +33,8 @@ calculated by using ordering information
stanbol.enhancer.chain.weighted.chain.name=Engines
stanbol.enhancer.chain.weighted.chain.description=Defines the Engines used by this Chain. \
-One engine name per line. Use "<engineName>;optional" if you want an engine to be optional.
\ No newline at end of file
+One engine name per line. Use "<engineName>;optional" if you want an engine to be optional.
+
+stanbol.enhancer.chain.chainproperties.name=Chain Properties
+stanbol.enhancer.chain.chainproperties.description=Enhancement Properties parsed \
+to all engines of the chain. Syntax: '{property}={value-1},{value-2},..,{value-n}'
\ No newline at end of file
Propchange: stanbol/trunk/enhancer/generic/servicesapi/
------------------------------------------------------------------------------
Merged /stanbol/branches/release-0.12/enhancer/generic/servicesapi:r1571146,1571150,1572586,1593490,1593899
Modified: stanbol/trunk/enhancer/generic/servicesapi/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/pom.xml?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/servicesapi/pom.xml (original)
+++ stanbol/trunk/enhancer/generic/servicesapi/pom.xml Tue May 13 06:26:20 2014
@@ -113,9 +113,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
- <dependency>
+ <dependency> <!-- used for debug level logging during tests -->
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
Modified: stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EngineException.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EngineException.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EngineException.java (original)
+++ stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/EngineException.java Tue May 13 06:26:20 2014
@@ -29,15 +29,33 @@ package org.apache.stanbol.enhancer.serv
public class EngineException extends EnhancementException {
private static final long serialVersionUID = 1L;
-
+ private EnhancementEngine enhancementEngine;
+ private ContentItem contentItem;
+ /**
+ *
+ * @param message
+ * @deprecated use the constructor with {@link EnhancementEngine} and
+ * {@link ContentItem} instead
+ */
public EngineException(String message) {
super(message);
}
-
+ /**
+ *
+ * @param message
+ * @param cause
+ * @deprecated use the constructor with {@link EnhancementEngine} and
+ * {@link ContentItem} instead
+ */
public EngineException(String message, Throwable cause) {
super(message, cause);
}
-
+ /**
+ *
+ * @param cause
+ * @deprecated use the constructor with {@link EnhancementEngine} and
+ * {@link ContentItem} instead
+ */
public EngineException(Throwable cause) {
super(cause);
}
@@ -50,5 +68,26 @@ public class EngineException extends Enh
"'%s' failed to process content item '%s' with type '%s': %s",
ee.getClass().getSimpleName(), ci.getUri().getUnicodeString(), ci.getMimeType(),
message == null ? cause : message), cause);
+ this.enhancementEngine = ee;
+ this.contentItem = ci;
+
+ }
+
+ /**
+ * The EnhancementEngine parsed to the Exception
+ * @return
+ * @since 0.12.1
+ */
+ public EnhancementEngine getEnhancementEngine() {
+ return enhancementEngine;
+ }
+
+ /**
+ * The ContentITem parsed to the Exception
+ * @return
+ * @since 0.12.1
+ */
+ public ContentItem getContentItem() {
+ return contentItem;
}
}
Modified: stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/InvalidContentException.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/InvalidContentException.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/InvalidContentException.java (original)
+++ stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/InvalidContentException.java Tue May 13 06:26:20 2014
@@ -25,20 +25,51 @@ package org.apache.stanbol.enhancer.serv
public class InvalidContentException extends EngineException {
private static final long serialVersionUID = 1L;
-
+
+ /**
+ *
+ * @param message
+ * @deprecated All EngineExceptions should parse the Engine and the
+ * ContentItem
+ */
+ @Deprecated
public InvalidContentException(String message) {
super(message);
}
-
+ /**
+ *
+ * @param message
+ * @param cause
+ * @deprecated All EngineExceptions should parse the Engine and the
+ * ContentItem
+ */
+ @Deprecated
public InvalidContentException(String message, Throwable cause) {
super(message, cause);
}
+ /**
+ * A EngineException caused by an invalid ContentItem
+ * @param ee the enhancement engine
+ * @param ci the content item
+ * @param cause the root cause
+ */
public InvalidContentException(EnhancementEngine ee, ContentItem ci,
Throwable cause) {
- super(String.format("'%s' failed to process invalid content item '%s'"
- + " with type '%s': %s", ee.getClass().getSimpleName(),
- ci.getUri().getUnicodeString(), ci.getMimeType(), cause.getMessage()), cause);
+ this(ee,ci, null,cause);
+ }
+ /**
+ *
+ * @param ee the enhancement engine
+ * @param ci the content item
+ * @param message a custom message why the parsed content item was invalid
+ * @param cause the root cause
+ * @since 0.12.1
+ */
+ public InvalidContentException(EnhancementEngine ee, ContentItem ci,
+ String message, Throwable cause) {
+ super(ee,ci, message == null ? "Invalid ContentItem" : message,
+ cause);
}
}
Modified: stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ConfigUtils.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ConfigUtils.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ConfigUtils.java (original)
+++ stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ConfigUtils.java Tue May 13 06:26:20 2014
@@ -17,6 +17,7 @@
package org.apache.stanbol.enhancer.servicesapi.helper;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -153,6 +154,51 @@ public final class ConfigUtils {
}
/**
+ * Utility that extracts enhancement properties from the parsed parameter maps.
+ * This will only consider keys starting with '<code>enhancer.</code>' as
+ * defined by <a href="https://issues.apache.org/jira/browse/STANBOL-488">STANBOL-488</a>
+ * @param parameters the paraemters (e.g. as returned as values by
+ * {@link #parseConfig(Iterator)})
+ * @return The enhancement properties extracted from the parsed parameters
+ * @since 0.12.1
+ */
+ public static Map<String,Object> getEnhancementProperties(Map<String, List<String>> parameters){
+ Map<String,Object> props = new HashMap<String,Object>();
+ for(Entry<String,List<String>> entry : parameters.entrySet()){
+ if(entry.getKey().startsWith("enhancer.")){
+ Object value;
+ if(entry.getValue().size() == 1){
+ value = entry.getValue().get(0);
+ } else {
+ value = entry.getValue();
+ }
+ if(value != null){
+ props.put(entry.getKey(), value);
+ }
+ }
+ }
+ return props;
+ }
+ /**
+ * Utility that extracts enhancement properties from a configuration line
+ * using the syntax
+ * <pre>
+ * {prop}={value-1},{value-2},..,{value-n}
+ * </pre>
+ * @param line the configuration of a single enhancement property
+ * @return The enhancement properties extracted from the parsed parameters
+ * @since 0.12.1
+ */
+ public static Map<String,Object> getEnhancementProperties(Collection<String> lines){
+ if(lines == null || lines.isEmpty()){
+ return null;
+ } else {
+ return getEnhancementProperties(getParameters(
+ lines.toArray(new String[lines.size()]), 0));
+ }
+ }
+
+ /**
* Internally used to parse single lines of an parsed {@link Iterable} or
* {@link Iterator}
* @param config the map used to write the parsed values
Modified: stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java?rev=1594140&r1=1594139&r2=1594140&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java (original)
+++ stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java Tue May 13 06:26:20 2014
@@ -356,4 +356,74 @@ public final class ContentItemHelper {
return mimeType.toString();
}
+ /*
+ * EnhancementProperties support for 0.12 (see STANBOL-1280)
+ */
+ /**
+ * URI used to register an {@link ContentItem#getPart(int, Class) contentPart}
+ * of the type {@link Map Map<String,Objext>} containing the
+ * EnhancementEngine properties <p>
+ */
+ public static final UriRef ENHANCEMENT_PROPERTIES_URI = new UriRef(
+ "urn:apache.org:stanbol.web:enhancement.properties");
+
+ /**
+ * Getter for the EnhancementProperties content part
+ * @param ci the content item
+ * @return the content part or <code>null</code> if not present.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String,Object> getEnhancementPropertiesContentPart(ContentItem ci){
+ if(ci == null){
+ throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
+ }
+ ci.getLock().readLock().lock();
+ try {
+ return ci.getPart(ENHANCEMENT_PROPERTIES_URI, Map.class);
+ } catch (NoSuchPartException e) {
+ return null;
+ } finally{
+ ci.getLock().readLock().unlock();
+ }
+
+ }
+
+ /**
+ * Initialises the EnhancementProperties ContentPart for an {@link ContentItem}.
+ * If the content part is already present it will just return the existing. If
+ * not it will register an empty one. The content part is registered with
+ * the URI {@link #ENHANCEMENT_PROPERTIES_URI}
+ * @param ci the contentItem MUST NOT be NULL
+ * @return the enhancement properties
+ * @throws IllegalArgumentException if <code>null</code> is parsed as {@link ContentItem}.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String,Object> initEnhancementPropertiesContentPart(ContentItem ci){
+ if(ci == null){
+ throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
+ }
+ Map<String,Object> enhancementProperties;
+ ci.getLock().readLock().lock();
+ try {
+ enhancementProperties = ci.getPart(ENHANCEMENT_PROPERTIES_URI, Map.class);
+ } catch (NoSuchPartException e) {
+ enhancementProperties = null;
+ } finally{
+ ci.getLock().readLock().unlock();
+ }
+ if(enhancementProperties == null){
+ ci.getLock().writeLock().lock();
+ try { //check again ... maybe an other thread has added this part
+ enhancementProperties = ci.getPart(ENHANCEMENT_PROPERTIES_URI, Map.class);
+ } catch (NoSuchPartException e) {
+ enhancementProperties = new HashMap<String,Object>();
+ ci.addPart(ENHANCEMENT_PROPERTIES_URI, enhancementProperties);
+ } finally{
+ ci.getLock().writeLock().unlock();
+ }
+ } //else was already present
+ return enhancementProperties;
+ }
+
+
}