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 2012/07/06 13:16:07 UTC

svn commit: r1358125 - in /uima/sandbox/trunk/TextMarker/uimaj-textmarker/src: main/java/org/apache/uima/textmarker/type/ test/java/org/apache/uima/textmarker/ test/java/org/apache/uima/textmarker/action/ test/resources/org/apache/uima/textmarker/action/

Author: pkluegl
Date: Fri Jul  6 11:16:06 2012
New Revision: 1358125

URL: http://svn.apache.org/viewvc?rev=1358125&view=rev
Log:
UIMA-2427
- fixed and added test

Added:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/PartOfTest.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.tm
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.txt
Modified:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/type/TextMarkerBasic.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/type/TextMarkerBasic.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/type/TextMarkerBasic.java?rev=1358125&r1=1358124&r2=1358125&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/type/TextMarkerBasic.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/type/TextMarkerBasic.java Fri Jul  6 11:16:06 2012
@@ -6,6 +6,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
@@ -28,7 +29,7 @@ public class TextMarkerBasic extends Ann
 
   private boolean lowMemoryProfile = true;
 
-  private Set<Type> partOf = new HashSet<Type>(INITIAL_CAPACITY);
+  private Map<String, Integer> partOf = new TreeMap<String, Integer>();
 
   private final Map<Type, Set<AnnotationFS>> beginMap = new HashMap<Type, Set<AnnotationFS>>(
           INITIAL_CAPACITY);
