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/06/28 01:26:05 UTC
svn commit: r1140369 - in /incubator/opennlp/sandbox/corpus-server: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/opennlp/
src/main/java/org/apache/opennlp/corpus_server/ src/main/resources/ src/...
Author: joern
Date: Mon Jun 27 23:26:04 2011
New Revision: 1140369
URL: http://svn.apache.org/viewvc?rev=1140369&view=rev
Log:
OPENNLP-206 Initial corpus server check in
Added:
incubator/opennlp/sandbox/corpus-server/pom.xml (with props)
incubator/opennlp/sandbox/corpus-server/src/
incubator/opennlp/sandbox/corpus-server/src/main/
incubator/opennlp/sandbox/corpus-server/src/main/java/
incubator/opennlp/sandbox/corpus-server/src/main/java/org/
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/resources/
incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml (with props)
incubator/opennlp/sandbox/corpus-server/src/main/webapp/
incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/
incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml (with props)
Modified:
incubator/opennlp/sandbox/corpus-server/ (props changed)
Propchange: incubator/opennlp/sandbox/corpus-server/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jun 27 23:26:04 2011
@@ -0,0 +1,7 @@
+target
+
+.settings
+
+.classpath
+
+.project
Added: incubator/opennlp/sandbox/corpus-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/pom.xml?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/pom.xml (added)
+++ incubator/opennlp/sandbox/corpus-server/pom.xml Mon Jun 27 23:26:04 2011
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>9</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.opennlp</groupId>
+ <artifactId>corpus-server</artifactId>
+ <version>0.0.1-incubating-SNAPSHOT</version>
+ <packaging>war</packaging>
+
+ <name>OpenNLP Corpus Server</name>
+
+ <prerequisites>
+ <maven>3.0</maven>
+ </prerequisites>
+
+ <repositories>
+ <repository>
+ <id>maven2-repository.java.net</id>
+ <name>Java.net Repository for Maven</name>
+ <url>http://download.java.net/maven/2/</url>
+ <layout>default</layout>
+ </repository>
+ <repository>
+ <id>maven-repository.java.net</id>
+ <name>Java.net Maven 1 Repository (legacy)</name>
+ <url>http://download.java.net/maven/1</url>
+ <layout>legacy</layout>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>1.8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>1.8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.8</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <compilerArgument>-Xlint</compilerArgument>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Propchange: incubator/opennlp/sandbox/corpus-server/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java Mon Jun 27 23:26:04 2011
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Path("/corpora")
+public class CorporaResource {
+
+ @Path("{corpus}")
+ public CorpusResource getCorpus(
+ @PathParam("corpus") String corpus) {
+ return new CorpusResource(corpus);
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java Mon Jun 27 23:26:04 2011
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class CorporaStore {
+
+ private static CorporaStore instance;
+
+ private Map<String, CorpusStore> corpora = new HashMap<String, CorpusStore>();
+
+ public static synchronized CorporaStore getStore() {
+
+ if (instance == null) {
+ instance = new CorporaStore();
+
+ instance.corpora.put("wikinews", new CorpusStore());
+ }
+
+ return instance;
+ }
+
+ public CorpusStore getCorpus(String corpusId) {
+ return corpora.get(corpusId);
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorporaStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java Mon Jun 27 23:26:04 2011
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+public class CorpusResource {
+
+ private final String corpus;
+
+ public CorpusResource(String corpus) {
+ this.corpus = corpus;
+ }
+
+ /**
+ * Adds a new CAS to the store.
+ *
+ */
+ // TODO: Should fail if resource already exists.
+ @POST
+ @Consumes(MediaType.TEXT_XML)
+ @Path("{casId}")
+ public void addCAS(@PathParam("casId") String casId,
+ byte[] cas) throws IOException {
+ CorpusStore corpusStore = CorporaStore.getStore().getCorpus(corpus);
+ corpusStore.addCAS(casId, cas);
+ }
+
+ /**
+ * Updates an existing CAS in the store.
+ */
+ // TODO: Should fail is resource does not exist
+ @PUT
+ @Consumes(MediaType.TEXT_XML)
+ @Path("{casId}")
+ public void updateCAS(@PathParam("casId") String casId,
+ byte[] cas) throws IOException {
+ CorpusStore corpusStore = CorporaStore.getStore().getCorpus(corpus);
+ corpusStore.addCAS(casId, cas);
+ }
+
+ /**
+ * Retrieves an existing CAS form the store.
+ * @param casId
+ * @return
+ */
+ @GET
+ @Produces(MediaType.TEXT_XML)
+ @Path("{casId}")
+ public byte[] getCAS(@PathParam("casId") String casId) {
+ CorpusStore corpusStore = CorporaStore.getStore().getCorpus(corpus);
+ return corpusStore.getCAS(casId);
+ }
+
+ /**
+ * Retrieves the type system for this corpus.
+ * @return
+ */
+ @GET
+ @Produces(MediaType.TEXT_XML)
+ @Path("_typesystem")
+ public byte[] getTypeSystem() {
+ CorpusStore corpusStore = CorporaStore.getStore().getCorpus(corpus);
+ return corpusStore.getTypeSystem();
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("_search")
+ public Collection<String> search(@QueryParam("q") String q) {
+ CorpusStore corpusStore = CorporaStore.getStore().getCorpus(corpus);
+ return corpusStore.search(q);
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java Mon Jun 27 23:26:04 2011
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Dummy in memory corpus store.
+ */
+public class CorpusStore {
+
+ private Map<String, byte[]> casStore = new HashMap<String, byte[]>();
+
+ public byte[] getCAS(String casId) {
+ return casStore.get(casId);
+ }
+
+ public void addCAS(String casID, byte[] content) {
+ casStore.put(casID, content);
+ }
+
+ public byte[] getTypeSystem() {
+
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+
+ InputStream tsIn = CorpusStore.class.getResourceAsStream("/TypeSystem.xml");
+
+ try {
+ byte buffer[] = new byte[1024];
+ int length;
+ while ((length = tsIn.read(buffer)) > 0 ) {
+ bytes.write(buffer, 0, length);
+ }
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return bytes.toByteArray();
+ }
+
+ public Collection<String> search(String query) {
+ return casStore.keySet();
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml Mon Jun 27 23:26:04 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+ <!--
+ ***************************************************************
+ * 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.
+ ***************************************************************
+ -->
+
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <name>TutorialTypeSystem</name>
+ <description>Type System Definition for the tutorial examples - as of Exercise 1</description>
+ <vendor>The Apache Software Foundation</vendor>
+ <version>1.0</version>
+ <types>
+ <typeDescription>
+ <name>org.apache.uima.tutorial.RoomNumber</name>
+ <description></description>
+ <supertypeName>uima.tcas.Annotation</supertypeName>
+ <features>
+ <featureDescription>
+ <name>building</name>
+ <description>Building containing this room</description>
+ <rangeTypeName>uima.cas.String</rangeTypeName>
+ </featureDescription>
+ </features>
+ </typeDescription>
+ </types>
+</typeSystemDescription>
\ No newline at end of file
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/resources/TypeSystem.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml?rev=1140369&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml Mon Jun 27 23:26:04 2011
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="WebApp_ID" version="2.5">
+ <display-name>OpenNLP Corpus Server</display-name>
+ <servlet>
+ <servlet-name>Jersey REST Service</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Jersey REST Service</servlet-name>
+ <url-pattern>/rest/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain