opennlp-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1354019 - 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/ ...
Date Tue, 26 Jun 2012 13:53:47 GMT
Author: joern
Date: Tue Jun 26 13:53:44 2012
New Revision: 1354019

URL: http://svn.apache.org/viewvc?rev=1354019&view=rev
Log:
OPENNLP-513 Added support to drop a corpus

Added:
    opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java
  (with props)
Modified:
    opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/CorpusServerImpl.java
    opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorporaStore.java
    opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/SearchService.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaChangeListener.java
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaStore.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/taskqueue/MemoryTaskQueueService.java

Modified: opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/CorpusServerImpl.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/CorpusServerImpl.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/CorpusServerImpl.java
(original)
+++ opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/CorpusServerImpl.java
Tue Jun 26 13:53:44 2012
@@ -50,6 +50,16 @@ public class CorpusServerImpl implements
     }
 
     @Override
+    public void droppedCorpus(CorpusStore store) {
+      try {
+        searchService.dropIndex(store);
+      } catch (IOException e) {
+        // TODO: Also log store name!
+        LOGGER.log(Level.WARNING, "Failed to index cas: " + store.getCorpusId(), e);
+      }
+    }
+    
+    @Override
     public void updatedCAS(CorpusStore store, String casId) {
       addedCAS(store, casId);
     }

Modified: opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorporaStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorporaStore.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorporaStore.java
(original)
+++ opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/DerbyCorporaStore.java
Tue Jun 26 13:53:44 2012
@@ -147,6 +147,29 @@ public class DerbyCorporaStore extends A
   }
   
   @Override
+  public void dropCorpus(String corpusName) throws IOException {
+
+    try {
+      Connection conn = dataSource.getConnection();
+      Statement s = conn.createStatement();
+      s.execute("drop table " + corpusName);
+      s.close();
+
+      conn.commit();
+      conn.close();
+    } catch (SQLException e) {
+      if (LOGGER.isLoggable(Level.SEVERE)) {
+        LOGGER.log(Level.SEVERE, "Failed to create corpus: " + corpusName, e);
+      }
+      throw new IOException(e);
+    }
+
+    for (CorporaChangeListener listener : getListeners()) {
+      listener.droppedCorpus(getCorpus(corpusName));
+    }
+  }
+  
+  @Override
   public CorpusStore getCorpus(String corpusId) {
     
     // It must be ensured that the table exist, otherwise

Modified: opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
(original)
+++ opennlp/sandbox/corpus-server-impl/src/main/java/org/apache/opennlp/corpus_server/impl/LuceneSearchService.java
Tue Jun 26 13:53:44 2012
@@ -207,8 +207,13 @@ public class LuceneSearchService impleme
     this.store = store;
     
     for (String corpusId : store.getCorpusIds()) {
-      createIndexWriter(corpusId, false);
-      LOGGER.info("Created Index Writer for " + corpusId + "corpus.");
+      try {
+        createIndexWriter(corpusId, false);
+        LOGGER.info("Created Index Writer for " + corpusId + "corpus.");
+      }
+      catch (IOException e) {
+        LOGGER.warning("Failed to open Index Writer for " + corpusId + "corpus.");
+      }
     }
   }
   
@@ -218,6 +223,10 @@ public class LuceneSearchService impleme
     LOGGER.info("Created Index Writer for " + store.getCorpusId() + " corpus.");
   }
   
+  public synchronized void dropIndex(CorpusStore store) throws IOException {
+    
+  }
+  
   @Override
   public synchronized void index(CorpusStore store, String casId) throws IOException {
     

Added: opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java?rev=1354019&view=auto
==============================================================================
--- opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java
(added)
+++ opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java
Tue Jun 26 13:53:44 2012
@@ -0,0 +1,59 @@
+/*
+ * 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 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;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+
+/**
+ * Command Line Tool to drop a corpus in the corpus server.
+ */
+public class DropCorpus {
+  public static void main(String[] args) throws Exception {
+
+    if (args.length != 2) {
+      System.out.println("DropCorpus address corpusName");
+      System.exit(-1);
+    }
+
+    String corpusName = args[1];
+
+    ClientConfig clientConfig = new DefaultClientConfig();
+    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
+        Boolean.TRUE);
+
+    Client c = Client.create(clientConfig);
+
+    WebResource r = c.resource(args[0]);
+
+    ClientResponse response = r.path("_dropCorpus")
+        .queryParam("corpusName", corpusName)
+        .accept(MediaType.APPLICATION_JSON)
+        // TODO: How to fix this? Shouldn't accept do it?
+        .header("Content-Type", MediaType.APPLICATION_JSON_TYPE)
+        .post(ClientResponse.class);
+
+    System.out.println("Result: " + response.getStatus());
+  }
+}

