You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2015/07/09 01:42:57 UTC

svn commit: r1689974 - in /ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc: ./ pretty/ pretty/cell/ pretty/textspan/

Author: seanfinan
Date: Wed Jul  8 23:42:56 2015
New Revision: 1689974

URL: http://svn.apache.org/r1689974
Log:
CTAKES-366  Unit tests for the PrettyTextWriter - should have been part of the original checkin

Added:
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultBaseItemCellTester.java
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultUmlsItemCellTester.java
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/
    ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/DefaultTextSpanTester.java

Added: ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultBaseItemCellTester.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultBaseItemCellTester.java?rev=1689974&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultBaseItemCellTester.java (added)
+++ ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultBaseItemCellTester.java Wed Jul  8 23:42:56 2015
@@ -0,0 +1,45 @@
+package org.apache.ctakes.core.cc.pretty.cell;
+
+
+import org.apache.ctakes.core.cc.pretty.textspan.DefaultTextSpan;
+import org.apache.ctakes.core.cc.pretty.textspan.TextSpan;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 7/6/2015
+ */
+final public class DefaultBaseItemCellTester {
+
+   @Test
+   public void testWidth() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final ItemCell itemCell1 = new DefaultBaseItemCell( textSpan, "testy", "TEST" );
+      assertEquals( "item cell for \"testy\" with pos TEST should have width 5", 5, itemCell1.getWidth() );
+      final ItemCell itemCell2 = new DefaultBaseItemCell( textSpan, "testy", "TESTIER" );
+      assertEquals( "item cell for \"testy\" with pos TESTIER should have width 7", 7, itemCell2.getWidth() );
+   }
+
+   @Test
+   public void testHeight() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final ItemCell itemCell1 = new DefaultBaseItemCell( textSpan, "testy", "TEST" );
+      assertEquals( "item cell for \"testy\" with pos TEST should have height 2", 2, itemCell1.getHeight() );
+   }
+
+   @Test
+   public void testLineText() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final ItemCell itemCell1 = new DefaultBaseItemCell( textSpan, "testy", "TEST" );
+      assertEquals( "item cell for \"testy\" with pos TEST should have line 0 \"testy\"", "testy", itemCell1
+            .getLineText( 0 ) );
+      assertEquals( "item cell for \"testy\" with pos TEST should have line 1 \"TEST\"", "TEST", itemCell1
+            .getLineText( 1 ) );
+      assertEquals( "item cell for \"testy\" with pos TEST should have line 2 \"\"", "", itemCell1.getLineText( 2 ) );
+   }
+
+
+}

