You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2014/12/18 22:06:54 UTC

svn commit: r1646533 - in /uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/impl/ test/java/org/apache/uima/analysis_engine/impl/ test/resources/TextAnalysisEngineImplTest/

Author: eae
Date: Thu Dec 18 21:06:54 2014
New Revision: 1646533

URL: http://svn.apache.org/r1646533
Log:
UIMA-3765

Added:
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java   (with props)
    uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml   (with props)
Modified:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/Util.java
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/Util.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/Util.java?rev=1646533&r1=1646532&r2=1646533&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/Util.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/Util.java Thu Dec 18 21:06:54 2014
@@ -32,19 +32,23 @@ import org.apache.uima.resource.impl.Cas
  */
 public class Util {
   
-  public static CASImpl getStartingView(CAS cas, boolean sofaAware, ComponentInfo componentInfo) {   
-    // if this is a sofa-aware component, give it the Base CAS
-    // if it is a sofa-unaware component, give it whatever view maps to the _InitialView
+  public static CASImpl getStartingView(CAS cas, boolean sofaAware, ComponentInfo componentInfo) {
+    // OLD behavior:
+      // if this is a sofa-aware component, give it the Base CAS
+      // if it is a sofa-unaware component, give it whatever view maps to the _InitialView
+    // NEW behavior:
+      // always return whatever view maps to the _InitialView
     CASImpl ci;
     // need to set the componentInfo for the getView to find the sofa mappings
     // Do this *before* the getView call below
     // note: this is in a shared view part of the CAS
     cas.setCurrentComponentInfo(componentInfo);  
-    if (sofaAware) {
-      ci = ((CASImpl) cas).getBaseCAS();
-    } else {
-      ci = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);
-    }
+//    if (sofaAware) {
+//      ci = ((CASImpl) cas).getBaseCAS();
+//    } else {
+//      ci = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);
+//    }
+    ci = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);
     
     return ci;
   }

Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java?rev=1646533&r1=1646532&r2=1646533&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java Thu Dec 18 21:06:54 2014
@@ -1575,6 +1575,24 @@ public class AnalysisEngine_implTest ext
     assertEquals("D/C/B/A/F/E/", TestAnnotator2.allContexts);
     cloneFile.delete();
   }
