Author: pkluegl Date: Wed Jun 5 15:53:27 2013 New Revision: 1489931 URL: http://svn.apache.org/r1489931 Log: UIMA-2969 - adapted implementation of MARKONCE: "not if part of"
Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java?rev=1489931&r1=1489930&r2=1489931&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java Wed Jun 5 15:53:27 2013 @@ -21,8 +21,6 @@ package org.apache.uima.ruta.action; import java.util.List; -import org.apache.uima.cas.CAS; -import org.apache.uima.cas.FSIterator; import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.ruta.RutaStream; @@ -30,6 +28,7 @@ import org.apache.uima.ruta.expression.n import org.apache.uima.ruta.expression.type.TypeExpression; import org.apache.uima.ruta.rule.RuleElement; import org.apache.uima.ruta.rule.RuleMatch; +import org.apache.uima.ruta.type.RutaBasic; import org.apache.uima.ruta.visitor.InferenceCrowd; public class MarkOnceAction extends MarkAction { @@ -44,28 +43,18 @@ public class MarkOnceAction extends Mark List<Integer> indexList = getIndexList(element, list, stream); List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList, element.getContainer()); + Type targetType = type.getType(element.getParent()); for (AnnotationFS matchedAnnotation : matchedAnnotations) { - - CAS cas = stream.getCas(); - if (matchedAnnotation == null) - return; - Type t = type.getType(element.getParent()); - AnnotationFS createAnnotation = cas.createAnnotation(t, matchedAnnotation.getBegin(), - matchedAnnotation.getEnd()); - boolean contains = false; - FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(t).iterator(createAnnotation); - while (iterator.isValid() - && ((AnnotationFS) iterator.get()).getEnd() == createAnnotation.getEnd()) { - AnnotationFS a = (AnnotationFS) iterator.get(); - if (a.getBegin() == createAnnotation.getBegin() && a.getEnd() == createAnnotation.getEnd() - && a.getType().getName().equals(createAnnotation.getType().getName())) { - contains = true; + boolean partof = false; + List<RutaBasic> basicsInWindow = stream.getBasicsInWindow(matchedAnnotation); + for (RutaBasic rutaBasic : basicsInWindow) { + if (rutaBasic.isPartOf(targetType)) { + partof = true; break; } - iterator.moveToNext(); } - if (!contains) { - super.execute(match, element, stream, crowd); + if (!partof) { + createAnnotation(matchedAnnotation, element, stream, match); } } } Modified: uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml?rev=1489931&r1=1489930&r2=1489931&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml (original) +++ uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml Wed Jun 5 15:53:27 2013 @@ -790,7 +790,8 @@ Document{-> MARKFAST(FirstName, FirstNam <title>MARKONCE</title> <para> The MARKONCE action has the same functionality as the MARK - action, but creates a new annotation only, if it is not yet existing. + action, but creates a new annotation only, + if each part of the matched annotation is not yet part of the given type. </para> <section> <title> @@ -809,7 +810,7 @@ Document{-> MARKFAST(FirstName, FirstNam </para> <para> This rule matches on a free line followed by a Paragraph and - annotates both in a single ParagraphAfterFreeline annotation, if it + annotates both in a single ParagraphAfterFreeline annotation, if no part is not already annotated with ParagraphAfterFreeline annotation. The two numerical expressions at the end of the MARKONCE action state that the matched text of the first and the second rule elements are