You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2022/01/10 10:24:18 UTC

[uima-ruta] branch UIMA-6408-Ruta-No-type-check-of-features-in-TRANSFER created (now 30ef597)

This is an automated email from the ASF dual-hosted git repository.

pkluegl pushed a change to branch UIMA-6408-Ruta-No-type-check-of-features-in-TRANSFER
in repository https://gitbox.apache.org/repos/asf/uima-ruta.git.


      at 30ef597  UIMA-6408: Ruta: No type check of features in TRANSFER

This branch includes the following new commits:

     new 30ef597  UIMA-6408: Ruta: No type check of features in TRANSFER

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[uima-ruta] 01/01: UIMA-6408: Ruta: No type check of features in TRANSFER

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkluegl pushed a commit to branch UIMA-6408-Ruta-No-type-check-of-features-in-TRANSFER
in repository https://gitbox.apache.org/repos/asf/uima-ruta.git

commit 30ef5979dd258f4a2ba91dbf8842b58aee85820d
Author: Peter Klügl <pe...@averbis.com>
AuthorDate: Mon Jan 10 11:24:01 2022 +0100

    UIMA-6408: Ruta: No type check of features in TRANSFER
    
    - log instead of thowing an exception
---
 .../apache/uima/ruta/action/TransferAction.java    | 15 +++++++-
 .../org/apache/uima/ruta/action/TransferTest.java  | 44 ++++++++++++++++++++--
 2 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java b/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java
index bf38e7b..cb4694b 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java
@@ -21,6 +21,7 @@ package org.apache.uima.ruta.action;
 
 import java.util.List;
 
+import org.apache.uima.UimaContextHolder;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.FeatureStructure;
@@ -79,10 +80,20 @@ public class TransferAction extends TypeSensitiveAction {
       if (newFeature != null) {
         if (feature.getRange().isPrimitive()) {
           String value = oldFS.getFeatureValueAsString(feature);
-          newFS.setFeatureValueFromString(newFeature, value);
+          try {
+            newFS.setFeatureValueFromString(newFeature, value);
+          } catch (Exception e) {
+            UimaContextHolder.getContext().getLogger().debug("Unable to transfer feature {}: {}",
+                    shortName, e.getMessage());
+          }
         } else {
           FeatureStructure value = oldFS.getFeatureValue(feature);
-          newFS.setFeatureValue(newFeature, value);
+          try {
+            newFS.setFeatureValue(newFeature, value);
+          } catch (Exception e) {
+            UimaContextHolder.getContext().getLogger().debug("Unable to transfer feature {}: {}",
+                    shortName, e.getMessage());
+          }
         }
       }
     }
diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/action/TransferTest.java b/ruta-core/src/test/java/org/apache/uima/ruta/action/TransferTest.java
index 31f4a89..bac9613 100644
--- a/ruta-core/src/test/java/org/apache/uima/ruta/action/TransferTest.java
+++ b/ruta-core/src/test/java/org/apache/uima/ruta/action/TransferTest.java
@@ -21,6 +21,9 @@ package org.apache.uima.ruta.action;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -30,8 +33,10 @@ import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.ruta.engine.Ruta;
 import org.apache.uima.ruta.engine.RutaEngine;
 import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
 import org.junit.Test;
 
 public class TransferTest {
@@ -45,8 +50,8 @@ public class TransferTest {
     complexTypes.put(type, CAS.TYPE_NAME_DOCUMENT_ANNOTATION);
     CAS cas = null;
     try {
-      cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, namespace + "/" + name
-              + ".txt", 50, false, false, complexTypes, null);
+      cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+              namespace + "/" + name + ".txt", 50, false, false, complexTypes, null);
     } catch (Exception e) {
       e.printStackTrace();
       assert (false);
@@ -63,7 +68,40 @@ public class TransferTest {
     Feature featureByBaseName = t.getFeatureByBaseName("language");
     String stringValue = afs.getStringValue(featureByBaseName);
     assertEquals("x-unspecified", stringValue);
-   
+
     cas.release();
   }
+
+  @Test
+  public void testIncompatibleFeatureRanges() throws Exception {
+
+    Map<String, String> typeMap = new LinkedHashMap<String, String>();
+    typeMap.put("Struct11", "uima.tcas.Annotation");
+    typeMap.put("Struct12", "uima.tcas.Annotation");
+    typeMap.put("Struct21", "uima.tcas.Annotation");
+    typeMap.put("Struct22", "uima.tcas.Annotation");
+    Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>();
+    featureMap.put("Struct11", Arrays.asList(new TestFeature("f", "", CAS.TYPE_NAME_ANNOTATION)));
+    featureMap.put("Struct12", Arrays.asList(new TestFeature("f", "", CAS.TYPE_NAME_STRING)));
+    featureMap.put("Struct21",
+            Arrays.asList(new TestFeature("array", "", CAS.TYPE_NAME_STRING_ARRAY)));
+    featureMap.put("Struct22",
+            Arrays.asList(new TestFeature("array", "", CAS.TYPE_NAME_BOOLEAN_ARRAY)));
+
+    CAS cas = RutaTestUtils.getCAS("This is a test.", typeMap, featureMap);
+    String script = "CW{->s:Struct11,s.f=CW};";
+    script += "CW{->s:Struct21,s.array={true, false, true}};";
+    script += "Struct11{-> TRANSFER(Struct12)};";
+    script += "Struct21{-> TRANSFER(Struct22)};";
+
+    Ruta.apply(cas, script, RutaTestUtils.getDebugParams());
+
+    if (RutaTestUtils.DEBUG_MODE) {
+      RutaTestUtils.storeTypeSystem(typeMap, featureMap);
+      RutaTestUtils.storeCas(cas, "testIncompatibleFeatureRanges");
+    }
+
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 0);
+
+  }
 }