You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by ja...@apache.org on 2012/10/31 06:26:55 UTC

svn commit: r1403989 [23/28] - in /incubator/ctakes/branches/SHARPn-cTAKES: Constituency Parser/src/org/chboston/cnlp/ctakes/parser/ Constituency Parser/src/org/chboston/cnlp/ctakes/parser/uima/ae/ Constituency Parser/src/org/chboston/cnlp/ctakes/parse...

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupParseUtilities.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupParseUtilities.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupParseUtilities.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupParseUtilities.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,8 +14,8 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
+package edu.mayo.bmi.uima.lookup.ae;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
@@ -58,24 +51,24 @@ import edu.mayo.bmi.lookup.algorithms.Lo
 import edu.mayo.bmi.uima.core.resource.FileResource;
 import edu.mayo.bmi.uima.core.resource.JdbcConnectionResource;
 import edu.mayo.bmi.uima.core.resource.LuceneIndexReaderResource;
-
-/**
- * @author Mayo Clinic
- */
-public class LookupParseUtilities
-{
-	//returns a set of LookupSpec objects
-	public static Set parseDescriptor(File descFile, UimaContext aContext, int maxListSize)
-			throws JDOMException, IOException, Exception
-	{
-		SAXBuilder saxBuilder = new SAXBuilder();
-		Document doc = saxBuilder.build(descFile);
-		maxSizeList = maxListSize;	//ohnlp-Bugs-3296301 fixes limit the search results to fixed 100 records.
-		Map dictMap = parseDictionaries(aContext, doc.getRootElement().getChild(
-				"dictionaries"));
-		//ohnlp-Bugs-3296301
-		return parseLookupBindingXml(aContext, dictMap, doc.getRootElement().getChild("lookupBindings"));
-	}
+
+/**
+ * @author Mayo Clinic
+ */
+public class LookupParseUtilities
+{
+	//returns a set of LookupSpec objects
+	public static Set parseDescriptor(File descFile, UimaContext aContext, int maxListSize)
+			throws JDOMException, IOException, Exception
+	{
+		SAXBuilder saxBuilder = new SAXBuilder();
+		Document doc = saxBuilder.build(descFile);
+		maxSizeList = maxListSize;	//ohnlp-Bugs-3296301 fixes limit the search results to fixed 100 records.
+		Map dictMap = parseDictionaries(aContext, doc.getRootElement().getChild(
+				"dictionaries"));
+		//ohnlp-Bugs-3296301
+		return parseLookupBindingXml(aContext, dictMap, doc.getRootElement().getChild("lookupBindings"));
+	}
 
 	public static Set parseDescriptor(File descFile, UimaContext aContext)
 	throws JDOMException, IOException, Exception
@@ -86,142 +79,142 @@ public class LookupParseUtilities
 		"dictionaries"));
 		//ohnlp-Bugs-3296301
 		return parseLookupBindingXml(aContext, dictMap, doc.getRootElement().getChild("lookupBindings"));
