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/04/29 11:48:28 UTC

svn commit: r1590931 - in /stanbol/trunk/enhancement-engines/dereference: core/ core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/ core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/ entityhub/src/main/java/org/apache/s...

Author: rwesten
Date: Tue Apr 29 09:48:28 2014
New Revision: 1590931

URL: http://svn.apache.org/r1590931
Log:
merged implementation for STANBOL-1334 to trunk

Modified:
    stanbol/trunk/enhancement-engines/dereference/core/pom.xml
    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/DereferenceEngineConfig.java
    stanbol/trunk/enhancement-engines/dereference/core/src/main/java/org/apache/stanbol/enhancer/engines/dereference/EntityDereferenceEngine.java
    stanbol/trunk/enhancement-engines/dereference/core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineTest.java
    stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java

Modified: stanbol/trunk/enhancement-engines/dereference/core/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/pom.xml?rev=1590931&r1=1590930&r2=1590931&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/pom.xml (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/pom.xml Tue Apr 29 09:48:28 2014
@@ -81,6 +81,11 @@
       <artifactId>org.apache.stanbol.commons.stanboltools.offline</artifactId>
       <version>1.0.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.namespaceprefix.service</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.stanbol</groupId>

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=1590931&r1=1590930&r2=1590931&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 Apr 29 09:48:28 2014
@@ -19,6 +19,7 @@ package org.apache.stanbol.enhancer.engi
 import org.apache.clerezza.rdf.core.Language;
 import org.apache.clerezza.rdf.core.PlainLiteral;
 import org.apache.clerezza.rdf.core.Triple;
+import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
 
 /**
  * Define configuration parameters for Dereference engines
@@ -63,6 +64,14 @@ public interface DereferenceConstants {
     boolean DEFAULT_FILTER_ACCEPT_LANGUAGES = true;
     
     /**
+     * Property used to configure the properties linking entities. If not present
+     * the {@link Properties#ENHANCER_ENTITY_REFERENCE} will be used. If present
+     * this property is not automatically added.<p>
+     * @since 0.12.1 (<a href="https://issues.apache.org/jira/browse/STANBOL-1334">STANBOL-1334</a>)
+     */
+    String ENTITY_REFERENCES = "enhancer.engines.dereference.references";
+    
+    /**
      * Property used to configure the fields that should be dereferenced.<p>
      * DereferenceEngines need to support a list of URIs but may also support more
      * complex syntax (such as the Entityhub FiedMapping). However parsing a

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=1590931&r1=1590930&r2=1590931&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 Apr 29 09:48:28 2014
@@ -2,6 +2,8 @@ package org.apache.stanbol.enhancer.engi
 
 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.commons.namespaceprefix.NamespaceMappingUtils.getConfiguredUri;
+import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_REFERENCE;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -11,42 +13,40 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
+import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.commons.lang.StringUtils;
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
 import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
+import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
 import org.osgi.framework.Constants;
 import org.osgi.service.cm.ConfigurationException;
 
 public class DereferenceEngineConfig implements DereferenceConstants {
 
-    
+    private final NamespacePrefixService nsPrefixService;
     private final Dictionary<String,Object> config;
-    
+    private String ldpath;
+    private List<String> dereferenced;
+    private List<UriRef> entityReferences;
+
     /**
      * Creates a DereferenceEngine configuration based on a Dictionary. Typically
      * the dictionary will contain keys as defined by {@link DereferenceConstants}
      * and {@link EnhancementEngine}
      * @param config the config - typically as parsed in the activate method of
      * an OSGI component.
+     * @param nsPrefixService the {@link NamespacePrefixService} used to resolve
+     * <code>{ns}:{local-name}</code> like configurations for the configured 
+     * {@link #getEntityReferences()} properties. If <code>null</code> 
+     * using qnames for the entity references will cause a 
+     * {@link ConfigurationException}
+     * @throws ConfigurationException if the parsed config is not valid
      */
-    public DereferenceEngineConfig(Dictionary<String,Object> config) throws ConfigurationException {
+    public DereferenceEngineConfig(Dictionary<String,Object> config, NamespacePrefixService nsPrefixService) throws ConfigurationException {
+        this.nsPrefixService = nsPrefixService;
         this.config = config;
         validateRequired(config);
     }
-    /**
-     * Constructor that parses the config (ATM only used by unit tests)
-     * @param name
-     * @param filterContentLang
-     * @param filterAcceptLang
-     * @throws ConfigurationException
-     */
-    protected DereferenceEngineConfig(String name, boolean filterContentLang, boolean filterAcceptLang) 
-            throws ConfigurationException {
-        config = new Hashtable<String,Object>();
-        config.put(EnhancementEngine.PROPERTY_NAME, name);
-        config.put(FILTER_CONTENT_LANGUAGES, filterContentLang);
-        config.put(FILTER_ACCEPT_LANGUAGES, filterAcceptLang);
-        validateRequired(config);
-    }
     
     /**
      * If filtering for non content language literals is active
@@ -67,29 +67,23 @@ public class DereferenceEngineConfig imp
         return value == null ? DEFAULT_FILTER_ACCEPT_LANGUAGES : 
             Boolean.parseBoolean(value.toString());
     }
-    
+    /**
+     * Validates the parsed configuration.
+     * @param config the configuration to validate
+     * @throws ConfigurationException for the first property with an invalid
+     * configuration. (1) if no name is set for the engine (2) the configured
+     * dereferenced fields are invalid (3) the configured LDPath program is
+     * invalid (4) the configured entity references are invalid
+     */
     private void validateRequired(Dictionary<String,Object> config) throws ConfigurationException {
         Object value = config.get(EnhancementEngine.PROPERTY_NAME);
         if(value == null || StringUtils.isBlank(value.toString())){
             throw new ConfigurationException(EnhancementEngine.PROPERTY_NAME, 
                 "The EnhancementEngine name MUST NOT be NULL nor empty!");
         }
-        value = config.get(DEREFERENCE_ENTITIES_FIELDS);
-        if(value != null && !(value instanceof String || value instanceof String[] ||
-                value instanceof Collection<?>)){
-            throw new ConfigurationException(DEREFERENCE_ENTITIES_FIELDS, 
-                "Dereference Entities Fields MUST BE parsed as String[], Collection<String> or "
-                + "String (single value). The actual value '"+value+"'(type: '"+value.getClass() 
-                + "') is NOT supported");
-        }
-        value = config.get(DEREFERENCE_ENTITIES_LDPATH);
-        if(value != null && !(value instanceof String || value instanceof String[] ||
-                value instanceof Collection<?>)){
-            throw new ConfigurationException(DEREFERENCE_ENTITIES_LDPATH, 
-                "Dereference LDPath statements MUST BE parsed as String, String[] or "
-                + "Collection<String>. The actual value '"+value+"'(type: '"+value.getClass() 
-                + "') is NOT supported");            
-        }        
+        this.dereferenced = parseDereferenceFields();
+        this.ldpath = parseLdPathProgram();
+        this.entityReferences = parseEntityReferences();
     }
 
     /**
@@ -113,6 +107,74 @@ public class DereferenceEngineConfig imp
         
     }
     /**
+     * Getter for the list of properties used to refer Entities as configured
+     * by the {@link DereferenceConstants#ENTITY_REFERENCES} property. <p>
+     * @return the configured entity references or a singleton list containing
+     * {@link Properties#ENHANCER_ENTITY_REFERENCE} if no custom configuration
+     * is present
+     * @since 0.12.1 (<a href="https://issues.apache.org/jira/browse/STANBOL-1334">STANBOL-1334</a>)
+     */
+    public List<UriRef> getEntityReferences() {
+        return entityReferences;
+    }
+    /**
+     * Parses the list of properties used to reference Entities from the
+     * {@link DereferenceConstants#ENTITY_REFERENCES} property
+     * @return the list of properties used to reference entities. If none are
+     * present this returns a singleton list containing 
+     * {@link Properties#ENHANCER_ENTITY_REFERENCE}
+     * @since 0.12.1 (<a href="https://issues.apache.org/jira/browse/STANBOL-1334">STANBOL-1334</a>)
+     */
+    public List<UriRef> parseEntityReferences() throws ConfigurationException {
+        Object value = config.get(ENTITY_REFERENCES);
+        final List<String> fields;
+        if(value instanceof String[]){
+            fields = Arrays.asList((String[])value);
+        } else if(value instanceof Collection<?>){
+            fields = new ArrayList<String>(((Collection<?>)value).size());
+            for(Object field : (Collection<?>)value){
+                if(field != null){
+                    fields.add(field.toString());
+                }
+            }
+        } else if(value instanceof String){
+            fields = Collections.singletonList((String)value);
+        } else if(value != null){ //unsupported type 
+            throw new ConfigurationException(ENTITY_REFERENCES, 
+                "Entity References MUST BE parsed as String[], Collection<String> or "
+                + "String (single value). The actual value '"+value+"'(type: '"+value.getClass() 
+                + "') is NOT supported");
+        } else { //not specified return the default
+            return Collections.singletonList(ENHANCER_ENTITY_REFERENCE);
+        }
+        //convert configured fields (incl. 'ns:local-name' configurations) to 
+        //full UriRef instances
+        List<UriRef> references = new ArrayList<UriRef>(fields.size());
+        for(String field : fields){
+            if(!StringUtils.isBlank(field)){
+                references.add(new UriRef(getConfiguredUri(nsPrefixService, 
+                    ENTITY_REFERENCES, field.trim())));
+            }
+        }
+        if(references.isEmpty()){ //no valid configuration left ... return the default
+            return Collections.singletonList(ENHANCER_ENTITY_REFERENCE); 
+        } else {
+            return references;
+        }
+    }
+    /**
+     * Getter for the list of dereferenced fields as configured by the 
+     * {@link DereferenceConstants#DEREFERENCE_ENTITIES_FIELDS} property.<p>
+     * <i>NOTE</i>: this is the list of configured values. This may still include 
+     * '<code>{ns}:{local-name}</code>' like values or special syntax supported
+     * by the actual {@link EntityDereferencer} implementation.
+     * @return the list of configured dereferenced fields. 
+     */
+    public List<String> getDereferenceFields(){
+        return dereferenced;
+    }
+
+    /**
      * Parsed the {@link DereferenceConstants#DEREFERENCE_ENTITIES_FIELDS}
      * config from the parsed Dictionary regardless if it is defined as 
      * <code>String[]</code>, <code>Collection&lt;String&gt;</code> or
@@ -123,7 +185,7 @@ public class DereferenceEngineConfig imp
      * that 
      * @return the {@link List} with the unprocessed dereference fields as list
      */
-    public List<String> getDereferenceFields(){
+    private List<String> parseDereferenceFields() throws ConfigurationException {
         Object value = config.get(DEREFERENCE_ENTITIES_FIELDS);
         final List<String> fields;
         if(value instanceof String[]){
@@ -139,12 +201,25 @@ public class DereferenceEngineConfig imp
             }
         } else if(value instanceof String){
             fields = Collections.singletonList((String)value);
-        } else { //value == null or of unsupported type 
+        } else if(value != null){
+            throw new ConfigurationException(DEREFERENCE_ENTITIES_FIELDS, 
+                "Dereference Entities Fields MUST BE parsed as String[], Collection<String> or "
+                + "String (single value). The actual value '"+value+"'(type: '"+value.getClass() 
+                + "') is NOT supported");
+        } else {//value == null
             fields = Collections.emptyList();
         }
         return fields;
     }
     /**
+     * Getter for the LDPath program as configured by the 
+     * {@link DereferenceConstants#DEREFERENCE_ENTITIES_LDPATH} property.
+     * @return the LDPath property
+     */
+    public String getLdPathProgram(){
+        return ldpath;
+    }
+    /**
      * Parses the LdPath program from the value of the 
      * {@link DereferenceConstants#DEREFERENCE_ENTITIES_LDPATH} property. <p>
      * This supports <code>String</code> (the program as a single String), 
@@ -154,7 +229,7 @@ public class DereferenceEngineConfig imp
      * done by the LdPath repository used by the dereferencer.
      * @return the unparsed LDPath program as String 
      */
-    public String getLdPathProgram(){
+    private String parseLdPathProgram() throws ConfigurationException {
         Object value = config.get(DEREFERENCE_ENTITIES_LDPATH);
         if(value == null){
             return null;
@@ -185,13 +260,20 @@ public class DereferenceEngineConfig imp
                     sb.append(line);
                 }
             }
-        } //else unsupported type - ignore
+        } else if(value != null) {//unsupported type
+            throw new ConfigurationException(DEREFERENCE_ENTITIES_LDPATH, 
+                "Dereference LDPath statements MUST BE parsed as String, String[] or "
+                + "Collection<String>. The actual value '"+value+"'(type: '"+value.getClass() 
+                + "') is NOT supported");            
+        }
         //if first == false we we have not found any non blank line -> return null!
         return !first ? sb.toString() : null;
     }
     /**
-     * The dictionary holding the config
-     * @return the dictionary holding the config
+     * The dictionary parsed to this configuration object. NOTE: that changes
+     * to this dictionary will not be reflected by the getters of this class.
+     * @return the dictionary holding the parsed configuration (expected to 
+     * be used as read-only).
      */
     public Dictionary<String,Object> getDict(){
         return config;

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=1590931&r1=1590930&r2=1590931&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 Apr 29 09:48:28 2014
@@ -224,20 +224,24 @@ public class EntityDereferenceEngine imp
             } //no content language filtering - leave contentLanguages empty
             //parse the referenced entities from the graph
             Set<UriRef> checked = new HashSet<UriRef>();
