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 2017/07/06 13:48:16 UTC

svn commit: r1801050 - in /uima/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/RutaStream.java test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java

Author: pkluegl
Date: Thu Jul  6 13:48:16 2017
New Revision: 1801050

URL: http://svn.apache.org/viewvc?rev=1801050&view=rev
Log:
UIMA-5412 - assign floats

Added:
    uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java   (with props)
Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1801050&r1=1801049&r2=1801050&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Thu Jul  6 13:48:16 2017
@@ -1231,6 +1231,9 @@ public class RutaStream extends FSIterat
     if (clazz.equals(Double.class) && expression instanceof INumberExpression) {
       double v = ((INumberExpression) expression).getDoubleValue(context, this);
       environment.setVariableValue(var, v);
+    } else if (clazz.equals(Float.class) && expression instanceof INumberExpression) {
+      float v = (float)((INumberExpression) expression).getDoubleValue(context, this);
+      environment.setVariableValue(var, v);
     } else if (clazz.equals(Integer.class) && expression instanceof INumberExpression) {
       int v = ((INumberExpression) expression).getIntegerValue(context, this);
       environment.setVariableValue(var, v);

Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java?rev=1801050&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java Thu Jul  6 13:48:16 2017
@@ -0,0 +1,56 @@
+/*
+ * 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.ruta.expression.number;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
+import org.junit.Test;
+
+public class FloatVariableExpressionTest {
+
+  @Test
+  public void testAssignOnFloat() throws Exception {
+    String script = "FLOAT a2,a1;";
+    script += "(NUM{PARSE(a1)} \"%\") {-> CREATE (Percent, \"value\" = a1, \"class\" = \"Percent\", \"unit\" = \"%\")};";
+    script += "(NUM{PARSE(a2)} \"‰\") {-> ASSIGN(a2, a2/10), CREATE (Percent, \"value\" = a2, \"class\" = \"Percent\", \"unit\" = \"‰\")};";
+    script += "p:Percent{p.unit == \"%\", p.value==10 -> T1};";
+    script += "p:Percent{p.unit == \"‰\", p.value==1 -> T2};";
+    Map<String, String> complexTypes = new HashMap<>();
+    complexTypes.put("Percent", CAS.TYPE_NAME_ANNOTATION);
+    Map<String, List<TestFeature>> featureMap = new HashMap<>();
+    List<TestFeature> list = new ArrayList<>();
+    list.add(new TestFeature("class", "", CAS.TYPE_NAME_STRING));
+    list.add(new TestFeature("value", "", CAS.TYPE_NAME_FLOAT));
+    list.add(new TestFeature("unit", "", CAS.TYPE_NAME_STRING));
+    featureMap.put("Percent", list);
+    CAS cas = RutaTestUtils.getCAS("10 % , 10 ‰", complexTypes, featureMap);
+    Ruta.apply(cas, script);
+    
+    RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "10 %");
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "10 ‰");
+  }
+
+}

Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/number/FloatVariableExpressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native