You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/03/16 09:44:17 UTC

svn commit: r1082095 - in /incubator/stanbol/trunk/enhancer: engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ integration-tests/src/test/java...

Author: rwesten
Date: Wed Mar 16 08:44:17 2011
New Revision: 1082095

URL: http://svn.apache.org/viewvc?rev=1082095&view=rev
Log:
STANBOL-115: Added Services configured by the default configuration to the EnhancerTestBase

The EnhancerTestBase now checks also for the "org.apache.stanbol.*ReferencedSiteEntityTaggingEnhancementEngine" . In addition it also checks the availability of the ReferencedSite "http:\\\\/\\\\/.*\\\\/entityhub\\\\/site\\\\/dbPedia\\\\/" by sending a GET request to "/entityhub/sites/referenced"

other changes:
 - The ZemantaEngine now throws an EngineExcetpion if the Zemanta service is not available
 - The Unit Test for the ZemantaEngine do no longer fail if the Zemanta service is not available. Now they are simply skiped
 - JCRContentItem (currently not part of the mvn build) does compile again
 

Modified:
    incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaAPIWrapper.java
    incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngine.java
    incubator/stanbol/trunk/enhancer/engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngineTest.java
    incubator/stanbol/trunk/enhancer/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
    incubator/stanbol/trunk/enhancer/stores/jcrstore/src/main/java/org/apache/stanbol/enhancer/store/jcr/JCRContentItem.java

Modified: incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaAPIWrapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaAPIWrapper.java?rev=1082095&r1=1082094&r2=1082095&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaAPIWrapper.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaAPIWrapper.java Wed Mar 16 08:44:17 2011
@@ -55,13 +55,13 @@ public class ZemantaAPIWrapper {
         apiKey = key;
     }
 