Propchange: opennlp/sandbox/corpus-server-tools/src/main/java/org/apache/opennlp/corpus_server/tools/DropCorpus.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
(original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
Tue Jun 26 13:53:44 2012
@@ -73,4 +73,14 @@ public class CorporaResource {
         return null;
       }
 	}
+  
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Path("_dropCorpus")
+  public void dropCorpus(@QueryParam("corpusName") String corpusName) throws IOException
{
+    CorpusServer corpusServer = CorpusServerBundle.getInstance().getCorpusServer();
+    
+    CorporaStore store = corpusServer.getStore();
+    store.dropCorpus(corpusName);
+  }
 }

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/SearchService.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/SearchService.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/SearchService.java
(original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/search/SearchService.java
Tue Jun 26 13:53:44 2012
@@ -41,6 +41,8 @@ public interface SearchService {
    */
   void createIndex(CorpusStore store) throws IOException;
   
+  void dropIndex(CorpusStore store) throws IOException;
+  
   /**
    * Indexes or re-indexes a CAS.
    * 

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaChangeListener.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaChangeListener.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaChangeListener.java
(original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaChangeListener.java
Tue Jun 26 13:53:44 2012
@@ -24,6 +24,8 @@ public interface CorporaChangeListener {
 
   void addedCorpus(CorpusStore store);
   
+  void droppedCorpus(CorpusStore store);
+  
   /**
    * Indicates that the CAS was added to the corpus.
    * 

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaStore.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaStore.java
(original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/CorporaStore.java
Tue Jun 26 13:53:44 2012
@@ -53,13 +53,21 @@ public interface CorporaStore {
   /**
    * Retrieves a corpus of the given name from the store.
    * 
-   * @param corpusId the name of the coprus to retrieve
+   * @param corpusId the name of the corpus to retrieve
    * 
    * @return the corpus or null if it does not exist
    */
   CorpusStore getCorpus(String corpusId) throws IOException;
   
   /**
+   * Drops the corpus. All data will be removed permanently.
+   * 
+   * @param corpusId
+   * @throws IOException
+   */
+  void dropCorpus(String corpusId) throws IOException;
+  
+  /**
    * Indicates that the store will no longer be used and no more
    * methods will be called.
    */

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=1354019&r1=1354018&r2=1354019&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
Tue Jun 26 13:53:44 2012
@@ -59,4 +59,9 @@ public class MemoryCorporaStore extends 
 	public MemoryCorpusStore getCorpus(String corpusId) {
 		return corpora.get(corpusId);
 	}
+	
+	@Override
+	public void dropCorpus(String corpusId) throws IOException {
+	  corpora.remove(corpusId);
+	}
 }

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java?rev=1354019&r1=1354018&r2=1354019&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
(original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
Tue Jun 26 13:53:44 2012
@@ -25,6 +25,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.opennlp.corpus_server.CorpusServer;
+import org.apache.opennlp.corpus_server.CorpusServerBundle;
 import org.apache.opennlp.corpus_server.store.CorpusStore;
 
 /**
@@ -41,19 +42,21 @@ public class MemoryTaskQueueService impl
   @Override
   public void createTaskQueue(String queueId, String corpusId, String query) {
 
-//    try {
-//      CorpusStore store = CorpusServer.getInstance().getStore().getCorpus(corpusId);
-//      List<String> hits = CorpusServer.getInstance().getSearchService().search(store,
query);
-//
-//      queues.put(queueId, new MemoryTaskQueue(hits));
-//
-//      if (LOGGER.isLoggable(Level.INFO)) {
-//        LOGGER.log(Level.INFO, "Created queue " + queueId +
-//            " with " + hits.size() + "CASes.");
-//      }
-//    } catch (IOException e) {
-//      LOGGER.log(Level.SEVERE, "Failed to create task queue: " + queueId, e);
-//    }
+    try {
+      CorpusServer corpusServer = CorpusServerBundle.getInstance().getCorpusServer();
+      
+      CorpusStore store = corpusServer.getStore().getCorpus(corpusId);
+      List<String> hits = corpusServer.getSearchService().search(store, query);
+
+      queues.put(queueId, new MemoryTaskQueue(hits));
+
+      if (LOGGER.isLoggable(Level.INFO)) {
+        LOGGER.log(Level.INFO, "Created queue " + queueId +
+            " with " + hits.size() + "CASes.");
+      }
+    } catch (IOException e) {
+      LOGGER.log(Level.SEVERE, "Failed to create task queue: " + queueId, e);
+    }
   }
 
   @Override



Mime
View raw message