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

svn commit: r1678940 - in /ctakes/trunk: ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/ ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/

Author: seanfinan
Date: Tue May 12 13:22:08 2015
New Revision: 1678940

URL: http://svn.apache.org/r1678940
Log:
CTAKES-359 : added additional check for <Result>true</Result> preceded by xml declaration

Modified:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java
    ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/ThreadedUmlsDictionaryLookupAnnotator.java
    ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/UmlsDictionaryLookupAnnotator.java

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java?rev=1678940&r1=1678939&r2=1678940&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java Tue May 12 13:22:08 2015
@@ -104,8 +104,8 @@ public enum UmlsUserApprover {
     * @return true if the server at umlsaddr approves of the vendor, user, password combination
     */
    public boolean isValidUMLSUser( final String umlsUrl, final String vendor,
-                                          final String user, final String pass ) {
-      final String cacheCode = umlsUrl+vendor+user+pass;
+                                   final String user, final String pass ) {
+      final String cacheCode = umlsUrl + vendor + user + pass;
       if ( _validUsers.contains( cacheCode ) ) {
          return true;
       }
@@ -136,7 +136,8 @@ public enum UmlsUserApprover {
             if ( trimline.isEmpty() ) {
                break;
             }
-            isValidUser = trimline.equalsIgnoreCase( "<Result>true</Result>" );
+            isValidUser = trimline.equalsIgnoreCase( "<Result>true</Result>" )
+                          || trimline.equalsIgnoreCase( "<?xml version='1.0' encoding='UTF-8'?><Result>true</Result>" );
          }
          writer.close();
          reader.close();

Modified: ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/ThreadedUmlsDictionaryLookupAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/ThreadedUmlsDictionaryLookupAnnotator.java?rev=1678940&r1=1678939&r2=1678940&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/ThreadedUmlsDictionaryLookupAnnotator.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/ThreadedUmlsDictionaryLookupAnnotator.java Tue May 12 13:22:08 2015
@@ -47,7 +47,7 @@ public class ThreadedUmlsDictionaryLooku
 
 
    @Override
-  public void initialize( final UimaContext aContext ) throws ResourceInitializationException {
+   public void initialize( final UimaContext aContext ) throws ResourceInitializationException {
       super.initialize( aContext );
       final String umlsAddress = EnvironmentVariable.getEnv( UMLSADDR_PARAM, aContext );
       final String umlsVendor = EnvironmentVariable.getEnv( UMLSVENDOR_PARAM, aContext );
@@ -79,22 +79,24 @@ public class ThreadedUmlsDictionaryLooku
          final URL url = new URL( umlsaddr );
          final URLConnection connection = url.openConnection();
          connection.setDoOutput( true );
-         try(final OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() );
-             final BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream() ) )){
-         
-           writer.write( data );
-           writer.flush();
-           boolean result = false;
+         try ( final OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() );
+               final BufferedReader reader = new BufferedReader( new InputStreamReader( connection
+                     .getInputStream() ) ) ) {
 
-           String line;
-           while ( (line = reader.readLine()) != null ) {
-             final String trimline = line.trim();
-             if ( trimline.isEmpty() ) {
-               break;
-             }
-             result = trimline.equalsIgnoreCase( "<Result>true</Result>" );
-           }
-           return result;
+            writer.write( data );
+            writer.flush();
+            boolean result = false;
+
+            String line;
+            while ( (line = reader.readLine()) != null ) {
+               final String trimline = line.trim();
+               if ( trimline.isEmpty() ) {
+                  break;
+               }
+               result = trimline.equalsIgnoreCase( "<Result>true</Result>" )
+                        || trimline.equalsIgnoreCase( "<?xml version='1.0' encoding='UTF-8'?><Result>true</Result>" );
+            }
+            return result;
          }
       } catch ( IOException ioE ) {
          LOGGER.error( ioE.getMessage() );

Modified: ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/UmlsDictionaryLookupAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/UmlsDictionaryLookupAnnotator.java?rev=1678940&r1=1678939&r2=1678940&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/UmlsDictionaryLookupAnnotator.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup/src/main/java/org/apache/ctakes/dictionary/lookup/ae/UmlsDictionaryLookupAnnotator.java Tue May 12 13:22:08 2015
@@ -18,14 +18,6 @@
  */
 package org.apache.ctakes.dictionary.lookup.ae;
 
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.ctakes.core.resource.FileResourceImpl;
 import org.apache.ctakes.core.resource.JdbcConnectionResourceImpl;
@@ -33,128 +25,136 @@ import org.apache.ctakes.utils.env.Envir
 import org.apache.log4j.Logger;
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
-import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.fit.factory.ExternalResourceFactory;
+import org.apache.uima.resource.ResourceInitializationException;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
 
 /**
  * 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
-	 */
-	public final static String UMLSADDR_PARAM = "ctakes.umlsaddr";
-	public final static String UMLSVENDOR_PARAM = "ctakes.umlsvendor";
-	public final static String UMLSUSER_PARAM = "ctakes.umlsuser";
-	public final static String UMLSPW_PARAM = "ctakes.umlspw";
-	
-	private Logger iv_logger = Logger.getLogger(getClass().getName());
-
-	private String UMLSAddr;
-	private String UMLSVendor;
-	private String UMLSUser;
-	private String UMLSPW;
-
-	@Override
-  public void initialize(UimaContext aContext)
-			throws ResourceInitializationException
-	{
-		super.initialize(aContext);
-
-		try {
-			UMLSAddr = EnvironmentVariable.getEnv(UMLSADDR_PARAM, aContext);
-			UMLSVendor = EnvironmentVariable.getEnv(UMLSVENDOR_PARAM, aContext);
-			UMLSUser = EnvironmentVariable.getEnv(UMLSUSER_PARAM, aContext);
-			UMLSPW = EnvironmentVariable.getEnv(UMLSPW_PARAM, aContext);
-			
-			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);
-		try(OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream())){
-      wr.write(data);
-      wr.flush();
-		}
-		try(BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()))){
-		  boolean result = false;
-		  String line;
-		  while ((line = rd.readLine()) != null) {
-		    if(line.trim().length()>0)
-		    {
-		      result = line.trim().equalsIgnoreCase("<Result>true</Result>");
-		    }
-		  }
-		  return result;
-		}
-	}
-	
-	public static AnalysisEngineDescription createAnnotatorDescription() throws ResourceInitializationException{
-	  try {
-      return AnalysisEngineFactory.createEngineDescription(UmlsDictionaryLookupAnnotator.class,
-          UMLSADDR_PARAM,
-          "https://uts-ws.nlm.nih.gov/restful/isValidUMLSUser",
-          UMLSVENDOR_PARAM,
-          "NLM-6515182895",
-          "LookupDescriptor",
-          ExternalResourceFactory.createExternalResourceDescription(
-              FileResourceImpl.class,
-              FileLocator.locateFile("org/apache/ctakes/dictionary/lookup/LookupDesc_Db.xml")),
-          "DbConnection",
-          ExternalResourceFactory.createExternalResourceDescription(
-              JdbcConnectionResourceImpl.class,
-              "",
-              JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
-              "org.hsqldb.jdbcDriver",
-              JdbcConnectionResourceImpl.PARAM_URL,
-              // Should be the following but it's WAY too slow
-               "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/umls2011ab/umls"),
-              //"jdbc:hsqldb:file:target/unpacked/org/apache/ctakes/dictionary/lookup/umls2011ab/umls"),
-          "RxnormIndexReader",
-          ExternalResourceFactory.createExternalResourceDescription(
-              JdbcConnectionResourceImpl.class,
-              "",
-              JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
-              "org.hsqldb.jdbcDriver",
-              JdbcConnectionResourceImpl.PARAM_URL,
-              "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/rxnorm-hsqldb/umls"),
-          "OrangeBookIndexReader",
-          ExternalResourceFactory.createExternalResourceDescription(
-              JdbcConnectionResourceImpl.class,
-              "",
-              JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
-              "org.hsqldb.jdbcDriver",
-              JdbcConnectionResourceImpl.PARAM_URL,
-              "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/orange_book_hsqldb/umls")
-              );
-    } catch (FileNotFoundException e) {
-      e.printStackTrace();
-      throw new ResourceInitializationException(e);
-    }
-            
-	}
+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
+    */
+   public final static String UMLSADDR_PARAM = "ctakes.umlsaddr";
+   public final static String UMLSVENDOR_PARAM = "ctakes.umlsvendor";
+   public final static String UMLSUSER_PARAM = "ctakes.umlsuser";
+   public final static String UMLSPW_PARAM = "ctakes.umlspw";
+
+   private Logger iv_logger = Logger.getLogger( getClass().getName() );
+
+   private String UMLSAddr;
+   private String UMLSVendor;
+   private String UMLSUser;
+   private String UMLSPW;
+
+   @Override
+   public void initialize( UimaContext aContext )
+         throws ResourceInitializationException {
+      super.initialize( aContext );
+
+      try {
+         UMLSAddr = EnvironmentVariable.getEnv( UMLSADDR_PARAM, aContext );
+         UMLSVendor = EnvironmentVariable.getEnv( UMLSVENDOR_PARAM, aContext );
+         UMLSUser = EnvironmentVariable.getEnv( UMLSUSER_PARAM, aContext );
+         UMLSPW = EnvironmentVariable.getEnv( UMLSPW_PARAM, aContext );
+
+         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 );
+      try ( OutputStreamWriter wr = new OutputStreamWriter( conn.getOutputStream() ) ) {
+         wr.write( data );
+         wr.flush();
+      }
+      try ( BufferedReader rd = new BufferedReader( new InputStreamReader( conn.getInputStream() ) ) ) {
+         boolean result = false;
+         String line;
+         while ( (line = rd.readLine()) != null ) {
+            if ( line.trim().length() > 0 ) {
+               result = line.trim().equalsIgnoreCase( "<Result>true</Result>" )
+                        ||
+                        line.trim().equalsIgnoreCase( "<?xml version='1.0' encoding='UTF-8'?><Result>true</Result>" );
+            }
+         }
+         return result;
+      }
+   }
+
+   public static AnalysisEngineDescription createAnnotatorDescription() throws ResourceInitializationException {
+      try {
+         return AnalysisEngineFactory.createEngineDescription( UmlsDictionaryLookupAnnotator.class,
+               UMLSADDR_PARAM,
+               "https://uts-ws.nlm.nih.gov/restful/isValidUMLSUser",
+               UMLSVENDOR_PARAM,
+               "NLM-6515182895",
+               "LookupDescriptor",
+               ExternalResourceFactory.createExternalResourceDescription(
+                     FileResourceImpl.class,
+                     FileLocator.locateFile( "org/apache/ctakes/dictionary/lookup/LookupDesc_Db.xml" ) ),
+               "DbConnection",
+               ExternalResourceFactory.createExternalResourceDescription(
+                     JdbcConnectionResourceImpl.class,
+                     "",
+                     JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
+                     "org.hsqldb.jdbcDriver",
+                     JdbcConnectionResourceImpl.PARAM_URL,
+                     // Should be the following but it's WAY too slow
+                     "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/umls2011ab/umls" ),
+               //"jdbc:hsqldb:file:target/unpacked/org/apache/ctakes/dictionary/lookup/umls2011ab/umls"),
+               "RxnormIndexReader",
+               ExternalResourceFactory.createExternalResourceDescription(
+                     JdbcConnectionResourceImpl.class,
+                     "",
+                     JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
+                     "org.hsqldb.jdbcDriver",
+                     JdbcConnectionResourceImpl.PARAM_URL,
+                     "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/rxnorm-hsqldb/umls" ),
+               "OrangeBookIndexReader",
+               ExternalResourceFactory.createExternalResourceDescription(
+                     JdbcConnectionResourceImpl.class,
+                     "",
+                     JdbcConnectionResourceImpl.PARAM_DRIVER_CLASS,
+                     "org.hsqldb.jdbcDriver",
+                     JdbcConnectionResourceImpl.PARAM_URL,
+                     "jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/orange_book_hsqldb/umls" )
+         );
+      } catch ( FileNotFoundException e ) {
+         e.printStackTrace();
+         throw new ResourceInitializationException( e );
+      }
+
+   }
 }