-            Iterator<Triple> entityReferences = metadata.filter(null, ENHANCER_ENTITY_REFERENCE, null);
-            while(entityReferences.hasNext()){
-                Triple triple = entityReferences.next();
-                Resource entityReference = triple.getObject();
-                if((entityReference instanceof UriRef) && //only URIs
-                		checked.add((UriRef)entityReference) && //do not check a URI twice
-                		chekcFallbackMode((UriRef)entityReference, metadata) && //fallback mode
-                		checkURI((UriRef)entityReference)){ //URI prefixes and patterns
-                    boolean added = referencedEntities.add((UriRef)entityReference);
-                    if(added && log.isTraceEnabled()){
-                        log.trace("  ... schedule Entity {}", entityReference);
+            for(UriRef referenceProperty : config.getEntityReferences()){
+                Iterator<Triple> entityReferences = metadata.filter(null, referenceProperty, null);
+                while(entityReferences.hasNext()){
+                    Triple triple = entityReferences.next();
+                    Resource entityReference = triple.getObject();
+                    if((entityReference instanceof UriRef) && //only URIs
+                    		checked.add((UriRef)entityReference) && //do not check a URI twice
+                    		chekcFallbackMode((UriRef)entityReference, metadata) && //fallback mode
+                    		checkURI((UriRef)entityReference)){ //URI prefixes and patterns
+                        boolean added = referencedEntities.add((UriRef)entityReference);
+                        if(added && log.isTraceEnabled()){
+                            log.trace("  ... schedule Entity {} (referenced-by: {})", 
+                                entityReference, referenceProperty);
+                        }
+                    } else if(log.isTraceEnabled()){
+                        log.trace(" ... ignore Entity {} (referenced-by: {})",
+                            entityReferences, referenceProperty);
                     }
-                } else if(log.isTraceEnabled()){
-                    log.trace(" ... ignore Entity {}",entityReferences);
                 }
             }
         } finally {

Modified: stanbol/trunk/enhancement-engines/dereference/core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineTest.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineTest.java?rev=1590931&r1=1590930&r2=1590931&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineTest.java (original)
+++ stanbol/trunk/enhancement-engines/dereference/core/src/test/java/org/apache/stanbol/enhancer/engines/dereference/DereferenceEngineTest.java Tue Apr 29 09:48:28 2014
@@ -16,6 +16,9 @@
  */
 package org.apache.stanbol.enhancer.engines.dereference;
 
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.ENTITY_REFERENCES;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.FILTER_ACCEPT_LANGUAGES;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.FILTER_CONTENT_LANGUAGES;
 import static org.apache.stanbol.enhancer.servicesapi.rdf.OntologicalClasses.SKOS_CONCEPT;
 import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_REFERENCE;
 import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDFS_LABEL;
@@ -23,6 +26,8 @@ import static org.apache.stanbol.enhance
 
 import java.io.IOException;
 import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Random;
 import java.util.concurrent.ExecutorService;
@@ -73,6 +78,9 @@ public class DereferenceEngineTest {
     public static final UriRef NAME = new UriRef(NamespaceEnum.rdfs+"label");
     public static final UriRef TYPE = new UriRef(NamespaceEnum.rdf+"type");
     public static final UriRef REDIRECT = new UriRef(NamespaceEnum.rdfs+"seeAlso");
+    
+    public static final UriRef OTHER_ENTITY_REFERENCE = new UriRef(
+        "http://www.example.org/stanbol/enhancer/dereference/test#other-entity-reference");
 
     private static final ContentItemFactory ciFactory = InMemoryContentItemFactory.getInstance();
     
@@ -84,6 +92,7 @@ public class DereferenceEngineTest {
     private static final int NUM_ENTITIES = 1000;
     
     public static final float PERCENTAGE_LINKED = 0.3f;
+    public static final float PERCENTAGE_LINKED_OTHER = 0.2f;
     public static final float PERCENTAGE_PRESENT = 0.9f;
     
     @BeforeClass
@@ -109,16 +118,25 @@ public class DereferenceEngineTest {
         log.info(" ... created {} Entities",numEntities);
         testMetadata = new IndexedMGraph();
         int numLinks = 0;
+        int numOtherLinks = 0;
         for(int i = 0; i < NUM_ENTITIES ; i++){
-            if(random.nextFloat() < PERCENTAGE_LINKED){
+            float r = random.nextFloat();
+            if(r < PERCENTAGE_LINKED){
                 UriRef enhancementUri = new UriRef("urn:test:enhancement"+i);
                 UriRef entityUri = new UriRef("urn:test:entity"+i);
                 //we do not need any other triple for testing in the contentItem
                 testMetadata.add(new TripleImpl(enhancementUri, ENHANCER_ENTITY_REFERENCE, entityUri));
                 numLinks++;
+            } else if((r-PERCENTAGE_LINKED) < PERCENTAGE_LINKED_OTHER){
+                UriRef enhancementUri = new UriRef("urn:test:enhancement"+i);
+                UriRef entityUri = new UriRef("urn:test:entity"+i);
+                //we do not need any other triple for testing in the contentItem
+                testMetadata.add(new TripleImpl(enhancementUri, OTHER_ENTITY_REFERENCE, entityUri));
+                numOtherLinks++;
             }
         }
-        log.info(" ... created {} Entity references ", numLinks);
+        log.info("> created {} Entity references and {} references using an alternative proeprty ", 
+            numLinks, numOtherLinks);
 
     }
 
@@ -140,8 +158,12 @@ public class DereferenceEngineTest {
                 return false;
             }  
         };
+        Dictionary<String,Object> dict = new Hashtable<String,Object>();
+        dict.put(EnhancementEngine.PROPERTY_NAME, "online");
+        dict.put(FILTER_CONTENT_LANGUAGES, false);
+        dict.put(FILTER_ACCEPT_LANGUAGES, false);
         EntityDereferenceEngine engine = new EntityDereferenceEngine(onlineDereferencer,
-            new DereferenceEngineConfig("online", false, false));
+            new DereferenceEngineConfig(dict, null));
         //engine in online mode
         Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
         //set engine in offline mode
@@ -152,31 +174,81 @@ public class DereferenceEngineTest {
     @Test
     public void testSyncDereferencing() throws Exception {
         ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
+        Dictionary<String,Object> dict = new Hashtable<String,Object>();
+        dict.put(EnhancementEngine.PROPERTY_NAME, "sync");
+        dict.put(FILTER_CONTENT_LANGUAGES, false);
+        dict.put(FILTER_ACCEPT_LANGUAGES, false);
         EntityDereferenceEngine engine = new EntityDereferenceEngine(syncDereferencer,
-            new DereferenceEngineConfig("sync", false, false));
+            new DereferenceEngineConfig(dict, null));
         Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
         engine.computeEnhancements(ci);
-        validateDereferencedEntities(ci.getMetadata());
+        validateDereferencedEntities(ci.getMetadata(), ENHANCER_ENTITY_REFERENCE);
     }
 
     @Test
     public void testAsyncDereferencing() throws Exception {
         ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
+        Dictionary<String,Object> dict = new Hashtable<String,Object>();
+        dict.put(EnhancementEngine.PROPERTY_NAME, "async");
+        dict.put(FILTER_CONTENT_LANGUAGES, false);
+        dict.put(FILTER_ACCEPT_LANGUAGES, false);
         EntityDereferenceEngine engine = new EntityDereferenceEngine(asyncDereferencer,
-            new DereferenceEngineConfig("async", false, false));
+            new DereferenceEngineConfig(dict,null));
         Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
         engine.computeEnhancements(ci);
-        validateDereferencedEntities(ci.getMetadata());
+        validateDereferencedEntities(ci.getMetadata(), ENHANCER_ENTITY_REFERENCE);
     }
 
-    private void validateDereferencedEntities(TripleCollection metadata) {
-        Iterator<Triple> referenced = metadata.filter(null, ENHANCER_ENTITY_REFERENCE, null);
+    /**
+     * Test for <a href="https://issues.apache.org/jira/browse/STANBOL-1334">STANBOL-1334</a>
+     * @throws Exception
+     */
+    @Test
+    public void testAsyncOtherEntityReferenceDereferencing() throws Exception {
+        ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
+        Dictionary<String,Object> dict = new Hashtable<String,Object>();
+        dict.put(EnhancementEngine.PROPERTY_NAME, "async");
+        dict.put(FILTER_CONTENT_LANGUAGES, false);
+        dict.put(FILTER_ACCEPT_LANGUAGES, false);
+        dict.put(ENTITY_REFERENCES,OTHER_ENTITY_REFERENCE.getUnicodeString());
+        DereferenceEngineConfig config = new DereferenceEngineConfig(dict,null);
+        EntityDereferenceEngine engine = new EntityDereferenceEngine(asyncDereferencer, config);
+        Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
+        engine.computeEnhancements(ci);
+        validateDereferencedEntities(ci.getMetadata(), OTHER_ENTITY_REFERENCE);
+    }
+    
+    /**
+     * Test for <a href="https://issues.apache.org/jira/browse/STANBOL-1334">STANBOL-1334</a>
+     * @throws Exception
+     */
+    @Test
+    public void testAsyncMultipleEntityReferenceDereferencing() throws Exception {
+        ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
+        Dictionary<String,Object> dict = new Hashtable<String,Object>();
+        dict.put(EnhancementEngine.PROPERTY_NAME, "async");
+        dict.put(FILTER_CONTENT_LANGUAGES, false);
+        dict.put(FILTER_ACCEPT_LANGUAGES, false);
+        dict.put(ENTITY_REFERENCES, new String[]{
+                OTHER_ENTITY_REFERENCE.getUnicodeString(), 
+                ENHANCER_ENTITY_REFERENCE.getUnicodeString()});
+        DereferenceEngineConfig config = new DereferenceEngineConfig(dict,null);
+        EntityDereferenceEngine engine = new EntityDereferenceEngine(asyncDereferencer, config);
+        Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
+        engine.computeEnhancements(ci);
+        validateDereferencedEntities(ci.getMetadata(), OTHER_ENTITY_REFERENCE, ENHANCER_ENTITY_REFERENCE);
+    }
+    
+    private void validateDereferencedEntities(TripleCollection metadata, UriRef...entityReferenceFields) {
         MGraph expected = new IndexedMGraph();
-        while(referenced.hasNext()){
-            UriRef entity = (UriRef)referenced.next().getObject();
-            Iterator<Triple> entityTriples = testData.filter(entity, null, null);
-            while(entityTriples.hasNext()){
-                expected.add(entityTriples.next());
+        for(UriRef entityReferenceField : entityReferenceFields){
+            Iterator<Triple> referenced = metadata.filter(null, entityReferenceField, null);
+            while(referenced.hasNext()){
+                UriRef entity = (UriRef)referenced.next().getObject();
+                Iterator<Triple> entityTriples = testData.filter(entity, null, null);
+                while(entityTriples.hasNext()){
+                    expected.add(entityTriples.next());
+                }
             }
         }
         MGraph notExpected = new IndexedMGraph(testData);

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=1590931&r1=1590930&r2=1590931&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 Apr 29 09:48:28 2014
@@ -151,7 +151,7 @@ public class EntityhubDereferenceEngine 
         bundleContext = ctx.getBundleContext();
         log.info("> activate {}",getClass().getSimpleName());
         //get the metadata later set to the enhancement engine
-        DereferenceEngineConfig engineConfig = new DereferenceEngineConfig(properties);
+        DereferenceEngineConfig engineConfig = new DereferenceEngineConfig(properties, prefixService);
         log.debug(" - engineName: {}", engineConfig.getEngineName());
         //parse the Entityhub Site used for dereferencing
         Object value = properties.get(SITE_ID);