Author: rwesten
Date: Tue Oct 30 22:37:50 2012
New Revision: 1403904

URL: http://svn.apache.org/viewvc?rev=1403904&view=rev
Log:
STANBOL-723: merged additions to the servicesapi helper classes from the 
disambiguation engine back into the trunk. This will allow to run 
disambiguation-mlt engine of the branch together with the servicesapi module of 
the trunk

Modified:
    stanbol/trunk/enhancer/generic/servicesapi/   (props changed)
    
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/impl/AbstractEnhancementEngine.java
    
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Properties.java

Propchange: stanbol/trunk/enhancer/generic/servicesapi/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Oct 30 22:37:50 2012
@@ -0,0 +1,4 @@
+/incubator/stanbol/branches/dbpedia-spotlight-engines/generic/servicesapi:1374978-1386535
+/incubator/stanbol/branches/disambiguation-engine/generic/servicesapi:1377975-1388016
+/incubator/stanbol/trunk/enhancer/generic/servicesapi:1339554,1339557-1339558
+/stanbol/branches/disambiguation-engine/generic/servicesapi:1388017-1403900

Modified: 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java?rev=1403904&r1=1403903&r2=1403904&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
 Tue Oct 30 22:37:50 2012
@@ -16,11 +16,13 @@
 */
 package org.apache.stanbol.enhancer.servicesapi.helper;
 
+import static java.util.Collections.singleton;
 import static 
org.apache.stanbol.enhancer.servicesapi.rdf.Properties.DC_LANGUAGE;
 import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.RDF_TYPE;
 import static 
org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.ENHANCER_TEXTANNOTATION;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
@@ -35,6 +37,7 @@ import org.apache.clerezza.rdf.core.Lite
 import org.apache.clerezza.rdf.core.LiteralFactory;
 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.TripleCollection;
 import org.apache.clerezza.rdf.core.TypedLiteral;
