Author: reto
Date: Tue Mar  5 03:33:33 2013
New Revision: 1452651

URL: http://svn.apache.org/r1452651
Log:
STANBOL-973: added archetype to create enhanement engines

Added:
    stanbol/trunk/development/archetypes/enhancement-engine/
    stanbol/trunk/development/archetypes/enhancement-engine/pom.xml
    stanbol/trunk/development/archetypes/enhancement-engine/src/
    stanbol/trunk/development/archetypes/enhancement-engine/src/main/
    stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/archetype-metadata.xml
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/README.md
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/nbactions.xml
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/pom.xml
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/
    
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/ExampleEnhancer.java
Modified:
    stanbol/trunk/pom.xml

Added: stanbol/trunk/development/archetypes/enhancement-engine/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/pom.xml?rev=1452651&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/enhancement-engine/pom.xml (added)
+++ stanbol/trunk/development/archetypes/enhancement-engine/pom.xml Tue Mar  5 
03:33:33 2013
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>enhancer-engine-archetype</artifactId>
+  <version>0.12.0-SNAPSHOT</version>
+  
+  <packaging>maven-archetype</packaging>
+
+  <name>Apache Stanbol Enhancer Engine Archetype</name>
+
+  <build>
+    <plugins>
+        <plugin>
+            <groupId>org.apache.rat</groupId>
+            <artifactId>apache-rat-plugin</artifactId>
+            <configuration>
+                <excludeSubProjects>false</excludeSubProjects>
+                <excludes>
+                    <!--
+                      The artifact files do not contain copyright notices
+                      as the generated skeleton shall not contain any such
+                      notice
+                    -->
+                    
<exclude>src/main/resources/archetype-resources/**</exclude>
+                </excludes>
+            </configuration>
+        </plugin>
+    </plugins>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.archetype</groupId>
+        <artifactId>archetype-packaging</artifactId>
+        <version>2.2</version>
+      </extension>
+    </extensions>
+
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-archetype-plugin</artifactId>
+          <version>2.2</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

Added: 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/archetype-metadata.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/archetype-metadata.xml?rev=1452651&view=auto
==============================================================================
--- 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/archetype-metadata.xml
 (added)
+++ 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/META-INF/maven/archetype-metadata.xml
 Tue Mar  5 03:33:33 2013
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor 
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"; 
name="example-engine"
+    
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+  <fileSets>
+    <fileSet filtered="true" packaged="true" encoding="UTF-8">
+      <directory>src/main/java</directory>
+      <includes>
+        <include>**/*.java</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory>src/main/assembly</directory>
+      <includes>
+        <include>**/*.xml</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory></directory>
+      <includes>
+        <include>nbactions.xml</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</archetype-descriptor>

Added: 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/README.md
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/README.md?rev=1452651&view=auto
==============================================================================
--- 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/README.md
 (added)
+++ 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/README.md
 Tue Mar  5 03:33:33 2013
@@ -0,0 +1,17 @@
+Example Apache Stanbol Enhancement Engine
+======
+
+This provides an example engine. The engine will add an ennnoation with a 
+rdfs:comment property to a sentence containing the number of charactes in
+the annotated document (e.g. "A text of 6 charaters" ) .
+
+To compile the engine run
+
+    mvn install
+
+To deploy the engine to a stanbol instance running on localhost port 8080 run
+
+    mvn org.apache.sling:maven-sling-plugin:install
+
+To see you engine in action you may use 
+http://localhost:8080/enhancer/chain/all-active to enhance an arbitrary text.
\ No newline at end of file

Added: 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/nbactions.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/nbactions.xml?rev=1452651&view=auto
==============================================================================
--- 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/nbactions.xml
 (added)
+++ 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/nbactions.xml
 Tue Mar  5 03:33:33 2013
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+  <action>
+    <actionName>CUSTOM-deploy to localhost:8080</actionName>
+    <displayName>deploy to localhost:8080</displayName>
+    <goals>
+      <goal>install</goal>
+      <goal>org.apache.sling:maven-sling-plugin:install</goal>
+    </goals>
+  </action>
+</actions>

Added: 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/pom.xml?rev=1452651&view=auto
==============================================================================
--- 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/pom.xml
 (added)
+++ 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/pom.xml
 Tue Mar  5 03:33:33 2013
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>${groupId}</groupId>
+  <artifactId>${artifactId}</artifactId>
+  <version>${version}</version>
+  <packaging>bundle</packaging>
+
+  <name>Skeleton for ${artifactId}</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>1.4.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
+      <version>0.10.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+      <version>1.7.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.clerezza</groupId>
+      <artifactId>rdf.ontologies</artifactId>
+      <version>0.11-incubating</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <extensions>true</extensions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+        <version>1.9.0</version>
+        <executions>
+          <execution>
+            <id>generate-scr-scrdescriptor</id>
+            <goals>
+              <goal>scr</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/ExampleEnhancer.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/ExampleEnhancer.java?rev=1452651&view=auto
==============================================================================
--- 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/ExampleEnhancer.java
 (added)
+++ 
stanbol/trunk/development/archetypes/enhancement-engine/src/main/resources/archetype-resources/src/main/java/ExampleEnhancer.java
 Tue Mar  5 03:33:33 2013
@@ -0,0 +1,91 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+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.InvalidContentException;
+import org.apache.stanbol.enhancer.servicesapi.ServiceProperties;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
+import org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper;
+import org.apache.stanbol.enhancer.servicesapi.impl.AbstractEnhancementEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true, metatype = true, inherit = true)
+@Service
+@Properties(value = {
+    @Property(name = EnhancementEngine.PROPERTY_NAME, value = 
"${artifactId}-example")
+})
+public class ExampleEnhancer extends AbstractEnhancementEngine
+        implements EnhancementEngine, ServiceProperties {
+
+    /**
+     * Using slf4j for logging
+     */
+    private static final Logger log = 
LoggerFactory.getLogger(ExampleEnhancer.class);
+
+    /**
+     * Default ordering means that ths engine is called after all engines that
+     * use a value within the ordering range defined by
+     * {@link ServiceProperties${symbol_pound}ORDERING_EXTRACTION_ENHANCEMENT} 
and what that
+     * the latter means will hoefully become clear with STANBOL-967
+     */
+    public Map getServiceProperties() {
+        return Collections.unmodifiableMap(Collections.singletonMap(
+                ENHANCEMENT_ENGINE_ORDERING, ORDERING_DEFAULT));
+    }
+
+    /**
+     * @return if and how (asynchronously) we can enhance a ContentItem
+     */
+    public int canEnhance(ContentItem ci) throws EngineException {
+        // check if content is present
+        try {
+            if ((ci.getBlob() == null)
+                    || (ci.getBlob().getStream().read() == -1)) {
+                return CANNOT_ENHANCE;
+            }
+        } catch (IOException e) {
+            log.error("Failed to get the text for "
+                    + "enhancement of content: " + ci.getUri(), e);
+            throw new InvalidContentException(this, ci, e);
+        }
+        // no reason why we should require to be executed synchronously
+        return ENHANCE_ASYNC;
+    }
+
+    public void computeEnhancements(ContentItem ci) throws EngineException {
+        try {
+            //get the (generated or submitted) text version of the ContentItem
+            Blob textBlob =
+                    ContentItemHelper.getBlob(ci,
+                    Collections.singleton("text/plain")).getValue();
+            String content = ContentItemHelper.getText(textBlob);
+            // get the metadata graph
+            MGraph metadata = ci.getMetadata();
+            // update some sample data
+            UriRef textAnnotation = 
EnhancementEngineHelper.createTextEnhancement(ci, this);
+            metadata.add(new TripleImpl(textAnnotation, RDFS.comment,
+                    new PlainLiteralImpl("A text of " + content.length() + " 
charaters")));
+        } catch (IOException ex) {
+            log.error("Exception reading content item.", ex);
+            throw new InvalidContentException("Exception reading content 
item.", ex);
+        }
+    }
+}

Modified: stanbol/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/pom.xml?rev=1452651&r1=1452650&r2=1452651&view=diff
==============================================================================
--- stanbol/trunk/pom.xml (original)
+++ stanbol/trunk/pom.xml Tue Mar  5 03:33:33 2013
@@ -87,6 +87,7 @@
     <module>launchers/full-war</module>
     
     <module>development/archetypes/statefull-webmodule</module>
+    <module>development/archetypes/enhancement-engine</module>
   </modules>
 
   <profiles>


Reply via email to