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 2015/11/06 19:16:24 UTC

svn commit: r1713009 - in /uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation: AnnotationAddressExpression.java AnnotationLabelExpression.java LabelAnnotationExpression.java

Author: pkluegl
Date: Fri Nov  6 18:16:24 2015
New Revision: 1713009

URL: http://svn.apache.org/viewvc?rev=1713009&view=rev
Log:
UIMA-4408 + UIMA-4683
- added some impls for address and label expression

Added:
    uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java   (with props)
    uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpression.java
      - copied, changed from r1712996, uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/LabelAnnotationExpression.java
Removed:
    uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/LabelAnnotationExpression.java

Added: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java?rev=1713009&view=auto
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java (added)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java Fri Nov  6 18:16:24 2015
@@ -0,0 +1,66 @@
+/*
+ * 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.annotation;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.LowLevelCAS;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
+
+
+/**
+ *  An expression referring to an annotation identified by its address.  
+ *
+ */
+public class AnnotationAddressExpression extends AbstractAnnotationExpression {
+
+  private String address;
+  
+  public AnnotationAddressExpression(String address) {
+    super();
+    this.address = address;
+  }
+  
+  
+  @Override
+  public AnnotationFS getAnnotation(MatchContext context, RutaStream stream) {
+    Integer ref = Integer.valueOf(address);
+    CAS cas = stream.getCas();
+    if(cas instanceof CASImpl) {
+      CASImpl casImpl = (CASImpl) cas;
+      LowLevelCAS lowLevelCAS = casImpl.getLowLevelCAS();
+      FeatureStructure fs = lowLevelCAS.ll_getFSForRef(ref);
+      if(fs instanceof AnnotationFS) {
+        return (AnnotationFS) fs;
+      }
+    }
+    return null;
+  }
+
+
+  public String getAddress() {
+    return address;
+  }
+  
+
+}

Propchange: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationAddressExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpression.java (from r1712996, uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/LabelAnnotationExpression.java)
URL: http://svn.apache.org/viewvc/uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpression.java?p2=uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpression.java&p1=uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/LabelAnnotationExpression.java&r1=1712996&r2=1713009&rev=1713009&view=diff
==============================================================================
--- uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/LabelAnnotationExpression.java (original)
+++ uima/ruta/branches/UIMA-4408/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpression.java Fri Nov  6 18:16:24 2015
@@ -19,16 +19,47 @@
 
 package org.apache.uima.ruta.expression.annotation;
 
+import java.util.List;
+
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.rule.MatchContext;
+import org.apache.uima.ruta.rule.RuleMatch;
 
-public class LabelAnnotationExpression extends AbstractAnnotationExpression {
+/**
+ * An expression referring to an annotation matched by a rule element identified by a label.
+ *
+ */
+public class AnnotationLabelExpression extends AbstractAnnotationExpression {
 
+private String label;
+  
+  public AnnotationLabelExpression(String label) {
+    super();
+    this.label = label;
+  }
+  
+  
   @Override
   public AnnotationFS getAnnotation(MatchContext context, RutaStream stream) {
-    // TODO Auto-generated method stub
-    return null;
+    RuleMatch ruleMatch = context.getRuleMatch();
+    List<AnnotationFS> annotations = ruleMatch.getMatchedAnnotationsOfLabel(label);
+    AnnotationFS annotation = null;
+    // TODO which one to return?
+    if(annotations != null && !annotations.isEmpty()) {
+      if(context.getDirection()) {
+        annotation = annotations.get(annotations.size()-1);
+      } else {
+        annotation = annotations.get(0);
+      }
+      
+    }
+    return annotation;
+  }
+
+
+  public String getLabel() {
+    return label;
   }
 
 }