+
+  public void testMultiViewAnnotatorInput() throws Exception {
+    try {
+      AnalysisEngineDescription transAnnotatorDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+              new XMLInputSource(JUnitExtension
+                      .getFile("TextAnalysisEngineImplTest/MultiViewAnnotator.xml")));
+      PrimitiveAnalysisEngine_impl ae = new PrimitiveAnalysisEngine_impl();
+      ae.initialize(transAnnotatorDesc, null);
+      CAS tcas = ae.newCAS();
+      tcas.setDocumentText("this beer is good");
+      assertTrue(tcas.getView("_InitialView").getDocumentText().equals("this beer is good"));
+      ae.process(tcas);
+      assertTrue(tcas.getView("GermanDocument").getViewName().equals("GermanDocument"));
+      assertTrue(tcas.getView("GermanDocument").getDocumentText().equals("das bier ist gut"));
+    } catch (Exception e) {
+      JUnitExtension.handleException(e);
+    }
+  }
   
   /*
    * Get size of file asif has a single line-end character

Added: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java?rev=1646533&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java (added)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java Thu Dec 18 21:06:54 2014
@@ -0,0 +1,117 @@
+/*
+ * 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.uima.analysis_engine.impl;
+
+import java.util.Arrays;
+import java.util.StringTokenizer;
+
+import org.apache.uima.analysis_engine.ResultSpecification;
+import org.apache.uima.analysis_engine.annotator.AnnotatorProcessException;
+import org.apache.uima.analysis_engine.annotator.Annotator_ImplBase;
+import org.apache.uima.analysis_engine.annotator.GenericAnnotator;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.SofaID;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+
+/**
+ * Simple English to German translator
+ * ... expects input "English" view to be delivered to process()
+ * 
+ */
+public class MultiViewAnnotator extends Annotator_ImplBase implements GenericAnnotator {
+
+  public void process(CAS aCas, ResultSpecification aResultSpec) throws AnnotatorProcessException {
+    CAS engTcas, germTcas;
+
+    engTcas = aCas;
+
+    // Create the output German text Sofa and open CAS view
+    germTcas = aCas.createView("GermanDocument");
+
+    // Get some necessary Type System constants
+    Type annot = engTcas.getAnnotationType();
+    Type cross = engTcas.getTypeSystem().getType("sofa.test.CrossAnnotation");
+    Feature other = cross.getFeatureByBaseName("otherAnnotation");
+
+    // Get the English text
+    String engText = engTcas.getDocumentText();
+
+    // Setup for translated text
+    int engEnd = 0;
+    int germBegin = 0;
+    int germEnd = 0;
+    StringBuffer translation = new StringBuffer();
+
+    // Parse the English text
+    StringTokenizer st = new StringTokenizer(engText);
+    while (st.hasMoreTokens()) {
+      String thisTok = st.nextToken();
+      int engBegin = engText.indexOf(thisTok, engEnd);
+      engEnd = engBegin + thisTok.length();
+
+      // Create token annotations on English text
+      AnnotationFS engAnnot = engTcas.createAnnotation(annot, engBegin, engEnd);
+      engTcas.getIndexRepository().addFS(engAnnot);
+
+      // Simple word-by-word translation
+      String germWord = Translate(thisTok);
+
+      // Accumulate the translated text
+      if (germBegin > 0) {
+        translation.append(' ');
+        germBegin += 1;
+      }
+      translation.append(germWord.toCharArray(), 0, germWord.length());
+
+      // Create token annotations on German text
+      germEnd = germBegin + germWord.length();
+      AnnotationFS germAnnot = germTcas.createAnnotation(cross, germBegin, germEnd);
+      germTcas.getIndexRepository().addFS(germAnnot);
+
+      // add link to English text
+      germAnnot.setFeatureValue(other, engAnnot);
+      germBegin = germEnd;
+    }
+
+    // Finally, set the output tranlation Sofa data
+    germTcas.setDocumentText(translation.toString());
+
+  }
+
+  static char wThis[] = { 't', 'h', 'i', 's' };
+
+  static char wBeer[] = { 'b', 'e', 'e', 'r' };
+
+  static char wIs[] = { 'i', 's' };
+
+  private String Translate(String word) {
+    String lword = word.toLowerCase();
+    if (Arrays.equals(wThis, lword.toCharArray()))
+      return "das";
+    if (Arrays.equals(wBeer, lword.toCharArray()))
+      return "bier";
+    if (Arrays.equals(wIs, lword.toCharArray()))
+      return "ist";
+    return "gut";
+  }
+
+}

Propchange: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/MultiViewAnnotator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml?rev=1646533&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml (added)
+++ uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml Thu Dec 18 21:06:54 2014
@@ -0,0 +1,65 @@
+<?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.
+ -->
+
+<!-- For testing only. -->
+
+<taeDescription xmlns="http://uima.apache.org/resourceSpecifier">
+<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+<primitive>true</primitive>
+<annotatorImplementationName>org.apache.uima.analysis_engine.impl.MultiViewAnnotator</annotatorImplementationName>
+ 
+<analysisEngineMetaData>
+<name>Multi View Annotator</name>
+<description>Takes a Text SofA as input and creates output SofA in de CAS.
+  For testing input view delivered to view-aware annotator.</description>
+<version>1.0</version>
+<vendor>The Apache Software Foundation</vendor>
+<typeSystemDescription>
+  <types>
+    <typeDescription>
+      <name>sofa.test.CrossAnnotation</name>
+      <description></description>
+      <supertypeName>uima.tcas.Annotation</supertypeName>
+      <features>
+	<featureDescription>
+	  <name>otherAnnotation</name>
+	  <description></description>
+	  <rangeTypeName>uima.tcas.Annotation</rangeTypeName>
+	</featureDescription>
+      </features>
+    </typeDescription>
+  </types>
+</typeSystemDescription>
+<capabilities>
+	<capability>
+		<inputs>					
+		</inputs>
+		<inputSofas>
+			<sofaName>EnglishDocument</sofaName>
+		</inputSofas>	
+		<outputSofas>
+			<sofaName>GermanDocument</sofaName>
+		</outputSofas>	
+		<!--outputs>
+		</outputs-->			
+	</capability>
+</capabilities>
+</analysisEngineMetaData>
+</taeDescription>

Propchange: uima/uimaj/trunk/uimaj-core/src/test/resources/TextAnalysisEngineImplTest/MultiViewAnnotator.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain