You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2012/03/16 10:55:02 UTC

svn commit: r1301407 - in /opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server: ./ search/ store/

Author: joern
Date: Fri Mar 16 09:55:01 2012
New Revision: 1301407

URL: http://svn.apache.org/viewvc?rev=1301407&view=rev
Log:
OPENNLP-475 Changed CorpusSever.getTypeSystem to return a byte array.

Modified:
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/LuceneSearchService.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorpusStore.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorpusStore.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorporaStore.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorpusStore.java

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java Fri Mar 16 09:55:01 2012
@@ -17,7 +17,6 @@
 
 package org.apache.opennlp.corpus_server;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.List;
 
@@ -34,8 +33,6 @@ import javax.ws.rs.core.MediaType;
 
 import org.apache.opennlp.corpus_server.search.SearchService;
 import org.apache.opennlp.corpus_server.store.CorpusStore;
-import org.apache.uima.resource.metadata.TypeSystemDescription;
-import org.xml.sax.SAXException;
 
 public class CorpusResource {
 
@@ -88,7 +85,7 @@ public class CorpusResource {
 	@Produces(MediaType.TEXT_XML)
 	@Path("{casId}")
 	public byte[] getCAS(@PathParam("casId") String casId) throws IOException{
-		return corpus.getCAS(casId);
+	  return corpus.getCAS(casId);
 	}
 
 	/**
@@ -99,19 +96,7 @@ public class CorpusResource {
 	@Produces(MediaType.TEXT_XML)
 	@Path("_typesystem")
 	public byte[] getTypeSystem() throws IOException {
-		TypeSystemDescription typeSystem = corpus.getTypeSystem();
-
-		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-		
-		try {
-			typeSystem.toXML(bytes);
-		} catch (SAXException e) {
-		  throw new IOException(e);
-		} catch (IOException e) {
-			throw new IllegalStateException("Writing to memory must not fail!");
-		}
-		
-		return bytes.toByteArray();
+	  return corpus.getTypeSystem();
 	}
 	
 	@GET

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/LuceneSearchService.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/LuceneSearchService.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/LuceneSearchService.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/LuceneSearchService.java Fri Mar 16 09:55:01 2012
@@ -239,7 +239,9 @@ public class LuceneSearchService impleme
     
     List<MetaDataObject> specs = new ArrayList<MetaDataObject>();
     specs.add(indexTypeDesc);
-    specs.add(store.getTypeSystem());
+    TypeSystemDescription tsDescription = UimaUtil.createTypeSystemDescription(
+          new ByteArrayInputStream(store.getTypeSystem()));
+    specs.add(tsDescription);
     
     // Note: This might be a performance problem
     CAS cas;

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorpusStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorpusStore.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorpusStore.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorpusStore.java Fri Mar 16 09:55:01 2012
@@ -19,8 +19,6 @@ package org.apache.opennlp.corpus_server
 
 import java.io.IOException;
 
-import org.apache.uima.resource.metadata.TypeSystemDescription;
-
 /**
  * A Corpus Store contains a set of CASes and is responsible to host them
  * together with a type system.
@@ -79,7 +77,7 @@ public interface CorpusStore {
    * @return
    * @throws IOException
    */
-  TypeSystemDescription getTypeSystem() throws IOException;
+  byte[] getTypeSystem() throws IOException;
   
   /**
    * Retrieves the index mapping for this corpus.

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorpusStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorpusStore.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorpusStore.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorpusStore.java Fri Mar 16 09:55:01 2012
@@ -17,7 +17,6 @@
 
 package org.apache.opennlp.corpus_server.store;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.sql.Blob;
 import java.sql.Connection;
@@ -30,9 +29,6 @@ import java.util.logging.Logger;
 
 import javax.sql.DataSource;
 
-import org.apache.opennlp.corpus_server.UimaUtil;
-import org.apache.uima.resource.metadata.TypeSystemDescription;
-
 public class DerbyCorpusStore implements CorpusStore {
 
   private final static Logger LOGGER = Logger.getLogger(
@@ -189,9 +185,9 @@ public class DerbyCorpusStore implements
   }
   
   @Override
-  public TypeSystemDescription getTypeSystem() throws IOException {
+  public byte[] getTypeSystem() throws IOException {
     
-    TypeSystemDescription tsDescription = null;
+    byte tsBytes[];
     
     try {
       Connection conn = dataSource.getConnection();
@@ -200,9 +196,10 @@ public class DerbyCorpusStore implements
           " WHERE name='_typesystem'");
       
       if (tsResult.next()) {
-        byte tsBytes[] = tsResult.getBytes(2);
-        tsDescription = UimaUtil.createTypeSystemDescription(
-            new ByteArrayInputStream(tsBytes));
+        tsBytes = tsResult.getBytes(2);
+      }
+      else {
+        throw new IOException("Failed to retrieve type system!");
       }
       
       tsResult.close();
@@ -217,7 +214,7 @@ public class DerbyCorpusStore implements
       throw new IOException(e);
     }
     
-    return tsDescription;
+    return tsBytes;
   }
   
   @Override

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorporaStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorporaStore.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorporaStore.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorporaStore.java Fri Mar 16 09:55:01 2012
@@ -17,15 +17,12 @@
 
 package org.apache.opennlp.corpus_server.store;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.opennlp.corpus_server.UimaUtil;
-
 public class MemoryCorporaStore extends AbstractCorporaStore {
 	
 	private static MemoryCorporaStore instance;
@@ -56,8 +53,7 @@ public class MemoryCorporaStore extends 
 	public void createCorpus(String corpusName,
 			byte typeSystemBytes[], byte indexMapping[]) {
 		corpora.put(corpusName, new MemoryCorpusStore(corpusName, 
-				UimaUtil.createTypeSystemDescription(
-				new ByteArrayInputStream(typeSystemBytes)), indexMapping));
+				typeSystemBytes, indexMapping));
 	}
 	
 	public MemoryCorpusStore getCorpus(String corpusId) {

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorpusStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorpusStore.java?rev=1301407&r1=1301406&r2=1301407&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorpusStore.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/MemoryCorpusStore.java Fri Mar 16 09:55:01 2012
@@ -32,15 +32,15 @@ import org.apache.uima.resource.metadata
 public class MemoryCorpusStore implements CorpusStore {
 
   private final String corpusName;
-  private final TypeSystemDescription typeSystem;
+  private final byte[] typeSystemBytes;
   private byte[] indexMapping;
 
   private Map<String, byte[]> casStore = new HashMap<String, byte[]>();
 
-  MemoryCorpusStore(String corpusName, TypeSystemDescription typeSystem,
+  MemoryCorpusStore(String corpusName, byte[] typeSystem,
       byte[] indexMapping) {
     this.corpusName = corpusName;
-    this.typeSystem = typeSystem;
+    this.typeSystemBytes = typeSystem;
     this.indexMapping = indexMapping;
   }
 
@@ -60,7 +60,10 @@ public class MemoryCorpusStore implement
     // Directly store data as xmi, but deserialization is needed to index and
     // validate it!
 
-    CAS cas = UimaUtil.createEmptyCAS(typeSystem);
+    TypeSystemDescription tsDescription = UimaUtil.createTypeSystemDescription(
+        new ByteArrayInputStream(typeSystemBytes));
+    
+    CAS cas = UimaUtil.createEmptyCAS(tsDescription);
 
     try {
       UimaUtil.deserializeXmiCAS(cas, new ByteArrayInputStream(content));
@@ -82,8 +85,8 @@ public class MemoryCorpusStore implement
     casStore.remove(casID);
   }
   
-  public TypeSystemDescription getTypeSystem() {
-    return typeSystem;
+  public byte[] getTypeSystem() {
+    return typeSystemBytes;
   }
 
   @Override