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/04 11:23:32 UTC
svn commit: r1088516 - in
/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark:
./ impl/
Author: bdelacretaz
Date: Mon Apr 4 09:23:32 2011
New Revision: 1088516
URL: http://svn.apache.org/viewvc?rev=1088516&view=rev
Log:
STANBOL-138 - Benchmark executes itself
Added:
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java (with props)
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java (with props)
Removed:
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkEngine.java
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkEngineImpl.java
Modified:
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java
incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkServlet.java
Modified: 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=1088516&r1=1088515&r2=1088516&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/Benchmark.java Mon Apr 4 09:23:32 2011
@@ -18,6 +18,9 @@ package org.apache.stanbol.enhancer.benc
import java.util.List;
+import org.apache.stanbol.enhancer.servicesapi.EngineException;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
+
/** A Benchmark is a named List of {@link TripleMatcherGroup} */
public interface Benchmark extends List<TripleMatcherGroup >{
/** Benchmark name */
@@ -25,4 +28,8 @@ public interface Benchmark extends List<
/** Benchmark input text */
String getInputText();
+
+ /** Execute the benchmark and return results
+ * @return null */
+ List<BenchmarkResult> execute(EnhancementJobManager jobManager) throws EngineException;
}
Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java?rev=1088516&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java Mon Apr 4 09:23:32 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.Set;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+/** Benchmark result for a single TripleMatcherGroup */
+public interface BenchmarkResult {
+ /** The TripleMatcherGroup that was evaluated */
+ TripleMatcherGroup getTripleMatcherGroup();
+
+ /** Was the benchmark successful? */
+ boolean successful();
+
+ /** More info about success or failure */
+ String getInfo();
+
+ /** Set of subjects that match our TripleMatcherGroup */
+ Set<UriRef> getMatchingSubjects();
+}
Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/BenchmarkResult.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: 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=1088516&r1=1088515&r2=1088516&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java (original)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkImpl.java Mon Apr 4 09:23:32 2011
@@ -17,9 +17,15 @@
package org.apache.stanbol.enhancer.benchmark.impl;
import java.util.LinkedList;
+import java.util.List;
import org.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkResult;
import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.EngineException;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
+import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
@SuppressWarnings("serial")
public class BenchmarkImpl extends LinkedList<TripleMatcherGroup> implements Benchmark {
@@ -35,6 +41,7 @@ public class BenchmarkImpl extends Linke
this.name = name;
}
+ /** @inheritDoc */
@Override
public String getName() {
return name;
@@ -44,8 +51,28 @@ public class BenchmarkImpl extends Linke
this.inputText = inputText;
}
+ /** @inheritDoc */
@Override
public String getInputText() {
return inputText;
}
+
+ @Override
+ public List<BenchmarkResult> execute(EnhancementJobManager jobManager) throws EngineException {
+ if(isEmpty()) {
+ return null;
+ }
+ if(inputText == null || inputText.length() == 0) {
+ throw new IllegalStateException("inputText is null or empty, cannot run benchmark");
+ }
+
+ final List<BenchmarkResult> result = new LinkedList<BenchmarkResult>();
+ final ContentItem ci = new InMemoryContentItem(inputText.getBytes(), "text/plain");
+ jobManager.enhanceContent(ci);
+ for(TripleMatcherGroup g : this) {
+ result.add(new BenchmarkResultImpl(g, ci.getMetadata().getGraph()));
+ }
+
+ return result;
+ }
}
Added: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java?rev=1088516&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java (added)
+++ incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java Mon Apr 4 09:23:32 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.Set;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkResult;
+import org.apache.stanbol.enhancer.benchmark.TripleMatcherGroup;
+
+public class BenchmarkResultImpl implements BenchmarkResult {
+
+ private final TripleMatcherGroup tmg;
+ private final boolean successful;
+ private String info;
+ private final Set<UriRef> matchingSubjects;
+
+ BenchmarkResultImpl(TripleMatcherGroup tmg, Graph graph) {
+ this.tmg = tmg;
+ matchingSubjects = tmg.getMatchingSubjects(graph);
+
+ if(tmg.isExpectGroup()) {
+ if(matchingSubjects.size() == 1) {
+ successful = true;
+ info = "EXPECT OK";
+ } else {
+ successful = false;
+ info = "EXPECT FAILED";
+ }
+ } else {
+ if(matchingSubjects.size() > 0) {
+ successful = false;
+ info = "COMPLAINT TRIGGERED";
+ } else {
+ successful = true;
+ info = "NO COMPLAINT";
+ }
+ }
+ info += ", matchingSubjects=" + matchingSubjects.size();
+ }
+
+ @Override
+ public String toString() {
+ return BenchmarkResult.class.getSimpleName()
+ + " "
+ + (successful ? "SUCCESSFUL" : "**FAILED**")
+ + " ("
+ + info
+ + "): "
+ + tmg.getDescription()
+ ;
+ }
+
+ @Override
+ public TripleMatcherGroup getTripleMatcherGroup() {
+ return tmg;
+ }
+
+ @Override
+ public boolean successful() {
+ return successful;
+ }
+
+ @Override
+ public String getInfo() {
+ return info;
+ }
+
+ @Override
+ public Set<UriRef> getMatchingSubjects() {
+ return matchingSubjects;
+ }
+}
Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/stanbol/trunk/enhancer/benchmark/src/main/java/org/apache/stanbol/enhancer/benchmark/impl/BenchmarkResultImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
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=1088516&r1=1088515&r2=1088516&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 Mon Apr 4 09:23:32 2011
@@ -17,6 +17,9 @@
package org.apache.stanbol.enhancer.benchmark.impl;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -26,7 +29,10 @@ import javax.servlet.http.HttpServletRes
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.apache.stanbol.enhancer.benchmark.Benchmark;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkParser;
+import org.apache.stanbol.enhancer.benchmark.BenchmarkResult;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
@@ -44,7 +50,10 @@ public class BenchmarkServlet extends Ht
private HttpService httpService;
@Reference
- private BenchmarkEngine benchmarkEngine;
+ private BenchmarkParser parser;
+
+ @Reference
+ private EnhancementJobManager jobManager;
public static final String PARAM_CONTENT = "content";
public static final String DEFAULT_MOUNT_PATH = "/benchmark";
@@ -129,15 +138,23 @@ public class BenchmarkServlet extends Ht
throw new ServletException("Missing " + PARAM_CONTENT + " parameter");
}
- response.setContentType("text/html");
+ response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
+ final PrintWriter pw = response.getWriter();
try {
- benchmarkEngine.runBenchmark(content, response.getWriter());
+ final List<? extends Benchmark> benchmarks = parser.parse(new StringReader(content));
+ for(Benchmark b : benchmarks) {
+ final List<BenchmarkResult> results = b.execute(jobManager);
+ for(BenchmarkResult r : results) {
+ pw.println(r.toString());
+ }
+ }
} catch(Exception e) {
- // TODO better error reporting
log.error("Exception in runBenchmark", e);
- response.getWriter().write(e.toString());
+ e.printStackTrace(pw);
+ } finally {
+ pw.flush();
}
}
}
\ No newline at end of file