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/07/31 17:02:18 UTC
svn commit: r1367596 - in /opennlp/sandbox:
corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/
corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/
corpus-server/src/main/java/org/apache/opennlp/corpus_server/ ...
Author: joern
Date: Tue Jul 31 15:02:18 2012
New Revision: 1367596
URL: http://svn.apache.org/viewvc?rev=1367596&view=rev
Log:
OPENNLP-528 Added method to replace the type system of a corpus.
Added:
opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java (with props)
Modified:
opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorpusStore.java
opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/FileUtil.java
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/store/CorpusStore.java
Modified: opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorpusStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorpusStore.java?rev=1367596&r1=1367595&r2=1367596&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorpusStore.java (original)
+++ opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorpusStore.java Tue Jul 31 15:02:18 2012
@@ -188,6 +188,36 @@ public class DerbyCorpusStore implements
}
@Override
+ public void replaceTypeSystem(byte[] newTypeSystem) throws IOException {
+ try {
+ Connection conn = dataSource.getConnection();
+ // Replace the type system
+ PreparedStatement typeSystemPS = conn.prepareStatement("update " +
+ corpusName + " set cas = ? where name = ?");
+
+ typeSystemPS.setString(2, "_typesystem");
+
+ Blob typeSystemBlob = conn.createBlob();
+ typeSystemBlob.setBytes(1, newTypeSystem);
+ typeSystemPS.setBlob(1, typeSystemBlob);
+
+ typeSystemPS.executeUpdate();
+
+ conn.commit();
+
+ typeSystemPS.close();
+ conn.close();
+ } catch (SQLException e) {
+
+ if (LOGGER.isLoggable(Level.SEVERE)) {
+ LOGGER.log(Level.SEVERE, "Failed to replace the Type System!", e);
+ }
+
+ throw new IOException(e);
+ }
+ }
+
+ @Override
public byte[] getTypeSystem() throws IOException {
byte tsBytes[];
Modified: opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/FileUtil.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/FileUtil.java?rev=1367596&r1=1367595&r2=1367596&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/FileUtil.java (original)
+++ opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/FileUtil.java Tue Jul 31 15:02:18 2012
@@ -32,14 +32,17 @@ public class FileUtil {
InputStream fileIn = new FileInputStream(file);
- byte buffer[] = new byte[1024];
- int length;
- while ((length = fileIn.read(buffer)) > 0) {
- fileBytes.write(buffer, 0, length);
+ try {
+ byte buffer[] = new byte[1024];
+ int length;
+ while ((length = fileIn.read(buffer)) > 0) {
+ fileBytes.write(buffer, 0, length);
+ }
}
-
- fileIn.close();
-
+ finally {
+ fileIn.close();
+ }
+
return fileBytes.toByteArray();
}
Added: opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java?rev=1367596&view=auto
==============================================================================
--- opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java (added)
+++ opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java Tue Jul 31 15:02:18 2012
@@ -0,0 +1,53 @@
+/*
+ * 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.opennlp.corpus_server.tools;
+
+import java.io.File;
+
+import javax.ws.rs.core.MediaType;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+
+public class ReplaceTypeSystem {
+
+ public static void main(String[] args) throws Exception {
+
+ if (args.length != 2) {
+ System.out.println("ReplaceTypeSystem address typeSystemFile");
+ System.exit(-1);
+ }
+
+ Client c = Client.create();
+
+ WebResource r = c.resource(args[0]);
+
+ File typeSystemFile = new File(args[1]);
+
+ byte typeSystemBytes[] = FileUtil.fileToBytes(typeSystemFile);
+
+ ClientResponse response = r.path("_replaceTypeSystem")
+ .accept(MediaType.TEXT_XML)
+ // TODO: How to fix this? Shouldn't accept do it?
+ .header("Content-Type", MediaType.TEXT_XML)
+ .put(ClientResponse.class, typeSystemBytes);
+
+ System.out.println("Response: " + response.getStatus());
+ }
+}
Propchange: opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/ReplaceTypeSystem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1367596&r1=1367595&r2=1367596&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 Tue Jul 31 15:02:18 2012
@@ -87,7 +87,24 @@ public class CorpusResource {
public byte[] getCAS(@PathParam("casId") String casId) throws IOException {
return corpus.getCAS(casId);
}
-
+
+ /**
+ * Note:
+ * The Type System is not checked for compatibility, if it does not work anymore
+ * the user needs to diagnose the problem himself and provide a new Type System to
+ * fix this.
+ *
+ * @param newTypeSystem
+ *
+ * @throws IOException
+ */
+ @PUT
+ @Consumes(MediaType.TEXT_XML)
+ @Path("_replaceTypeSystem")
+ public void replaceTypeSystem(byte[] newTypeSystem) throws IOException {
+ corpus.replaceTypeSystem(newTypeSystem);
+ }
+
/**
* Retrieves the type system for this corpus.
*
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=1367596&r1=1367595&r2=1367596&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 Tue Jul 31 15:02:18 2012
@@ -72,6 +72,14 @@ public interface CorpusStore {
void removeCAS(String casID) throws IOException;
/**
+ * Replaces the existing Type System with a new one.
+ *
+ * @param newTypeSystem
+ * @throws IOException
+ */
+ void replaceTypeSystem(byte[] newTypeSystem) throws IOException;
+
+ /**
* Retrieves the type system description of this corpus.
*
* @return