clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r980042 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator: ./ src/main/java/org/apache/clerezza/uima/metadatagenerator/ src/test/java/org/apache/clerezza/uima/meta...
Date Wed, 28 Jul 2010 12:59:53 GMT
Author: tommaso
Date: Wed Jul 28 12:59:53 2010
New Revision: 980042

URL: http://svn.apache.org/viewvc?rev=980042&view=rev
Log:
[CLEREZZA-193] - fixed Export-Package in POM and MediaType handling

Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/pom.xml
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/pom.xml?rev=980042&r1=980041&r2=980042&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/pom.xml
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/pom.xml
Wed Jul 28 12:59:53 2010
@@ -68,7 +68,7 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
-            <Export-Package>org.apache.clerezza.uima.*</Export-Package>
+            <Export-Package>org.apache.clerezza.uima.metadatagenerator.*</Export-Package>
           </instructions>
         </configuration>
       </plugin>

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java?rev=980042&r1=980041&r2=980042&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
Wed Jul 28 12:59:53 2010
@@ -20,10 +20,10 @@ import java.util.List;
  * An implementation of <code>MetaDataGenerator</code> generates meta data about
specified data
  * depending on its media type using Apache UIMA.
  */
-@Component(metatype=true)
+@Component(metatype = true)
 @Services({
-  @Service(MetaDataGenerator.class),
-  @Service(UIMABaseMetadataGenerator.class)
+        @Service(MetaDataGenerator.class),
+        @Service(UIMABaseMetadataGenerator.class)
 })
 public class UIMABaseMetadataGenerator implements MetaDataGenerator {
 
@@ -31,52 +31,68 @@ public class UIMABaseMetadataGenerator i
 
   @Override
   public void generate(GraphNode node, byte[] data, MediaType mediaType) {
-    // FIXME only TEXT_PLAIN, also different MediaTypes should be served
-    if (MediaType.TEXT_PLAIN.equals(mediaType.getType())) {
-      try {
-        // add language to the document
-        addLanguage(node, data);
-
-        // add wide purpose subject to the document
-        addCategory(node, data);
-
-        // add calais annotations' nodes
-        addCalaisAnnotations(node, data);
-
-        // add alchemyAPI's annotations' nodes
-        addAlchemyAPIEntities(node,data);
-
-      } catch (Throwable e) {
-        // do nothing
-      }
+    try {
+      String text = getTextToAnalyze(data, mediaType);
+
+      // add language to the document
+      addLanguage(node, text);
+
+      // add wide purpose subject to the document
+      addCategory(node, text);
+
+      // add calais annotations' nodes
+      addCalaisAnnotations(node, text);
+
+      // add alchemyAPI's annotations' nodes
+      addAlchemyAPIEntities(node, text);
+
+    } catch (Throwable e) {
+      // do nothing
+    }
+  }
+
+  private String getTextToAnalyze(byte[] data, MediaType mediaType) throws UnsupportedMediaTypeException
{
+    String text = null;
+    if (MediaType.TEXT_PLAIN.equals(mediaType)) {
+      text = new String(data);
+    }
+    if (text == null) {
+      throw new UnsupportedMediaTypeException(mediaType.getType());
     }
+    return text;
   }
 
-  private void addCategory(GraphNode node, byte[] data) throws UIMAException {
+
+  private void addCategory(GraphNode node, String data) throws UIMAException {
     // get category to bind it to the node
-    String category = facade.getCategory(data.toString());
+    String category = facade.getCategory(data);
     node.addPropertyValue(DC.subject, category);
   }
 
-  private void addLanguage(GraphNode node, byte[] data) throws UIMAException {
+  private void addLanguage(GraphNode node, String data) throws UIMAException {
     // get language to bind it to the node
-    String language = facade.getLanguage(data.toString());
+    String language = facade.getLanguage(data);
     node.addPropertyValue(DCTERMS.language, language);
   }
 
-  private void addCalaisAnnotations(GraphNode existingNode, byte[] data) throws UIMAException
{
+  private void addCalaisAnnotations(GraphNode existingNode, String data) throws UIMAException
{
     // analyze document text and get the corresponding OpenCalais annotations
-    List<Annotation> calaisAnnotations = facade.getCalaisAnnotations(data.toString());
+    List<Annotation> calaisAnnotations = facade.getCalaisAnnotations(data);
     // convert annotations to nodes inside the current graph
     UIMAUtils.enhanceNode(existingNode, calaisAnnotations);
 
   }
 
-  private void addAlchemyAPIEntities(GraphNode existingNode, byte[] data) throws UIMAException
{
+  private void addAlchemyAPIEntities(GraphNode existingNode, String data) throws UIMAException
{
     // analyze document text and get the corresponding AlchemyAPI Tags
-    List<FeatureStructure> alchemyAPIEntities = facade.getAlchemyAPITags(data.toString());
+    List<FeatureStructure> alchemyAPIEntities = facade.getAlchemyAPITags(data);
     // convert entities to nodes inside the current graph
     UIMAUtils.enhanceNode(existingNode, alchemyAPIEntities);
   }
 
+  private class UnsupportedMediaTypeException extends Throwable {
+    private UnsupportedMediaTypeException(String s) {
+      super(s);
+    }
+  }
 }

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java?rev=980042&r1=980041&r2=980042&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java
Wed Jul 28 12:59:53 2010
@@ -32,8 +32,8 @@ public class UIMABaseMetadataGeneratorTe
       String textToAnalyze = "Italy, the defending champions and four-time World Cup winners,
suffer a shock World Cup defeat to Slovakia, who win a remarkable game 3-2 to book their place
in the last 16";
       MGraph mGraph = new SimpleMGraph();
       GraphNode node = new GraphNode(new UriRef("test"), mGraph.getGraph());
-      MediaType mediaType = MediaType.valueOf("multipart/form-data; boundary=AaB03x");
-      baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), mediaType);
+      MediaType wrongMediaType = MediaType.valueOf("multipart/form-data; boundary=AaB03x");
+      baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), wrongMediaType);
     } catch (Exception e) {
       fail(e.getLocalizedMessage());
     }



Mime
View raw message