Added: ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultUmlsItemCellTester.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultUmlsItemCellTester.java?rev=1689974&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultUmlsItemCellTester.java (added)
+++ ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/cell/DefaultUmlsItemCellTester.java Wed Jul  8 23:42:56 2015
@@ -0,0 +1,129 @@
+package org.apache.ctakes.core.cc.pretty.cell;
+
+
+import org.apache.ctakes.core.cc.pretty.SemanticGroup;
+import org.apache.ctakes.core.cc.pretty.textspan.DefaultTextSpan;
+import org.apache.ctakes.core.cc.pretty.textspan.TextSpan;
+import org.junit.Test;
+
+import java.util.*;
+
+import static org.apache.ctakes.core.cc.pretty.cell.UmlsItemCell.ENTITY_FILL;
+import static org.junit.Assert.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 7/6/2015
+ */
+final public class DefaultUmlsItemCellTester {
+
+   static private final Collection<String> FIBOS = Arrays
+         .asList( "C001", "C002", "C003", "C005", "C008", "C013", "C021" );
+   static private final Collection<String> BOTTLES = Arrays.asList( "C099", "C098", "C097" );
+   static private final Collection<String> SINGLE = Collections.singletonList( "C100" );
+
+   @Test
+   public void testWidth() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final Map<String, Collection<String>> semanticCuis = new HashMap<>( 2 );
+      semanticCuis.put( "Bottle", BOTTLES );
+      final ItemCell itemCell1 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have width 8", 8, itemCell1.getWidth() );
+
+      semanticCuis.put( "Fibonacci", FIBOS );
+      final ItemCell itemCell2 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertEquals( "item cell for 5-10 with semantic \"Fibonacci\" should have width 9", 9, itemCell2.getWidth() );
+
+      final ItemCell itemCell3 = new DefaultUmlsItemCell( new DefaultTextSpan( 5, 25 ), 1, semanticCuis );
+      assertEquals( "item cell for 5-25 with semantic \"Fibonacci\" should have width 20", 20, itemCell3.getWidth() );
+   }
+
+   @Test
+   public void testHeight() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final Map<String, Collection<String>> semanticCuis = new HashMap<>( 2 );
+      semanticCuis.put( "Bottle", BOTTLES );
+      final ItemCell itemCell1 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      final int height1 = 1 + 1 + BOTTLES.size();
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have height " + height1,
+            height1, itemCell1.getHeight() );
+
+      semanticCuis.put( "Fibonacci", FIBOS );
+      final ItemCell itemCell2 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      final int height2 = height1 + 1 + FIBOS.size();
+      assertEquals( "item cell for 5-10 with semantic \"Fibonacci\" should have height " + height2,
+            height2, itemCell2.getHeight() );
+
+      final ItemCell itemCell3 = new DefaultUmlsItemCell( textSpan, -1, semanticCuis );
+      final int height3 = height2 + 1;
+      assertEquals( "item cell for 5-10 with negated semantic \"Fibonacci\" should have height " + height3,
+            height3, itemCell3.getHeight() );
+   }
+
+   @Test
+   public void testNegated() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final Map<String, Collection<String>> semanticCuis = new HashMap<>( 1 );
+      semanticCuis.put( "Bottle", BOTTLES );
+      final UmlsItemCell itemCell1 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertFalse( "\"item cell for 5-10 with semantic \"Bottle\" should not be negated", itemCell1.isNegated() );
+
+      final UmlsItemCell itemCell2 = new DefaultUmlsItemCell( textSpan, -1, semanticCuis );
+      assertTrue( "\"item cell for 5-10 with semantic \"Bottle\" should be negated", itemCell2.isNegated() );
+   }
+
+
+   @Test
+   public void testCustomLineText() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final Map<String, Collection<String>> semanticCuis = new HashMap<>( 3 );
+      semanticCuis.put( "Bottle", BOTTLES );
+      final ItemCell itemCell1 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertEquals(
+            "item cell for 5-10 with semantic \"Bottle\" should have line 0 " + ENTITY_FILL, ENTITY_FILL, itemCell1
+            .getLineText( 0 ) );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have line 1 \"Bottle\"", "Bottle", itemCell1
+            .getLineText( 1 ) );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have line 2 \"C097\"", "C097", itemCell1
+            .getLineText( 2 ) );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have line 3 \"C098\"", "C098", itemCell1
+            .getLineText( 3 ) );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have line 4 \"C099\"", "C099", itemCell1
+            .getLineText( 4 ) );
+      assertEquals( "item cell for 5-10 with semantic \"Bottle\" should have line 5 \"\"", "", itemCell1
+            .getLineText( 5 ) );
+
+      final ItemCell itemCell2 = new DefaultUmlsItemCell( textSpan, -1, semanticCuis );
+      assertEquals( "item cell for 5-10 with negated semantic \"Bottle\" should have line 5 \"Negated\"", "Negated", itemCell2
+            .getLineText( 5 ) );
+
+      semanticCuis.put( "Singleton", SINGLE );
+      semanticCuis.put( "Fibonacci", FIBOS );
+      final ItemCell itemCell3 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertEquals( "item cell for 5-10 with negated semantic \"Fibonacci\" should have line 5 \"Fibonacci\"", "Fibonacci", itemCell3
+            .getLineText( 5 ) );
+      assertEquals( "item cell for 5-10 with negated semantic \"Fibonacci\" should have line 13 \"Singleton\"", "Singleton", itemCell3
+            .getLineText( 13 ) );
+   }
+
+   @Test
+   public void testStandardLineText() {
+      final TextSpan textSpan = new DefaultTextSpan( 5, 10 );
+      final Map<String, Collection<String>> semanticCuis = new HashMap<>( 3 );
+      semanticCuis.put( SemanticGroup.MEDICATION.getName(), BOTTLES );
+      semanticCuis.put( SemanticGroup.ANATOMICAL_SITE.getName(), SINGLE );
+      semanticCuis.put( SemanticGroup.FINDING.getName(), FIBOS );
+      final ItemCell itemCell1 = new DefaultUmlsItemCell( textSpan, 1, semanticCuis );
+      assertEquals( "item cell for 5-10 with ctakes semantics should have line 1 "
+                    + SemanticGroup.ANATOMICAL_SITE.getName(),
+            SemanticGroup.ANATOMICAL_SITE.getName(), itemCell1.getLineText( 1 ) );
+      assertEquals( "item cell for 5-10 with ctakes semantics should have line 3 "
+                    + SemanticGroup.FINDING.getName(),
+            SemanticGroup.FINDING.getName(), itemCell1.getLineText( 3 ) );
+      assertEquals( "item cell for 5-10 with ctakes semantics should have line 11 "
+                    + SemanticGroup.MEDICATION.getName(),
+            SemanticGroup.MEDICATION.getName(), itemCell1.getLineText( 11 ) );
+   }
+
+}

