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 2016/08/18 13:21:45 UTC
svn commit: r1756779 - in
/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine:
DifferentSeeder.java DifferentSeederTest.java
Author: pkluegl
Date: Thu Aug 18 13:21:45 2016
New Revision: 1756779
URL: http://svn.apache.org/viewvc?rev=1756779&view=rev
Log:
UIMA-5061
- added another test
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java (with props)
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java (with props)
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java?rev=1756779&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java Thu Aug 18 13:21:45 2016
@@ -0,0 +1,55 @@
+/*
+ * 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.engine;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.seed.RutaAnnotationSeeder;
+
+public class DifferentSeeder implements RutaAnnotationSeeder {
+
+ @Override
+ public Type seed(String text, CAS cas) {
+ Type t1 = RutaTestUtils.getTestType(cas, 1);
+ Type t2 = RutaTestUtils.getTestType(cas, 2);
+ Type t3 = RutaTestUtils.getTestType(cas, 3);
+ Type t4 = RutaTestUtils.getTestType(cas, 4);
+ String documentText = cas.getDocumentText();
+
+ annotate(cas, "This", t1, documentText);
+ annotate(cas, "is", t2, documentText);
+ annotate(cas, "a", t3, documentText);
+ annotate(cas, "test", t4, documentText);
+
+ return cas.getAnnotationType();
+ }
+
+ private void annotate(CAS cas, String regex, Type type, String documentText) {
+ Matcher matcher = Pattern.compile(regex).matcher(documentText);
+ while (matcher.find()) {
+ AnnotationFS seed = cas.createAnnotation(type, matcher.start(), matcher.end());
+ cas.addFsToIndexes(seed);
+ }
+ }
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeeder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java?rev=1756779&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java Thu Aug 18 13:21:45 2016
@@ -0,0 +1,59 @@
+/*
+ * 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.engine;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.jcas.JCas;
+import org.junit.Test;
+
+public class DifferentSeederTest {
+
+ @Test
+ public void test() throws Exception {
+ CAS cas = RutaTestUtils.getCAS("This is a test.");
+ JCas jcas = cas.getJCas();
+
+ String script = "";
+ script += "ANY{-> T5};";
+ script += "CW{-> T6};";
+ script += "T1{-> T7};";
+ script += "T2 T3{-> T8};";
+ script += "T1 # T4{-> T9};";
+
+ AnalysisEngine ae = AnalysisEngineFactory.createEngine(RutaEngine.class,
+ RutaEngine.PARAM_RULES, script,
+ RutaEngine.PARAM_SEEDERS, new String[] {DifferentSeeder.class.getName()});
+
+ ae.process(jcas);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "This");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "is", "is");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "test");
+ RutaTestUtils.assertAnnotationsEquals(cas, 5, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 6, 0);
+ RutaTestUtils.assertAnnotationsEquals(cas, 7, 1, "This");
+ RutaTestUtils.assertAnnotationsEquals(cas, 8, 1, "a");
+ RutaTestUtils.assertAnnotationsEquals(cas, 9, 1, "test");
+
+ }
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/engine/DifferentSeederTest.java
------------------------------------------------------------------------------
svn:eol-style = native