You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2019/11/30 18:58:22 UTC

svn commit: r1870639 [1/2] - in /ctakes/trunk/ctakes-tiny-rest: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ctakes/ src/main/java/org/apache/ctakes/rest/ src/main/java/org/apache/ctakes/rest/se...

Author: seanfinan
Date: Sat Nov 30 18:58:21 2019
New Revision: 1870639

URL: http://svn.apache.org/viewvc?rev=1870639&view=rev
Log:
Add tiny rest service.  
ctakes-web-rest is heavyweight and is a complete ctakes installation.  
Tiny rest is more standalone and can be utilized in flexible installations.

Added:
    ctakes/trunk/ctakes-tiny-rest/
    ctakes/trunk/ctakes-tiny-rest/pom.xml
    ctakes/trunk/ctakes-tiny-rest/src/
    ctakes/trunk/ctakes-tiny-rest/src/main/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/AbstractTinyController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/DefaultTinyController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/RestPipelineRunner.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyFhirJsonController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPrettyPrintController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPropertyController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyXmiController.java
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/MANIFEST.MF
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/ctakes-rest-service-servlet.xml
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/web.xml
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/index.jsp
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/app.js
    ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/jquery.js

Added: ctakes/trunk/ctakes-tiny-rest/pom.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/pom.xml?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/pom.xml (added)
+++ ctakes/trunk/ctakes-tiny-rest/pom.xml Sat Nov 30 18:58:21 2019
@@ -0,0 +1,56 @@
+<?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/xsd/maven-4.0.0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+   <artifactId>ctakes-tiny-rest</artifactId>
+   <name>Apache cTAKES Tiny Rest Service</name>
+   <parent>
+      <artifactId>ctakes</artifactId>
+      <groupId>org.apache.ctakes</groupId>
+      <version>4.0.1-SNAPSHOT</version>
+   </parent>
+   <description>Tiny Rest Service to run a ctakes pipeline.</description>
+
+   <properties>
+      <springframework.version>4.3.12.RELEASE</springframework.version>
+   </properties>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.springframework</groupId>
+         <artifactId>spring-web</artifactId>
+         <version>${springframework.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.apache.ctakes</groupId>
+         <artifactId>ctakes-fhir</artifactId>
+      </dependency>
+
+   </dependencies>
+
+   <build>
+   </build>
+
+</project>

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/AbstractTinyController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/AbstractTinyController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/AbstractTinyController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/AbstractTinyController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,49 @@
+package org.apache.ctakes.rest.service;
+
+
+import org.apache.log4j.Logger;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 10/30/2019
+ */
+abstract public class AbstractTinyController implements TinyController {
+
+   static private final Logger LOGGER = Logger.getLogger( "TinyController" );
+
+   static private volatile boolean _initialized = false;
+
+   @PostConstruct
+   public void init() throws ResourceInitializationException {
+      synchronized ( LOGGER ) {
+         if ( _initialized ) {
+            return;
+         }
+         LOGGER.info( "Initializing analysis engine ..." );
+         try {
+            // The first access of a singleton enum instantiates it.
+            RestPipelineRunner.getInstance();
+         } catch ( ExceptionInInitializerError initE ) {
+            throw new ResourceInitializationException( initE );
+         }
+         LOGGER.info( "Analysis Engine Initialized." );
+         _initialized = true;
+      }
+   }
+
+   @RequestMapping( value = "/process", method = RequestMethod.POST )
+//   @ResponseBody
+   public String processText( @RequestBody final String text ) throws AnalysisEngineProcessException {
+      return RestPipelineRunner.getInstance().process( this, text );
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/DefaultTinyController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/DefaultTinyController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/DefaultTinyController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/DefaultTinyController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,48 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.fhir.cc.FhirJsonWriter;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/*
+ * Rest web service that takes clinical text
+ * as input and produces extracted text as output
+ */
+@RestController
+@RequestMapping
+public class DefaultTinyController extends AbstractTinyController {
+
+
+   /**
+    * Returns the document information according to the fhir standard, formatted in json.
+    * {@inheritDoc}
+    */
+   @Override
+   public String getResultText( final JCas jCas ) throws AnalysisEngineProcessException {
+      return FhirJsonWriter.createJson( jCas );
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/RestPipelineRunner.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/RestPipelineRunner.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/RestPipelineRunner.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/RestPipelineRunner.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,95 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.core.pipeline.PipelineBuilder;
+import org.apache.ctakes.core.pipeline.PiperFileReader;
+import org.apache.log4j.Logger;
+import org.apache.uima.UIMAException;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CASRuntimeException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.JCasPool;
+
+import java.io.IOException;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 11/5/2019
+ */
+public enum RestPipelineRunner {
+   INSTANCE;
+
+   static public RestPipelineRunner getInstance() {
+      return INSTANCE;
+   }
+
+   static private final Logger LOGGER = Logger.getLogger( "RestPipelineRunner" );
+
+   // Use a constant piper name.
+   // This piper can wrap (load *) another piper that contains the actual desired pipeline.
+   static private final String REST_PIPER_FILE_PATH = "TinyRestPipeline.piper";
+
+   private final AnalysisEngine _engine;
+   private final JCasPool _pool;
+
+   RestPipelineRunner() {
+      try {
+         final PiperFileReader reader = new PiperFileReader( REST_PIPER_FILE_PATH );
+         final PipelineBuilder builder = reader.getBuilder();
+
+         final AnalysisEngineDescription pipeline = builder.getAnalysisEngineDesc();
+         _engine = UIMAFramework.produceAnalysisEngine( pipeline );
+         _pool = new JCasPool( 2, _engine );
+      } catch ( IOException | UIMAException multE ) {
+         throw new ExceptionInInitializerError( multE );
+      }
+   }
+
+   public String process( final TinyController tinyController, final String text )
+         throws AnalysisEngineProcessException {
+      if ( text == null || text.trim().isEmpty() ) {
+         return "";
+      }
+      synchronized ( REST_PIPER_FILE_PATH ) {
+         final JCas jcas = _pool.getJCas( -1 );
+         if ( jcas == null ) {
+            throw new AnalysisEngineProcessException( new Throwable( "Could not acquire JCas from pool." ) );
+         }
+         try {
+            jcas.reset();
+            jcas.setDocumentText( text );
+            _engine.process( jcas );
+            final String resultText = tinyController.getResultText( jcas );
+            _pool.releaseJCas( jcas );
+            return resultText;
+         } catch ( CASRuntimeException | AnalysisEngineProcessException multE ) {
+            LOGGER.error( "Error processing text." );
+            throw new AnalysisEngineProcessException( multE );
+         }
+      }
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,34 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 11/5/2019
+ */
+public interface TinyController {
+
+   String getResultText( final JCas jCas ) throws AnalysisEngineProcessException;
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyFhirJsonController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyFhirJsonController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyFhirJsonController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyFhirJsonController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,47 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.fhir.cc.FhirJsonWriter;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/*
+ * Rest web service that takes clinical text
+ * as input and produces extracted text as output
+ */
+@RestController
+@RequestMapping( "/fhirjson" )
+public class TinyFhirJsonController extends AbstractTinyController {
+
+   /**
+    * Returns the document information according to the fhir standard, formatted in json.
+    * {@inheritDoc}
+    */
+   @Override
+   public String getResultText( final JCas jCas ) throws AnalysisEngineProcessException {
+      return FhirJsonWriter.createJson( jCas );
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPrettyPrintController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPrettyPrintController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPrettyPrintController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPrettyPrintController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,64 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.core.cc.pretty.plaintext.PrettyTextWriter;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Collection;
+
+
+/*
+ * Rest web service that takes clinical text
+ * as input and produces extracted text as output
+ */
+@RestController
+@RequestMapping( "/prettyprint" )
+public class TinyPrettyPrintController extends AbstractTinyController {
+
+
+   /**
+    * Returns the document information in a marked plain text format.
+    * {@inheritDoc}
+    */
+   @Override
+   public String getResultText( final JCas jCas ) throws AnalysisEngineProcessException {
+      try ( final StringWriter stringWriter = new StringWriter();
+            final BufferedWriter writer = new BufferedWriter( stringWriter ) ) {
+         final Collection<Sentence> sentences = JCasUtil.select( jCas, Sentence.class );
+         for ( Sentence sentence : sentences ) {
+            PrettyTextWriter.writeSentence( jCas, sentence, writer );
+         }
+         return stringWriter.toString();
+      } catch ( IOException ioE ) {
+         throw new AnalysisEngineProcessException( ioE );
+      }
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPropertyController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPropertyController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPropertyController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyPropertyController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,64 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.core.cc.property.plaintext.PropertyTextWriter;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.util.JCasUtil;
+import org.apache.uima.jcas.JCas;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Collection;
+
+
+/*
+ * Rest web service that takes clinical text
+ * as input and produces extracted text as output
+ */
+@RestController
+@RequestMapping( "/property" )
+public class TinyPropertyController extends AbstractTinyController {
+
+
+   /**
+    * Returns the document entities and relations in a list.
+    * {@inheritDoc}
+    */
+   @Override
+   public String getResultText( final JCas jCas ) throws AnalysisEngineProcessException {
+      try ( final StringWriter stringWriter = new StringWriter();
+            final BufferedWriter writer = new BufferedWriter( stringWriter ) ) {
+         final Collection<Sentence> sentences = JCasUtil.select( jCas, Sentence.class );
+         for ( Sentence sentence : sentences ) {
+            PropertyTextWriter.writeSentence( jCas, sentence, writer );
+         }
+         return stringWriter.toString();
+      } catch ( IOException ioE ) {
+         throw new AnalysisEngineProcessException( ioE );
+      }
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyXmiController.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyXmiController.java?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyXmiController.java (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/java/org/apache/ctakes/rest/service/TinyXmiController.java Sat Nov 30 18:58:21 2019
@@ -0,0 +1,63 @@
+package org.apache.ctakes.rest.service;
+
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+
+import org.apache.ctakes.core.cc.XMISerializer;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.jcas.JCas;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.xml.sax.SAXException;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/*
+ * Rest web service that takes clinical text
+ * as input and produces extracted text as output
+ */
+@RestController
+@RequestMapping( "/xmi" )
+public class TinyXmiController extends AbstractTinyController {
+
+
+   /**
+    * Returns the document information formatted in uima xmi.
+    * {@inheritDoc}
+    */
+   @Override
+   public String getResultText( final JCas jCas ) throws AnalysisEngineProcessException {
+      try ( final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+            OutputStream outputStream = new BufferedOutputStream( byteStream ) ) {
+         XmiCasSerializer casSerializer = new XmiCasSerializer( jCas.getTypeSystem() );
+         XMISerializer xmiSerializer = new XMISerializer( outputStream );
+         casSerializer.serialize( jCas.getCas(), xmiSerializer.getContentHandler() );
+         return byteStream.toString();
+      } catch ( SAXException | IOException multiE ) {
+         throw new AnalysisEngineProcessException( multiE );
+      }
+   }
+
+
+}

Added: ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/MANIFEST.MF?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/MANIFEST.MF (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/webapp/META-INF/MANIFEST.MF Sat Nov 30 18:58:21 2019
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+

Added: ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/ctakes-rest-service-servlet.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/ctakes-rest-service-servlet.xml?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/ctakes-rest-service-servlet.xml (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/ctakes-rest-service-servlet.xml Sat Nov 30 18:58:21 2019
@@ -0,0 +1,16 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context
+        http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
+   <mvc:annotation-driven/>
+   <context:component-scan base-package="org.apache.ctakes.rest.service"/>
+   <mvc:cors>
+      <!-- allowed-origin can be set to specific valid URLs to tighten security -->
+      <mvc:mapping path="/service/**" allowed-origins="*"
+                   allowed-methods="POST, GET, PUT, OPTIONS, DELETE"
+                   allowed-headers="Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization"
+                   exposed-headers="Origin,Access-Control-Request-Method,Access-Control-Allow-Origin,Access-Control-Allow-Credentials"
+                   allow-credentials="false"/>
+   </mvc:cors>
+</beans>

Added: ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/web.xml?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/web.xml (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/webapp/WEB-INF/web.xml Sat Nov 30 18:58:21 2019
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+   <display-name>ctakes-rest-service</display-name>
+   <servlet>
+      <servlet-name>ctakes-rest-service</servlet-name>
+      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+      <load-on-startup>0</load-on-startup>
+   </servlet>
+   <servlet-mapping>
+      <servlet-name>ctakes-rest-service</servlet-name>
+      <url-pattern>/service/*</url-pattern>
+   </servlet-mapping>
+   <!--    <filter>-->
+   <!--        <filter-name>CORS</filter-name>-->
+   <!--        <filter-class>org.apache.ctakes.rest.filter.CORSFilter</filter-class>-->
+   <!--    </filter>-->
+   <!--    <filter-mapping>-->
+   <!--        <filter-name>CORS</filter-name>-->
+   <!--        <url-pattern>/service/*</url-pattern>-->
+   <!--    </filter-mapping>-->
+</web-app>

Added: ctakes/trunk/ctakes-tiny-rest/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/webapp/index.jsp?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/webapp/index.jsp (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/webapp/index.jsp Sat Nov 30 18:58:21 2019
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+
+<html>
+    <head>
+<!--        <link rel="stylesheet" type="text/css" href="css/index.css">    -->
+        <title> cTAKES Proof of Function Service </title>
+		<script type="text/javascript" src="js/jquery.js"></script>			
+		<script type="text/javascript" src="js/app.js"></script>
+        <script>var myContextPath = "${pageContext.request.contextPath}"</script>
+    </head>
+    <body>
+        <img src="http://ctakes.apache.org/images/ctakes_logo.jpg"/>
+        <br>Version: 4.0.1</br>
+		</br>
+        <h3>cTAKES Tiny REST Service Tester</h3>
+        <textarea id="documentText" name="documentText" rows="6" cols="75" onFocus="this.value=''">Enter your text for analysis.</textarea>
+        <br>
+        <input type="button" value="FHIR" name="fhirjson" id="fhirjson"/>
+        <input type="button" value="Text" name="text" id="text"/>
+        <input type="button" value="Property" name="property" id="property"/>
+        <input type="button" value="XMI" name="xmi" id="xmi"/>
+        <br>
+         <textarea id="resultText" name="resultText" rows="6" cols="75" readonly>Your Result will appear here.</textarea>
+         <br>
+</body>
+</html>

Added: ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/app.js
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/app.js?rev=1870639&view=auto
==============================================================================
--- ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/app.js (added)
+++ ctakes/trunk/ctakes-tiny-rest/src/main/webapp/js/app.js Sat Nov 30 18:58:21 2019
@@ -0,0 +1,86 @@
+$(document).ready(function() {
+     $('#fhirjson').click(function() {
+         document.getElementById("resultText").innerHTML = "Processing ...";
+         try {
+            $.ajax({
+				url: myContextPath + "/service/fhirjson",
+				type: "POST",
+				crossDomain: true,
+				cache: false,
+				async: true,
+				data: document.getElementById("documentText").value,
+				error: function(xhr, statusText, error) {
+					 document.getElementById("resultText").innerHTML = "Error processing REST call";
+				},
+				success: function(response, statusText, xhr) {
+				   document.getElementById("resultText").innerHTML = response;
+				}
+			})
+        } catch (err) {
+             document.getElementById("resultText").innerHTML = "Error invoking REST call";
+        }
+    });
+     $('#text').click(function() {
+         document.getElementById("resultText").innerHTML = "Processing ...";
+         try {
+            $.ajax({
+				url: myContextPath + "/service/text",
+				type: "POST",
+				crossDomain: true,
+				cache: false,
+				async: true,
+				data: document.getElementById("documentText").value,
+				error: function(xhr, statusText, error) {
+					 document.getElementById("resultText").innerHTML = "Error processing REST call";
+				},
+				success: function(response, statusText, xhr) {
+				   document.getElementById("resultText").innerHTML = response;
+				}
+			})
+        } catch (err) {
+             document.getElementById("resultText").innerHTML = "Error invoking REST call";
+        }
+    });
+     $('#property').click(function() {
+         document.getElementById("resultText").innerHTML = "Processing ...";
+         try {
+            $.ajax({
+				url: myContextPath + "/service/property",
+				type: "POST",
+				crossDomain: true,
+				cache: false,
+				async: true,
+				data: document.getElementById("documentText").value,
+				error: function(xhr, statusText, error) {
+					 document.getElementById("resultText").innerHTML = "Error processing REST call";
+				},
+				success: function(response, statusText, xhr) {
+				   document.getElementById("resultText").innerHTML = response;
+				}
+			})
+        } catch (err) {
+             document.getElementById("resultText").innerHTML = "Error invoking REST call";
+        }
+    });
+     $('#xmi').click(function() {
+         document.getElementById("resultText").innerHTML = "Processing ...";
+         try {
+            $.ajax({
+				url: myContextPath + "/service/xmi",
+				type: "POST",
+				crossDomain: true,
+				cache: false,
+				async: true,
+				data: document.getElementById("documentText").value,
+				error: function(xhr, statusText, error) {
+					 document.getElementById("resultText").innerHTML = "Error processing REST call";
+				},
+				success: function(response, statusText, xhr) {
+				   document.getElementById("resultText").innerHTML = response;
+				}
+			})
+        } catch (err) {
+             document.getElementById("resultText").innerHTML = "Error invoking REST call";
+        }
+    });
+});