Author: pkluegl Date: Wed Aug 28 15:49:09 2013 New Revision: 1518266 URL: http://svn.apache.org/r1518266 Log: UIMA-3228 - added MARKFIRST action
Added: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkFirstAction.java uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFirstActionTest.java Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ActionVerbalizer.java uima/sandbox/ruta/trunk/ruta-docbook/src/docbook/tools.ruta.language.actions.xml uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaKeywords.java Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaLexer.g Wed Aug 28 15:49:09 2013 @@ -189,6 +189,10 @@ MARKTABLE MARKLAST : 'MARKLAST' ; + +MARKFIRST + : 'MARKFIRST' + ; REPLACE : 'REPLACE' Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g Wed Aug 28 15:49:09 2013 @@ -1280,6 +1280,7 @@ action returns [AbstractRutaAction resu | a = actionMarkScore | a = actionMarkFast | a = actionMarkLast + | a = actionMarkFirst | a = actionReplace | a = actionFilterType | a = actionRetainType @@ -1518,6 +1519,12 @@ actionMarkLast returns [AbstractRutaActi MARKLAST LPAREN type = typeExpression RPAREN {action = ActionFactory.createMarkLastAction(type, $blockDeclaration::env);} ; + +actionMarkFirst returns [AbstractRutaAction action = null] + : + MARKFIRST LPAREN type = typeExpression RPAREN + {action = ActionFactory.createMarkFirstAction(type, $blockDeclaration::env);} + ; actionReplace returns [AbstractRutaAction action = null] : Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java Wed Aug 28 15:49:09 2013 @@ -269,4 +269,8 @@ public class ActionFactory { return new ImplicitMarkAction(te); } + public static AbstractRutaAction createMarkFirstAction(TypeExpression type, RutaBlock env) { + return new MarkFirstAction(type); + } + } Added: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkFirstAction.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkFirstAction.java?rev=1518266&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkFirstAction.java (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkFirstAction.java Wed Aug 28 15:49:09 2013 @@ -0,0 +1,48 @@ +/* + * 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.action; + +import java.util.List; + +import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.ruta.RutaStream; +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 MarkFirstAction extends AbstractMarkAction { + + public MarkFirstAction(TypeExpression type) { + super(type); + } + + @Override + public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) { + List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(null, + element.getContainer()); + for (AnnotationFS matchedAnnotation : matchedAnnotations) { + RutaBasic beginAnchor = stream.getBeginAnchor(matchedAnnotation.getBegin()); + createAnnotation(beginAnchor, element, stream, match); + } + } + +} Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ActionVerbalizer.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ActionVerbalizer.java?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ActionVerbalizer.java (original) +++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ActionVerbalizer.java Wed Aug 28 15:49:09 2013 @@ -45,6 +45,7 @@ import org.apache.uima.ruta.action.Impli import org.apache.uima.ruta.action.LogAction; import org.apache.uima.ruta.action.MarkAction; import org.apache.uima.ruta.action.MarkFastAction; +import org.apache.uima.ruta.action.MarkFirstAction; import org.apache.uima.ruta.action.MarkLastAction; import org.apache.uima.ruta.action.MarkOnceAction; import org.apache.uima.ruta.action.MarkTableAction; @@ -113,6 +114,8 @@ public class ActionVerbalizer { return "MARKFAST"; } else if (action instanceof MarkLastAction) { return "MARKLAST"; + } else if (action instanceof MarkFirstAction) { + return "MARKFIRST"; } else if (action instanceof ReplaceAction) { return "REPLACE"; } else if (action instanceof RetainTypeAction) { @@ -309,6 +312,9 @@ public class ActionVerbalizer { } else if (action instanceof MarkLastAction) { MarkLastAction a = (MarkLastAction) action; return name + verbalizer.verbalize(a.getType()) + ")"; + } else if (action instanceof MarkFirstAction) { + MarkFirstAction a = (MarkFirstAction) action; + return name + verbalizer.verbalize(a.getType()) + ")"; } else if (action instanceof ReplaceAction) { ReplaceAction a = (ReplaceAction) action; return name + verbalizer.verbalize(a.getReplacement()) + ")"; Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFirstActionTest.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFirstActionTest.java?rev=1518266&view=auto ============================================================================== --- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFirstActionTest.java (added) +++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/action/MarkFirstActionTest.java Wed Aug 28 15:49:09 2013 @@ -0,0 +1,62 @@ +/* + * 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.action; + +import static org.junit.Assert.assertEquals; + +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.cas.text.AnnotationIndex; +import org.apache.uima.ruta.RutaTestUtils; +import org.apache.uima.ruta.engine.Ruta; +import org.junit.Test; + +public class MarkFirstActionTest { + + @Test + public void test() { + String document = "Peter Kluegl, Joern Kottmann, Marshall Schor."; + String script = "Document{-> MARKFIRST(T1)};\n"; + CAS cas = null; + try { + cas = RutaTestUtils.getCAS(document); + Ruta.apply(cas, script); + } catch (Exception e) { + e.printStackTrace(); + } + + Type t = null; + AnnotationIndex<AnnotationFS> ai = null; + FSIterator<AnnotationFS> iterator = null; + + t = RutaTestUtils.getTestType(cas, 1); + ai = cas.getAnnotationIndex(t); + iterator = ai.iterator(); + assertEquals(1, ai.size()); + assertEquals("Peter", iterator.next().getCoveredText()); + + if (cas != null) { + cas.release(); + } + + } +} 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=1518266&r1=1518265&r2=1518266&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 Aug 28 15:49:09 2013 @@ -768,6 +768,34 @@ Document{-> MARKFAST(FirstName, FirstNam </section> </section> + <section id="ugr.tools.ruta.language.actions.markfirst"> + <title>MARKFIRST</title> + <para> + The MARKFIRST action annotates the first token (basic annotation) of the matched + annotation with the given type. + </para> + <section> + <title> + <emphasis role="bold">Definition:</emphasis> + </title> + <para> + <programlisting><![CDATA[MARKFIRST(TypeExpression)]]></programlisting> + </para> + </section> + <section> + <title> + <emphasis role="bold">Example:</emphasis> + </title> + <para> + <programlisting><![CDATA[Document{->MARKFIRST(First)};]]></programlisting> + </para> + <para> + This rule annotates the first token of the document with the + annotation First. + </para> + </section> + </section> + <section id="ugr.tools.ruta.language.actions.marklast"> <title>MARKLAST</title> <para> Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g (original) +++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaLexer.g Wed Aug 28 15:49:09 2013 @@ -189,7 +189,11 @@ MARKTABLE MARKLAST : 'MARKLAST' ; - + +MARKFIRST + : 'MARKFIRST' + ; + REPLACE : 'REPLACE' ; Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g (original) +++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/antlr3/org/apache/uima/ruta/ide/core/parser/RutaParser.g Wed Aug 28 15:49:09 2013 @@ -1294,6 +1294,7 @@ result = ActionFactory.createEmptyAction | a = actionMarkScore | a = actionMarkFast | a = actionMarkLast + | a = actionMarkFirst | a = actionReplace | a = actionRetainType | a = actionFilterType @@ -1557,6 +1558,13 @@ actionMarkLast returns [RutaAction actio RPAREN ; +actionMarkFirst returns [RutaAction action = null] + : + name = MARKFIRST LPAREN type = typeExpression + {action = ActionFactory.createAction(name, type);} + RPAREN + ; + actionReplace returns [RutaAction action = null] : Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaKeywords.java URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaKeywords.java?rev=1518266&r1=1518265&r2=1518266&view=diff ============================================================================== --- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaKeywords.java (original) +++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaKeywords.java Wed Aug 28 15:49:09 2013 @@ -36,7 +36,7 @@ public class RutaKeywords implements IRu "FILTERTYPE", "CREATE", "FILL", "MARKTABLE", "UNMARK", "TRANSFER", "MARKONCE", "TRIE", "GATHER", "EXEC", "MARKLAST", "ADD", "REMOVE", "MERGE", "GET", "GETLIST", "REMOVEDUPLICATE", "GETFEATURE", "MATCHEDTEXT", "CLEAR", "UNMARKALL", "SHIFT", "CONFIGURE", "DYNAMICANCHORING", - "TRIM", "ADDRETAINTYPE", "REMOVERETAINTYPE", "ADDFILTERTYPE", "REMOVEFILTERTYPE" }; + "TRIM", "ADDRETAINTYPE", "REMOVERETAINTYPE", "ADDFILTERTYPE", "REMOVEFILTERTYPE", "MARKFIRST" }; private static String[] basic = { "ALL", "ANY", "AMP", "BREAK", "W", "NUM", "PM", "Document", "MARKUP", "SW", "CW", "CAP", "PERIOD", "NBSP", "SENTENCEEND", "COLON", "COMMA", "SEMICOLON",