@@ -45,15 +46,53 @@ public class TextMarkerBasic extends Ann
   }
 
   public void addPartOf(Type type) {
-    partOf.add(type);
+    Integer count = partOf.get(type.getName());
+    if (count == null) {
+      count = 0;
+    }
+    count++;
+    partOf.put(type.getName(), count);
+    if (!lowMemoryProfile) {
+      TypeSystem typeSystem = getCAS().getTypeSystem();
+      Type parent = typeSystem.getParent(type);
+      if (parent != null) {
+        addPartOf(parent);
+      }
+    }
   }
 
   public void removePartOf(Type type) {
-    partOf.remove(type);
+    Integer count = partOf.get(type.getName());
+    if (count != null && count > 0) {
+      count--;
+      partOf.put(type.getName(), count);
+    }
+    if (!lowMemoryProfile) {
+      TypeSystem typeSystem = getCAS().getTypeSystem();
+      Type parent = typeSystem.getParent(type);
+      if (parent != null) {
+        removePartOf(parent);
+      }
+    }
   }
 
   public boolean isPartOf(Type type) {
-    return partOf.contains(type);
+    Integer count = partOf.get(type.getName());
+    if (count != null && count > 0) {
+      return true;
+    }
+    if (lowMemoryProfile) {
+      List<Type> subsumedTypes = getCAS().getTypeSystem().getProperlySubsumedTypes(type);
+      for (Type each : subsumedTypes) {
+        Integer parentCount = partOf.get(each.getName());
+        if (parentCount != null && parentCount > 0) {
+          return true;
+        }
+      }
+
+    }
+    return false;
+
   }
 
   public Set<AnnotationFS> getBeginAnchors(Type type) {

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java?rev=1358125&r1=1358124&r2=1358125&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java Fri Jul  6 11:16:06 2012
@@ -1,5 +1,6 @@
 package org.apache.uima.textmarker;
 
+import org.apache.uima.textmarker.action.PartOfTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
@@ -7,7 +8,7 @@ import org.junit.runners.Suite.SuiteClas
 @RunWith(Suite.class)
 @SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, FilteringTest.class,
     QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class,
-    RuleInferenceTest2.class, RuleInferenceTest3.class, LongGreedyTest.class })
+    RuleInferenceTest2.class, RuleInferenceTest3.class, LongGreedyTest.class, PartOfTest.class })
 public class AllTests {
 
 }

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java?rev=1358125&r1=1358124&r2=1358125&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java Fri Jul  6 11:16:06 2012
@@ -37,7 +37,7 @@ public class DynamicAnchoringTest2 {
     CAS cas = null;
     try {
       cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
-              + ".txt", 50, true);
+              + ".txt", 50, true,  null);
     } catch (Exception e) {
       e.printStackTrace();
       assert (false);

Modified: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java?rev=1358125&r1=1358124&r2=1358125&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java Fri Jul  6 11:16:06 2012
@@ -25,6 +25,9 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.analysis_engine.AnalysisEngine;
@@ -50,11 +53,11 @@ public class TextMarkerTestUtils {
           throws URISyntaxException, IOException, InvalidXMLException,
           ResourceInitializationException, AnalysisEngineProcessException,
           ResourceConfigurationException {
-    return process(ruleFileName, textFileName, amount, false);
+    return process(ruleFileName, textFileName, amount, false, null);
   }
 
   public static CAS process(String ruleFileName, String textFileName, int amount,
-          boolean dynamicAnchoring) throws URISyntaxException, IOException, InvalidXMLException,
+          boolean dynamicAnchoring, Map<String,String> complexTypes) throws URISyntaxException, IOException, InvalidXMLException,
           ResourceInitializationException, AnalysisEngineProcessException,
           ResourceConfigurationException {
     URL resource = TextMarkerTestUtils.class.getClassLoader().getResource(ruleFileName);
@@ -71,6 +74,13 @@ public class TextMarkerTestUtils {
       basicTypeSystem.addType(TYPE + i, "Type for Testing", "uima.tcas.Annotation");
     }
 
+    if(complexTypes!= null) {
+      Set<Entry<String,String>> entrySet = complexTypes.entrySet();
+      for (Entry<String, String> entry : entrySet) {
+        basicTypeSystem.addType(entry.getKey(), "Type for Testing", entry.getValue());
+      }
+    }
+    
     Collection<TypeSystemDescription> tsds = new ArrayList<TypeSystemDescription>();
     tsds.add(basicTypeSystem);
     TypeSystemDescription mergeTypeSystems = CasCreationUtils.mergeTypeSystems(tsds);

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/PartOfTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/PartOfTest.java?rev=1358125&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/PartOfTest.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/action/PartOfTest.java Fri Jul  6 11:16:06 2012
@@ -0,0 +1,76 @@
+/*
+ * 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.textmarker.action;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+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.textmarker.TextMarkerTestUtils;
+import org.junit.Test;
+
+public class PartOfTest {
+
+  @Test
+  public void test() {
+    String name = this.getClass().getSimpleName();
+    String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+    Map<String,String> complexTypes = new TreeMap<String, String>();
+    complexTypes.put("org.apache.uima.WithInitial", "uima.tcas.Annotation");
+    complexTypes.put("org.apache.uima.Initial", "uima.tcas.Annotation");
+    complexTypes.put("org.apache.uima.WithInitialEnd", "org.apache.uima.WithInitial");
+    
+    CAS cas = null;
+    try {
+      cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+              + ".txt", 50, false, complexTypes);
+    } catch (Exception e) {
+      e.printStackTrace();
+      assert (false);
+    }
+    Type t = null;
+    AnnotationIndex<AnnotationFS> ai = null;
+    FSIterator<AnnotationFS> iterator = null;
+
+    t = TextMarkerTestUtils.getTestType(cas, 1);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(2, ai.size());
+    iterator = ai.iterator();
+    assertEquals("Vitamine", iterator.next().getCoveredText());
+    assertEquals("A", iterator.next().getCoveredText());
+ 
+    t = TextMarkerTestUtils.getTestType(cas, 2);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    iterator = ai.iterator();
+    assertEquals("A", iterator.next().getCoveredText());
+ 
+    t = TextMarkerTestUtils.getTestType(cas, 3);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(0, ai.size());
+
+  }
+}

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.tm
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.tm?rev=1358125&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.tm (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.tm Fri Jul  6 11:16:06 2012
@@ -0,0 +1,12 @@
+PACKAGE org.apache.uima;
+
+DECLARE WithInitial, Initial;
+DECLARE WithInitial WithInitialEnd;
+
+DECLARE T1, T2, T3, T4, T5;
+
+CW{-> MARK(WithInitialEnd,1,2)} CW{-> MARK(Initial)} PERIOD;
+
+ANY{PARTOF(WithInitialEnd) -> MARK(T1)};
+Initial {PARTOF(WithInitial) -> MARK(T2)};
+SW{PARTOF(WithInitialEnd) -> MARK(T3)};
\ No newline at end of file

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.txt
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.txt?rev=1358125&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.txt (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/action/PartOfTest.txt Fri Jul  6 11:16:06 2012
@@ -0,0 +1 @@
+I like Vitamine A.
\ No newline at end of file