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 2011/07/04 19:41:24 UTC
svn commit: r1142747 - in
/incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer:
CreateCorpus.java FileUtil.java WikinewsImporter.java
Author: joern
Date: Mon Jul 4 17:41:24 2011
New Revision: 1142747
URL: http://svn.apache.org/viewvc?rev=1142747&view=rev
Log:
OPENNLP-209 Added one more util to create a corpus in the corpus server
Added:
incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java (with props)
incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java (with props)
Modified:
incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/WikinewsImporter.java
Added: incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java?rev=1142747&view=auto
==============================================================================
--- incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java (added)
+++ incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java Mon Jul 4 17:41:24 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.wikinews_importer;
+
+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;
+
+/**
+ * Command Line Tool to create a new corpus in the corpus server.
+ */
+public class CreateCorpus {
+ public static void main(String[] args) throws Exception {
+
+ if (args.length != 3) {
+ System.out.println("CreateCorpus address corpusName typeSystemFile");
+ System.exit(-1);
+ }
+
+ String corpusName = args[1];
+
+ Client c = Client.create();
+
+ WebResource r = c.resource(args[0]);
+
+ byte typeSystemBytes[] = FileUtil.fileToBytes(new File(args[2]));
+
+
+ // load ts file from disk into mem ...
+
+ ClientResponse response = r
+ .path("_createCorpus")
+ .queryParam("corpusName", corpusName)
+ .accept(MediaType.TEXT_XML)
+ // TODO: How to fix this? Shouldn't accept do it?
+ .header("Content-Type", MediaType.TEXT_XML)
+ .post(ClientResponse.class, typeSystemBytes);
+
+ System.out.println("Result: " + response.getStatus());
+ }
+}
Propchange: incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/CreateCorpus.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java?rev=1142747&view=auto
==============================================================================
--- incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java (added)
+++ incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java Mon Jul 4 17:41:24 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.wikinews_importer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class FileUtil {
+
+ static byte[] fileToBytes(File file) throws IOException {
+
+ ByteArrayOutputStream fileBytes = new ByteArrayOutputStream(
+ (int) file.length());
+
+ InputStream fileIn = new FileInputStream(file);
+
+ byte buffer[] = new byte[1024];
+ int length;
+ while ((length = fileIn.read(buffer)) > 0) {
+ fileBytes.write(buffer, 0, length);
+ }
+
+ fileIn.close();
+
+ return fileBytes.toByteArray();
+ }
+
+}
Propchange: incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/FileUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/WikinewsImporter.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/WikinewsImporter.java?rev=1142747&r1=1142746&r2=1142747&view=diff
==============================================================================
--- incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/WikinewsImporter.java (original)
+++ incubator/opennlp/sandbox/wikinews-importer/src/main/java/org/apache/opennlp/wikinews_importer/WikinewsImporter.java Mon Jul 4 17:41:24 2011
@@ -17,10 +17,7 @@
package org.apache.opennlp.wikinews_importer;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
import javax.ws.rs.core.MediaType;
@@ -40,27 +37,16 @@ public class WikinewsImporter {
Client c = Client.create();
WebResource r = c.resource(args[0]);
-
- // read file into bytes
- File xmiFile = new File(args[1]);
- ByteArrayOutputStream xmiBytes = new ByteArrayOutputStream((int) xmiFile.length());
-
- InputStream xmiIn = new FileInputStream(xmiFile);
- byte buffer[] = new byte[1024];
- int length;
- while ((length = xmiIn.read(buffer)) > 0) {
- xmiBytes.write(buffer, 0, length);
- }
-
- xmiIn.close();
+ File xmiFile = new File(args[1]);
+ byte xmiBytes[] = FileUtil.fileToBytes(xmiFile);
ClientResponse response = r
.path(xmiFile.getName())
.accept(MediaType.TEXT_XML)
// TODO: How to fix this? Shouldn't accept do it?
.header("Content-Type", MediaType.TEXT_XML)
- .post(ClientResponse.class, xmiBytes.toByteArray());
+ .post(ClientResponse.class, xmiBytes);
System.out.println(xmiFile.getName() + " " + response.getStatus());
}