-    public Graph enhance(String textToAnalyze) {
+    public Graph enhance(String textToAnalyze) throws IOException {
         InputStream is = sendRequest(textToAnalyze);
         Graph zemantaResponseGraph = parseResponse(is);
         return zemantaResponseGraph;
     }
 
-    private InputStream sendRequest(String textToAnalyze) {
+    private InputStream sendRequest(String textToAnalyze) throws IOException {
         try {
             URL url = new URL(URL);
             HttpURLConnection httpURLConnection = (HttpURLConnection) url
@@ -97,10 +97,7 @@ public class ZemantaAPIWrapper {
             log.error(e.getMessage(),e);
         } catch (MalformedURLException e) {
             log.error(e.getMessage(),e);
-        } catch (IOException e) {
-            log.error(e.getMessage(),e);
         }
-
         return null;
     }
 

Modified: incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngine.java?rev=1082095&r1=1082094&r2=1082095&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngine.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/zemanta/src/main/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngine.java Wed Mar 16 08:44:17 2011
@@ -151,7 +151,11 @@ public class ZemantaEnhancementEngine im
         //we need to store the results of Zemanta in an temp graph
         MGraph results = new SimpleMGraph();
         ZemantaAPIWrapper zemanta = new ZemantaAPIWrapper(key);
-        results.addAll(zemanta.enhance(text));
+        try {
+            results.addAll(zemanta.enhance(text));
+        } catch (IOException e) {
+           throw new EngineException("Unable to get Enhancement from remote Zemanta Service",e);
+        }
         //now we need to process the results and convert them into the Enhancer
         //annotation structure
         processRecognition(results, graph, text, ciId);

Modified: incubator/stanbol/trunk/enhancer/engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngineTest.java?rev=1082095&r1=1082094&r2=1082095&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngineTest.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/zemanta/src/test/java/org/apache/stanbol/enhancer/engines/zemanta/impl/ZemantaEnhancementEngineTest.java Wed Mar 16 08:44:17 2011
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertTru
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.UnknownHostException;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -44,6 +45,7 @@ import org.apache.clerezza.rdf.core.seri
 import org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider;
 import org.apache.stanbol.enhancer.engines.zemanta.impl.ZemantaEnhancementEngine;
 import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.EngineException;
 import org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper;
 import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
 import org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses;
@@ -123,13 +125,21 @@ public class ZemantaEnhancementEngineTes
     @Test
     public void tesetBioText() throws Exception {
         ContentItem ci = wrapAsContentItem(BIO_DOMAIN_TEXT);
-        zemantaEngine.computeEnhancements(ci);
+        try {
+            zemantaEngine.computeEnhancements(ci);
+        } catch (EngineException e) {
+            if(e.getCause() != null && e.getCause() instanceof UnknownHostException){
+                log.warn("Zemanta Service not reachable -> offline? -> deactivate test");
+                return;
+            }
+            throw e;
+        }
         JenaSerializerProvider serializer = new JenaSerializerProvider();
         serializer.serialize(System.out, ci.getMetadata(), TURTLE);
         int textAnnoNum = checkAllTextAnnotations(ci.getMetadata(), BIO_DOMAIN_TEXT);
         log.info(textAnnoNum + " TextAnnotations found ...");
         int entityAnnoNum = checkAllEntityAnnotations(ci.getMetadata());
-        log.info(textAnnoNum + " EntityAnnotations found ...");
+        log.info(entityAnnoNum + " EntityAnnotations found ...");
     }
 
     /*

Modified: incubator/stanbol/trunk/enhancer/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java?rev=1082095&r1=1082094&r2=1082095&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java (original)
+++ incubator/stanbol/trunk/enhancer/integration-tests/src/test/java/org/apache/stanbol/enhancer/it/EnhancerTestBase.java Wed Mar 16 08:44:17 2011
@@ -74,7 +74,23 @@ public class EnhancerTestBase extends St
                     "org.apache.stanbol.*OpenCalaisEngine",
                     "org.apache.stanbol.*EntityMentionEnhancementEngine",
                     "org.apache.stanbol.*RelatedTopicEnhancementEngine",
-                    "org.apache.stanbol.*CachingDereferencerEngine"
+                    "org.apache.stanbol.*CachingDereferencerEngine",
+                    //added by rwesten
+                    "org.apache.stanbol.*ReferencedSiteEntityTaggingEnhancementEngine"
+                );
+                
+                /*  List of expected referencedSites could also be made 
+                 *  configurable via system properties, but we don't expect it 
+                 *  to change often. 
+                 */
+                executor.execute(
+                        builder.buildGetRequest("/entityhub/sites/referenced")
+                        .withHeader("Accept", "application/json")
+                )
+                .assertStatus(200)
+                .assertContentType("application/json")
+                .assertContentRegexp(
+                    "http:\\\\/\\\\/.*\\\\/entityhub\\\\/site\\\\/dbPedia\\\\/"
                 );
                 log.info("Enhancement engines checked, all present");
                 return true;

Modified: incubator/stanbol/trunk/enhancer/stores/jcrstore/src/main/java/org/apache/stanbol/enhancer/store/jcr/JCRContentItem.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/stores/jcrstore/src/main/java/org/apache/stanbol/enhancer/store/jcr/JCRContentItem.java?rev=1082095&r1=1082094&r2=1082095&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/stores/jcrstore/src/main/java/org/apache/stanbol/enhancer/store/jcr/JCRContentItem.java (original)
+++ incubator/stanbol/trunk/enhancer/stores/jcrstore/src/main/java/org/apache/stanbol/enhancer/store/jcr/JCRContentItem.java Wed Mar 16 08:44:17 2011
@@ -47,7 +47,7 @@ public class JCRContentItem implements C
     private static final String JCR_DATA = "jcr:data";
     private static final String JCR_MIME_TYPE = "jcr:mimeType";
 
-    private static final Logger log = LoggerFactory.getLogger(getClass());
+    private static final Logger log = LoggerFactory.getLogger(JCRContentItem.class);
 
     private Node jcrNode;