You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by bd...@apache.org on 2011/04/01 18:57:44 UTC

svn commit: r1087804 - in /incubator/stanbol/trunk/enhancer: ./ benchmark/ benchmark/src/ benchmark/src/main/ benchmark/src/main/java/ benchmark/src/main/java/org/ benchmark/src/main/java/org/apache/ benchmark/src/main/java/org/apache/stanbol/ benchmar...

Author: bdelacretaz
Date: Fri Apr  1 16:57:43 2011
New Revision: 1087804

URL: http://svn.apache.org/viewvc?rev=1087804&view=rev
Log:
STANBOL-138 - enhancer benchmark tool, work in progress: engine mostly ok, basic presentation

Added:
    incubator/stanbol/trunk/enhancer/benchmark/   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/pom.xml   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/test/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/
    incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt   (with props)
Modified:
    incubator/stanbol/trunk/enhancer/pom.xml

Propchange: incubator/stanbol/trunk/enhancer/benchmark/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Apr  1 16:57:43 2011
@@ -0,0 +1,12 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+sling
+

Added: incubator/stanbol/trunk/enhancer/benchmark/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/pom.xml?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/pom.xml (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/pom.xml Fri Apr  1 16:57:43 2011
@@ -0,0 +1,92 @@
+<?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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.stanbol</groupId>
+        <artifactId>org.apache.stanbol.enhancer.parent</artifactId>
+        <version>${stanbol-version}</version>
+        <relativePath>../parent/pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>org.apache.stanbol.enhancer.benchmark</artifactId>
+    <version>${stanbol-version}</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Stanbol Enhancer Benchmark</name>
+    <scm>
+        <connection>
+            scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/enhancer/benchmark/
+        </connection>
+        <developerConnection>
+            scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/enhancer/benchmark/
+        </developerConnection>
+        <url>http://incubator.apache.org/stanbol/</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.stanbol.enhancer.benchmark
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.stanbol.enhancer.benchmark.impl.*
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>org.apache.clerezza.rdf.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.stanbol</groupId>
+            <artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Propchange: incubator/stanbol/trunk/enhancer/benchmark/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark;
+
+import java.util.List;
+
+/** A Benchmark is a named List of {@link TripleMatcherGroup} */
+public interface Benchmark extends List<TripleMatcherGroup >{
+    /** Benchmark name */
+    String getName();
+    
+    /** Benchmark input text */
+    String getInputText();
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark;
+
+import java.io.Writer;
+
+public interface BenchmarkEngine {
+    /** Run supplied benchmarks and write results to output */
+    void runBenchmark(String benchmarks, Writer output) throws Exception;
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.List;
+
+public interface BenchmarkParser {
+    
+    // Marker strings in the benchmark text input
+    static final String COMMENT_MARKER = "#";
+    static final String FIELD_SEPARATOR = ":";
+    static final String INPUT_SECTION_MARKER = "= INPUT =";  
+    static final String EXPECT_SECTION_MARKER = "= EXPECT =";  
+    static final String COMPLAIN_SECTION_MARKER = "= COMPLAIN =";  
+    static final String DESCRIPTION_FIELD = "Description";
+    
+    /** Parse the supplied text in a List of Benchmark
+     * 
+     *  @param r is closed by this method after parsing or failure
+     *  @throws IOException on I/O or syntax error
+     */
+    List<? extends Benchmark> parse(Reader r) throws IOException;
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkParser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark;
+
+import org.apache.clerezza.rdf.core.Triple;
+
+/** TripleMatcher is used to count how many Triples
+ *  match a given statement in the benchmark tool.
+ *  
+ *  TripleMatchers are usually parsed from expressions like
+ *  <pre>
+ *  http://somePredicate URI http://someURI
+ *  </pre>
+ *  or
+ *  <pre>
+ *  http://somePredicate REGEXP someRegularExpression
+ *  </pre>
+ *  
+ *  Which look for triples which have the specified predicate
+ *  and an Object that matches the rest of the expression using
+ *  the specified matching operator (URI, REGEXP etc).
+ *  
+ *  The parsing is not part of this interface, it's an implementation
+ *  concern.
+ */
+public interface TripleMatcher {
+    boolean matches(Triple t);
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcher.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.UriRef;
+
+/** A group of TripleMatcher, used to check that 
+ *  enhancements match all the TripleMatcher in 
+ *  the group. 
+ */
+public interface TripleMatcherGroup {
+    /** @return this group's description */
+    String getDescription();
+    
+    /** An "expect" group is expected to be found in
+     *  the input, whereas non-expect ("complain") groups
+     *  should not be found 
+     */
+    boolean isExpectGroup();
+    
+    /** Return the set of UriRef that match all
+     *  TripleMatcher in this group for supplied Graph
+     */
+    Set<UriRef> getMatchingSubjects(Graph g);
+    
+    /** @return our TripleMatcher */
+    Collection<TripleMatcher> getMatchers();
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/TripleMatcherGroup.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.RuntimeErrorException;
+import javax.servlet.ServletException;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkEngine;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkParser;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
+import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+
+@Component(immediate=false)
+@Service
+public class BenchmarkEngineImpl implements BenchmarkEngine {
+
+    public static final String ENCODING = "UTF-8";
+    
+    @Reference
+    private EnhancementJobManager jobManager;
+    
+    @Reference 
+    private BenchmarkParser parser;
+
+    @Override
+    public void runBenchmark(String benchmarkText, Writer output) throws Exception {
+        final PrintWriter pw = new PrintWriter(output);
+        
+        // TODO better formatting
+        pw.println("<pre>");
+        
+        try {
+            final List<? extends Benchmark> benchmarks = 
+                parser.parse(new StringReader(benchmarkText));
+            
+            if(benchmarks.isEmpty()) {
+                throw new ServletException(
+                        "No valid benchmarks found in input [" 
+                        + benchmarkText + "]"); 
+            }
+            
+            for(Benchmark b : benchmarks) {
+                // TODO move this to benchmark class
+                // TODO Benchmark should validate itself
+                final ContentItem ci = new InMemoryContentItem(b.getInputText().getBytes(), "text/plain");
+                jobManager.enhanceContent(ci);
+                pw.println("BENCHMARK:" + b.getName());
+                for(TripleMatcherGroup g :  b) {
+                    final Set<UriRef> s = g.getMatchingSubjects(ci.getMetadata().getGraph());
+                    if(g.isExpectGroup()) {
+                        if(s.size() == 1) {
+                            pw.print("EXPECT OK: " + g.getDescription());
+                        } else {
+                            pw.print("**ERROR** EXPECT FAILED: " + g.getDescription());
+                        }
+                    } else {
+                        if(s.size() > 0) {
+                            pw.print("**ERROR** COMPLAIN: " + s.size() + " matches for group " + g.getDescription()); 
+                        } else {
+                            pw.print("NO COMPLAINTS: " + g.getDescription()); 
+                        }
+                    } 
+                    pw.println(" (" + s.size() + " matches)");
+                }
+                pw.println("END OF BENCHMARK:" + b.getName());
+                pw.flush();
+            }
+
+        } finally {
+            pw.println("</pre>");
+            pw.flush();
+        }
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.util.LinkedList;
+
+import org.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+
+@SuppressWarnings("serial")
+public class BenchmarkImpl extends LinkedList<TripleMatcherGroup> implements Benchmark {
+    
+    private String name;
+    private String inputText;
+    
+    /** Not public: meant to be constructed by parsing */
+    BenchmarkImpl() {
+    }
+    
+    void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    void setInputText(String inputText) {
+        this.inputText = inputText;
+    }
+    
+    @Override
+    public String getInputText() {
+        return inputText;
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkParser;
+
+/** BenchmarkParser implementation */
+@Component
+@Service
+public class BenchmarkParserImpl implements BenchmarkParser {
+
+    private static class ParserContext {
+        List<BenchmarkImpl> benchmarks;
+        BenchmarkImpl currentBenchmark;
+        TripleMatcherGroupImpl currentGroup;
+    }
+    
+    private static abstract class State {
+        protected final ParserContext ctx;
+        
+        State(ParserContext ctx) {
+            this.ctx = ctx;
+        }
+        
+        State read(String line) throws IOException {
+            if(line != null) {
+                line = line.trim();
+                if(line.length() > 0 && !line.startsWith(COMMENT_MARKER)) {
+                    // Switch states on marker lines, or let current state
+                    // parse current line
+                    if(INPUT_SECTION_MARKER.equals(line)) {
+                        return new InputState(ctx);
+                    } else if(EXPECT_SECTION_MARKER.equals(line)) {
+                        return new MatcherGroupState(ctx, true);
+                    } else if(COMPLAIN_SECTION_MARKER.equals(line)) {
+                        return new MatcherGroupState(ctx, false);
+                    } else {
+                        return consume(line);
+                    }
+                }
+            }
+            return this;
+        }
+        
+        /** Get field value if current line is in the form "KEY: value here",
+         *  null if not.
+         */
+        protected static String getField(String line, String fieldName) {
+            String value = null;
+            if(line.startsWith(fieldName + FIELD_SEPARATOR)) {
+                value = line.substring(line.indexOf(FIELD_SEPARATOR) + 1).trim();
+            }
+            return value;
+        }
+        
+        /** Consume supplied line and return the next state 
+         *  (which might this one if no state change is needed) 
+         */
+        protected abstract State consume(String line) throws IOException;
+    };
+    
+    private static class InitState extends State {
+        InitState(ParserContext ctx) {
+            super(ctx);
+        }
+        
+        protected State consume(String line) {
+            return this;
+        }
+    };
+    
+    private static class InputState extends State {
+        InputState(ParserContext ctx) {
+            super(ctx);
+            ctx.currentBenchmark = new BenchmarkImpl();
+            ctx.benchmarks.add(ctx.currentBenchmark);
+        }
+        
+        protected State consume(String line) {
+            // Add all lines to the benchmark's input text,
+            // separated by one space
+            final String cur = ctx.currentBenchmark.getInputText();
+            if(cur == null) {
+                ctx.currentBenchmark.setInputText(line);
+            } else {
+                ctx.currentBenchmark.setInputText(cur + " " + line);
+            }
+            return this;
+        }
+    };
+    
+    private static class MatcherGroupState extends State {
+        private final boolean isExpect;
+        
+        MatcherGroupState(ParserContext ctx, boolean isExpect) {
+            super(ctx);
+            this.isExpect = isExpect;
+        }
+        
+        protected State consume(String line) throws IOException {
+            // Description field starts a new group
+            final String desc = getField(line, DESCRIPTION_FIELD);
+            if(desc != null) {
+                ctx.currentGroup = new TripleMatcherGroupImpl(isExpect, desc);
+                ctx.currentBenchmark.add(ctx.currentGroup);
+            } else {
+                // Each line is a new matcher
+                ctx.currentGroup.addMatcher(new TripleMatcherImpl(line));
+            }
+            return this;
+        }
+    }
+    
+    @Override
+    public List<? extends Benchmark> parse(Reader r) throws IOException {
+        final BufferedReader br = new BufferedReader(r);
+        final ParserContext ctx = new ParserContext();
+        ctx.benchmarks = new ArrayList<BenchmarkImpl>();
+        State state = new InitState(ctx);
+        
+        try {
+            String line = null;
+            while( (line = br.readLine()) != null) {
+                state = state.read(line);
+            }
+        } finally {
+            br.close();
+        }
+        
+        return ctx.benchmarks;
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkParserImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkEngine;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Front-end servlet for the benchmark module */
+@Component(immediate=true, metatype=false)
+@SuppressWarnings("serial")
+public class BenchmarkServlet extends HttpServlet {
+    
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Reference
+    private HttpService httpService;
+    
+    @Reference
+    private BenchmarkEngine benchmarkEngine;
+    
+    public static final String PARAM_CONTENT = "content";
+    public static final String DEFAULT_MOUNT_PATH = "/benchmark";
+    
+    @Property(value=DEFAULT_MOUNT_PATH)
+    public static final String MOUNT_PATH_PROPERTY = "mount.path";
+    private String mountPath; 
+
+    // TODO temp example
+    public static final String EXAMPLE =
+        "= INPUT =\n"
+        + "# Comments such as this one are ignored\n"
+        + "# This is the enhancer input, can be split on several lines\n"
+        + "Bob\n"
+        + "Marley was born in Kingston, Jamaica.\n"
+        + "\n"
+        + "= EXPECT =\n"
+        + "# EXPECT defines groups of predicate/object matchers that we expect to find in the output\n"
+        + "# Each group applies to one given enhancement: for the expectation to succeed, at least\n"
+        + "# one enhancement must match all lines in the group\n"
+        + "\n"
+        + "Description: Kingston must be found\n"
+        + "http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Kingston%2C_Jamaica\n"
+        + "\n"
+        + "Description: This one should fail\n"
+        + "http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Basel\n"
+        + "\n"
+        + "# The description: line starts a new group\n"
+        + "Description: Bob Marley must be found as a musical artist\n"
+        + "http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist\n"
+        + "http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Bob_Marley\n"
+        + "\n"
+        + "= COMPLAIN =\n"
+        + "\n"
+        + "Description: Miles Davis must not be found\n"
+        + "http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist\n"
+        + "http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Miles_Davis\n"
+        + "\n"
+        + "Description: Bob Marley in the COMPLAIN section should fail\n"
+        + "http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist\n"
+        + "http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Bob_Marley\n"
+    ;
+        
+    /** Register with HttpService when activated */
+    public void activate(ComponentContext ctx) throws ServletException, NamespaceException {
+        mountPath = (String)ctx.getProperties().get(MOUNT_PATH_PROPERTY);
+        if(mountPath == null) {
+            mountPath = DEFAULT_MOUNT_PATH;
+        }
+        
+        httpService.registerServlet(mountPath, this, null, null);
+        log.info("Servlet mounted at {}", mountPath);
+    }
+    
+    public void deactivate(ComponentContext ctx) {
+        httpService.unregister(mountPath);
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
+    throws ServletException, IOException {
+        
+        // TODO need a nicer page...
+        final StringBuilder sb = new StringBuilder();
+        sb.append("<html><body>");
+        sb.append("<form method='POST'>");
+        sb.append("<input type='submit'/><br/>");
+        sb.append("<textarea name='content' rows='60' cols='120'>" + EXAMPLE + "</textarea>");
+        sb.append("</form>");
+        sb.append("</body></html>");
+        
+        response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
+        response.getWriter().write(sb.toString());
+    }
+    
+    @Override
+    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
+    throws ServletException, IOException {
+        final String content = request.getParameter(PARAM_CONTENT);
+        if(content == null) {
+            throw new ServletException("Missing " + PARAM_CONTENT + " parameter");
+        }
+        
+        response.setContentType("text/html");
+        response.setCharacterEncoding("UTF-8");
+        
+        try {
+            benchmarkEngine.runBenchmark(content, response.getWriter());
+        } catch(Exception e) {
+            // TODO better error reporting
+            log.error("Exception in runBenchmark", e);
+            response.getWriter().write(e.toString());
+        }
+  }
+ }
\ No newline at end of file

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcher;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+
+public class TripleMatcherGroupImpl implements TripleMatcherGroup {
+
+    private List<TripleMatcher> matchers = new ArrayList<TripleMatcher>();
+    private boolean isExpect;
+    private String description;
+    
+    TripleMatcherGroupImpl(boolean isExpect, String description) {
+        this.isExpect = isExpect;
+        this.description = description;
+    }
+     
+    void addMatcher(TripleMatcher m) {
+        matchers.add(m);
+    }
+
+    @Override
+    public String toString() {
+         return getClass().getSimpleName() + " (" + description + ")";
+    }
+
+    @Override
+    public boolean isExpectGroup() {
+        return isExpect;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+    
+    @Override
+    public Set<UriRef> getMatchingSubjects(Graph g) {
+        if(matchers.isEmpty()) {
+            return new HashSet<UriRef>();
+        }
+
+        // For all matchers, find the set of subjects that match
+        // and compute the intersection of those sets
+        Set<UriRef> intersection = null;
+        for(TripleMatcher m : matchers) {
+            final Set<UriRef> s = new HashSet<UriRef>();
+            final Iterator<Triple> it = g.iterator();
+            while(it.hasNext()) {
+                final Triple t = it.next();
+                if(m.matches(t)) {
+                    final NonLiteral n = t.getSubject();
+                    if(n instanceof UriRef) {
+                        s.add((UriRef)n);
+                    } else {
+                        // TODO do we need to handle non-UriRef subjects?
+                    }
+                }
+            }
+            
+            if(intersection == null) {
+                intersection = s;
+            } else {
+                intersection.retainAll(s);
+            }
+        }
+        
+        return intersection;
+    }
+
+    @Override
+    public Collection<TripleMatcher> getMatchers() {
+        return matchers;
+    }
+}
\ No newline at end of file

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.io.IOException;
+
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcher;
+
+class TripleMatcherImpl implements TripleMatcher {
+
+    private final String operator;
+    private final UriRef predicateUri;
+    private final UriRef objectUri;
+    
+    /** Build from a line supplied by the parser.
+     *  Format is PREDICATE_URI OPERATOR ARGUMENTS, 
+     */
+    TripleMatcherImpl(String line) throws IOException {
+        final String [] parts = line.split(" ");
+        if(parts.length < 3) {
+            throw new IOException("Invalid TripleMatcher format in line [" + line + "]");
+        }
+        
+        predicateUri = new UriRef(parts[0]);
+        
+        operator = parts[1];
+        if("URI".equals(operator)) {
+            objectUri = new UriRef(parts[2]);
+        } else {
+            // TODO support other operators
+            objectUri = null;
+        }
+    }
+    
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " (" + predicateUri + " " + operator + " " + objectUri + ")";
+    }
+    
+    @Override
+    public boolean matches(Triple t) {
+        return 
+            objectUri != null
+            && t.getPredicate().equals(predicateUri)
+            && t.getObject().equals(objectUri)
+        ;
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,131 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BasicBenchmarkParserTest {
+
+    public static final String RESOURCE_ENCODING = "UTF-8";
+    private List<? extends Benchmark> benchmarks;
+    
+    @Before
+    public void parse() throws IOException {
+        benchmarks = new BenchmarkParserImpl().parse(getTestBenchmark("/benchmarks/benchmark1.txt"));
+    }
+    
+    private Reader getTestBenchmark(String path) {
+        final InputStream is = BasicBenchmarkParserTest.class.getResourceAsStream(path);
+        if(is == null) {
+            throw new IllegalArgumentException("Cannot read resource [" + path + "]");
+        }
+        
+        try {
+            return new InputStreamReader(is, RESOURCE_ENCODING);
+        } catch (UnsupportedEncodingException e) {
+            throw new Error("Unsupported encoding?? " + RESOURCE_ENCODING, e);
+        }
+    }
+    
+    @Test
+    public void testStructureAndDescriptions() throws Exception {
+        assertEquals("Number of benchmarks", 2, benchmarks.size());
+        
+        final Iterator<? extends Benchmark> bit = benchmarks.iterator();
+        {
+            final Benchmark b = bit.next();
+            assertEquals("Bob Marley was born in Kingston, Jamaica.", b.getInputText()); 
+            assertEquals("First benchmark group count", 2, b.size());
+            final Iterator<TripleMatcherGroup> git = b.iterator();
+            assertEquals("Kingston must be found", git.next().getDescription());
+            assertEquals("Bob Marley must be found as a musical artist", git.next().getDescription());
+            assertFalse(git.hasNext());
+        }
+        
+        {
+            final Benchmark b = bit.next();
+            assertEquals("Paris Hilton might live in Paris, but she prefers New York.", b.getInputText()); 
+            assertEquals("Second benchmark group count", 5, b.size());
+            final Iterator<TripleMatcherGroup> git = b.iterator();
+            for(int i=1; i <= 5; i++) {
+                assertEquals("Second benchmark group " + i, git.next().getDescription());
+            }
+            assertFalse(git.hasNext());
+        }
+    }
+
+    @Test
+    public void testExpectComplain() throws Exception {
+        assertEquals("Number of benchmarks", 2, benchmarks.size());
+        
+        final Iterator<? extends Benchmark> bit = benchmarks.iterator();
+        {
+            // First benchmark has two expect groups and no complains
+            final Iterator<TripleMatcherGroup> git = bit.next().iterator();
+            assertTrue(git.next().isExpectGroup());
+            assertTrue(git.next().isExpectGroup());
+            assertFalse(git.hasNext());
+        }
+        {
+            // Second benchmark has 3 expect groups and 2 complains
+            final Iterator<TripleMatcherGroup> git = bit.next().iterator();
+            assertTrue(git.next().isExpectGroup());
+            assertTrue(git.next().isExpectGroup());
+            assertTrue(git.next().isExpectGroup());
+            assertFalse(git.next().isExpectGroup());
+            assertFalse(git.next().isExpectGroup());
+            assertFalse(git.hasNext());
+        }
+    }
+    
+    @Test
+    public void testMatcherCount() throws Exception {
+        assertEquals("Number of benchmarks", 2, benchmarks.size());
+        
+        final Iterator<? extends Benchmark> bit = benchmarks.iterator();
+        
+        // Number of matchers in each group of each benchmark
+        final int [][] matchersCount = {
+                { 2, 3 },
+                { 1, 2, 3, 2, 1 }
+        };
+        
+        for(int [] counts : matchersCount) {
+            final Iterator<TripleMatcherGroup> git = bit.next().iterator();
+            for(int count : counts) {
+                assertTrue("Iterator has more data at count=" + count, git.hasNext());
+                final TripleMatcherGroup g = git.next();
+                assertEquals("Matchers count matches for " + g, count, g.getMatchers().size());
+            }
+        }
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/BasicBenchmarkParserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class TripleMatcherGroupImplTest {
+    private MGraph graph;
+    
+    @Before
+    public void createGraph() {
+        graph = new SimpleMGraph();
+        graph.add(TripleUtil.uriTriple("S1", "P1", "01"));
+        graph.add(TripleUtil.uriTriple("S1", "P1", "02"));
+        graph.add(TripleUtil.uriTriple("S2", "P1", "01"));
+        graph.add(TripleUtil.uriTriple("S2", "P1", "02"));
+        graph.add(TripleUtil.uriTriple("S3", "P1", "01"));
+        graph.add(TripleUtil.uriTriple("S4", "P1", "02"));
+    }
+    
+    @Test
+    public void basicTest() throws Exception {
+        final TripleMatcherGroupImpl group = new TripleMatcherGroupImpl(true, "no description");
+        
+        assertEquals(
+                "Empty matcher group should find nothing",
+                0,
+                group.getMatchingSubjects(graph.getGraph()).size());
+        
+        // Add two matchers, only S1 and S2 match all of them
+        group.addMatcher(new TripleMatcherImpl("P1 URI 01"));
+        group.addMatcher(new TripleMatcherImpl("P1 URI 02"));
+        
+        final Set<UriRef> actual = group.getMatchingSubjects(graph.getGraph());
+        final Set<UriRef> expected = TripleUtil.uriRefSet("S1", "S2");
+        
+        assertEquals("Size of results " + actual + " matches " + expected, expected.size(), actual.size());
+        assertTrue("Content of results " + actual + " matches " + expected, expected.containsAll(actual));
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherGroupImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class TripleMatcherImplTest {
+    
+    @Test
+    public void testMatches() throws Exception {
+        final TripleMatcherImpl m = new TripleMatcherImpl("FOO URI BAR");
+        assertTrue(m.matches(TripleUtil.uriTriple("me","FOO","BAR")));
+        assertTrue(m.matches(TripleUtil.uriTriple("you","FOO","BAR")));
+        assertFalse(m.matches(TripleUtil.uriTriple("me","wii","BAR")));
+        assertFalse(m.matches(TripleUtil.uriTriple("me","FOO","wii")));
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleMatcherImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java Fri Apr  1 16:57:43 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+package org.apache.stanbol.enhancer.benchmark.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+
+public class TripleUtil {
+    static Triple uriTriple(String subject, String predicate, String object) {
+        return new TripleImpl(new UriRef(subject), new UriRef(predicate), new UriRef(object));
+    }
+    
+    static Set<UriRef> uriRefSet(String...uri) {
+        final Set<UriRef> result = new HashSet<UriRef>();
+        for(String str : uri) {
+            result.add(new UriRef(str));
+        }
+        return result;
+    }
+}

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/java/org/apache/stanbol/enhancer/benchmark/impl/TripleUtil.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt?rev=1087804&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt Fri Apr  1 16:57:43 2011
@@ -0,0 +1,53 @@
+# Stanbol enhancer benchmark example
+
+= INPUT =
+Bob Marley was born in Kingston, Jamaica. 
+
+= EXPECT = 
+# Comments such as this one are ignored 
+# EXPECT defines groups of predicate/object matchers that we expect to find in the output 
+# Each group applies to one given enhancement: for the expectation to succeed, at least 
+# one enhancement must match all lines in the group
+Description: Kingston must be found 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Kingston%2C_Jamaica 
+http://purl.org/dc/terms/creator REGEXP org.apache..*ReferencedSiteEntityTaggingEnhancementEngine 
+
+# The description: line starts a new group 
+Description: Bob Marley must be found as a musical artist 
+http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Bob_Marley 
+http://purl.org/dc/terms/creator REGEXP org.apache.*EntityMentionEnhancementEngine 
+
+= COMPLAIN = 
+
+# COMPLAIN statements are similar to EXPECT but we expect them *not* to be fulfilled by 
+# the enhancer output.
+# There are none in this example 
+
+
+# INPUT starts a new benchmark
+= INPUT =
+Paris Hilton might live in Paris, but
+she prefers New York. 
+
+= EXPECT = 
+Description: Second benchmark group 1 
+http://fise.iks-project.eu/ontology/entity-reference URI http://example.com/foo 
+
+Description: Second benchmark group 2 
+http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Miles_Davis 
+
+Description: Second benchmark group 3 
+http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Miles_Davis 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/FOO 
+
+= COMPLAIN = 
+Description: Second benchmark group 4 
+http://fise.iks-project.eu/ontology/entity-type URI http://dbpedia.org/ontology/MusicalArtist 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Miles_Davis 
+
+Description: Second benchmark group 5 
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Miles_Davis 
+

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/test/resources/benchmarks/benchmark1.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/stanbol/trunk/enhancer/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/pom.xml?rev=1087804&r1=1087803&r2=1087804&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/pom.xml (original)
+++ incubator/stanbol/trunk/enhancer/pom.xml Fri Apr  1 16:57:43 2011
@@ -61,6 +61,7 @@
     <module>engines/zemanta</module>
 
     <module>jersey</module>
+    <module>benchmark</module>
 
     <module>clerezza/org.apache.stanbol.enhancer.clerezza</module>
     <module>clerezza/clerezza-sparql</module>