-	}
-	private static Map parseDictionaries(UimaContext aContext,
-			Element dictetteersEl) throws AnnotatorContextException, Exception
-	{
-		Map m = new HashMap();
-		Iterator dictItr = dictetteersEl.getChildren().iterator();
-		while (dictItr.hasNext())
-		{
-			Element dictEl = (Element) dictItr.next();
-			String id = dictEl.getAttributeValue("id");
-			DictionaryEngine dictEngine = LookupParseUtilities.parseDictionaryXml(
-					aContext,
-					dictEl);
-			m.put(id, dictEngine);
-		}
-		return m;
-	}
-
-	private static DictionaryEngine parseDictionaryXml(UimaContext annotCtx,
-			Element rootDictEl) throws AnnotatorContextException, Exception
-	{
-		String extResrcKey = rootDictEl.getAttributeValue("externalResourceKey");
-		Boolean keepCase = new Boolean(rootDictEl.getAttributeValue("caseSensitive"));
-		Object extResrc = annotCtx.getResourceObject(extResrcKey);
-		if (extResrc == null)
-		{
-			throw new Exception("Unable to find external resource with key:"
-					+ extResrcKey);
-		}
-
-		Element lookupFieldEl = rootDictEl.getChild("lookupField");
-		String lookupFieldName = lookupFieldEl.getAttributeValue("fieldName");
-
-		Dictionary dict;
-
-		Element implEl = (Element) rootDictEl.getChild("implementation")
-				.getChildren()
-				.get(0);
-		String implType = implEl.getName();
-		if (implType.equals("luceneImpl"))
-		{
-			if (!(extResrc instanceof LuceneIndexReaderResource))
-			{
-				throw new Exception("Expected external resource to be:"
-						+ LuceneIndexReaderResource.class);
-			}
-			IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
+	}
+	private static Map parseDictionaries(UimaContext aContext,
+			Element dictetteersEl) throws AnnotatorContextException, Exception
+	{
+		Map m = new HashMap();
+		Iterator dictItr = dictetteersEl.getChildren().iterator();
+		while (dictItr.hasNext())
+		{
+			Element dictEl = (Element) dictItr.next();
+			String id = dictEl.getAttributeValue("id");
+			DictionaryEngine dictEngine = LookupParseUtilities.parseDictionaryXml(
+					aContext,
+					dictEl);
+			m.put(id, dictEngine);
+		}
+		return m;
+	}
+
+	private static DictionaryEngine parseDictionaryXml(UimaContext annotCtx,
+			Element rootDictEl) throws AnnotatorContextException, Exception
+	{
+		String extResrcKey = rootDictEl.getAttributeValue("externalResourceKey");
+		Boolean keepCase = new Boolean(rootDictEl.getAttributeValue("caseSensitive"));
+		Object extResrc = annotCtx.getResourceObject(extResrcKey);
+		if (extResrc == null)
+		{
+			throw new Exception("Unable to find external resource with key:"
+					+ extResrcKey);
+		}
+
+		Element lookupFieldEl = rootDictEl.getChild("lookupField");
+		String lookupFieldName = lookupFieldEl.getAttributeValue("fieldName");
+
+		Dictionary dict;
+
+		Element implEl = (Element) rootDictEl.getChild("implementation")
+				.getChildren()
+				.get(0);
+		String implType = implEl.getName();
+		if (implType.equals("luceneImpl"))
+		{
+			if (!(extResrc instanceof LuceneIndexReaderResource))
+			{
+				throw new Exception("Expected external resource to be:"
+						+ LuceneIndexReaderResource.class);
+			}
+			IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
 			IndexSearcher indexSearcher = new IndexSearcher(indexReader);
-			// Added 'MaxListSize' ohnlp-Bugs-3296301
-			dict = new LuceneDictionaryImpl(indexSearcher, lookupFieldName, maxSizeList);
-		}
-		else if (implType.equals("jdbcImpl"))
-		{
-			String tableName = implEl.getAttributeValue("tableName");
-			if (!(extResrc instanceof JdbcConnectionResource))
-			{
-				throw new Exception("Expected external resource to be:"
-						+ JdbcConnectionResource.class);
-			}
-			Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
-			dict = new JdbcDictionaryImpl(conn, tableName, lookupFieldName);
-		}
-        else if (implType.equals("csvImpl"))
-        {
-            String fieldDelimiter = implEl.getAttributeValue("delimiter");            
-            if (!(extResrc instanceof FileResource))
-            {
-                throw new Exception("Expected external resource to be:"
-                        + FileResource.class);
-            }
-
-            String idxFieldNameStr = implEl.getAttributeValue("indexedFieldNames");
-            StringTokenizer st = new StringTokenizer(idxFieldNameStr, ",");
-            int arrIdx = 0;
-            String[] idxFieldNameArr = new String[st.countTokens()];
-            while (st.hasMoreTokens())
-            {
-                idxFieldNameArr[arrIdx++] = st.nextToken().trim();
-            }
-            
-            File csvFile = ((FileResource) extResrc).getFile();
-            StringTable strTable = StringTableFactory.build(
-                    new FileReader(csvFile),
-                    fieldDelimiter,
-                    idxFieldNameArr,
-                    true);
-            dict = new StringTableDictionaryImpl(strTable, lookupFieldName);
-        }
-		else
-		{
-			throw new Exception("Unsupported impl type:" + implType);
-		}
-
-		Iterator metaFieldItr = rootDictEl.getChild("metaFields")
-				.getChildren()
-				.iterator();
-		while (metaFieldItr.hasNext())
-		{
-			Element metaFieldEl = (Element) metaFieldItr.next();
-			String metaFieldName = metaFieldEl.getAttributeValue("fieldName");
-			dict.retainMetaData(metaFieldName);
-		}
-
-		DictionaryEngine dictEngine = new DictionaryEngine(dict, keepCase.booleanValue()); 
-
-	    Element excludeList = rootDictEl.getChild("excludeList");
-	    
-	    if (excludeList != null && excludeList.getChildren() != null && excludeList.getChildren().size() > 0) {
-	    	addExcludeList(dictEngine, excludeList.getChildren().iterator());
-	    }
-
-		return dictEngine;
-	}
-
-	
-	/*
-	 * Word(s) not to look up
-	 * TODO Consider adding common words as possible performance improvement
-	 */
-	private static void addExcludeList(DictionaryEngine ge, Iterator itr) {
-
-		HashSet hs = new HashSet();
-	    
-		while(itr.hasNext()) {
-			Element item = (Element) itr.next();
-			String s = (String)item.getAttributeValue("value");
-			System.out.println("Adding exclude value["+s+"]"); // TODO - use logger      
-			hs.add(s);
-	    }
-	    
-	    StringPreLookupFilterImpl plf = new StringPreLookupFilterImpl(hs);
-	    ge.addPreLookupFilter(plf);
-	}
-
-	
-	private static Set parseLookupBindingXml(UimaContext annotCtx,
+			// Added 'MaxListSize' ohnlp-Bugs-3296301
+			dict = new LuceneDictionaryImpl(indexSearcher, lookupFieldName, maxSizeList);
+		}
+		else if (implType.equals("jdbcImpl"))
+		{
+			String tableName = implEl.getAttributeValue("tableName");
+			if (!(extResrc instanceof JdbcConnectionResource))
+			{
+				throw new Exception("Expected external resource to be:"
+						+ JdbcConnectionResource.class);
+			}
+			Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
+			dict = new JdbcDictionaryImpl(conn, tableName, lookupFieldName);
+		}
+        else if (implType.equals("csvImpl"))
+        {
+            String fieldDelimiter = implEl.getAttributeValue("delimiter");            
+            if (!(extResrc instanceof FileResource))
+            {
+                throw new Exception("Expected external resource to be:"
+                        + FileResource.class);
+            }
+
+            String idxFieldNameStr = implEl.getAttributeValue("indexedFieldNames");
+            StringTokenizer st = new StringTokenizer(idxFieldNameStr, ",");
+            int arrIdx = 0;
+            String[] idxFieldNameArr = new String[st.countTokens()];
+            while (st.hasMoreTokens())
+            {
+                idxFieldNameArr[arrIdx++] = st.nextToken().trim();
+            }
+            
+            File csvFile = ((FileResource) extResrc).getFile();
+            StringTable strTable = StringTableFactory.build(
+                    new FileReader(csvFile),
+                    fieldDelimiter,
+                    idxFieldNameArr,
+                    true);
+            dict = new StringTableDictionaryImpl(strTable, lookupFieldName);
+        }
+		else
+		{
+			throw new Exception("Unsupported impl type:" + implType);
+		}
+
+		Iterator metaFieldItr = rootDictEl.getChild("metaFields")
+				.getChildren()
+				.iterator();
+		while (metaFieldItr.hasNext())
+		{
+			Element metaFieldEl = (Element) metaFieldItr.next();
+			String metaFieldName = metaFieldEl.getAttributeValue("fieldName");
+			dict.retainMetaData(metaFieldName);
+		}
+
+		DictionaryEngine dictEngine = new DictionaryEngine(dict, keepCase.booleanValue()); 
+
+	    Element excludeList = rootDictEl.getChild("excludeList");
+	    
+	    if (excludeList != null && excludeList.getChildren() != null && excludeList.getChildren().size() > 0) {
+	    	addExcludeList(dictEngine, excludeList.getChildren().iterator());
+	    }
+
+		return dictEngine;
+	}
+
+	
+	/*
+	 * Word(s) not to look up
+	 * TODO Consider adding common words as possible performance improvement
+	 */
+	private static void addExcludeList(DictionaryEngine ge, Iterator itr) {
+
+		HashSet hs = new HashSet();
+	    
+		while(itr.hasNext()) {
+			Element item = (Element) itr.next();
+			String s = (String)item.getAttributeValue("value");
+			System.out.println("Adding exclude value["+s+"]"); // TODO - use logger      
+			hs.add(s);
+	    }
+	    
+	    StringPreLookupFilterImpl plf = new StringPreLookupFilterImpl(hs);
+	    ge.addPreLookupFilter(plf);
+	}
+
+	
+	private static Set parseLookupBindingXml(UimaContext annotCtx,
 			Map dictMap, Element lookupBindingsEl) throws Exception {
 
 		Set lsSet = new HashSet();
@@ -286,7 +279,7 @@ public class LookupParseUtilities
 	/**
 	 * Get the maximum list size to be returned from a lucene index
 	 * @return maxSizeList
-	 */
+	 */
 	public static int getMaxSizeList () {
 		return maxSizeList;
 	}
@@ -297,21 +290,21 @@ public class LookupParseUtilities
 	public static void setMaxSizeList (int maxListSize) {
 		maxSizeList = maxListSize;
 	}
-	
-	private static Properties parsePropertiesXml(Element propsEl)
-	{
-		Properties props = new Properties();
-		Iterator itr = propsEl.getChildren().iterator();
-		while (itr.hasNext())
-		{
-			Element propEl = (Element) itr.next();
-			String key = propEl.getAttributeValue("key");
-			String value = propEl.getAttributeValue("value");
-			props.put(key, value);
-		}
-		return props;
+	
+	private static Properties parsePropertiesXml(Element propsEl)
+	{
+		Properties props = new Properties();
+		Iterator itr = propsEl.getChildren().iterator();
+		while (itr.hasNext())
+		{
+			Element propEl = (Element) itr.next();
+			String key = propEl.getAttributeValue("key");
+			String value = propEl.getAttributeValue("value");
+			props.put(key, value);
+		}
+		return props;
 	}
 	// Added 'maxListSize'.  Size equals max int by default 
 	private static int  maxSizeList = Integer.MAX_VALUE; //ohnlp-Bugs-3296301
-
-}
\ No newline at end of file
+
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupSpec.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupSpec.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupSpec.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/LookupSpec.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,46 +14,46 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
-import edu.mayo.bmi.lookup.algorithms.LookupAlgorithm;
-
-/**
- * A container for three related classes used to lookup terms in a dictionary and process hits found.
- * <li>a lookup algorithm - a class with a <code>lookup</code> method that returns hits</li>
- * <li>a lookup initializer - a collection of methods used to initialize/control the lookup algorithm</li>
- * <li>a lookup consumer - class which processes hits found by the lookup algorithm,
- * and typically adds annotations to the CAS</li>
- * 
- * @author Mayo Clinic
- */
-public class LookupSpec
-{
-    private LookupAlgorithm iv_lookupAlgorithm;
-    private LookupInitializer iv_lookupInitializer;
-    private LookupConsumer iv_lookupConsumer;
-
-    public LookupSpec(LookupAlgorithm lookupAlgorithm,
-            LookupInitializer lookupInitializer, LookupConsumer lookupConsumer)
-    {
-        iv_lookupAlgorithm = lookupAlgorithm;
-        iv_lookupInitializer = lookupInitializer;
-        iv_lookupConsumer = lookupConsumer;
-    }
-
-    public LookupAlgorithm getLookupAlgorithm()
-    {
-        return iv_lookupAlgorithm;
-    }
-
-    public LookupInitializer getLookupInitializer()
-    {
-        return iv_lookupInitializer;
-    }
-
-    public LookupConsumer getLookupConsumer()
-    {
-        return iv_lookupConsumer;
-    }
-
-}
+package edu.mayo.bmi.uima.lookup.ae;
+
+import edu.mayo.bmi.lookup.algorithms.LookupAlgorithm;
+
+/**
+ * A container for three related classes used to lookup terms in a dictionary and process hits found.
+ * <li>a lookup algorithm - a class with a <code>lookup</code> method that returns hits</li>
+ * <li>a lookup initializer - a collection of methods used to initialize/control the lookup algorithm</li>
+ * <li>a lookup consumer - class which processes hits found by the lookup algorithm,
+ * and typically adds annotations to the CAS</li>
+ * 
+ * @author Mayo Clinic
+ */
+public class LookupSpec
+{
+    private LookupAlgorithm iv_lookupAlgorithm;
+    private LookupInitializer iv_lookupInitializer;
+    private LookupConsumer iv_lookupConsumer;
+
+    public LookupSpec(LookupAlgorithm lookupAlgorithm,
+            LookupInitializer lookupInitializer, LookupConsumer lookupConsumer)
+    {
+        iv_lookupAlgorithm = lookupAlgorithm;
+        iv_lookupInitializer = lookupInitializer;
+        iv_lookupConsumer = lookupConsumer;
+    }
+
+    public LookupAlgorithm getLookupAlgorithm()
+    {
+        return iv_lookupAlgorithm;
+    }
+
+    public LookupInitializer getLookupInitializer()
+    {
+        return iv_lookupInitializer;
+    }
+
+    public LookupConsumer getLookupConsumer()
+    {
+        return iv_lookupConsumer;
+    }
+
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/NamedEntityLookupConsumerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/NamedEntityLookupConsumerImpl.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/NamedEntityLookupConsumerImpl.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/NamedEntityLookupConsumerImpl.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,8 +14,8 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
+package edu.mayo.bmi.uima.lookup.ae;
+
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -42,30 +35,30 @@ import edu.mayo.bmi.uima.core.type.texts
 import edu.mayo.bmi.uima.core.type.textsem.IdentifiedAnnotation;
 import edu.mayo.bmi.uima.core.type.textsem.MedicationEventMention;
 import edu.mayo.bmi.uima.core.type.constants.CONST;
-
-/**
- * @author Mayo Clinic
- */
-public class NamedEntityLookupConsumerImpl extends BaseLookupConsumerImpl
-		implements LookupConsumer
-{
-
-	private final String CODE_MF_PRP_KEY = "codeMetaField";
-
-	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
+
+/**
+ * @author Mayo Clinic
+ */
+public class NamedEntityLookupConsumerImpl extends BaseLookupConsumerImpl
+		implements LookupConsumer
+{
+
+	private final String CODE_MF_PRP_KEY = "codeMetaField";
+
+	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
 
 	private final String TYPE_ID_FIELD = "typeIdField";
-	
+	
 	private Properties iv_props;
 	
-	private static int iv_maxSize;
-
-	public NamedEntityLookupConsumerImpl(UimaContext aCtx, Properties props, int maxListSize)
-	{
-		// TODO property validation could be done here
+	private static int iv_maxSize;
+
+	public NamedEntityLookupConsumerImpl(UimaContext aCtx, Properties props, int maxListSize)
+	{
+		// TODO property validation could be done here
 		iv_props = props;
-		iv_maxSize = maxListSize;
-	}
+		iv_maxSize = maxListSize;
+	}
 	public NamedEntityLookupConsumerImpl(UimaContext aCtx, Properties props)
 	{
 		// TODO property validation could be done here
@@ -94,36 +87,36 @@ public class NamedEntityLookupConsumerIm
 		return codes.size();
 	}
 
-	
-	public void consumeHits(JCas jcas, Iterator lhItr)
-			throws AnalysisEngineProcessException
+	
+	public void consumeHits(JCas jcas, Iterator lhItr)
+			throws AnalysisEngineProcessException
 	{
 
-		String typeId = null;
-		Iterator hitsByOffsetItr = organizeByOffset(lhItr);
-		while (hitsByOffsetItr.hasNext())
-		{
-			Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
+		String typeId = null;
+		Iterator hitsByOffsetItr = organizeByOffset(lhItr);
+		while (hitsByOffsetItr.hasNext())
+		{
+			Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
 
-			
+			
 			FSArray ocArr = new FSArray(jcas, countUniqueCodes(hitsAtOffsetCol));
-			
-			int ocArrIdx = 0;
-
-			// iterate over the LookupHit objects and create
-			// a corresponding JCas OntologyConcept object that will
-			// be placed in a FSArray
-			Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
-			int neBegin = -1;
-			int neEnd = -1;
+			
+			int ocArrIdx = 0;
+
+			// iterate over the LookupHit objects and create
+			// a corresponding JCas OntologyConcept object that will
+			// be placed in a FSArray
+			Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
+			int neBegin = -1;
+			int neEnd = -1;
 			Set<String> codes = new HashSet<String>();
-			while (lhAtOffsetItr.hasNext())
-			{
-				LookupHit lh = (LookupHit) lhAtOffsetItr.next();
-				neBegin = lh.getStartOffset();
-				neEnd = lh.getEndOffset();
-
-				MetaDataHit mdh = lh.getDictMetaDataHit();
+			while (lhAtOffsetItr.hasNext())
+			{
+				LookupHit lh = (LookupHit) lhAtOffsetItr.next();
+				neBegin = lh.getStartOffset();
+				neEnd = lh.getEndOffset();
+
+				MetaDataHit mdh = lh.getDictMetaDataHit();
 
 				String code = mdh.getMetaFieldValue(iv_props.getProperty(CODE_MF_PRP_KEY));
 				if (codes.contains(code)) {
@@ -143,8 +136,8 @@ public class NamedEntityLookupConsumerIm
 
 					codes.add(code);
 
-				}
-			}
+				}
+			}
 
 			int tid=CONST.NE_TYPE_ID_UNKNOWN;
 			if(typeId != null){
@@ -162,14 +155,14 @@ public class NamedEntityLookupConsumerIm
 			} else {
 				neAnnot = new EntityMention(jcas);	
 			
-			}
-			
-			neAnnot.setBegin(neBegin);
-			neAnnot.setEnd(neEnd);
-			neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
+			}
+			
+			neAnnot.setBegin(neBegin);
+			neAnnot.setEnd(neEnd);
+			neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
 			neAnnot.setOntologyConceptArr(ocArr);
 			neAnnot.setTypeID(tid);
-			neAnnot.addToIndexes();			
-		}
+			neAnnot.addToIndexes();			
+		}
 	}
-}
\ No newline at end of file
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/OrangeBookFilterConsumerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/OrangeBookFilterConsumerImpl.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/OrangeBookFilterConsumerImpl.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/OrangeBookFilterConsumerImpl.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,8 +14,8 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
+package edu.mayo.bmi.uima.lookup.ae;
+
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -49,42 +42,42 @@ import edu.mayo.bmi.uima.core.type.texts
 import edu.mayo.bmi.uima.core.type.textsem.IdentifiedAnnotation;
 import edu.mayo.bmi.uima.core.type.textsem.MedicationEventMention;
 import edu.mayo.bmi.uima.core.type.constants.CONST;
-
-/**
- * Implementation that takes Rxnorm dictionary lookup hits and stores only the
- * ones that are also present in the Orange Book.
- * 
- * @author Mayo Clinic
- */
-public class OrangeBookFilterConsumerImpl extends BaseLookupConsumerImpl
-		implements LookupConsumer
-{
-	// LOG4J logger based on class name
-	private Logger iv_logger = Logger.getLogger(getClass().getName());
-
-	private final String CODE_MF_PRP_KEY = "codeMetaField";
-
-	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
-
-	private final String LUCENE_FILTER_RESRC_KEY_PRP_KEY = "luceneFilterExtResrcKey";
-
-	private Properties iv_props;
-
+
+/**
+ * Implementation that takes Rxnorm dictionary lookup hits and stores only the
+ * ones that are also present in the Orange Book.
+ * 
+ * @author Mayo Clinic
+ */
+public class OrangeBookFilterConsumerImpl extends BaseLookupConsumerImpl
+		implements LookupConsumer
+{
+	// LOG4J logger based on class name
+	private Logger iv_logger = Logger.getLogger(getClass().getName());
+
+	private final String CODE_MF_PRP_KEY = "codeMetaField";
+
+	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
+
+	private final String LUCENE_FILTER_RESRC_KEY_PRP_KEY = "luceneFilterExtResrcKey";
+
+	private Properties iv_props;
+
 	private Searcher iv_searcher;
 	//ohnlp-Bugs-3296301 limits the search results to fixed 100 records.
 	// Added 'MaxListSize'
-	private int iv_maxHits;
-
-	public OrangeBookFilterConsumerImpl(UimaContext aCtx, Properties props, int maxListSize)
-			throws Exception
-	{
-		// TODO property validation could be done here
-		iv_props = props;
-		iv_maxHits = maxListSize;
-		String resrcName = iv_props.getProperty(LUCENE_FILTER_RESRC_KEY_PRP_KEY);
-		LuceneIndexReaderResource resrc = (LuceneIndexReaderResource) aCtx.getResourceObject(resrcName);
-		iv_searcher = new IndexSearcher(resrc.getIndexReader());
-	}
+	private int iv_maxHits;
+
+	public OrangeBookFilterConsumerImpl(UimaContext aCtx, Properties props, int maxListSize)
+			throws Exception
+	{
+		// TODO property validation could be done here
+		iv_props = props;
+		iv_maxHits = maxListSize;
+		String resrcName = iv_props.getProperty(LUCENE_FILTER_RESRC_KEY_PRP_KEY);
+		LuceneIndexReaderResource resrc = (LuceneIndexReaderResource) aCtx.getResourceObject(resrcName);
+		iv_searcher = new IndexSearcher(resrc.getIndexReader());
+	}
 	public OrangeBookFilterConsumerImpl(UimaContext aCtx, Properties props)
 	throws Exception
 	{
@@ -94,92 +87,92 @@ public class OrangeBookFilterConsumerImp
 		LuceneIndexReaderResource resrc = (LuceneIndexReaderResource) aCtx.getResourceObject(resrcName);
 		iv_searcher = new IndexSearcher(resrc.getIndexReader());
 		iv_maxHits = Integer.MAX_VALUE;
-	}
-	public void consumeHits(JCas jcas, Iterator lhItr)
-			throws AnalysisEngineProcessException
-	{
-		Iterator hitsByOffsetItr = organizeByOffset(lhItr);
-		while (hitsByOffsetItr.hasNext())
-		{
-			Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
-
-			// iterate over the LookupHit objects
-			// code is only valid if the covered text is also present in the
-			// filter
-			Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
-			int neBegin = -1;
-			int neEnd = -1;
-			Collection validCodeCol = new HashSet();
-			while (lhAtOffsetItr.hasNext())
-			{
-				LookupHit lh = (LookupHit) lhAtOffsetItr.next();
-				neBegin = lh.getStartOffset();
-				neEnd = lh.getEndOffset();
-
-				String text = jcas.getDocumentText().substring(
-						lh.getStartOffset(),
-						lh.getEndOffset());
-				text = text.trim().toLowerCase();
-
-				MetaDataHit mdh = lh.getDictMetaDataHit();
-				String code = mdh.getMetaFieldValue(iv_props.getProperty(CODE_MF_PRP_KEY));
-
-				if (isValid("trade_name", text) || isValid("ingredient", text))
-				{
-					validCodeCol.add(code);
-				}
-				else
-				{
-					iv_logger.warn("Filtered out: "+text);
-				}
-			}
-
-			if (validCodeCol.size() > 0)
-			{
-				FSArray ocArr = createOntologyConceptArr(jcas, validCodeCol);
-				IdentifiedAnnotation neAnnot = new MedicationEventMention(jcas); // medication NEs are EventMention
-				neAnnot.setTypeID(CONST.NE_TYPE_ID_DRUG);
-				neAnnot.setBegin(neBegin);
-				neAnnot.setEnd(neEnd);
-				neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
-				neAnnot.setOntologyConceptArr(ocArr);
-				neAnnot.addToIndexes();
-			}
-		}
-	}
-
-	/**
-	 * For each valid code, a corresponding JCas OntologyConcept object is
-	 * created and stored in a FSArray.
-	 * 
-	 * @param jcas
-	 * @param validCodeCol
-	 * @return
-	 */
-	private FSArray createOntologyConceptArr(JCas jcas, Collection validCodeCol)
-	{
-		FSArray ocArr = new FSArray(jcas, validCodeCol.size());
-		int ocArrIdx = 0;
-		Iterator validCodeItr = validCodeCol.iterator();
-		while (validCodeItr.hasNext())
-		{
-			String validCode = (String) validCodeItr.next();
-			OntologyConcept oc = new OntologyConcept(jcas);
-			oc.setCode(validCode);
-			oc.setCodingScheme(iv_props.getProperty(CODING_SCHEME_PRP_KEY));
-
-			ocArr.set(ocArrIdx, oc);
-			ocArrIdx++;
-		}
-		return ocArr;
-	}
-
-	private boolean isValid(String fieldName, String str)
-			throws AnalysisEngineProcessException
-	{
-		try
-		{
-			Query q = new TermQuery(new Term(fieldName, str));
+	}
+	public void consumeHits(JCas jcas, Iterator lhItr)
+			throws AnalysisEngineProcessException
+	{
+		Iterator hitsByOffsetItr = organizeByOffset(lhItr);
+		while (hitsByOffsetItr.hasNext())
+		{
+			Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
+
+			// iterate over the LookupHit objects
+			// code is only valid if the covered text is also present in the
+			// filter
+			Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
+			int neBegin = -1;
+			int neEnd = -1;
+			Collection validCodeCol = new HashSet();
+			while (lhAtOffsetItr.hasNext())
+			{
+				LookupHit lh = (LookupHit) lhAtOffsetItr.next();
+				neBegin = lh.getStartOffset();
+				neEnd = lh.getEndOffset();
+
+				String text = jcas.getDocumentText().substring(
+						lh.getStartOffset(),
+						lh.getEndOffset());
+				text = text.trim().toLowerCase();
+
+				MetaDataHit mdh = lh.getDictMetaDataHit();
+				String code = mdh.getMetaFieldValue(iv_props.getProperty(CODE_MF_PRP_KEY));
+
+				if (isValid("trade_name", text) || isValid("ingredient", text))
+				{
+					validCodeCol.add(code);
+				}
+				else
+				{
+					iv_logger.warn("Filtered out: "+text);
+				}
+			}
+
+			if (validCodeCol.size() > 0)
+			{
+				FSArray ocArr = createOntologyConceptArr(jcas, validCodeCol);
+				IdentifiedAnnotation neAnnot = new MedicationEventMention(jcas); // medication NEs are EventMention
+				neAnnot.setTypeID(CONST.NE_TYPE_ID_DRUG);
+				neAnnot.setBegin(neBegin);
+				neAnnot.setEnd(neEnd);
+				neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
+				neAnnot.setOntologyConceptArr(ocArr);
+				neAnnot.addToIndexes();
+			}
+		}
+	}
+
+	/**
+	 * For each valid code, a corresponding JCas OntologyConcept object is
+	 * created and stored in a FSArray.
+	 * 
+	 * @param jcas
+	 * @param validCodeCol
+	 * @return
+	 */
+	private FSArray createOntologyConceptArr(JCas jcas, Collection validCodeCol)
+	{
+		FSArray ocArr = new FSArray(jcas, validCodeCol.size());
+		int ocArrIdx = 0;
+		Iterator validCodeItr = validCodeCol.iterator();
+		while (validCodeItr.hasNext())
+		{
+			String validCode = (String) validCodeItr.next();
+			OntologyConcept oc = new OntologyConcept(jcas);
+			oc.setCode(validCode);
+			oc.setCodingScheme(iv_props.getProperty(CODING_SCHEME_PRP_KEY));
+
+			ocArr.set(ocArrIdx, oc);
+			ocArrIdx++;
+		}
+		return ocArr;
+	}
+
+	private boolean isValid(String fieldName, String str)
+			throws AnalysisEngineProcessException
+	{
+		try
+		{
+			Query q = new TermQuery(new Term(fieldName, str));
 
             TopDocs topDoc = iv_searcher.search(q, iv_maxHits);
             ScoreDoc[] hits = topDoc.scoreDocs;
@@ -190,11 +183,11 @@ public class OrangeBookFilterConsumerImp
             else
             {
                 return false;
-            }
-		}
-		catch (Exception e)
-		{
-			throw new AnalysisEngineProcessException(e);
-		}
-	}
-}
\ No newline at end of file
+            }
+		}
+		catch (Exception e)
+		{
+			throw new AnalysisEngineProcessException(e);
+		}
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsDictionaryLookupAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsDictionaryLookupAnnotator.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsDictionaryLookupAnnotator.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsDictionaryLookupAnnotator.java Wed Oct 31 05:26:43 2012
@@ -1,116 +1,109 @@
-/*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0 
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and 
- * limitations under the License. 
- */
-package edu.mayo.bmi.uima.lookup.ae;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-import org.apache.uima.UimaContext;
-import org.apache.uima.resource.ResourceInitializationException;
-
-/**
- * UIMA annotator that identified entities based on lookup.
- * 
- * @author Mayo Clinic
- */
-public class UmlsDictionaryLookupAnnotator extends DictionaryLookupAnnotator
-{
-	/* Special implementation to pre bundle the UMLS SnowmedCT/RxNorm dictionaries
-	 * Performs a check for user's UMLS licence at init time via their RESTful API
-	 * User's will need to configure their UMLS username/password in their config
-	 */
-	private final static String UMLSADDR_PARAM = "UMLSAddr";
-	private final static String UMLSVENDOR_PARAM = "UMLSVendor";
-	private final static String UMLSUSER_PARAM = "UMLSUser";
-	private final static String UMLSPW_PARAM = "UMLSPW";
-	
-	private Logger iv_logger = Logger.getLogger(getClass().getName());
-	private UimaContext iv_context;
-	private Set iv_lookupSpecSet = new HashSet();
-	private String UMLSAddr;
-	private String UMLSVendor;
-	private String UMLSUser;
-	private String UMLSPW;
-
-	public void initialize(UimaContext aContext)
-			throws ResourceInitializationException
-	{
-		super.initialize(aContext);
-		iv_context = aContext;
-
-		try {
-			UMLSAddr = (String) iv_context.getConfigParameterValue(UMLSADDR_PARAM);
-			UMLSVendor = (String) iv_context.getConfigParameterValue(UMLSVENDOR_PARAM);
-			UMLSUser = (String) iv_context.getConfigParameterValue(UMLSUSER_PARAM);
-			UMLSPW = (String) iv_context.getConfigParameterValue(UMLSPW_PARAM);
-			
-			iv_logger.info("Using " + UMLSADDR_PARAM + ":" + UMLSAddr + ":" + UMLSUser);
-			if(!isValidUMLSUser(UMLSAddr, UMLSVendor, UMLSUser, UMLSPW))
-			{
-				iv_logger.error("Error: Invalid UMLS License.  A UMLS License is required to use the UMLS dictionary lookup. \n" +
-						"Error: You may request one at: https://uts.nlm.nih.gov/license.html \n" +
-						"Please verify your UMLS license settings in the DictionaryLookupAnnotatorUMLS.xml configuration.");
-				throw new Exception("Failed to initilize.  Invalid UMLS License");
-			}
-			
-		} catch (Exception e) {
-			throw new ResourceInitializationException(e);
-		}	
-	}
-
-	public static boolean isValidUMLSUser(String umlsaddr, String vendor, String username, String password) throws Exception {
-		String data = URLEncoder.encode("licenseCode", "UTF-8") + "="
-				+ URLEncoder.encode(vendor, "UTF-8");
-		data += "&" + URLEncoder.encode("user", "UTF-8") + "="
-				+ URLEncoder.encode(username, "UTF-8");
-		data += "&" + URLEncoder.encode("password", "UTF-8") + "="
-				+ URLEncoder.encode(password, "UTF-8");
-		URL url = new URL(umlsaddr);
-		URLConnection conn = url.openConnection();
-		conn.setDoOutput(true);
-		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
-		wr.write(data);
-		wr.flush();
-		boolean result = false;
-		BufferedReader rd = new BufferedReader(new InputStreamReader(
-				conn.getInputStream()));
-		String line;
-		while ((line = rd.readLine()) != null) {
-			if(line!=null && line.trim().length()>0)
-			{
-			 result = line.trim().equalsIgnoreCase("<Result>true</Result>");
-			}
-		}
-		wr.close();
-		rd.close();
-		return result;
-	}
-}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ */
+package edu.mayo.bmi.uima.lookup.ae;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.apache.uima.UimaContext;
+import org.apache.uima.resource.ResourceInitializationException;
+
+/**
+ * UIMA annotator that identified entities based on lookup.
+ * 
+ * @author Mayo Clinic
+ */
+public class UmlsDictionaryLookupAnnotator extends DictionaryLookupAnnotator
+{
+	/* Special implementation to pre bundle the UMLS SnowmedCT/RxNorm dictionaries
+	 * Performs a check for user's UMLS licence at init time via their RESTful API
+	 * User's will need to configure their UMLS username/password in their config
+	 */
+	private final static String UMLSADDR_PARAM = "UMLSAddr";
+	private final static String UMLSVENDOR_PARAM = "UMLSVendor";
+	private final static String UMLSUSER_PARAM = "UMLSUser";
+	private final static String UMLSPW_PARAM = "UMLSPW";
+	
+	private Logger iv_logger = Logger.getLogger(getClass().getName());
+	private UimaContext iv_context;
+	private Set iv_lookupSpecSet = new HashSet();
+	private String UMLSAddr;
+	private String UMLSVendor;
+	private String UMLSUser;
+	private String UMLSPW;
+
+	public void initialize(UimaContext aContext)
+			throws ResourceInitializationException
+	{
+		super.initialize(aContext);
+		iv_context = aContext;
+
+		try {
+			UMLSAddr = (String) iv_context.getConfigParameterValue(UMLSADDR_PARAM);
+			UMLSVendor = (String) iv_context.getConfigParameterValue(UMLSVENDOR_PARAM);
+			UMLSUser = (String) iv_context.getConfigParameterValue(UMLSUSER_PARAM);
+			UMLSPW = (String) iv_context.getConfigParameterValue(UMLSPW_PARAM);
+			
+			iv_logger.info("Using " + UMLSADDR_PARAM + ":" + UMLSAddr + ":" + UMLSUser);
+			if(!isValidUMLSUser(UMLSAddr, UMLSVendor, UMLSUser, UMLSPW))
+			{
+				iv_logger.error("Error: Invalid UMLS License.  A UMLS License is required to use the UMLS dictionary lookup. \n" +
+						"Error: You may request one at: https://uts.nlm.nih.gov/license.html \n" +
+						"Please verify your UMLS license settings in the DictionaryLookupAnnotatorUMLS.xml configuration.");
+				throw new Exception("Failed to initilize.  Invalid UMLS License");
+			}
+			
+		} catch (Exception e) {
+			throw new ResourceInitializationException(e);
+		}	
+	}
+
+	public static boolean isValidUMLSUser(String umlsaddr, String vendor, String username, String password) throws Exception {
+		String data = URLEncoder.encode("licenseCode", "UTF-8") + "="
+				+ URLEncoder.encode(vendor, "UTF-8");
+		data += "&" + URLEncoder.encode("user", "UTF-8") + "="
+				+ URLEncoder.encode(username, "UTF-8");
+		data += "&" + URLEncoder.encode("password", "UTF-8") + "="
+				+ URLEncoder.encode(password, "UTF-8");
+		URL url = new URL(umlsaddr);
+		URLConnection conn = url.openConnection();
+		conn.setDoOutput(true);
+		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+		wr.write(data);
+		wr.flush();
+		boolean result = false;
+		BufferedReader rd = new BufferedReader(new InputStreamReader(
+				conn.getInputStream()));
+		String line;
+		while ((line = rd.readLine()) != null) {
+			if(line!=null && line.trim().length()>0)
+			{
+			 result = line.trim().equalsIgnoreCase("<Result>true</Result>");
+			}
+		}
+		wr.close();
+		rd.close();
+		return result;
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedConsumerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedConsumerImpl.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedConsumerImpl.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedConsumerImpl.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,8 +14,8 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
+package edu.mayo.bmi.uima.lookup.ae;
+
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -47,151 +40,151 @@ import edu.mayo.bmi.uima.core.type.texts
 import edu.mayo.bmi.uima.core.type.textsem.MedicationEventMention;
 import edu.mayo.bmi.uima.core.type.textsem.IdentifiedAnnotation;
 import edu.mayo.bmi.uima.core.type.constants.CONST;
-
-/**
- * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
- * objects only the ones that have a SNOMED synonym.
- * Override abstract method <code>getSnomedCodes</code> and implement 
- * looking up the CUI->SNOMED mappings 
- * 
- * @author Mayo Clinic
- */
-public abstract class UmlsToSnomedConsumerImpl extends BaseLookupConsumerImpl implements
-		LookupConsumer
-{
-
-	private final String CUI_MF_PRP_KEY = "cuiMetaField";
-	private final String TUI_MF_PRP_KEY = "tuiMetaField";
-
-	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
-
-	private final String ANT_SITE_TUIS_PRP_KEY = "anatomicalSiteTuis";
-	private final String PROCEDURE_TUIS_PRP_KEY = "procedureTuis";
-	private final String DISORDER_TUIS_PRP_KEY = "disorderTuis";
-	private final String FINDING_TUIS_PRP_KEY = "findingTuis";
-
-	private Set antSiteTuiSet = new HashSet();
-	private Set procedureTuiSet = new HashSet();
-	private Set disorderTuiSet = new HashSet();
-	private Set findingTuiSet = new HashSet();
-	private Set validTuiSet = new HashSet();
-	
-	protected Properties props;
-
-	
-	public UmlsToSnomedConsumerImpl(UimaContext aCtx, Properties properties)
-			throws Exception
-	{
-		// TODO property validation could be done here
-		props = properties;
-
-		antSiteTuiSet = loadList(props.getProperty(ANT_SITE_TUIS_PRP_KEY));
-		procedureTuiSet = loadList(props.getProperty(PROCEDURE_TUIS_PRP_KEY));
-		disorderTuiSet = loadList(props.getProperty(DISORDER_TUIS_PRP_KEY));
-		findingTuiSet = loadList(props.getProperty(FINDING_TUIS_PRP_KEY));
-
-		validTuiSet.addAll(antSiteTuiSet);
-		validTuiSet.addAll(procedureTuiSet);
-		validTuiSet.addAll(disorderTuiSet);
-		validTuiSet.addAll(findingTuiSet);
-	}
-
-	
-	/**
-	 * Searches for the Snomed codes that are synonyms of the UMLS concept with CUI <code>umlsCode</code>
-	 * 
-	 * @param umlsCode
-	 * @return Set of SNOMED codes for the given UMLS CUI.
-	 * @throws SQLException, DictionaryException
-	 */
-	protected abstract Set getSnomedCodes(String umlsCode) throws SQLException, DictionaryException;
-	
-
-	public void consumeHits(JCas jcas, Iterator lhItr)
-			throws AnalysisEngineProcessException
-	{
-		try
-		{
-
-			Iterator hitsByOffsetItr = organizeByOffset(lhItr);
-			while (hitsByOffsetItr.hasNext())
-			{
-				Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
-
-				// Iterate over the LookupHit objects and group Snomed codes by NE type
-				// For each NE type for which there is a hit, get all the Snomed codes
-				// that map to the given CUI.
-
-				// Use key "cui,tui" to avoid duplicates at this offset
-				Set cuiTuiSet = new HashSet();
-
-				// key = type of named entity (java.lang.Integer)
-				// val = set of UmlsConcept objects (java.util.Set)
-				Map conceptMap = new HashMap();
-				
-				Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
-				int neBegin = -1;
-				int neEnd = -1;
-				while (lhAtOffsetItr.hasNext())
-				{
-					LookupHit lh = (LookupHit) lhAtOffsetItr.next();
-					neBegin = lh.getStartOffset();
-					neEnd = lh.getEndOffset();
-
-					MetaDataHit mdh = lh.getDictMetaDataHit();
-					String cui = mdh.getMetaFieldValue(props.getProperty(CUI_MF_PRP_KEY));
-					String tui = mdh.getMetaFieldValue(props.getProperty(TUI_MF_PRP_KEY));
-										
-					//String text = lh.getDictMetaDataHit().getMetaFieldValue("text");
-					if (validTuiSet.contains(tui)) 
-					{
-						String cuiTuiKey = getUniqueKey(cui, tui);
-						if (!cuiTuiSet.contains(cuiTuiKey))
-						{
-							cuiTuiSet.add(cuiTuiKey);
-							Set snomedCodeSet = getSnomedCodes(cui);
-							if (snomedCodeSet.size() > 0)
-							{
-								Integer neType = new Integer(getNamedEntityType(tui));
-								Set conceptSet;
-								if (conceptMap.containsKey(neType)) {
-									conceptSet = (Set) conceptMap.get(neType);
-								}
-								else {
-									conceptSet = new HashSet();
-								}
-
-								Collection conceptCol = createConceptCol(
-										jcas,
-										cui,
-										tui,
-										snomedCodeSet);
-								conceptSet.addAll(conceptCol);
-
-								conceptMap.put(neType, conceptSet);
-							}
-						}
-					}
-				}
-
-				Iterator neTypeItr = conceptMap.keySet().iterator();
-				while (neTypeItr.hasNext())
-				{
-					Integer neType = (Integer) neTypeItr.next();
-					Set conceptSet = (Set) conceptMap.get(neType);
-
-					// Skip updating CAS if all Concepts for this type were filtered out
-					// for this span.
-					if (conceptSet.size() > 0) {
-						FSArray conceptArr = new FSArray(jcas, conceptSet.size());
-						int arrIdx = 0;
-						Iterator conceptItr = conceptSet.iterator();
-						while (conceptItr.hasNext())
-						{
-							UmlsConcept uc = (UmlsConcept) conceptItr.next();
-							conceptArr.set(arrIdx, uc);
-							arrIdx++;
-						}
+
+/**
+ * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
+ * objects only the ones that have a SNOMED synonym.
+ * Override abstract method <code>getSnomedCodes</code> and implement 
+ * looking up the CUI->SNOMED mappings 
+ * 
+ * @author Mayo Clinic
+ */
+public abstract class UmlsToSnomedConsumerImpl extends BaseLookupConsumerImpl implements
+		LookupConsumer
+{
+
+	private final String CUI_MF_PRP_KEY = "cuiMetaField";
+	private final String TUI_MF_PRP_KEY = "tuiMetaField";
+
+	private final String CODING_SCHEME_PRP_KEY = "codingScheme";
+
+	private final String ANT_SITE_TUIS_PRP_KEY = "anatomicalSiteTuis";
+	private final String PROCEDURE_TUIS_PRP_KEY = "procedureTuis";
+	private final String DISORDER_TUIS_PRP_KEY = "disorderTuis";
+	private final String FINDING_TUIS_PRP_KEY = "findingTuis";
+
+	private Set antSiteTuiSet = new HashSet();
+	private Set procedureTuiSet = new HashSet();
+	private Set disorderTuiSet = new HashSet();
+	private Set findingTuiSet = new HashSet();
+	private Set validTuiSet = new HashSet();
+	
+	protected Properties props;
+
+	
+	public UmlsToSnomedConsumerImpl(UimaContext aCtx, Properties properties)
+			throws Exception
+	{
+		// TODO property validation could be done here
+		props = properties;
+
+		antSiteTuiSet = loadList(props.getProperty(ANT_SITE_TUIS_PRP_KEY));
+		procedureTuiSet = loadList(props.getProperty(PROCEDURE_TUIS_PRP_KEY));
+		disorderTuiSet = loadList(props.getProperty(DISORDER_TUIS_PRP_KEY));
+		findingTuiSet = loadList(props.getProperty(FINDING_TUIS_PRP_KEY));
+
+		validTuiSet.addAll(antSiteTuiSet);
+		validTuiSet.addAll(procedureTuiSet);
+		validTuiSet.addAll(disorderTuiSet);
+		validTuiSet.addAll(findingTuiSet);
+	}
+
+	
+	/**
+	 * Searches for the Snomed codes that are synonyms of the UMLS concept with CUI <code>umlsCode</code>
+	 * 
+	 * @param umlsCode
+	 * @return Set of SNOMED codes for the given UMLS CUI.
+	 * @throws SQLException, DictionaryException
+	 */
+	protected abstract Set getSnomedCodes(String umlsCode) throws SQLException, DictionaryException;
+	
+
+	public void consumeHits(JCas jcas, Iterator lhItr)
+			throws AnalysisEngineProcessException
+	{
+		try
+		{
+
+			Iterator hitsByOffsetItr = organizeByOffset(lhItr);
+			while (hitsByOffsetItr.hasNext())
+			{
+				Collection hitsAtOffsetCol = (Collection) hitsByOffsetItr.next();
+
+				// Iterate over the LookupHit objects and group Snomed codes by NE type
+				// For each NE type for which there is a hit, get all the Snomed codes
+				// that map to the given CUI.
+
+				// Use key "cui,tui" to avoid duplicates at this offset
+				Set cuiTuiSet = new HashSet();
+
+				// key = type of named entity (java.lang.Integer)
+				// val = set of UmlsConcept objects (java.util.Set)
+				Map conceptMap = new HashMap();
+				
+				Iterator lhAtOffsetItr = hitsAtOffsetCol.iterator();
+				int neBegin = -1;
+				int neEnd = -1;
+				while (lhAtOffsetItr.hasNext())
+				{
+					LookupHit lh = (LookupHit) lhAtOffsetItr.next();
+					neBegin = lh.getStartOffset();
+					neEnd = lh.getEndOffset();
+
+					MetaDataHit mdh = lh.getDictMetaDataHit();
+					String cui = mdh.getMetaFieldValue(props.getProperty(CUI_MF_PRP_KEY));
+					String tui = mdh.getMetaFieldValue(props.getProperty(TUI_MF_PRP_KEY));
+										
+					//String text = lh.getDictMetaDataHit().getMetaFieldValue("text");
+					if (validTuiSet.contains(tui)) 
+					{
+						String cuiTuiKey = getUniqueKey(cui, tui);
+						if (!cuiTuiSet.contains(cuiTuiKey))
+						{
+							cuiTuiSet.add(cuiTuiKey);
+							Set snomedCodeSet = getSnomedCodes(cui);
+							if (snomedCodeSet.size() > 0)
+							{
+								Integer neType = new Integer(getNamedEntityType(tui));
+								Set conceptSet;
+								if (conceptMap.containsKey(neType)) {
+									conceptSet = (Set) conceptMap.get(neType);
+								}
+								else {
+									conceptSet = new HashSet();
+								}
+
+								Collection conceptCol = createConceptCol(
+										jcas,
+										cui,
+										tui,
+										snomedCodeSet);
+								conceptSet.addAll(conceptCol);
+
+								conceptMap.put(neType, conceptSet);
+							}
+						}
+					}
+				}
+
+				Iterator neTypeItr = conceptMap.keySet().iterator();
+				while (neTypeItr.hasNext())
+				{
+					Integer neType = (Integer) neTypeItr.next();
+					Set conceptSet = (Set) conceptMap.get(neType);
+
+					// Skip updating CAS if all Concepts for this type were filtered out
+					// for this span.
+					if (conceptSet.size() > 0) {
+						FSArray conceptArr = new FSArray(jcas, conceptSet.size());
+						int arrIdx = 0;
+						Iterator conceptItr = conceptSet.iterator();
+						while (conceptItr.hasNext())
+						{
+							UmlsConcept uc = (UmlsConcept) conceptItr.next();
+							conceptArr.set(arrIdx, uc);
+							arrIdx++;
+						}
 
 						IdentifiedAnnotation neAnnot;
 						if (neType.intValue() == CONST.NE_TYPE_ID_DRUG) {
@@ -200,95 +193,95 @@ public abstract class UmlsToSnomedConsum
 							neAnnot = new EntityMention(jcas);	
 						
 						}
-
-						neAnnot.setTypeID(neType.intValue());
-						neAnnot.setBegin(neBegin);
-						neAnnot.setEnd(neEnd);
-						neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
-						neAnnot.setOntologyConceptArr(conceptArr);
-						neAnnot.addToIndexes();
-					}
-					
-				}
-			}
-		}
-		catch (Exception e) {
-			throw new AnalysisEngineProcessException(e);
-		}
-	}
-
-	private int getNamedEntityType(String tui) throws Exception
-	{
-		if (disorderTuiSet.contains(tui)) {
-			return CONST.NE_TYPE_ID_DISORDER;
-		}
-		else if (findingTuiSet.contains(tui)) {
-			return CONST.NE_TYPE_ID_FINDING;
-		}
-		else if (antSiteTuiSet.contains(tui)) {
-			return CONST.NE_TYPE_ID_ANATOMICAL_SITE;
-		}
-		else if (procedureTuiSet.contains(tui)) {
-			return CONST.NE_TYPE_ID_PROCEDURE;
-		}
-		else {
-			throw new Exception("TUI is not part of valid named entity types: "
-					+ tui);
-		}
-	}
-
-	/**
-	 * For each SNOMED code, create a corresponding JCas UmlsConcept object and
-	 * store in a Collection.
-	 * 
-	 * @param jcas
-	 * @param snomedCodesCol
-	 * @return
-	 */
-	private Collection createConceptCol(JCas jcas, String cui, String tui,
-			Collection snomedCodesCol)
-	{
-		List conceptList = new ArrayList();
-		Iterator codeItr = snomedCodesCol.iterator();
-		while (codeItr.hasNext())
-		{
-			String snomedCode = (String) codeItr.next();
-			UmlsConcept uc = new UmlsConcept(jcas);
-			uc.setCode(snomedCode);
-			uc.setCodingScheme(props.getProperty(CODING_SCHEME_PRP_KEY));
-			uc.setCui(cui);
-			uc.setTui(tui);
-			conceptList.add(uc);
-		}
-		return conceptList;
-	}
-
-	private String getUniqueKey(String cui, String tui)
-	{
-		StringBuffer sb = new StringBuffer();
-		sb.append(cui);
-		sb.append(':');
-		sb.append(tui);
-		return sb.toString();
-	}
-
-	/**
-	 * Load a comma delimited list
-	 * @param delimitedString
-	 * @return
-	 */
-	private Set loadList(String delimitedString)
-	{
-		String[] stringArr = delimitedString.split(",");
-		Set stringSet = new HashSet();
-		for (int i = 0; i < stringArr.length; i++)
-		{
-			String s = stringArr[i].trim();
-			if (s.length() > 0)
-			{
-				stringSet.add(s);
-			}
-		}
-		return stringSet;
-	}
-}
\ No newline at end of file
+
+						neAnnot.setTypeID(neType.intValue());
+						neAnnot.setBegin(neBegin);
+						neAnnot.setEnd(neEnd);
+						neAnnot.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_DICT_LOOKUP);
+						neAnnot.setOntologyConceptArr(conceptArr);
+						neAnnot.addToIndexes();
+					}
+					
+				}
+			}
+		}
+		catch (Exception e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+	}
+
+	private int getNamedEntityType(String tui) throws Exception
+	{
+		if (disorderTuiSet.contains(tui)) {
+			return CONST.NE_TYPE_ID_DISORDER;
+		}
+		else if (findingTuiSet.contains(tui)) {
+			return CONST.NE_TYPE_ID_FINDING;
+		}
+		else if (antSiteTuiSet.contains(tui)) {
+			return CONST.NE_TYPE_ID_ANATOMICAL_SITE;
+		}
+		else if (procedureTuiSet.contains(tui)) {
+			return CONST.NE_TYPE_ID_PROCEDURE;
+		}
+		else {
+			throw new Exception("TUI is not part of valid named entity types: "
+					+ tui);
+		}
+	}
+
+	/**
+	 * For each SNOMED code, create a corresponding JCas UmlsConcept object and
+	 * store in a Collection.
+	 * 
+	 * @param jcas
+	 * @param snomedCodesCol
+	 * @return
+	 */
+	private Collection createConceptCol(JCas jcas, String cui, String tui,
+			Collection snomedCodesCol)
+	{
+		List conceptList = new ArrayList();
+		Iterator codeItr = snomedCodesCol.iterator();
+		while (codeItr.hasNext())
+		{
+			String snomedCode = (String) codeItr.next();
+			UmlsConcept uc = new UmlsConcept(jcas);
+			uc.setCode(snomedCode);
+			uc.setCodingScheme(props.getProperty(CODING_SCHEME_PRP_KEY));
+			uc.setCui(cui);
+			uc.setTui(tui);
+			conceptList.add(uc);
+		}
+		return conceptList;
+	}
+
+	private String getUniqueKey(String cui, String tui)
+	{
+		StringBuffer sb = new StringBuffer();
+		sb.append(cui);
+		sb.append(':');
+		sb.append(tui);
+		return sb.toString();
+	}
+
+	/**
+	 * Load a comma delimited list
+	 * @param delimitedString
+	 * @return
+	 */
+	private Set loadList(String delimitedString)
+	{
+		String[] stringArr = delimitedString.split(",");
+		Set stringSet = new HashSet();
+		for (int i = 0; i < stringArr.length; i++)
+		{
+			String s = stringArr[i].trim();
+			if (s.length() > 0)
+			{
+				stringSet.add(s);
+			}
+		}
+		return stringSet;
+	}
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedDbConsumerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedDbConsumerImpl.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedDbConsumerImpl.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedDbConsumerImpl.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,8 +14,8 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
+package edu.mayo.bmi.uima.lookup.ae;
+
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -34,38 +27,38 @@ import java.util.Set;
 import org.apache.uima.UimaContext;
  
 import edu.mayo.bmi.uima.core.resource.JdbcConnectionResource;
-
-/**
- * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
- * objects only the ones that have a SNOMED synonym, by looking in a database 
- * for SNOMED codes that map to the identified CUI.
- * 
- * @author Mayo Clinic
- */
-public class UmlsToSnomedDbConsumerImpl extends UmlsToSnomedConsumerImpl implements
-		LookupConsumer
-{
-	
-	private final String DB_CONN_RESRC_KEY_PRP_KEY = "dbConnExtResrcKey";
-	private final String MAP_PREP_STMT_PRP_KEY = "mapPrepStmt";
+
+/**
+ * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
+ * objects only the ones that have a SNOMED synonym, by looking in a database 
+ * for SNOMED codes that map to the identified CUI.
+ * 
+ * @author Mayo Clinic
+ */
+public class UmlsToSnomedDbConsumerImpl extends UmlsToSnomedConsumerImpl implements
+		LookupConsumer
+{
+	
+	private final String DB_CONN_RESRC_KEY_PRP_KEY = "dbConnExtResrcKey";
+	private final String MAP_PREP_STMT_PRP_KEY = "mapPrepStmt";
 	//ohnlp-Bugs-3296301 fix limited search results to fixed 100 records.
 	// Added 'MaxListSize'
-	private static int iv_maxListSize;
-	private PreparedStatement mapPrepStmt;
-
-	public UmlsToSnomedDbConsumerImpl(UimaContext aCtx, Properties properties, int maxListSize)
-			throws Exception
-	{
-		super(aCtx, properties);
-		iv_maxListSize = maxListSize;
-		String resrcName = props.getProperty(DB_CONN_RESRC_KEY_PRP_KEY);
-		JdbcConnectionResource resrc = (JdbcConnectionResource) aCtx.getResourceObject(resrcName);
-
-		String prepStmtSql = props.getProperty(MAP_PREP_STMT_PRP_KEY);
-		Connection conn = resrc.getConnection();
-		mapPrepStmt = conn.prepareStatement(prepStmtSql);
-
-	}
+	private static int iv_maxListSize;
+	private PreparedStatement mapPrepStmt;
+
+	public UmlsToSnomedDbConsumerImpl(UimaContext aCtx, Properties properties, int maxListSize)
+			throws Exception
+	{
+		super(aCtx, properties);
+		iv_maxListSize = maxListSize;
+		String resrcName = props.getProperty(DB_CONN_RESRC_KEY_PRP_KEY);
+		JdbcConnectionResource resrc = (JdbcConnectionResource) aCtx.getResourceObject(resrcName);
+
+		String prepStmtSql = props.getProperty(MAP_PREP_STMT_PRP_KEY);
+		Connection conn = resrc.getConnection();
+		mapPrepStmt = conn.prepareStatement(prepStmtSql);
+
+	}
 
 
 	public UmlsToSnomedDbConsumerImpl(UimaContext aCtx, Properties properties)
@@ -79,28 +72,28 @@ public class UmlsToSnomedDbConsumerImpl 
 		Connection conn = resrc.getConnection();
 		mapPrepStmt = conn.prepareStatement(prepStmtSql);
 
-	}
-
-	/**
-	 * Queries the given UMLS CUI against the DB. Returns a set of SNOMED codes.
-	 * 
-	 * @param umlsCode
-	 * @return
-	 * @throws SQLException
-	 */
-	protected Set getSnomedCodes(String umlsCode) throws SQLException
-	{
-		Set codeSet = new HashSet();
-		mapPrepStmt.setString(1, umlsCode);
-		ResultSet rs = mapPrepStmt.executeQuery();
-		while (rs.next())
-		{
-			String snomedCode = rs.getString(1).trim();
-			codeSet.add(snomedCode);
-		}
-		
-		return codeSet;
-
-	}
-
-}
\ No newline at end of file
+	}
+
+	/**
+	 * Queries the given UMLS CUI against the DB. Returns a set of SNOMED codes.
+	 * 
+	 * @param umlsCode
+	 * @return
+	 * @throws SQLException
+	 */
+	protected Set getSnomedCodes(String umlsCode) throws SQLException
+	{
+		Set codeSet = new HashSet();
+		mapPrepStmt.setString(1, umlsCode);
+		ResultSet rs = mapPrepStmt.executeQuery();
+		while (rs.next())
+		{
+			String snomedCode = rs.getString(1).trim();
+			codeSet.add(snomedCode);
+		}
+		
+		return codeSet;
+
+	}
+
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedLuceneConsumerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/dictionary%20lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedLuceneConsumerImpl.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedLuceneConsumerImpl.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/dictionary lookup/src/edu/mayo/bmi/uima/lookup/ae/UmlsToSnomedLuceneConsumerImpl.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,9 +14,9 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.uima.lookup.ae;
-
-
+package edu.mayo.bmi.uima.lookup.ae;
+
+
 import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
@@ -42,28 +35,28 @@ import edu.mayo.bmi.dictionary.Dictionar
 import edu.mayo.bmi.dictionary.MetaDataHit;
 import edu.mayo.bmi.dictionary.lucene.LuceneDictionaryImpl;
 import edu.mayo.bmi.uima.core.resource.FileResource;
-
-/**
- * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
- * objects only the ones that have a SNOMED synonym, by looking in a lucene index 
- * for SNOMED codes that map to the identified CUI.
- * 
- * @author Mayo Clinic
- */
-public class UmlsToSnomedLuceneConsumerImpl extends UmlsToSnomedConsumerImpl implements
-		LookupConsumer
-{
-
-	// LOG4J logger based on class name
-	private Logger logger = Logger.getLogger(getClass().getName());
-
+
+/**
+ * Implementation that takes UMLS dictionary lookup hits and stores as NamedEntity 
+ * objects only the ones that have a SNOMED synonym, by looking in a lucene index 
+ * for SNOMED codes that map to the identified CUI.
+ * 
+ * @author Mayo Clinic
+ */
+public class UmlsToSnomedLuceneConsumerImpl extends UmlsToSnomedConsumerImpl implements
+		LookupConsumer
+{
+
+	// LOG4J logger based on class name
+	private Logger logger = Logger.getLogger(getClass().getName());
+
 	//ohnlp-Bugs-3296301 limits the search results to fixed 100 records.
 	// Added 'MaxListSize'
-	private static int iv_maxListSize;
-	private final String SNOMED_MAPPING_PRP_KEY = "snomedCodeMappingField";
+	private static int iv_maxListSize;
+	private final String SNOMED_MAPPING_PRP_KEY = "snomedCodeMappingField";
 	private final String CUI_MAPPING_PRP_KEY = "cuiMappingField";
-	private final String SNOMED_CODE_LIST_CONFIG_PARM = "CodesListIndexDirectory";
-	
+	private final String SNOMED_CODE_LIST_CONFIG_PARM = "CodesListIndexDirectory";
+	
 	private LuceneDictionaryImpl snomedLikeCodesIndex;
 
 	public UmlsToSnomedLuceneConsumerImpl(UimaContext aCtx, Properties properties)
@@ -73,12 +66,12 @@ public class UmlsToSnomedLuceneConsumerI
 	}
 
 	// ohnlp Bugs tracker ID: 3390078 do not reload lucene index for each document, load in constructor
-	public UmlsToSnomedLuceneConsumerImpl(UimaContext aCtx, Properties properties, int maxListSize)
-			throws Exception
-	{
+	public UmlsToSnomedLuceneConsumerImpl(UimaContext aCtx, Properties properties, int maxListSize)
+			throws Exception
+	{
 		super(aCtx,properties);
-		iv_maxListSize = maxListSize;
-		
+		iv_maxListSize = maxListSize;
+		
 		IndexReader indexReader;
 		String indexDirAbsPath = null;
 		try {
@@ -117,30 +110,30 @@ public class UmlsToSnomedLuceneConsumerI
 		}
 
 	}
-
-
-	/**
-	 * Find all Snomed codes that map to the given UMLS code (CUI),
-	 * by looking in a lucene index
-	 * 
-	 * @param umlsCode a UMLS CUI
-	 * @return Set of Snomed codes that map to the given UMLS code (CUI).
-	 * @see getSnomedCodes in <code>UmlsToSnomedConsumerImpl</code> for example of using a database
-	 */
-	protected Set getSnomedCodes(String umlsCode) throws DictionaryException
-	{
-		Set codeSet = new HashSet();
-		
+
+
+	/**
+	 * Find all Snomed codes that map to the given UMLS code (CUI),
+	 * by looking in a lucene index
+	 * 
+	 * @param umlsCode a UMLS CUI
+	 * @return Set of Snomed codes that map to the given UMLS code (CUI).
+	 * @see getSnomedCodes in <code>UmlsToSnomedConsumerImpl</code> for example of using a database
+	 */
+	protected Set getSnomedCodes(String umlsCode) throws DictionaryException
+	{
+		Set codeSet = new HashSet();
+		
 		String valueFieldName = props.getProperty(SNOMED_MAPPING_PRP_KEY);
-		// Get the entries with field lookupFieldName having value umlsCode
-		Collection<MetaDataHit> mdhCollection = snomedLikeCodesIndex.getEntries(umlsCode);
-	        
-		for (MetaDataHit mdh: mdhCollection) {
-		    codeSet.add(mdh.getMetaFieldValue(valueFieldName));
-		}
-		
-		return codeSet;
-
-	}
-
-}
\ No newline at end of file
+		// Get the entries with field lookupFieldName having value umlsCode
+		Collection<MetaDataHit> mdhCollection = snomedLikeCodesIndex.getEntries(umlsCode);
+	        
+		for (MetaDataHit mdh: mdhCollection) {
+		    codeSet.add(mdh.getMetaFieldValue(valueFieldName));
+		}
+		
+		return codeSet;
+
+	}
+
+}

Modified: incubator/ctakes/branches/SHARPn-cTAKES/document preprocessor/src/edu/mayo/bmi/nlp/preprocessor/Annotation.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/document%20preprocessor/src/edu/mayo/bmi/nlp/preprocessor/Annotation.java?rev=1403989&r1=1403988&r2=1403989&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/document preprocessor/src/edu/mayo/bmi/nlp/preprocessor/Annotation.java (original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/document preprocessor/src/edu/mayo/bmi/nlp/preprocessor/Annotation.java Wed Oct 31 05:26:43 2012
@@ -1,18 +1,11 @@
 /*
- * Copyright: (c) 2009   Mayo Foundation for Medical Education and 
- * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
- * triple-shield Mayo logo are trademarks and service marks of MFMER.
- *
- * Except as contained in the copyright notice above, or as used to identify 
- * MFMER as the author of this software, the trade names, trademarks, service
- * marks, or product names of the copyright holder shall not be used in
- * advertising, promotion or otherwise in connection with this software without
- * prior written authorization of the copyright holder.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0 
  * 
  * Unless required by applicable law or agreed to in writing, software
@@ -21,15 +14,15 @@
  * See the License for the specific language governing permissions and 
  * limitations under the License. 
  */
-package edu.mayo.bmi.nlp.preprocessor;
-
-/**
- *
- * @author Mayo Clinic
- */
-public class Annotation
-{
-	public String iv_type;
-	public int startOffset;
-	public int endOffset;
-}
+package edu.mayo.bmi.nlp.preprocessor;
+
+/**
+ *
+ * @author Mayo Clinic
+ */
+public class Annotation
+{
+	public String iv_type;
+	public int startOffset;
+	public int endOffset;
+}