You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2020/03/22 19:09:38 UTC

[uima-uimafit] branch bugfix/UIMA-6204-createReaderDescription-does-not-discover-type-priorities created (now bdb6c54)

This is an automated email from the ASF dual-hosted git repository.

rec pushed a change to branch bugfix/UIMA-6204-createReaderDescription-does-not-discover-type-priorities
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git.


      at bdb6c54  [UIMA-6204] createReaderDescription does not discover type priorities

This branch includes the following new commits:

     new bdb6c54  [UIMA-6204] createReaderDescription does not discover type priorities

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[uima-uimafit] 01/01: [UIMA-6204] createReaderDescription does not discover type priorities

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch bugfix/UIMA-6204-createReaderDescription-does-not-discover-type-priorities
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git

commit bdb6c546133c8914ca0a92915e9e6ff62e36628f
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Sun Mar 22 20:09:29 2020 +0100

    [UIMA-6204] createReaderDescription does not discover type priorities
    
    - Auto-detect type priorities and index definitions in createReaderDescripton
    - Added unit tests for auto-detection of types, prios and indexes to AnalysisEngineFactoryTest and CollectionReaderFactoryTest
    - Ugraded a unit test in TypePrioritiesFactoryTest to assertj
---
 .../uima/fit/factory/CollectionReaderFactory.java  | 13 +++--
 .../fit/factory/AnalysisEngineFactoryTest.java     | 45 +++++++++++++----
 .../fit/factory/CollectionReaderFactoryTest.java   | 59 ++++++++++++++++++----
 .../fit/factory/TypePrioritiesFactoryTest.java     |  8 +--
 4 files changed, 100 insertions(+), 25 deletions(-)

diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/factory/CollectionReaderFactory.java b/uimafit-core/src/main/java/org/apache/uima/fit/factory/CollectionReaderFactory.java
index de53ef7..86df13d 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/factory/CollectionReaderFactory.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/factory/CollectionReaderFactory.java
@@ -437,8 +437,10 @@ public final class CollectionReaderFactory {
 
   /**
    * A simple factory method for creating a CollectionReaderDescription with a given class, type
-   * system description, and configuration data The type system is detected automatically using
-   * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}.
+   * system description, and configuration data. The type system is detected automatically using
+   * {@link TypeSystemDescriptionFactory#createTypeSystemDescription()}. Type priorities are
+   * detected automatically using {@link TypePrioritiesFactory#createTypePriorities()}. Indexes are
+   * detected automatically using {@link FsIndexFactory#createFsIndexCollection()}.
    * 
    * @param readerClass
    *          The class of the CollectionReader to be created.
@@ -453,8 +455,11 @@ public final class CollectionReaderFactory {
   public static CollectionReaderDescription createReaderDescription(
           Class<? extends CollectionReader> readerClass, Object... configurationData)
           throws ResourceInitializationException {
-    TypeSystemDescription tsd = createTypeSystemDescription();
-    return createReaderDescription(readerClass, tsd, (TypePriorities) null, configurationData);
+    TypeSystemDescription typeSystem = createTypeSystemDescription();
+    TypePriorities typePriorities = createTypePriorities();
+    FsIndexCollection fsIndexCollection = createFsIndexCollection();
+    return createReaderDescription(readerClass, typeSystem, typePriorities, fsIndexCollection,
+            (Capability[]) null, configurationData);
   }
 
   /**
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/factory/AnalysisEngineFactoryTest.java b/uimafit-core/src/test/java/org/apache/uima/fit/factory/AnalysisEngineFactoryTest.java
index 6cb703a..e5ee069 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/factory/AnalysisEngineFactoryTest.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/factory/AnalysisEngineFactoryTest.java
@@ -21,6 +21,9 @@ package org.apache.uima.fit.factory;
 import static java.util.Arrays.asList;
 import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine;
 import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineDescription;
+import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineFromPath;
+import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -60,6 +63,7 @@ import org.apache.uima.fit.factory.testAes.ParameterizedAE;
 import org.apache.uima.fit.factory.testAes.SerializationTestAnnotator;
 import org.apache.uima.fit.factory.testAes.ViewNames;
 import org.apache.uima.fit.pipeline.SimplePipeline;
+import org.apache.uima.fit.type.AnalyzedText;
 import org.apache.uima.fit.type.Sentence;
 import org.apache.uima.fit.type.Token;
 import org.apache.uima.fit.util.CasIOUtil;
@@ -70,25 +74,19 @@ import org.apache.uima.pear.tools.PackageBrowser;
 import org.apache.uima.pear.tools.PackageInstaller;
 import org.apache.uima.resource.PearSpecifier;
 import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.resource.metadata.Capability;
 import org.apache.uima.resource.metadata.ConfigurationParameter;
 import org.apache.uima.resource.metadata.ConfigurationParameterDeclarations;
 import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.resource.metadata.FsIndexDescription;
 import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
 import org.apache.uima.resource.metadata.TypePriorities;
 import org.apache.uima.resource.metadata.TypePriorityList;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.util.XMLInputSource;
 import org.custommonkey.xmlunit.XMLAssert;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Assert;
 import org.junit.Test;
 
-/**
- */
-
 public class AnalysisEngineFactoryTest extends ComponentTestBase {
 
   @Test
@@ -106,8 +104,8 @@ public class AnalysisEngineFactoryTest extends ComponentTestBase {
 
   @Test
   public void testCreateAnalysisEngineFromPath() throws UIMAException, IOException {
-    AnalysisEngine engine = AnalysisEngineFactory
-            .createEngineFromPath("src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml");
+    AnalysisEngine engine = createEngineFromPath(
+            "src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml");
     assertNotNull(engine);
   }
 
@@ -590,4 +588,33 @@ public class AnalysisEngineFactoryTest extends ComponentTestBase {
     cas.setDocumentLanguage("en");
     ae.process(cas);
   }
+  
+  @Test
+  public void thatCreateEngineDescriptorAutoDetectionWorks() throws Exception
+  {
+    AnalysisEngineDescription aed = createEngineDescription(NoOpAnnotator.class);
+    
+    TypeSystemDescription tsd = createTypeSystemDescription();
+    assertThat(tsd.getType(Token.class.getName()))
+        .as("Token type auto-detection")
+        .isNotNull();
+    assertThat(tsd.getType(Sentence.class.getName()))
+        .as("Sentence type auto-detection")
+        .isNotNull();
+    assertThat(tsd.getType(AnalyzedText.class.getName()))
+        .as("AnalyzedText type auto-detection")
+        .isNotNull();
+
+    TypePriorityList[] typePrioritiesLists = typePriorities.getPriorityLists();
+    assertThat(typePrioritiesLists.length).isEqualTo(1);
+    assertThat(typePrioritiesLists[0].getTypes())
+        .as("Type priorities auto-detection")
+        .containsExactly(Sentence.class.getName(), AnalyzedText.class.getName(), Token.class.getName());
+
+    FsIndexDescription[] indexes = aed.getAnalysisEngineMetaData().getFsIndexCollection().getFsIndexes();
+    assertThat(indexes.length).isEqualTo(1);
+    assertThat(indexes[0])
+        .extracting(FsIndexDescription::getLabel, FsIndexDescription::getTypeName, FsIndexDescription::getKind)
+        .containsExactly("Automatically Scanned Index", Token.class.getName(), FsIndexDescription.KIND_SORTED);
+  }
 }
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/factory/CollectionReaderFactoryTest.java b/uimafit-core/src/test/java/org/apache/uima/fit/factory/CollectionReaderFactoryTest.java
index a43eba7..e2f1a73 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/factory/CollectionReaderFactoryTest.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/factory/CollectionReaderFactoryTest.java
@@ -18,6 +18,11 @@
  */
 package org.apache.uima.fit.factory;
 
+import static org.apache.uima.fit.factory.CollectionReaderFactory.createReader;
+import static org.apache.uima.fit.factory.CollectionReaderFactory.createReaderDescription;
+import static org.apache.uima.fit.factory.CollectionReaderFactory.createReaderFromPath;
+import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
@@ -33,24 +38,26 @@ import org.apache.uima.fit.ComponentTestBase;
 import org.apache.uima.fit.descriptor.ResourceMetaData;
 import org.apache.uima.fit.factory.testCrs.SingleFileXReader;
 import org.apache.uima.fit.pipeline.JCasIterator;
+import org.apache.uima.fit.type.AnalyzedText;
+import org.apache.uima.fit.type.Sentence;
 import org.apache.uima.fit.type.Token;
 import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.TypePriorityList;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.util.Progress;
 import org.junit.Test;
 
-/**
- */
-
 public class CollectionReaderFactoryTest extends ComponentTestBase {
 
   @Test
   public void testCreateCollectionReader() throws UIMAException, IOException {
 
     CollectionReader reader = CollectionReaderFactory.createReader(
-            SingleFileXReader.class, typeSystemDescription, SingleFileXReader.PARAM_FILE_NAME,
-            "src/test/resources/data/docs/test.xmi", SingleFileXReader.PARAM_XML_SCHEME,
-            SingleFileXReader.XMI);
+            SingleFileXReader.class, typeSystemDescription, 
+            SingleFileXReader.PARAM_FILE_NAME, "src/test/resources/data/docs/test.xmi", 
+            SingleFileXReader.PARAM_XML_SCHEME, SingleFileXReader.XMI);
 
     JCasIterator jCasIterator = new JCasIterator(reader, typeSystemDescription);
     jCas = jCasIterator.next();
@@ -61,7 +68,7 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
     assertEquals("A", token.getPos());
     assertEquals("all", token.getStem());
 
-    reader = CollectionReaderFactory.createReader(
+    reader = createReader(
             "org.apache.uima.fit.factory.testCrs.SingleFileXReader",
             SingleFileXReader.PARAM_FILE_NAME, "src/test/resources/data/docs/test.xmi",
             SingleFileXReader.PARAM_XML_SCHEME, SingleFileXReader.XMI);
@@ -75,7 +82,7 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
     assertEquals(".", token.getPos());
     assertEquals(".", token.getStem());
 
-    reader = CollectionReaderFactory.createReaderFromPath(
+    reader = createReaderFromPath(
             "src/test/resources/org/apache/uima/fit/factory/testCrs/SingleFileXReader.xml",
             SingleFileXReader.PARAM_FILE_NAME, "src/test/resources/data/docs/test.xmi",
             SingleFileXReader.PARAM_XML_SCHEME, SingleFileXReader.XMI);
@@ -88,7 +95,6 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
     assertEquals("friends", token.getCoveredText());
     assertEquals("F", token.getPos());
     assertEquals("friend", token.getStem());
-
   }
 
   @Test
@@ -103,6 +109,35 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
   }
 
   @Test
+  public void thatCreateReaderDescriptorAutoDetectionWorks() throws Exception
+  {
+    CollectionReaderDescription aed = createReaderDescription(TestCR.class);
+    
+    TypeSystemDescription tsd = createTypeSystemDescription();
+    assertThat(tsd.getType(Token.class.getName()))
+        .as("Token type auto-detection")
+        .isNotNull();
+    assertThat(tsd.getType(Sentence.class.getName()))
+        .as("Sentence type auto-detection")
+        .isNotNull();
+    assertThat(tsd.getType(AnalyzedText.class.getName()))
+        .as("AnalyzedText type auto-detection")
+        .isNotNull();
+
+    TypePriorityList[] typePrioritiesLists = typePriorities.getPriorityLists();
+    assertThat(typePrioritiesLists.length).isEqualTo(1);
+    assertThat(typePrioritiesLists[0].getTypes())
+        .as("Type priorities auto-detection")
+        .containsExactly(Sentence.class.getName(), AnalyzedText.class.getName(), Token.class.getName());
+
+    FsIndexDescription[] indexes = aed.getCollectionReaderMetaData().getFsIndexCollection().getFsIndexes();
+    assertThat(indexes.length).isEqualTo(1);
+    assertThat(indexes[0])
+        .extracting(FsIndexDescription::getLabel, FsIndexDescription::getTypeName, FsIndexDescription::getKind)
+        .containsExactly("Automatically Scanned Index", Token.class.getName(), FsIndexDescription.KIND_SORTED);
+  }
+
+  @Test
   public void testResourceMetaData() throws Exception
   {
     CollectionReaderDescription desc = CollectionReaderFactory
@@ -117,6 +152,8 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
     assertEquals("uimaFIT", meta.getVendor());
   }
 
+  
+  
   @ResourceMetaData(name = "dummy", version = "1.0", description = "Just a dummy", copyright = "ASL 2.0", vendor = "uimaFIT")
   private class TestCR extends CollectionReader_ImplBase {
 
@@ -124,19 +161,23 @@ public class CollectionReaderFactoryTest extends ComponentTestBase {
       // do not instantiate
     }
 
+    @Override
     public void getNext(CAS acas) throws IOException, CollectionException {
       // Not required for test
     }
 
+    @Override
     public void close() throws IOException {
       // Not required for test
     }
 
+    @Override
     public Progress[] getProgress() {
       // Not required for test
       return null;
     }
 
+    @Override
     public boolean hasNext() throws IOException, CollectionException {
       // Not required for test
       return false;
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java b/uimafit-core/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java
index db60a19..97e0eaf 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java
@@ -21,6 +21,7 @@ package org.apache.uima.fit.factory;
 
 import static org.apache.uima.fit.factory.TypePrioritiesFactory.createTypePriorities;
 import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import org.apache.uima.fit.type.Sentence;
@@ -54,8 +55,9 @@ public class TypePrioritiesFactoryTest {
     TypePriorities typePriorities = createTypePriorities();
 
     TypePriorityList[] typePrioritiesLists = typePriorities.getPriorityLists();
-    assertEquals(1, typePrioritiesLists.length);
-    assertEquals(Sentence.class.getName(), typePrioritiesLists[0].getTypes()[0]);
-    assertEquals(Token.class.getName(), typePrioritiesLists[0].getTypes()[1]);
+    assertThat(typePrioritiesLists.length).isEqualTo(1);
+    assertThat(typePrioritiesLists[0].getTypes())
+        .as("Type priorities auto-detection")
+        .containsExactly(Sentence.class.getName(), Token.class.getName());
   }
 }