Added: ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/DefaultTextSpanTester.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/DefaultTextSpanTester.java?rev=1689974&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/DefaultTextSpanTester.java (added)
+++ ctakes/trunk/ctakes-core/src/test/java/org/apache/ctakes/core/cc/pretty/textspan/DefaultTextSpanTester.java Wed Jul  8 23:42:56 2015
@@ -0,0 +1,49 @@
+package org.apache.ctakes.core.cc.pretty.textspan;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 7/6/2015
+ */
+final public class DefaultTextSpanTester {
+
+   @Test
+   public void testEndOverlap() {
+      final TextSpan textSpan1 = new DefaultTextSpan( 5, 15 );
+      final TextSpan textSpan2 = new DefaultTextSpan( 10, 20 );
+      assertTrue( "Text Span 5-15 should overlap text span 10-20", textSpan1.overlaps( textSpan2 ) );
+      assertTrue( "Text Span 10-20 should overlap text span 5-15", textSpan2.overlaps( textSpan1 ) );
+   }
+
+   @Test
+   public void testInnerOverlap() {
+      final TextSpan textSpan1 = new DefaultTextSpan( 5, 25 );
+      final TextSpan textSpan2 = new DefaultTextSpan( 10, 20 );
+      assertTrue( "Text Span 5-25 should overlap text span 10-20", textSpan1.overlaps( textSpan2 ) );
+      assertTrue( "Text Span 10-20 should overlap text span 5-25", textSpan2.overlaps( textSpan1 ) );
+   }
+
+   @Test
+   public void testNoOverlap() {
+      final TextSpan textSpan1 = new DefaultTextSpan( 5, 10 );
+      final TextSpan textSpan2 = new DefaultTextSpan( 10, 20 );
+      assertFalse( "Text Span 5-10 should not overlap text span 10-20", textSpan1.overlaps( textSpan2 ) );
+      assertFalse( "Text Span 10-20 should not overlap text span 5-10", textSpan2.overlaps( textSpan1 ) );
+      final TextSpan thirdTextSpan = new DefaultTextSpan( 100, 200 );
+      assertFalse( "Text Span 5-10 should not overlap text span 100-200", textSpan1.overlaps( thirdTextSpan ) );
+      assertFalse( "Text Span 100-200 should not overlap text span 5-10", thirdTextSpan.overlaps( textSpan1 ) );
+   }
+
+   @Test
+   public void testWidth() {
+      final TextSpan textSpan1 = new DefaultTextSpan( 5, 10 );
+      assertEquals( "Text Span 5-10 should have width 5", 5, textSpan1.getWidth() );
+      final TextSpan textSpan2 = new DefaultTextSpan( 10, 20 );
+      assertEquals( "Text Span 10-20 should have width 10", 10, textSpan2.getWidth() );
+   }
+
+}