You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by al...@apache.org on 2017/12/05 00:51:19 UTC
svn commit: r1817141 - in /ctakes/trunk: ctakes-ytex-uima/
ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/
ctakes-ytex/src/main/java/org/apache/ctakes/util/
ctakes-ytex/src/test/java/org/apache/ctakes/ytex/
Author: alexz
Date: Tue Dec 5 00:51:19 2017
New Revision: 1817141
URL: http://svn.apache.org/viewvc?rev=1817141&view=rev
Log:
CTAKES-415
Added:
ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/
Modified:
ctakes/trunk/ctakes-ytex-uima/pom.xml
ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DateAnnotatorTest.java
ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java
ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java
Modified: ctakes/trunk/ctakes-ytex-uima/pom.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex-uima/pom.xml?rev=1817141&r1=1817140&r2=1817141&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex-uima/pom.xml (original)
+++ ctakes/trunk/ctakes-ytex-uima/pom.xml Tue Dec 5 00:51:19 2017
@@ -179,13 +179,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <excludes>
- <exclude>**/DBCollectionReaderTest*</exclude>
- <exclude>**/DBConsumerTest*</exclude>
- <exclude>**/DictionaryLookupAnnotatorTest*</exclude>
- <exclude>**/SenseDisambiguatorAnnotatorTest*</exclude>
- <exclude>**/SparseDataExporterTest*</exclude>
- </excludes>
+ <skip>true</skip>
</configuration>
<executions>
<execution>
@@ -195,6 +189,7 @@
<goal>test</goal>
</goals>
<configuration>
+ <skip>false</skip>
<forkMode>always</forkMode>
<systemPropertyVariables>
<log4j.configuration>file:${project.basedir}/src/test/resources/log4j.properties</log4j.configuration>
@@ -227,28 +222,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <version>${maven-failsafe-plugin.version}</version>
- <configuration>
- <includes>
- <include>**/DBCollectionReaderTest</include>
- <include>**/DBConsumerTest</include>
- <include>**/DictionaryLookupAnnotatorTest</include>
- <!-- TODO: include>**/SenseDisambiguatorAnnotatorTest</include -->
- <include>**/SparseDataExporterTest</include>
- </includes>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
Modified: ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DateAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DateAnnotatorTest.java?rev=1817141&r1=1817140&r2=1817141&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DateAnnotatorTest.java (original)
+++ ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DateAnnotatorTest.java Tue Dec 5 00:51:19 2017
@@ -18,7 +18,10 @@
*/
package org.apache.ctakes.ytex.uima.annotators;
+import com.ibm.icu.text.SimpleDateFormat;
import org.apache.ctakes.typesystem.type.textsem.DateAnnotation;
+import org.apache.ctakes.ytex.uima.types.Date;
+import org.apache.log4j.Logger;
import org.apache.uima.UIMAException;
import org.apache.uima.cas.text.AnnotationIndex;
import org.apache.uima.jcas.JCas;
@@ -26,6 +29,12 @@ import org.apache.uima.jcas.tcas.Annotat
import org.junit.Assert;
import org.junit.Test;
import org.apache.uima.fit.factory.JCasFactory;
+import sun.java2d.pipe.SpanShapeRenderer;
+
+import java.net.URL;
+import java.text.ParseException;
+
+import static org.junit.Assert.*;
/**
* TODO get rid of hard-coded path to Types.xml - load from classpath
@@ -34,27 +43,48 @@ import org.apache.uima.fit.factory.JCasF
*/
public class DateAnnotatorTest {
+ private final static Logger LOGGER = Logger.getLogger(DateAnnotatorTest.class);
+
/**
* Verify that date parsing with a manually created date works
* @throws UIMAException
*/
@Test
public void testParseDate() throws UIMAException {
- JCas jCas = JCasFactory.createJCasFromPath("src/main/resources/org/apache/ctakes/ytex/types/TypeSystem.xml");
- String date = (new java.util.Date()).toString();
- jCas.setDocumentText(date);
+ URL urlTypeSystem = getClass().getClassLoader().getResource("org/apache/ctakes/ytex/types/TypeSystem.xml");
+ JCas jCas = JCasFactory.createJCasFromPath(urlTypeSystem.getPath());
+
+ java.util.Date dtExpected = new java.util.Date();
+ String sExpected = dtExpected.toString();
+
+ LOGGER.info(String.format("date to be annotated: %s", sExpected));
+ jCas.setDocumentText(sExpected);
+
+ // create the annotation
DateAnnotation ctakesDate = new DateAnnotation(jCas);
ctakesDate.setBegin(0);
- ctakesDate.setEnd(date.length());
+ ctakesDate.setEnd(sExpected.length());
ctakesDate.addToIndexes();
DateAnnotator dateAnnotator = new DateAnnotator();
- dateAnnotator.dateType = org.apache.ctakes.ytex.uima.types.Date.class.getName();
+ dateAnnotator.dateType = Date.class.getName();
dateAnnotator.process(jCas);
- AnnotationIndex<Annotation> ytexDates = jCas.getAnnotationIndex(org.apache.ctakes.ytex.uima.types.Date.type);
- Assert.assertTrue(ytexDates.iterator().hasNext());
- String dateParsed = ((org.apache.ctakes.ytex.uima.types.Date)ytexDates.iterator().next()).getDate();
- Assert.assertNotNull(dateParsed);
- System.out.println(dateParsed);
+ AnnotationIndex<Annotation> ytexDates = jCas.getAnnotationIndex(Date.type);
+ assertTrue(ytexDates.iterator().hasNext());
+
+ // return the parsed
+ String sParsed = ((Date)ytexDates.iterator().next()).getDate();
+ assertNotNull("Expected a parsed Date string", sParsed);
+ LOGGER.info(String.format("date from annotation: %s", sParsed));
+ java.util.Date dtParsed = null;
+ try {
+ dtParsed = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(sParsed);
+ } catch (ParseException e) {
+ assertFalse("Expected a real java.util.Date object", true);
+ }
+ // java.util.Date.equals is not advised. Comparing Date.getTime ignores the miliseconds.
+ assertNotNull("Expected a not NULL java.util.Date object", dtParsed);
+ assertTrue("Expected what we converted .toString to be parsed",
+ (dtExpected.getTime() - dtParsed.getTime()) < 1000 /*1 second*/);
}
}
Modified: ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java?rev=1817141&r1=1817140&r2=1817141&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java (original)
+++ ctakes/trunk/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java Tue Dec 5 00:51:19 2017
@@ -18,39 +18,42 @@
*/
package org.apache.ctakes.ytex.uima.annotators;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import javax.sql.DataSource;
-
+import com.google.common.collect.Lists;
import org.apache.ctakes.typesystem.type.refsem.OntologyConcept;
import org.apache.ctakes.typesystem.type.textsem.EntityMention;
+import org.apache.ctakes.util.JdbcOperationsHelper;
import org.apache.ctakes.ytex.kernel.dao.ConceptDao;
import org.apache.ctakes.ytex.kernel.model.ConceptGraph;
import org.apache.ctakes.ytex.kernel.wsd.WordSenseDisambiguator;
import org.apache.ctakes.ytex.uima.ApplicationContextHolder;
import org.apache.uima.UIMAException;
import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.fit.factory.JCasFactory;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.cas.FSArray;
import org.apache.uima.jcas.tcas.Annotation;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.apache.uima.fit.factory.JCasFactory;
-import com.google.common.collect.Lists;
+import javax.sql.DataSource;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+public class SenseDisambiguatorAnnotatorTest extends JdbcOperationsHelper {
+ private ConceptDao conceptDao;
+ private ApplicationContext appCtx = null;
-public class SenseDisambiguatorAnnotatorTest {
- ConceptDao conceptDao;
@Before
public void setUp() throws Exception {
- BeanFactory appCtx = ContextSingletonBeanFactoryLocator
+ appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
.getInstance("classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
.useBeanFactory("kernelApplicationContext").getFactory();
conceptDao = appCtx.getBean(ConceptDao.class);
@@ -58,38 +61,23 @@ public class SenseDisambiguatorAnnotator
jdbcTemplate.setDataSource(appCtx.getBean(DataSource.class));
Properties ytexProperties = (Properties)appCtx.getBean("ytexProperties");
String dbtype = ytexProperties.getProperty("db.type");
- if("hsql".equals(dbtype) || "mysql".equals(dbtype))
- jdbcTemplate.execute("drop table if exists test_concepts");
- if("mssql".equals(dbtype))
- jdbcTemplate.execute("if exists(select * from sys.objects where object_id = object_id('test_concepts')) drop table test_concepts");
- if ("orcl".equals(dbtype)) {
- // just try dropping the table, catch exception and hope all is well
- try {
- jdbcTemplate.execute("drop table test_concepts");
- } catch (Exception ignore) {
- }
- }
- jdbcTemplate
- .execute("create table test_concepts(parent varchar(20), child varchar(20))");
- jdbcTemplate
- .execute("insert into test_concepts values ('root', 'animal')");
- jdbcTemplate
- .execute("insert into test_concepts values ('animal', 'vertebrate')");
- jdbcTemplate
- .execute("insert into test_concepts values ('vertebrate', 'cat')");
- jdbcTemplate
- .execute("insert into test_concepts values ('vertebrate', 'dog')");
- jdbcTemplate
- .execute("insert into test_concepts values ('root', 'bacteria')");
- jdbcTemplate
- .execute("insert into test_concepts values ('bacteria', 'e coli')");
- conceptDao.createConceptGraph(null, "test",
- "select child, parent from test_concepts", true,
+ dropTableIfExist(jdbcTemplate, dbtype, "test_concepts");
+
+ jdbcTemplate.execute("create table test_concepts(parent varchar(20), child varchar(20))");
+ jdbcTemplate.execute("insert into test_concepts values ('root', 'animal')");
+ jdbcTemplate.execute("insert into test_concepts values ('animal', 'vertebrate')");
+ jdbcTemplate.execute("insert into test_concepts values ('vertebrate', 'cat')");
+ jdbcTemplate.execute("insert into test_concepts values ('vertebrate', 'dog')");
+ jdbcTemplate.execute("insert into test_concepts values ('root', 'bacteria')");
+ jdbcTemplate.execute("insert into test_concepts values ('bacteria', 'e coli')");
+ conceptDao.createConceptGraph(null,
+ "test",
+ "select child, parent from test_concepts",
+ true,
Collections.EMPTY_SET);
ConceptGraph cg = conceptDao.getConceptGraph("test");
Assert.assertNotNull(cg);
- ((ConfigurableApplicationContext) appCtx).close();
}
/**
@@ -101,8 +89,8 @@ public class SenseDisambiguatorAnnotator
System.setProperty("ytex.conceptGraphName", "test");
System.setProperty("ytex.conceptPreload", "false");
System.setProperty("ytex.conceptSetName", "");
- JCas jCas = JCasFactory
- .createJCasFromPath("src/main/resources/org/apache/ctakes/ytex/types/TypeSystem.xml");
+ URL urlTypeSystem = getClass().getClassLoader().getResource("org/apache/ctakes/ytex/types/TypeSystem.xml");
+ JCas jCas = JCasFactory.createJCasFromPath(urlTypeSystem.getPath());
String text = "concept1 concept2 concept3";
jCas.setDocumentText(text);
EntityMention em1 = new EntityMention(jCas);
@@ -124,8 +112,7 @@ public class SenseDisambiguatorAnnotator
em3.addToIndexes();
SenseDisambiguatorAnnotator sda = new SenseDisambiguatorAnnotator();
- sda.wsd = ApplicationContextHolder.getApplicationContext().getBean(
- WordSenseDisambiguator.class);
+ sda.wsd = ApplicationContextHolder.getApplicationContext().getBean(WordSenseDisambiguator.class);
sda.process(jCas);
AnnotationIndex<Annotation> annoIdx = jCas.getAnnotationIndex(EntityMention.type);
List<Annotation> annoList = Lists.newArrayList(annoIdx);
@@ -141,6 +128,14 @@ public class SenseDisambiguatorAnnotator
}
}
+ @After
+ public void tearDown() throws Exception {
+ if (appCtx != null) {
+ ((ConfigurableApplicationContext) appCtx).close();
+ appCtx = null;
+ }
+ }
+
private void setConcepts(JCas jCas, EntityMention em1, String[] concepts) {
FSArray em1oc = new FSArray(jCas, concepts.length);
for (int i = 0; i < concepts.length; i++) {
Modified: ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java?rev=1817141&r1=1817140&r2=1817141&view=diff
==============================================================================
--- ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java (original)
+++ ctakes/trunk/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java Tue Dec 5 00:51:19 2017
@@ -25,6 +25,7 @@ import java.util.Properties;
import javax.sql.DataSource;
+import org.apache.ctakes.util.JdbcOperationsHelper;
import org.apache.ctakes.ytex.kernel.SimSvcContextHolder;
import org.apache.ctakes.ytex.kernel.dao.ConceptDao;
import org.apache.ctakes.ytex.kernel.metric.ConceptPairSimilarity;
@@ -39,13 +40,11 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import static org.junit.Assert.*;
-public class ConceptDaoTest {
+public class ConceptDaoTest extends JdbcOperationsHelper {
static private final Logger LOGGER = Logger.getLogger(ConceptDaoTest.class);
@@ -53,40 +52,6 @@ public class ConceptDaoTest {
private ApplicationContext appCtx = null;
- /**
- * Helper function to drop a 'table' from a DB, using SQL syntax
- *
- * @param jdbc
- * @param dbEngineType
- * @param sqlTableName
- */
- private final void dropTableIfExist(JdbcOperations jdbc, final String dbEngineType, final String sqlTableName) {
- // TODO: consider refactor using JOOQ
- String sqlStatement = "";
- switch (dbEngineType.toLowerCase()) {
- case "hsql":
- case "mysql":
- sqlStatement = String.format("DROP TABLE IF EXISTS %s", sqlTableName);
- break;
- case "mssql":
- sqlStatement = String.format("IF EXISTS(SELECT * FROM sys.objects WHERE object_id = object_id('%s')) DROP TABLE %s", sqlTableName);
- break;
- case "orcl":
- sqlStatement = String.format("DROP TABLE %s", sqlTableName);
- break;
- default:
- LOGGER.warn(String.format("unsupported DB engine type: %s", dbEngineType));
- break;
- }
- if (!sqlStatement.isEmpty()) {
- try {
- jdbc.execute(sqlStatement);
- } catch (DataAccessException e) {
- LOGGER.warn("couldn't drop table test_concepts. Maybe it doesn't even exists", e);
- }
- }
- }
-
@Before
public void setUp() throws Exception {
appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator