ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vjapa...@apache.org
Subject svn commit: r1554701 [2/2] - in /ctakes/branches/ytex: ctakes-ytex-res/src/main/resources/org/apache/ctakes/ytex/ ctakes-ytex-res/src/main/resources/org/apache/ctakes/ytex/kernel/ ctakes-ytex-uima/ ctakes-ytex-uima/conceptGraph/ ctakes-ytex-uima/desc/a...
Date Wed, 01 Jan 2014 23:39:31 GMT
Modified: ctakes/branches/ytex/ctakes-ytex-uima/pom.xml
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex-uima/pom.xml?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex-uima/pom.xml (original)
+++ ctakes/branches/ytex/ctakes-ytex-uima/pom.xml Wed Jan  1 23:39:31 2014
@@ -81,11 +81,10 @@
 			<scope>test</scope>
 		</dependency>
 
-		<!-- begin dependencies added from ctakes-assertion-->
-		<!-- maven is so friggin 
-			pedantic and won't load the transitive dependencies of ctakes-assertion because 
-			of ctakes-assertion pom not being absolutely perfect arghh. manually add 
-			dependencies here -->
+		<!-- begin dependencies added from ctakes-assertion -->
+		<!-- maven is so friggin pedantic and won't load the transitive dependencies 
+			of ctakes-assertion because of ctakes-assertion pom not being absolutely 
+			perfect arghh. manually add dependencies here -->
 		<dependency>
 			<groupId>org.scala-lang</groupId>
 			<artifactId>scala-library</artifactId>
@@ -98,7 +97,7 @@
 			<version>0.4.0</version>
 			<scope>test</scope>
 		</dependency>
-		<!-- end dependencies added from ctakes-assertion-->		
+		<!-- end dependencies added from ctakes-assertion -->
 		<!-- <dependency> <groupId>org.apache.ctakes</groupId> <artifactId>ctakes-core-res</artifactId> 
 			<scope>test</scope> </dependency> -->
 		<dependency>
@@ -170,7 +169,6 @@
 
 			<plugin>
 				<artifactId>maven-surefire-plugin</artifactId>
-				<version>2.12</version>
 				<configuration>
 					<includes>
 						<include>**/Test*.java</include>
@@ -178,7 +176,13 @@
 						<include>**/*Tests.java</include>
 						<include>**/*TestCase.java</include>
 					</includes>
+					<systemPropertyVariables>
+						<log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
+					</systemPropertyVariables>
 					<argLine>-Xmx1536m</argLine>
+					<forkMode>always</forkMode>
+					<forkCount>1</forkCount>
+					<reuseForks>false</reuseForks>
 					<forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds>
 					<additionalClasspathElements>
 						<additionalClasspathElement>${project.basedir}/../ctakes-assertion-res/src/main/resources</additionalClasspathElement>

Modified: ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DBConsumerTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DBConsumerTest.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DBConsumerTest.java (original)
+++ ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DBConsumerTest.java Wed Jan  1 23:39:31 2014
@@ -1,33 +1,25 @@
 package org.apache.ctakes.ytex.uima.annotators;
 
-import java.io.File;
 import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.util.Properties;
 
 import javax.sql.DataSource;
 
-import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.ctakes.ytex.uima.ApplicationContextHolder;
+import org.apache.ctakes.ytex.uima.TestUtils;
 import org.apache.ctakes.ytex.uima.types.DocKey;
 import org.apache.ctakes.ytex.uima.types.KeyValuePair;
 import org.apache.uima.UIMAException;
-import org.apache.uima.UIMAFramework;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.cas.FSArray;
-import org.apache.uima.util.InvalidXMLException;
-import org.apache.uima.util.XMLInputSource;
-import org.apache.uima.util.XMLParser;
 import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.uimafit.factory.AggregateBuilder;
 
 import com.google.common.base.Strings;
 
@@ -38,6 +30,12 @@ import com.google.common.base.Strings;
  * 
  */
 public class DBConsumerTest {
+	static ApplicationContext ctx = null;
+
+	@BeforeClass
+	public static void setup() {
+		ctx = ApplicationContextHolder.getApplicationContext();
+	}
 
 	/**
 	 * hsql will not write data unless the connection is explicitly closed. for
@@ -50,7 +48,7 @@ public class DBConsumerTest {
 	 */
 	@AfterClass
 	public static void cleanup() {
-
+		((ConfigurableApplicationContext)ctx).close();
 		// ApplicationContext ctx = ApplicationContextHolder
 		// .getApplicationContext();
 		// DataSource ds = ctx.getBean(DataSource.class);
@@ -95,14 +93,7 @@ public class DBConsumerTest {
 		// JCas jCas =
 		// JCasFactory.createJCasFromPath("src/main/resources/org/apache/ctakes/ytex/types/TypeSystem.xml");
 		String text = "Title: US Abdomen\n\nDr. Doolitle asked patient\nto take a deep breath\nand exhale slowly.  Patient coughed.  Prescribed acetominophen";
-		AggregateBuilder builder = new AggregateBuilder();
-		addDescriptor(builder, "desc/analysis_engine/SegmentRegexAnnotator.xml");
-		addDescriptor(builder,
-				"desc/analysis_engine/SentenceDetectorAnnotator.xml");
-		addDescriptor(builder,
-				"../ctakes-core/desc/analysis_engine/TokenizerAnnotator.xml");
-		addDescriptor(builder, "desc/analysis_engine/DBConsumer.xml");
-		AnalysisEngine engine = builder.createAggregate();
+		AnalysisEngine engine = TestUtils.createTokenizerAE(null);
 		JCas jCas = engine.newJCas();
 		jCas.setDocumentText(text);
 		// create a docKey so we can find the doc
@@ -117,8 +108,6 @@ public class DBConsumerTest {
 		docKey.addToIndexes();
 		// run the analysis engine
 		engine.process(jCas);
-		ApplicationContext ctx = ApplicationContextHolder
-				.getApplicationContext();
 		DataSource ds = ctx.getBean(DataSource.class);
 		Properties ytexProperties = (Properties) ctx.getBean("ytexProperties");
 		String schema = ytexProperties.getProperty("db.schema");
@@ -142,11 +131,4 @@ public class DBConsumerTest {
 		Assert.assertTrue(query, jt.queryForInt(query) > 1);
 	}
 
-	private void addDescriptor(AggregateBuilder builder, String path)
-			throws IOException, InvalidXMLException {
-		File fileCtakes = new File(path);
-		XMLParser parser = UIMAFramework.getXMLParser();
-		XMLInputSource source = new XMLInputSource(fileCtakes);
-		builder.add(parser.parseAnalysisEngineDescription(source));
-	}
 }

Modified: ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DictionaryLookupAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DictionaryLookupAnnotatorTest.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DictionaryLookupAnnotatorTest.java (original)
+++ ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/DictionaryLookupAnnotatorTest.java Wed Jan  1 23:39:31 2014
@@ -63,7 +63,7 @@ public class DictionaryLookupAnnotatorTe
 		String text = "Dr. Doolitle asked patient\nto take a deep breath\nand exhale slowly.  Patient coughed and complained of abdominal pain.  Patient was administered acetaminophen.";
 		AggregateBuilder builder = new AggregateBuilder();
 		addDescriptor(builder,
-				"desc/analysis_engine/AggregatePlaintextUMLSProcessor.xml");
+				"desc/analysis_engine/AggregatePlaintextUMLSProcessorMinimal.xml");
 		// addDescriptor(builder,
 		// "desc/analysis_engine/SentenceDetectorAnnotator.xml");
 		// addDescriptor(builder,

Modified: ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java (original)
+++ ctakes/branches/ytex/ctakes-ytex-uima/src/test/java/org/apache/ctakes/ytex/uima/annotators/SenseDisambiguatorAnnotatorTest.java Wed Jan  1 23:39:31 2014
@@ -2,6 +2,7 @@ package org.apache.ctakes.ytex.uima.anno
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 
 import javax.sql.DataSource;
 
@@ -19,7 +20,7 @@ import org.apache.uima.jcas.tcas.Annotat
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.springframework.context.ApplicationContext;
+import org.springframework.beans.factory.BeanFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -29,17 +30,21 @@ import com.google.common.collect.Lists;
 
 public class SenseDisambiguatorAnnotatorTest {
 	ConceptDao conceptDao;
-	ApplicationContext appCtx;
-
 	@Before
 	public void setUp() throws Exception {
-		appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
+		BeanFactory appCtx = ContextSingletonBeanFactoryLocator
 				.getInstance("classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
 				.useBeanFactory("kernelApplicationContext").getFactory();
 		conceptDao = appCtx.getBean(ConceptDao.class);
 		JdbcTemplate jdbcTemplate = new JdbcTemplate();
 		jdbcTemplate.setDataSource(appCtx.getBean(DataSource.class));
-		jdbcTemplate.execute("drop table if exists test_concepts");
+		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");
+		//TODO if("orcl".equals(dbtype)))
 		jdbcTemplate
 				.execute("create table test_concepts(parent varchar(20), child varchar(20))");
 		jdbcTemplate
@@ -54,7 +59,7 @@ public class SenseDisambiguatorAnnotator
 				.execute("insert into test_concepts values ('root', 'bacteria')");
 		jdbcTemplate
 				.execute("insert into test_concepts values ('bacteria', 'e coli')");
-		conceptDao.createConceptGraph("test",
+		conceptDao.createConceptGraph(null, "test",
 				"select child, parent from test_concepts", true,
 				Collections.EMPTY_SET);
 		ConceptGraph cg = conceptDao.getConceptGraph("test");
@@ -94,7 +99,7 @@ public class SenseDisambiguatorAnnotator
 		em3.addToIndexes();
 		
 		SenseDisambiguatorAnnotator sda = new SenseDisambiguatorAnnotator();
-		sda.wsd = ApplicationContextHolder.getSimApplicationContext().getBean(
+		sda.wsd = ApplicationContextHolder.getApplicationContext().getBean(
 				WordSenseDisambiguator.class);
 		sda.process(jCas);
 		AnnotationIndex<Annotation> annoIdx = jCas.getAnnotationIndex(EntityMention.type);

Modified: ctakes/branches/ytex/ctakes-ytex/README
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/README?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/README (original)
+++ ctakes/branches/ytex/ctakes-ytex/README Wed Jan  1 23:39:31 2014
@@ -7,14 +7,33 @@ Introduction
 Need buildhelper m2e plugin
 
 == Developing ==
+We have currently tested mysql and ms sql server, oracle is pending.  HSQL is used only for unit testing.  
+
 YTEX is driven by a property file, ytex.properties.  The property file used when running ytex java programs 
-(aside from junit tests) is src\main\resources\org\apache\ctakes\ytex\ytex.properties.  Create this file
-for use when running java programs.
+(aside from junit tests) is src\main\resources\org\apache\ctakes\ytex\ytex.properties.  Refer to the example
+properties files under /ctakes-ytex-res/src/main/resources/org/apache/ctakes/ytex
 
 YTEX relies on some config files generated from templates via an ant build script.  These config files are 
 generated automatically by the maven build (which runs the ant build script).  
-M2E is a bit (understatement) buggy, you may have to run the maven
-build from the command line so that things work correctly.
+The maven eclipse integration is a bit buggy; you should run the maven build from the command line so that 
+things work correctly.
+
+For development, you must set up a database.  There are 2 types of database setups, depending on if you have a UMLS
+installation (and you've configured ytex to use it):
+* With UMLS - YTEX will generate a dictionary lookup table from your UMLS database.  This requires tokenizing every 
+string in MRCONSO which will take a while.  If you have UMLS installed and want to use it, configure the 
+umls.schema/umls.catalog properties in ytex.properties.
+* Without UMLS - YTEX will load a pre-fabricated dictionary lookup table generated from the UMLS 2013AA.  This is included
+in the ctakes-resources zip from sourceforge.  You have to copy v_snomed_fword_lookup.txt to ctakes-ytex\scripts\data\umls\.
+
+After running the maven build, run the ant script to set up your database.  Make sure java and ant are in your path, 
+and run the following commands
+* Windows
+cd ctakes-ytex\scripts\data
+ant -Dconfig.local=..\..\target\classes all > ..\..\target\build.out 2>&1
+* Linux
+cd ctakes-ytex/scripts/data
+ant -Dconfig.local=../../target/classes all > ../../target/build.out 2>&1
 
 == Testing ==
 

Modified: ctakes/branches/ytex/ctakes-ytex/scripts/build-classpath.xml
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/scripts/build-classpath.xml?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/scripts/build-classpath.xml (original)
+++ ctakes/branches/ytex/ctakes-ytex/scripts/build-classpath.xml Wed Jan  1 23:39:31 2014
@@ -73,8 +73,7 @@
 		<!--
 		<pathelement location="${ctakes.home}/ctakes-ytex-uima/target/classes" />
 		-->
-		<fileset dir="${ctakes.home}/ctakes-ytex/target/lib" includes="**/*.jar" excludes="**/ant-*.jar" />
-		<fileset dir="${ctakes.home}/ctakes-ytex-uima/target/lib" includes="**/*.jar" excludes="**/ant-*.jar" />
+		<fileset dir="${ctakes.home}" includes="ctakes-assertion/lib/*.jar,ctakes-ytex/target/lib/*.jar,ctakes-ytex-uima/target/lib/*.jar" excludes="**/ant-*.jar" />
 	</path>
 	<path id="kernel.cp.prod">
 		<pathelement location="${config.local}" />

Modified: ctakes/branches/ytex/ctakes-ytex/scripts/data/hsql/umls/create_view.sql
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/scripts/data/hsql/umls/create_view.sql?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/scripts/data/hsql/umls/create_view.sql (original)
+++ ctakes/branches/ytex/ctakes-ytex/scripts/data/hsql/umls/create_view.sql Wed Jan  1 23:39:31 2014
@@ -2,7 +2,7 @@ CREATE CACHED TABLE v_snomed_fword_looku
   cui char(8) not null,
   tui char(8) null,
   fword varchar(70) not null,
-  fstem varchar(70) not null,
+  fstem varchar(70) null,
   tok_str varchar(250) not null,
-  stem_str varchar(250) not null
+  stem_str varchar(250) null
 );

Modified: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/dao/DBUtil.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/dao/DBUtil.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/dao/DBUtil.java (original)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/dao/DBUtil.java Wed Jan  1 23:39:31 2014
@@ -23,6 +23,7 @@ public class DBUtil {
 	private static boolean oracle;
 	private static boolean mysql;
 	private static boolean mssql;
+	private static boolean hsql;
 	private static String escapeBegin;
 	private static String escapeEnd;
 
@@ -34,17 +35,18 @@ public class DBUtil {
 			ytexProperties.load(ytexPropsIn);
 			oracle = "orcl".equals(ytexProperties.getProperty("db.type"));
 			mysql = "mysql".equals(ytexProperties.getProperty("db.type"));
-			mssql = "mssql".equals(ytexProperties.getProperty("db.type"));
+			hsql = "hsql".equals(ytexProperties.getProperty("db.type"));
+			
 			if (mssql) {
 				escapeBegin = "[";
 				escapeEnd = "]";
 			} else if (mysql) {
 				escapeBegin = "`";
 				escapeEnd = "`";
-			} else if (oracle) {
+			} else  {
 				escapeBegin = "";
 				escapeEnd = "";
-			}
+			} 
 		} catch (Exception e) {
 			log.error("initalizer", e);
 		} finally {

Modified: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDao.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDao.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDao.java (original)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDao.java Wed Jan  1 23:39:31 2014
@@ -5,7 +5,6 @@ import java.util.Set;
 
 import org.apache.ctakes.ytex.kernel.model.ConceptGraph;
 
-
 /**
  * create/retrieve concept graphs. store concept graph on file system as they
  * can get big (>10MB). This is not a problem for sql server/oracle, but may
@@ -17,27 +16,52 @@ import org.apache.ctakes.ytex.kernel.mod
 public interface ConceptDao {
 
 	/**
-	 * retrieve an existing concept graph.
+	 * retrieve an existing concept graph. This attempts to find the concept
+	 * graph as follows:
+	 * <ul>
+	 * <li>classpath: attempt to load
+	 * org/apache/ctakes/ytex/conceptGraph/[name].gz</li>
+	 * <li>relative to org.apache.ctakes.ytex.conceptGraphDir: if that fails
+	 * then relative to the directory defined by the system property/ytex
+	 * property org.apache.ctakes.ytex.conceptGraphDir</li>
+	 * <li>relative to ytex.properties: if the org...conceptGraphDir property is
+	 * not defined, then look for [directory of
+	 * ytex.properties]/conceptGraph/[name].gz</li>
+	 * </ul>
 	 * 
 	 * @param name
-	 *            name of concept graph. Will retrieve from file system. @see
-	 *            #createConceptGraph
+	 *            name of concept graph. Will retrieve from classpath/file
+	 *            system. @see #createConceptGraph
 	 * @return
 	 */
 	public abstract ConceptGraph getConceptGraph(String name);
 
 	/**
-	 * create the concept graph with specified name using specified query.
+	 * create the concept graph with specified name using specified query. Will
+	 * create a file [name].gz under dir.
 	 * 
+	 * @param dir
+	 *            directory of concept graph (optional). If null will use
+	 *            directory specified by the system property/ytex property
+	 *            org.apache.ctakes.ytex.conceptGraphDir. If the property is not
+	 *            defined, use [directory of ytex.properties]/conceptGraph
 	 * @param name
-	 *            name of concept graph. will create file
-	 *            ${org.apache.ctakes.ytex.conceptGraphDir}/[name].gz
+	 *            name of concept graph
 	 * @param query
 	 *            returns 2 string columns, 1st column is the child concept, 2nd
 	 *            column is the parent concept.
-	 * @return ConceptGraph the concept graph generated using this query.
+	 * @param checkCycle
+	 *            if true will check for cycles and remove them (default true).
+	 *            If this is set to false, then only pagerank can be used on
+	 *            this graph.
+	 * @param forbiddenConcepts
+	 *            set of concepts whose edges will not be added to the concept
+	 *            graph (optional). By default, this includes umls concepts like
+	 *            C1274012 (Ambiguous concept).
+	 * @return ConceptGraph the generated concept graph
 	 */
-	public abstract void createConceptGraph(String name, String query,
-			final boolean checkCycle, final Set<String> forbiddenConcepts) throws IOException;
+	public abstract void createConceptGraph(String dir, String name,
+			String query, final boolean checkCycle,
+			final Set<String> forbiddenConcepts) throws IOException;
 
 }
\ No newline at end of file

Modified: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDaoImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDaoImpl.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDaoImpl.java (original)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/dao/ConceptDaoImpl.java Wed Jan  1 23:39:31 2014
@@ -9,13 +9,14 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.OutputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -42,11 +43,12 @@ import org.hibernate.SessionFactory;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowCallbackHandler;
 
-
+import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
 public class ConceptDaoImpl implements ConceptDao {
+	private static final String CONCEPT_GRAPH_PATH = "org/apache/ctakes/ytex/conceptGraph/";
 	/**
 	 * the default concept id for the root. override with -Dytex.defaultRootId
 	 */
@@ -79,8 +81,22 @@ public class ConceptDaoImpl implements C
 	}
 
 	/**
-	 * create a concept graph. 1st param - name of concept graph. 2nd param -
-	 * query to retrieve parent-child pairs.
+	 * create a concept graph.
+	 * 
+	 * This expects a property file in the classpath under
+	 * CONCEPT_GRAPH_PATH/[name].xml
+	 * <p/>
+	 * If the properties file is found in a directory, the concept graph will be
+	 * written there.
+	 * <p/>
+	 * Else (e.g. if the props file is coming from a jar), the concept graph
+	 * will be written to the directory specified via the system property/ytex
+	 * property 'org.apache.ctakes.ytex.conceptGraphDir'
+	 * <p/>
+	 * Else if the 'org.apache.ctakes.ytex.conceptGraphDir' property is not
+	 * defined, the concept graph will be written to the conceptGraph
+	 * subdirectory relative to ytex.properties (if ytex.properties is in a
+	 * directory).
 	 * 
 	 * @param args
 	 */
@@ -88,22 +104,40 @@ public class ConceptDaoImpl implements C
 	public static void main(String args[]) throws ParseException, IOException {
 		Options options = new Options();
 		options.addOption(OptionBuilder
-				.withArgName("prop")
+				.withArgName("name")
 				.hasArg()
 				.isRequired()
 				.withDescription(
-						"property file with queries and other parameters. todo desc")
-				.create("prop"));
+						"name of concept graph.  A property file with the name "
+								+ CONCEPT_GRAPH_PATH
+								+ "/[name].xml must exist on the classpath")
+				.create("name"));
 		try {
 			CommandLineParser parser = new GnuParser();
 			CommandLine line = parser.parse(options, args);
+			String name = line.getOptionValue("name");
+			URL url = ConceptDaoImpl.class.getClassLoader().getResource(
+					CONCEPT_GRAPH_PATH + "/" + name + ".xml");
+			File fDir = null;
+			if (url != null) {
+				if ("file".equals(url.getProtocol())) {
+					File f;
+					try {
+						f = new File(url.toURI());
+					} catch (URISyntaxException e) {
+						f = new File(url.getPath());
+					}
+					fDir = f.getParentFile();
+				}
+			}
 			Properties props = FileUtil.loadProperties(
 					line.getOptionValue("prop"), true);
 			String conceptGraphName = props
 					.getProperty("org.apache.ctakes.ytex.conceptGraphName");
 			String conceptGraphQuery = props
 					.getProperty("org.apache.ctakes.ytex.conceptGraphQuery");
-			String strCheckCycle = props.getProperty("org.apache.ctakes.ytex.checkCycle", "true");
+			String strCheckCycle = props.getProperty(
+					"org.apache.ctakes.ytex.checkCycle", "true");
 			String forbiddenConceptList = props
 					.getProperty("org.apache.ctakes.ytex.forbiddenConcepts");
 			Set<String> forbiddenConcepts;
@@ -122,9 +156,9 @@ public class ConceptDaoImpl implements C
 				KernelContextHolder
 						.getApplicationContext()
 						.getBean(ConceptDao.class)
-						.createConceptGraph(conceptGraphName,
-								conceptGraphQuery, checkCycle,
-								forbiddenConcepts);
+						.createConceptGraph(fDir.getAbsolutePath(),
+								conceptGraphName, conceptGraphQuery,
+								checkCycle, forbiddenConcepts);
 			} else {
 				printHelp(options);
 			}
@@ -217,21 +251,16 @@ public class ConceptDaoImpl implements C
 	 * @see org.apache.ctakes.ytex.kernel.dao.ConceptDao#createConceptGraph
 	 */
 	@Override
-	public void createConceptGraph(String name, String query,
+	public void createConceptGraph(String dir, String name, String query,
 			final boolean checkCycle, final Set<String> forbiddenConcepts)
 			throws IOException {
-		ConceptGraph conceptGraph = getConceptGraph(name);
+		ConceptGraph conceptGraph = this.readConceptGraph(name);
 		if (conceptGraph != null) {
 			if (log.isWarnEnabled())
-				log.warn("createConceptGraph(): concept graph already exist, exiting");
+				log.warn("createConceptGraph(): concept graph already exists, will not create a new one.  Delete existing concept graph if you want to recreate it.");
 		} else {
 			if (log.isInfoEnabled())
-				log.info("createConceptGraph(): file not found, initializing concept graph from database.");
-			// final Map<String, ConcRel> conceptMap = new HashMap<String,
-			// ConcRel>();
-			// final List<String> conceptList = new ArrayList<String>();
-			// final Map<String, Integer> conceptIndexMap = new HashMap<String,
-			// Integer>();
+				log.info("createConceptGraph(): file not found, creating concept graph from database.");
 			final ConceptGraph cg = new ConceptGraph();
 			final Set<String> roots = new HashSet<String>();
 			this.jdbcTemplate.query(query, new RowCallbackHandler() {
@@ -258,8 +287,9 @@ public class ConceptDaoImpl implements C
 			if (roots.size() == 1) {
 				rootId = roots.iterator().next();
 			} else {
-				rootId = System.getProperty("org.apache.ctakes.ytex.defaultRootId",
-						DEFAULT_ROOT_ID);
+				rootId = System
+						.getProperty("org.apache.ctakes.ytex.defaultRootId",
+								DEFAULT_ROOT_ID);
 				ConcRel crRoot = cg.addConcept(rootId);
 				for (String crChildId : roots) {
 					ConcRel crChild = cg.getConceptMap().get(crChildId);
@@ -268,65 +298,79 @@ public class ConceptDaoImpl implements C
 				}
 			}
 			cg.setRoot(rootId);
-			// // can't get the maximum depth unless we're sure there are no
+			// can't get the maximum depth unless we're sure there are no
 			// cycles
 			// if (checkCycle)
 			// cg.setDepthMax(calculateDepthMax(rootId, cg.getConceptMap()));
 			if (checkCycle) {
 				log.info("computing intrinsic info for concept graph: " + name);
 				this.intrinsicInfoContentEvaluator
-						.evaluateIntrinsicInfoContent(name,
-								getConceptGraphDir(), cg);
+						.evaluateIntrinsicInfoContent(name, dir, cg);
 			}
-			log.info("writing concept graph: " + name);
-			writeConceptGraph(name, cg);
-			writeConceptGraphProps(name, query, checkCycle);
+			writeConceptGraph(dir, name, cg);
 		}
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
-	 * @see org.apache.ctakes.ytex.kernel.dao.ConceptDao#getConceptGraph(java.util.Set)
+	 * @see
+	 * org.apache.ctakes.ytex.kernel.dao.ConceptDao#getConceptGraph(java.util
+	 * .Set)
 	 */
 	public ConceptGraph getConceptGraph(String name) {
-		File f = new File(getConceptGraphFileName(name));
-		if (log.isInfoEnabled())
-			log.info("getConceptGraph(" + name
-					+ ") initializing concept graph from file: " + f.getPath());
-		if (f.exists()) {
-			if (log.isInfoEnabled())
-				log.info("getConceptGraph(" + name
-						+ ") file exists, reading concept graph");
-			return initializeConceptGraph(this.readConceptGraph(f));
+		ConceptGraph cg = this.readConceptGraph(name);
+		if (cg != null) {
+			this.initializeConceptGraph(cg);
+			if(log.isInfoEnabled()) {
+				log.info(String.format("concept graph %s, vertices: %s", name, cg.getConceptList().size()));
+			}
+		}
+		return cg;
+	}
+
+	private File urlToFile(URL url) {
+		if (url != null && "file".equals(url.getProtocol())) {
+			File f;
+			try {
+				f = new File(url.toURI());
+			} catch (URISyntaxException e) {
+				f = new File(url.getPath());
+			}
+			return f;
 		} else {
 			return null;
 		}
+
 	}
 
-	public String getConceptGraphDir() {
-		String cdir = ytexProperties.getProperty("org.apache.ctakes.ytex.conceptGraphDir");
-		if (cdir == null || cdir.length() == 0) {
-			// see if org.apache.ctakes.ytex home is defined in org.apache.ctakes.ytex properties
-			String ytexHome = ytexProperties.getProperty("org.apache.ctakes.ytex.home");
-			if (ytexHome == null || ytexHome.length() == 0) {
-				// see if org.apache.ctakes.ytex home is defined in the environment
-				ytexHome = System.getenv().get("YTEX_HOME");
-			}
-			if (ytexHome == null || ytexHome.length() == 0) {
-				log.warn("none of org.apache.ctakes.ytex.conceptGraphDir, org.apache.ctakes.ytex.home, or YTEX_HOME are defined - assuming conceptGraphDir is ./conceptGraph");
-				// default to current directory
-				ytexHome = ".";
+	/**
+	 * use value of org.apache.ctakes.ytex.conceptGraphDir if defined. else try
+	 * to determine ytex.properties location and use the conceptGraph directory
+	 * there. else return null
+	 * 
+	 * @return
+	 */
+	public String getDefaultConceptGraphDir() {
+		String cdir = System.getProperty(
+				"org.apache.ctakes.ytex.conceptGraphDir", ytexProperties
+						.getProperty("org.apache.ctakes.ytex.conceptGraphDir"));
+		// default to [ytex.properties directory]/conceptGraph
+		if (Strings.isNullOrEmpty(cdir)) {
+			URL url = this.getClass().getResource(
+					"/org/apache/ctakes/ytex/ytex.properties");
+			File f = urlToFile(url);
+			if (f != null) {
+				File baseDir = f.getParentFile();
+				if (baseDir.exists() && baseDir.isDirectory()) {
+					cdir = baseDir.getAbsolutePath() + File.separator
+							+ "conceptGraph";
+				}
 			}
-			cdir = ytexHome + File.separator + "conceptGraph";
 		}
 		return cdir;
 	}
 
-	private String getConceptGraphFileName(String name) {
-		return getConceptGraphDir() + File.separator + name + ".gz";
-	}
-
 	public DataSource getDataSource(DataSource ds) {
 		return this.jdbcTemplate.getDataSource();
 	}
@@ -400,12 +444,40 @@ public class ConceptDaoImpl implements C
 		return cg;
 	}
 
-	private ConceptGraph readConceptGraph(File file) {
+	private ConceptGraph readConceptGraph(String name) {
 		ObjectInputStream is = null;
 		try {
-			is = new ObjectInputStream(new BufferedInputStream(
-					new GZIPInputStream(new FileInputStream(file))));
-			return (ConceptGraph) is.readObject();
+			// try loading from classpath
+			InputStream resIs = this.getClass().getClassLoader()
+					.getResourceAsStream(CONCEPT_GRAPH_PATH + name + ".gz");
+			if (resIs == null) {
+				String cdir = this.getDefaultConceptGraphDir();
+				if (cdir == null) {
+					throw new IllegalArgumentException(
+							"could not determine default concept graph directory; please set property org.apache.ctakes.ytex.conceptGraphDir");
+				}
+				File f = new File(cdir + "/" + name + ".gz");
+				log.info("could not load conceptGraph from classpath, attempt to load from: "
+						+ f.getAbsolutePath());
+				if (f.exists()) {
+					resIs = new FileInputStream(f);
+				} else {
+					log.info(f.getAbsolutePath()
+							+ " not found, cannot load concept graph");
+				}
+			} else {
+				log.info("loading concept graph from "
+						+ this.getClass().getClassLoader()
+								.getResource(CONCEPT_GRAPH_PATH + name + ".gz"));
+			}
+			if (resIs != null) {
+				is = new ObjectInputStream(new BufferedInputStream(
+						new GZIPInputStream(resIs)));
+				return (ConceptGraph) is.readObject();
+			} else {
+				log.info("could not load conceptGraph: " + name);
+				return null;
+			}
 		} catch (IOException ioe) {
 			throw new RuntimeException(ioe);
 		} catch (ClassNotFoundException e) {
@@ -479,9 +551,18 @@ public class ConceptDaoImpl implements C
 	 * @param name
 	 * @param cg
 	 */
-	private void writeConceptGraph(String name, ConceptGraph cg) {
+	private void writeConceptGraph(String dir, String name, ConceptGraph cg) {
 		ObjectOutputStream os = null;
-		File cgFile = new File(getConceptGraphFileName(name));
+		String outputDir = dir;
+		if (Strings.isNullOrEmpty(outputDir)) {
+			outputDir = getDefaultConceptGraphDir();
+		}
+		if (Strings.isNullOrEmpty(outputDir)) {
+			throw new IllegalArgumentException(
+					"could not determine default concept graph directory; please set property org.apache.ctakes.ytex.conceptGraphDir");
+		}
+		File cgFile = new File(outputDir + "/" + name + ".gz");
+		log.info("writing concept graph: " + cgFile.getAbsolutePath());
 		if (!cgFile.getParentFile().exists())
 			cgFile.getParentFile().mkdirs();
 		try {
@@ -502,32 +583,4 @@ public class ConceptDaoImpl implements C
 		}
 	}
 
-	private void writeConceptGraphProps(String name, String query,
-			boolean checkCycle) {
-		File propFile = new File(FileUtil.addFilenameToDir(
-				this.getConceptGraphDir(), name + ".xml"));
-		try {
-			if (!propFile.exists()) {
-				Properties props = new Properties();
-				props.put("org.apache.ctakes.ytex.conceptGraphQuery", query);
-				props.put("org.apache.ctakes.ytex.conceptGraphName", name);
-				props.put("org.apache.ctakes.ytex.checkCycle", checkCycle ? "true" : "false");
-				OutputStream os = null;
-				try {
-					os = new FileOutputStream(propFile);
-					props.storeToXML(os, "created on " + (new Date()));
-				} finally {
-					if (os != null) {
-						try {
-							os.close();
-						} catch (Exception e) {
-						}
-					}
-				}
-			}
-		} catch (IOException ioe) {
-			throw new RuntimeException(ioe);
-		}
-	}
-
 }

Modified: ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/metric/ConceptSimilarityServiceImpl.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/metric/ConceptSimilarityServiceImpl.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/metric/ConceptSimilarityServiceImpl.java (original)
+++ ctakes/branches/ytex/ctakes-ytex/src/main/java/org/apache/ctakes/ytex/kernel/metric/ConceptSimilarityServiceImpl.java Wed Jan  1 23:39:31 2014
@@ -273,13 +273,13 @@ public class ConceptSimilarityServiceImp
 	private Cache lcsCache;
 	private String lcsImputedType = ImputedFeatureEvaluator.MeasureType.INFOGAIN
 			.getName();
+
 	private PageRankService pageRankService;
 
 	private boolean preload = true;
 	private Map<String, Double> corpusICMap;
 
 	private Map<SimilarityMetricEnum, SimilarityMetric> similarityMetricMap = null;
-
 	private PlatformTransactionManager transactionManager;
 
 	private List<String> tuiList;
@@ -299,6 +299,69 @@ public class ConceptSimilarityServiceImp
 		tuis.add(tui);
 	}
 
+	@Override
+	public Object[] getBestLCS(Set<String> lcses, boolean intrinsicIC,
+			Map<String, Double> conceptFilter) {
+		Map<String, Double> lcsICMap = new HashMap<String, Double>(lcses.size());
+		// if (isPreload()) {
+		// look in conceptInfoMap for info content
+		for (String lcs : lcses) {
+			lcsICMap.put(lcs, getIC(lcs, intrinsicIC));
+			// }
+			// } else {
+			// // load info content on demand
+			// Map<String, FeatureRank> frMap = getICOnDemand(lcses,
+			// intrinsicIC);
+			// for (Map.Entry<String, FeatureRank> frMapEntry :
+			// frMap.entrySet()) {
+			// lcsICMap.put(frMapEntry.getKey(), frMapEntry.getValue()
+			// .getEvaluation());
+			// }
+		}
+		if (conceptFilter != null) {
+			double currentBest = -1;
+			Set<String> bestLcses = new HashSet<String>();
+			for (String lcs : lcses) {
+				if (conceptFilter.containsKey(lcs)) {
+					double lcsEval = conceptFilter.get(lcs);
+					if (currentBest == -1 || lcsEval > currentBest) {
+						bestLcses.clear();
+						bestLcses.add(lcs);
+						currentBest = lcsEval;
+					} else if (currentBest == lcsEval) {
+						bestLcses.add(lcs);
+					}
+				}
+			}
+			if (currentBest < 0)
+				currentBest = 0d;
+			if (bestLcses.size() > 0) {
+				return this.getBestLCS(bestLcses, lcsICMap);
+			} else {
+				// no lcses made the cut
+				return null;
+			}
+		} else {
+			// unfiltered - get the lowest ic
+			return this.getBestLCS(lcses, lcsICMap);
+		}
+	}
+
+	public Object[] getBestLCS(Set<String> lcses, Map<String, Double> icMap) {
+		double ic = -1;
+		String bestLCS = null;
+		for (String lcs : lcses) {
+			Double ictmp = icMap.get(lcs);
+			if (ictmp != null && ic < ictmp.doubleValue()) {
+				ic = ictmp;
+				bestLCS = lcs;
+			}
+		}
+		if (ic < 0)
+			ic = 0d;
+		return new Object[] { bestLCS, ic };
+	}
+
 	// /**
 	// * return lin measure. optionally filter lin measure so that only concepts
 	// * that have an lcs that is relevant to the classification task have a
@@ -391,84 +454,16 @@ public class ConceptSimilarityServiceImp
 	// return null;
 	// }
 
-	@Override
-	public Object[] getBestLCS(Set<String> lcses, boolean intrinsicIC,
-			Map<String, Double> conceptFilter) {
-		Map<String, Double> lcsICMap = new HashMap<String, Double>(lcses.size());
-		// if (isPreload()) {
-		// look in conceptInfoMap for info content
-		for (String lcs : lcses) {
-			lcsICMap.put(lcs, getIC(lcs, intrinsicIC));
-			// }
-			// } else {
-			// // load info content on demand
-			// Map<String, FeatureRank> frMap = getICOnDemand(lcses,
-			// intrinsicIC);
-			// for (Map.Entry<String, FeatureRank> frMapEntry :
-			// frMap.entrySet()) {
-			// lcsICMap.put(frMapEntry.getKey(), frMapEntry.getValue()
-			// .getEvaluation());
-			// }
-		}
-		if (conceptFilter != null) {
-			double currentBest = -1;
-			Set<String> bestLcses = new HashSet<String>();
-			for (String lcs : lcses) {
-				if (conceptFilter.containsKey(lcs)) {
-					double lcsEval = conceptFilter.get(lcs);
-					if (currentBest == -1 || lcsEval > currentBest) {
-						bestLcses.clear();
-						bestLcses.add(lcs);
-						currentBest = lcsEval;
-					} else if (currentBest == lcsEval) {
-						bestLcses.add(lcs);
-					}
-				}
-			}
-			if (currentBest < 0)
-				currentBest = 0d;
-			if (bestLcses.size() > 0) {
-				return this.getBestLCS(bestLcses, lcsICMap);
-			} else {
-				// no lcses made the cut
-				return null;
-			}
-		} else {
-			// unfiltered - get the lowest ic
-			return this.getBestLCS(lcses, lcsICMap);
-		}
+	public CacheManager getCacheManager() {
+		return cacheManager;
 	}
 
-	private Map<String, FeatureRank> getICOnDemand(Set<String> lcses,
-			boolean intrinsicIC) {
-		if (lcses == null || lcses.isEmpty())
-			return new HashMap<String, FeatureRank>(0);
-		Map<String, FeatureRank> lcsICMap;
-		lcsICMap = this.classifierEvaluationDao
-				.getFeatureRanks(
-						lcses,
-						intrinsicIC ? null : this.corpusName,
-						intrinsicIC ? null : this.conceptSetName,
-						null,
-						intrinsicIC ? IntrinsicInfoContentEvaluator.INTRINSIC_INFOCONTENT
-								: InfoContentEvaluator.INFOCONTENT, null, 0d,
-						this.getConceptGraphName());
-		return lcsICMap;
+	public ClassifierEvaluationDao getClassifierEvaluationDao() {
+		return classifierEvaluationDao;
 	}
 
-	public Object[] getBestLCS(Set<String> lcses, Map<String, Double> icMap) {
-		double ic = -1;
-		String bestLCS = null;
-		for (String lcs : lcses) {
-			Double ictmp = icMap.get(lcs);
-			if (ictmp != null && ic < ictmp.doubleValue()) {
-				ic = ictmp;
-				bestLCS = lcs;
-			}
-		}
-		if (ic < 0)
-			ic = 0d;
-		return new Object[] { bestLCS, ic };
+	public ConceptDao getConceptDao() {
+		return conceptDao;
 	}
 
 	// private String createKey(String c1, String c2) {
@@ -479,18 +474,6 @@ public class ConceptSimilarityServiceImp
 	// }
 	// }
 
-	public CacheManager getCacheManager() {
-		return cacheManager;
-	}
-
-	public ClassifierEvaluationDao getClassifierEvaluationDao() {
-		return classifierEvaluationDao;
-	}
-
-	public ConceptDao getConceptDao() {
-		return conceptDao;
-	}
-
 	@Override
 	public ConceptGraph getConceptGraph() {
 		return cg;
@@ -513,31 +496,26 @@ public class ConceptSimilarityServiceImp
 		return cuiTuiMap;
 	}
 
-	// /**
-	// * get the concept with the lowest Information Content of all the LCSs.
-	// * Functionality copied from umls interface.
-	// *
-	// * @todo make this configurable/add a parameter - avg/min/max/median?
-	// * @param lcses
-	// * @return
-	// */
-	// public double getIC(Iterable<String> lcses) {
-	// double ic = 0;
-	// for (String lcs : lcses) {
-	// double ictmp = getIC(lcs);
-	// if (ic < ictmp)
-	// ic = ictmp;
-	// }
-	// return ic;
-	// }
-	//
-	// public double getIC(String concept1) {
-	// Double dRetVal = corpusICMap.get(concept1);
-	// if (dRetVal != null)
-	// return (double) dRetVal;
-	// else
-	// return 0;
-	// }
+	@Override
+	public int getDepth(String concept) {
+		// if (isPreload()) {
+		// // preloaded all concept info - depth should be there
+		// ConceptInfo ci = this.getPreloadedConceptInfo(concept);
+		// if (ci != null)
+		// return (int) ci.getDepth();
+		// } else {
+		// // get the feature ranks for the intrinsic infocontent -
+		// // rank = depth
+		// Map<String, FeatureRank> frMap = getICOnDemand(new HashSet<String>(
+		// Arrays.asList(concept)), true);
+		// if (frMap.containsKey(concept))
+		// return frMap.get(concept).getRank();
+		// }
+		ConcRel cr = this.cg.getConceptMap().get(concept);
+		if (cr != null)
+			return cr.getDepth();
+		return 0;
+	}
 
 	@Override
 	public double getIC(String concept, boolean intrinsicICMap) {
@@ -575,27 +553,49 @@ public class ConceptSimilarityServiceImp
 		// return 0d;
 	}
 
-	@Override
-	public int getDepth(String concept) {
-		// if (isPreload()) {
-		// // preloaded all concept info - depth should be there
-		// ConceptInfo ci = this.getPreloadedConceptInfo(concept);
-		// if (ci != null)
-		// return (int) ci.getDepth();
-		// } else {
-		// // get the feature ranks for the intrinsic infocontent -
-		// // rank = depth
-		// Map<String, FeatureRank> frMap = getICOnDemand(new HashSet<String>(
-		// Arrays.asList(concept)), true);
-		// if (frMap.containsKey(concept))
-		// return frMap.get(concept).getRank();
-		// }
-		ConcRel cr = this.cg.getConceptMap().get(concept);
-		if (cr != null)
-			return cr.getDepth();
-		return 0;
+	private Map<String, FeatureRank> getICOnDemand(Set<String> lcses,
+			boolean intrinsicIC) {
+		if (lcses == null || lcses.isEmpty())
+			return new HashMap<String, FeatureRank>(0);
+		Map<String, FeatureRank> lcsICMap;
+		lcsICMap = this.classifierEvaluationDao
+				.getFeatureRanks(
+						lcses,
+						intrinsicIC ? null : this.corpusName,
+						intrinsicIC ? null : this.conceptSetName,
+						null,
+						intrinsicIC ? IntrinsicInfoContentEvaluator.INTRINSIC_INFOCONTENT
+								: InfoContentEvaluator.INFOCONTENT, null, 0d,
+						this.getConceptGraphName());
+		return lcsICMap;
 	}
 
+	// /**
+	// * get the concept with the lowest Information Content of all the LCSs.
+	// * Functionality copied from umls interface.
+	// *
+	// * @todo make this configurable/add a parameter - avg/min/max/median?
+	// * @param lcses
+	// * @return
+	// */
+	// public double getIC(Iterable<String> lcses) {
+	// double ic = 0;
+	// for (String lcs : lcses) {
+	// double ictmp = getIC(lcs);
+	// if (ic < ictmp)
+	// ic = ictmp;
+	// }
+	// return ic;
+	// }
+	//
+	// public double getIC(String concept1) {
+	// Double dRetVal = corpusICMap.get(concept1);
+	// if (dRetVal != null)
+	// return (double) dRetVal;
+	// else
+	// return 0;
+	// }
+
 	public int getLCS(String concept1, String concept2, Set<String> lcses,
 			List<LCSPath> lcsPaths) {
 		int lcsDist = 0;
@@ -625,6 +625,10 @@ public class ConceptSimilarityServiceImp
 		return lcsDist;
 	}
 
+	public Cache getLcsCache() {
+		return lcsCache;
+	}
+
 	@SuppressWarnings("unchecked")
 	private int getLCSFromCache(ConcRel cr1, ConcRel cr2, Set<String> lcses) {
 		OrderedPair<String> cacheKey = new OrderedPair<String>(
@@ -699,7 +703,6 @@ public class ConceptSimilarityServiceImp
 				return null;
 			}
 		});
-		this.lcsCache = getCacheManager().getCache("lcsCache");
 		log.info("end initialization for concept graph: " + conceptGraphName);
 	}
 
@@ -858,6 +861,19 @@ public class ConceptSimilarityServiceImp
 		return preload;
 	}
 
+	public int lcs(String concept1, String concept2, List<LCSPath> lcsPaths) {
+		ConcRel cr1 = cg.getConceptMap().get(concept1);
+		ConcRel cr2 = cg.getConceptMap().get(concept2);
+		int dist = -1;
+		if (cr1 != null && cr2 != null) {
+			Set<ConcRel> crlcses = new HashSet<ConcRel>();
+			Map<ConcRel, LCSPath> crpaths = new HashMap<ConcRel, LCSPath>();
+			dist = ConcRel.getLeastCommonConcept(cr1, cr2, crlcses, crpaths);
+			lcsPaths.addAll(crpaths.values());
+		}
+		return dist;
+	}
+
 	// /*
 	// * (non-Javadoc)
 	// *
@@ -886,23 +902,6 @@ public class ConceptSimilarityServiceImp
 	// }
 	// }
 
-	public int lcs(String concept1, String concept2, List<LCSPath> lcsPaths) {
-		ConcRel cr1 = cg.getConceptMap().get(concept1);
-		ConcRel cr2 = cg.getConceptMap().get(concept2);
-		int dist = -1;
-		if (cr1 != null && cr2 != null) {
-			Set<ConcRel> crlcses = new HashSet<ConcRel>();
-			Map<ConcRel, LCSPath> crpaths = new HashMap<ConcRel, LCSPath>();
-			dist = ConcRel.getLeastCommonConcept(cr1, cr2, crlcses, crpaths);
-			lcsPaths.addAll(crpaths.values());
-		}
-		return dist;
-	}
-
-	// public double lin(String concept1, String concept2) {
-	// return filteredLin(concept1, concept2, null);
-	// }
-
 	/**
 	 * For the given label and cutoff, get the corresponding concepts whose
 	 * propagated ig meets the threshold. Used by lin kernel to find concepts
@@ -935,6 +934,10 @@ public class ConceptSimilarityServiceImp
 		return minEval;
 	}
 
+	// public double lin(String concept1, String concept2) {
+	// return filteredLin(concept1, concept2, null);
+	// }
+
 	public void setCacheManager(CacheManager cacheManager) {
 		this.cacheManager = cacheManager;
 	}
@@ -960,6 +963,10 @@ public class ConceptSimilarityServiceImp
 		this.corpusName = corpusName;
 	}
 
+	public void setLcsCache(Cache lcsCache) {
+		this.lcsCache = lcsCache;
+	}
+
 	public void setLcsImputedType(String lcsImputedType) {
 		this.lcsImputedType = lcsImputedType;
 	}

Modified: ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java
URL: http://svn.apache.org/viewvc/ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java?rev=1554701&r1=1554700&r2=1554701&view=diff
==============================================================================
--- ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java (original)
+++ ctakes/branches/ytex/ctakes-ytex/src/test/java/org/apache/ctakes/ytex/ConceptDaoTest.java Wed Jan  1 23:39:31 2014
@@ -29,15 +29,15 @@ public class ConceptDaoTest {
 
 	@Before
 	public void setUp() throws Exception {
-		 ClassLoader cl = ClassLoader.getSystemClassLoader();
-		 
-		URL[] urls = ((URLClassLoader)cl).getURLs();
-	 
-	        for(URL url: urls){
-	        	System.out.println(url.getFile());
-	        }		
-		URL is = this.getClass().getClassLoader().getResource("org/apache/ctakes/ytex/kernelBeanRefContext.xml");
-		System.out.println(is);
+//		 ClassLoader cl = ClassLoader.getSystemClassLoader();
+//		 
+//		URL[] urls = ((URLClassLoader)cl).getURLs();
+//	 
+//	        for(URL url: urls){
+//	        	System.out.println(url.getFile());
+//	        }		
+//		URL is = this.getClass().getClassLoader().getResource("org/apache/ctakes/ytex/kernelBeanRefContext.xml");
+//		System.out.println(is);
 		appCtx = (ApplicationContext) ContextSingletonBeanFactoryLocator
 				.getInstance("classpath*:org/apache/ctakes/ytex/kernelBeanRefContext.xml")
 				.useBeanFactory("kernelApplicationContext").getFactory();
@@ -65,7 +65,8 @@ public class ConceptDaoTest {
 				.execute("insert into test_concepts values ('root', 'bacteria')");
 		jdbcTemplate
 				.execute("insert into test_concepts values ('bacteria', 'e coli')");
-		conceptDao.createConceptGraph("test",
+		System.out.println("Create concept graph"); 
+		conceptDao.createConceptGraph(null, "test",
 				"select child, parent from test_concepts", true,
 				Collections.EMPTY_SET);
 		ConceptGraph cg = conceptDao.getConceptGraph("test");



Mime
View raw message