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/05 15:10:52 UTC

svn commit: r1089025 - in /incubator/stanbol/trunk/enhancer/benchmark: ./ src/main/java/org/apache/stanbol/enhancer/benchmark/impl/ src/main/resources/examples/ src/main/resources/velocity/

Author: bdelacretaz
Date: Tue Apr  5 13:10:52 2011
New Revision: 1089025

URL: http://svn.apache.org/viewvc?rev=1089025&view=rev
Log:
STANBOL-138 - example benchmarks added

Added:
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt   (with props)
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt   (with props)
Modified:
    incubator/stanbol/trunk/enhancer/benchmark/pom.xml
    incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-input.html
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-results.html
    incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark.css

Modified: incubator/stanbol/trunk/enhancer/benchmark/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/pom.xml?rev=1089025&r1=1089024&r2=1089025&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/pom.xml (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/pom.xml Tue Apr  5 13:10:52 2011
@@ -113,6 +113,10 @@
             <version>1.7</version>
         </dependency>
         <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.velocity</groupId>
             <artifactId>velocity-tools</artifactId>
             <version>2.0</version>

Modified: 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=1089025&r1=1089024&r2=1089025&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java Tue Apr  5 13:10:52 2011
@@ -17,7 +17,11 @@
 package org.apache.stanbol.enhancer.benchmark.impl;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Properties;
 
 import javax.servlet.ServletException;
@@ -25,6 +29,8 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.LineIterator;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
@@ -58,6 +64,8 @@ public class BenchmarkServlet extends Ht
     
     public static final String PARAM_CONTENT = "content";
     public static final String DEFAULT_MOUNT_PATH = "/benchmark";
+    public static final String DEFAULT_BENCHMARK = "default.txt";
+    public static final String EXAMPLE_BENCHMARKS_RESOURCE_ROOT = "/examples";
     
     @Property(value=DEFAULT_MOUNT_PATH)
     public static final String MOUNT_PATH_PROPERTY = "mount.path";
@@ -106,21 +114,61 @@ public class BenchmarkServlet extends Ht
     protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {
         
-        if(request.getPathInfo() != null && request.getPathInfo().endsWith(".css")) {
+        final String path = request.getPathInfo() == null ? "" : request.getPathInfo(); 
+        if(path.endsWith(".css")) {
+            // Serve our css
             final Template t = velocity.getTemplate("/velocity/benchmark.css");
             response.setContentType("text/css");
             response.setCharacterEncoding("UTF-8");
             t.merge(getVelocityContext(request, null), response.getWriter());
+            
+        } else if(path.length() < 2){
+            // No benchmark specified -> redirect to default
+            response.sendRedirect(getExampleBenchmarkPath(request, DEFAULT_BENCHMARK));
+            
         } else {
+            // Benchmark input form pre-filled with selected example
             final Template t = velocity.getTemplate("/velocity/benchmark-input.html");
             final VelocityContext ctx = getVelocityContext(request, "Benchmark Input");
             ctx.put("formAction", request.getContextPath() + mountPath);
+            ctx.put("benchmarkText", getBenchmarkText(path)); 
+            ctx.put("benchmarkPaths", getExampleBenchmarkPaths(request)); 
+            ctx.put("currentBenchmarkPath", path); 
             response.setContentType("text/html");
             response.setCharacterEncoding("UTF-8");
             t.merge(ctx, response.getWriter());
         }
     }
     
+    private String getExampleBenchmarkPath(HttpServletRequest request, String name) {
+        return request.getContextPath() + mountPath + "/" + name;
+    }
+    
+    private List<String> getExampleBenchmarkPaths(HttpServletRequest request) throws IOException {
+        // TODO how to enumerate bundle resources?
+        final String list = getBenchmarkText("/LIST.txt");
+        final LineIterator it = new LineIterator(new StringReader(list));
+        final List<String> result = new LinkedList<String>();
+        while(it.hasNext()) {
+            result.add(getExampleBenchmarkPath(request, it.nextLine()));
+        }
+        return result;
+    }
+
+    /** Return example benchmark text from our class resources */
+    private String getBenchmarkText(String path) throws IOException {
+        final InputStream is = getClass().getResourceAsStream(EXAMPLE_BENCHMARKS_RESOURCE_ROOT + path);
+        if(is == null) {
+            return "";
+        }
+        
+        try {
+            return IOUtils.toString(is);
+        } finally {
+            is.close();
+        }
+    }
+    
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt?rev=1089025&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt Tue Apr  5 13:10:52 2011
@@ -0,0 +1,2 @@
+default.txt
+jamaica.txt
\ No newline at end of file

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/LIST.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt?rev=1089025&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt Tue Apr  5 13:10:52 2011
@@ -0,0 +1,53 @@
+# Default example benchmarks
+            
+= INPUT =
+# Comments such as this one are ignored
+# This is the enhancer input, can be split on several lines
+Bob
+Marley was born in Kingston, Jamaica.
+
+= EXPECT =
+# 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
+
+Description: This one should fail
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Basel
+
+# 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
+
+= COMPLAIN =
+
+Description: Miles Davis must not be found
+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: Bob Marley in the COMPLAIN section should fail
+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
+
+
+= INPUT =
+Second benchmark: something happened in Geneva yesterday.
+
+= EXPECT =
+Description: Geneva, Switzerland must be found
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva
+
+
+= INPUT =
+Third benchmark: something happened in Geneva, Ohio yesterday.
+
+= EXPECT =
+Description: Geneva, Ohio must be found
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva%2C_Ohio
+
+= COMPLAIN =
+Description: Geneva, Switzerland must not be found
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/default.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt?rev=1089025&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt Tue Apr  5 13:10:52 2011
@@ -0,0 +1,19 @@
+= INPUT =
+Bob Marley was born in Kingston, Jamaica.
+
+= EXPECT =
+Description: Kingston must be found
+http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Kingston%2C_Jamaica
+
+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
+
+= COMPLAIN =
+Description: Miles Davis must not be found
+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: Bob Marley in the COMPLAIN section should fail
+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
\ No newline at end of file

Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/examples/jamaica.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-input.html
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-input.html?rev=1089025&r1=1089024&r2=1089025&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-input.html (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-input.html Tue Apr  5 13:10:52 2011
@@ -6,7 +6,7 @@
 <body>
 	<div class="home">
 		<a href="http://incubator.apache.org/stanbol">
-			<img src="/static/images/apache_stanbol_logo_cropped.png" alt="Apache Stanbol" />
+            <img src="/static/home/images/apache_stanbol_logo_cropped.png" alt="Apache Stanbol" />
 		</a>
 	</div>
 	 
@@ -16,64 +16,20 @@
  	</div>
  	 
  	<div class="content">
+        <div class="benchmarkLinks">
+     	    <ul>
+            #foreach($path in $benchmarkPaths)
+                <li><a href="$path">$path</a></li>                
+            #end
+            </ul>
+        </div>         
+        <h2>Benchmark example: $currentBenchmarkPath</h2>   
 		<form method='POST' action="$formAction">
-			<div style="text-align:right"><input type='submit'/></div>
+			<div style="text-align:right">
+			    <input type='submit'/>
+			</div>
 			<br/>
-	        <textarea name='content' rows='80' cols='120' style:"width=100%; height=100%;">
-# Here are examples benchmarks, see unit tests for more detailed syntax information.	        
-= INPUT =
-# Comments such as this one are ignored
-# This is the enhancer input, can be split on several lines
-Bob
-Marley was born in Kingston, Jamaica.
-
-= EXPECT =
-# 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
-
-Description: This one should fail
-http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/resource/Basel
-
-# 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
-
-= COMPLAIN =
-
-Description: Miles Davis must not be found
-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: Bob Marley in the COMPLAIN section should fail
-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
-
-
-= INPUT =
-Second benchmark: something happened in Geneva yesterday.
-
-= EXPECT =
-Description: Geneva, Switzerland must be found
-http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva
-
-
-= INPUT =
-Third benchmark: something happened in Geneva, Ohio yesterday.
-
-= EXPECT =
-Description: Geneva, Ohio must be found
-http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva%2C_Ohio
-
-= COMPLAIN =
-Description: Geneva, Switzerland must not be found
-http://fise.iks-project.eu/ontology/entity-reference URI http://dbpedia.org/page/Geneva
-
-	        </textarea>
+	        <textarea name='content' rows='80' cols='120' style:"width=100%; height=100%;">$benchmarkText</textarea>
 		</form>
 	</div>		
 </body>

Modified: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-results.html
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-results.html?rev=1089025&r1=1089024&r2=1089025&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-results.html (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark-results.html Tue Apr  5 13:10:52 2011
@@ -6,7 +6,7 @@
 <body>
 	<div class="home">
 		<a href="http://incubator.apache.org/stanbol">
-			<img src="/static/images/apache_stanbol_logo_cropped.png" alt="Apache Stanbol" />
+			<img src="/static/home/images/apache_stanbol_logo_cropped.png" alt="Apache Stanbol" />
 		</a>
 	</div>
 	 

Modified: incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark.css
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark.css?rev=1089025&r1=1089024&r2=1089025&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark.css (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/resources/velocity/benchmark.css Tue Apr  5 13:10:52 2011
@@ -1,4 +1,4 @@
-@import url("$contextPath/static/style/stanbol.css");
+@import url("$contextPath/static/home/style/stanbol.css");
 
 .benchmark {
 	margin-bottom: 2em;