@@ -205,6 +208,23 @@ public class EnhancementEngineHelper {
         return enhancement;
     }
     /**
+     * Adds the parsed {@link EnhancementEngine} as dc:contributer to the
+     * enhancement and also sets the dc:modified property accordingly
+     * @param metadata the {@link ContentItem#getMetadata()}
+     * @param enhancement the enhancement
+     * @param engine the engine
+     */
+    public static void addContributingEngine(MGraph metadata, UriRef 
enhancement,
+                                             EnhancementEngine engine){
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        // TODO: use a public dereferencing URI instead?
+        metadata.add(new TripleImpl(enhancement, Properties.DC_CONTRIBUTOR,
+            literalFactory.createTypedLiteral(engine.getClass().getName())));
+        //set the modification date to the current date.
+        set(metadata,enhancement,Properties.DC_MODIFIED,new 
Date(),literalFactory);
+    }
+    
+    /**
      * Create a new extraction instance in the metadata-graph of the content
      * item along with default properties (dc:creator and dc:created) and 
return
      * the UriRef of the extraction so that engines can further add
@@ -288,6 +308,76 @@ public class EnhancementEngineHelper {
         }
     }
     /**
+     * Replaces all current values of the property for the resource
+     * with the parsed value
+     * @param graph the graph
+     * @param resource the resource
+     * @param property the property
+     * @param value the value
+     */
+    public static void set(MGraph graph, NonLiteral resource, UriRef property, 
Resource value){
+        set(graph,resource,property,value == null ? null : 
singleton(value),null);
+    }
+    /**
+     * Replaces all current values of the property for the resource
+     * with the parsed values
+     * @param graph the graph
+     * @param resource the resource
+     * @param property the property
+     * @param value the value
+     */
+    public static void set(MGraph graph, NonLiteral resource, UriRef property, 
Collection<Resource> values){
+        set(graph,resource,property,values,null);
+    }
+
+    /**
+     * Replaces all current values of the property for the resource
+     * with the parsed value
+     * @param graph the graph
+     * @param resource the resource
+     * @param property the property
+     * @param value the value. In case it is an instance of {@link Resource} it
+     * is directly added to the graph. Otherwise the parsed {@link 
LiteralFactory}
+     * is used to create a {@link TypedLiteral} for the parsed value.
+     * @param literalFactory the {@link LiteralFactory} used in case the parsed
+     * value is not an {@link Resource}
+     */
+    public static void set(MGraph graph, NonLiteral resource, UriRef property,
+                           Object value, LiteralFactory literalFactory){
+        set(graph,resource,property,value == null ? null : 
singleton(value),literalFactory);
+    }
+    /**
+     * Replaces all current values of the property for the resource
+     * with the parsed values
+     * @param graph the graph
+     * @param resource the resource
+     * @param property the property
+     * @param value the value. In case it is an instance of {@link Resource} it
+     * is directly added to the graph. Otherwise the parsed {@link 
LiteralFactory}
+     * is used to create a {@link TypedLiteral} for the parsed value.
+     * @param literalFactory the {@link LiteralFactory} used in case the parsed
+     * value is not an {@link Resource}
+     */
+    public static void set(MGraph graph, NonLiteral resource, UriRef property,
+                               Collection<?> values, LiteralFactory 
literalFactory){
+        Iterator<Triple> currentValues = graph.filter(resource, property, 
null);
+        while(currentValues.hasNext()){
+            currentValues.next();
+            currentValues.remove();
+        }
+        if(values != null){
+            for(Object value : values){
+                if(value instanceof Resource){
+                    graph.add(new TripleImpl(resource, property, (Resource) 
value));
+                } else if (value != null){
+                    graph.add(new TripleImpl(resource, property, 
+                        literalFactory.createTypedLiteral(value)));
+                }
+            }
+        }
+    }
+    
+    /**
      * Getter for the typed literal values of the property for a resource
      * @param <T> the java class the literal value needs to be converted to.
      * Note that the parsed LiteralFactory needs to support this conversion

Modified: 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java?rev=1403904&r1=1403903&r2=1403904&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/impl/AbstractEnhancementEngine.java
 Tue Oct 30 22:37:50 2012
@@ -93,4 +93,12 @@ public abstract class AbstractEnhancemen
     public final String getName(){
         return name;
     }
+    /**
+     * Prints the simple name of the Class and the configured Name.
+     */
+    @Override
+    public String toString() {
+        return String.format("%s(name=%s)", getClass().getSimpleName(),name);
+    }
+
 }

Modified: 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Properties.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Properties.java?rev=1403904&r1=1403903&r2=1403904&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Properties.java
 (original)
+++ 
stanbol/trunk/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/rdf/Properties.java
 Tue Oct 30 22:37:50 2012
@@ -61,11 +61,27 @@ public class Properties {
             + "created");
 
     /**
+     * Modification date of a resource. Used by Stanbol Enhancer to annotate 
the 
+     * modification date of the enhancement if it was changed by an other
+     * enhancement engine as the one creating it. Multiple changes of the
+     * creating enhancement engines are not considered as modifications.
+     */
+    public static final UriRef DC_MODIFIED = new UriRef(NamespaceEnum.dc
+            + "modified");
+
+    /**
      * The entity responsible for the creation of a resource. Used by Stanbol 
Enhancer to
      * annotate the enhancement engine that created an enhancement
      */
     public static final UriRef DC_CREATOR = new UriRef(NamespaceEnum.dc
             + "creator");
+    /**
+     * The entity contributed to a resource. Used by Stanbol Enhancer to
+     * annotate the enhancement engine that changed an enhancement originally
+     * created by an other enhancemetn engine
+     */
+    public static final UriRef DC_CONTRIBUTOR = new UriRef(NamespaceEnum.dc
+            + "contributor");
 
     /**
      * The nature or genre of the resource. Stanbol Enhancer uses this 
property to refer to


Reply via email to