Author: pkluegl Date: Fri Nov 8 13:47:38 2019 New Revision: 1869559 URL: http://svn.apache.org/viewvc?rev=1869559&view=rev Log: UIMA-4622: improving old action
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java?rev=1869559&r1=1869558&r2=1869559&view=diff ============================================================================== --- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java (original) +++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java Fri Nov 8 13:47:38 2019 @@ -35,8 +35,6 @@ import org.apache.uima.ruta.expression.s import org.apache.uima.ruta.rule.MatchContext; import org.apache.uima.ruta.rule.RuleElement; import org.apache.uima.ruta.rule.RuleMatch; -import org.apache.uima.ruta.rule.RutaMatcher; -import org.apache.uima.ruta.rule.RutaRuleElement; import org.apache.uima.ruta.visitor.InferenceCrowd; public class GetFeatureAction extends AbstractRutaAction { @@ -55,36 +53,31 @@ public class GetFeatureAction extends Ab public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { RuleMatch match = context.getRuleMatch(); RuleElement element = context.getElement(); - // TODO refactor RutaBlock parent = element.getParent(); - Type type = null; - if (element instanceof RutaRuleElement) { - RutaMatcher matcher = ((RutaRuleElement) element).getMatcher(); - if (matcher != null) { - type = matcher.getType(parent, stream); - } - } - if (type == null) { + AnnotationFS annotation = context.getAnnotation(); + if (annotation == null) { return; } String stringValue = featureStringExpression.getStringValue(context, stream); - Feature featureByBaseName = type.getFeatureByBaseName(stringValue); + RutaEnvironment environment = parent.getEnvironment(); List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOfElement(element); for (AnnotationFS annotationFS : matchedAnnotations) { - if (annotationFS.getType().getFeatureByBaseName(stringValue) == null) { + Feature featureByBaseName = annotationFS.getType().getFeatureByBaseName(stringValue); + if (featureByBaseName == null) { Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Can't access feature " + stringValue + ", because it's not defined in the matched type: " + annotationFS.getType().getName()); - return; + continue; } TypeSystem typeSystem = stream.getCas().getTypeSystem(); Type range = featureByBaseName.getRange(); String featName = range.getName(); + if (environment.getVariableType(variable).equals(String.class) && typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), range)) { Object value = annotationFS.getStringValue(featureByBaseName); Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java?rev=1869559&r1=1869558&r2=1869559&view=diff ============================================================================== --- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java (original) +++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/CreateTest.java Fri Nov 8 13:47:38 2019 @@ -89,7 +89,7 @@ public class CreateTest { } @Test - public void testFeature() { + public void testFeature() throws Exception { String document = "Test."; String script = ""; script += "W{-> CREATE(Inner, \"word\" = W)};"; @@ -122,13 +122,8 @@ public class CreateTest { String fn3 = "word"; list.add(new TestFeature(fn3, "", "uima.tcas.Annotation")); - CAS cas = null; - try { - cas = RutaTestUtils.getCAS(document, typeMap, featureMap); - Ruta.apply(cas, script); - } catch (Exception e) { - e.printStackTrace(); - } + CAS cas = RutaTestUtils.getCAS(document, typeMap, featureMap); + Ruta.apply(cas, script); Type t = null; AnnotationIndex<AnnotationFS> ai = null; @@ -145,6 +140,5 @@ public class CreateTest { assertEquals("Test", ((AnnotationFS) fv1).getCoveredText()); - cas.release(); } } Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java?rev=1869559&r1=1869558&r2=1869559&view=diff ============================================================================== --- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java (original) +++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/GetFeatureTest.java Fri Nov 8 13:47:38 2019 @@ -29,9 +29,7 @@ public class GetFeatureTest { public void test() { CAS cas = RutaTestUtils.processTestScript(this.getClass()); - RutaTestUtils.assertAnnotationsEquals(cas, 1, 1); - - cas.release(); } + }