ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1630589 - in /ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2: concept/ dictionary/ util/
Date Thu, 09 Oct 2014 20:30:08 GMT
Author: seanfinan
Date: Thu Oct  9 20:30:08 2014
New Revision: 1630589

URL: http://svn.apache.org/r1630589
Log:
UmlsUserApprover utilization of current ctakes umls cli parameter setting
Checks for umls parameter values moved to UmlsUserApprover
UmlsJdbc** now use improved UmlsUserApprover
DictionaryDescriptorParser logs/throws new error if descriptor fnf

Modified:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/concept/UmlsJdbcConceptFactory.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/DictionaryDescriptorParser.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/UmlsJdbcRareWordDictionary.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/concept/UmlsJdbcConceptFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/concept/UmlsJdbcConceptFactory.java?rev=1630589&r1=1630588&r2=1630589&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/concept/UmlsJdbcConceptFactory.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/concept/UmlsJdbcConceptFactory.java
Thu Oct  9 20:30:08 2014
@@ -18,27 +18,15 @@ final public class UmlsJdbcConceptFactor
 
    static private final Logger LOGGER = Logger.getLogger( "UmlsJdbcConceptFactory" );
 
-   private final static String URL_PARAM = "umlsUrl";
-   private final static String VENDOR_PARAM = "umlsVendor";
-   private final static String USER_PARAM = "umlsUser";
-   private final static String PASS_PARAM = "umlsPass";
-
-
    final private ConceptFactory _delegateConceptFactory;
 
 
    public UmlsJdbcConceptFactory( final String name, final UimaContext uimaContext, final
Properties properties )
          throws SQLException {
-      final String umlsUrl = properties.getProperty( URL_PARAM );
-      final String vendor = properties.getProperty( VENDOR_PARAM );
-      final String user = properties.getProperty( USER_PARAM );
-      final String pass = properties.getProperty( PASS_PARAM );
-      final boolean isValidUser = UmlsUserApprover.isValidUMLSUser( umlsUrl, vendor, user,
pass );
+      final boolean isValidUser = UmlsUserApprover.isValidUMLSUser( uimaContext, properties
);
       if ( !isValidUser ) {
-         LOGGER.error( "UMLS Account at " + umlsUrl + " is not valid for user " + user +
" with " + pass );
          throw new SQLException( "Invalid User for UMLS Concept Factory " + name );
       }
-      LOGGER.info( "UMLS Account at " + umlsUrl + " for user " + user + " has been validated"
);
       _delegateConceptFactory = new JdbcConceptFactory( name, uimaContext, properties );
    }
 

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/DictionaryDescriptorParser.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/DictionaryDescriptorParser.java?rev=1630589&r1=1630588&r2=1630589&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/DictionaryDescriptorParser.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/DictionaryDescriptorParser.java
Thu Oct  9 20:30:08 2014
@@ -99,7 +99,7 @@ final public class DictionaryDescriptorP
    static private final String PROPERTIES_KEY = "properties";
 
    // Added 'maxListSize'.  Size equals max int by default  - used for lucene dictionaries
-   private static int MAX_LIST_SIZE = Integer.MAX_VALUE; //ohnlp-Bugs-3296301
+   final private static int MAX_LIST_SIZE = Integer.MAX_VALUE; //ohnlp-Bugs-3296301
 
    /**
     * Initiates the parsing of the XML descriptor file containing definition of dictionaries
and a consumer for the
@@ -115,6 +115,11 @@ final public class DictionaryDescriptorP
    static public DictionarySpec parseDescriptor( final File descriptorFile, final UimaContext
uimaContext )
          throws AnnotatorContextException {
       LOGGER.info( "Parsing dictionary specifications: " + descriptorFile.getPath() );
+      if ( !descriptorFile.canRead() ) {
+         LOGGER.error( "Missing Dictionary specifications file " + descriptorFile.getPath()
);
+         throw new AnnotatorContextException( "Missing Dictionary specifications file " +
descriptorFile.getPath(),
+               EMPTY_OBJECT_ARRAY );
+      }
       final SAXBuilder saxBuilder = new SAXBuilder();
       Document doc;
       try {

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/UmlsJdbcRareWordDictionary.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/UmlsJdbcRareWordDictionary.java?rev=1630589&r1=1630588&r2=1630589&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/UmlsJdbcRareWordDictionary.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/dictionary/UmlsJdbcRareWordDictionary.java
Thu Oct  9 20:30:08 2014
@@ -19,27 +19,15 @@ final public class UmlsJdbcRareWordDicti
 
    static private final Logger LOGGER = Logger.getLogger( "UmlsJdbcRareWordDictionary" );
 
-   private final static String URL_PARAM = "umlsUrl";
-   private final static String VENDOR_PARAM = "umlsVendor";
-   private final static String USER_PARAM = "umlsUser";
-   private final static String PASS_PARAM = "umlsPass";
-
-
    final private RareWordDictionary _delegateDictionary;
 
 
    public UmlsJdbcRareWordDictionary( final String name, final UimaContext uimaContext, final
Properties properties )
          throws SQLException {
-      final String umlsUrl = properties.getProperty( URL_PARAM );
-      final String vendor = properties.getProperty( VENDOR_PARAM );
-      final String user = properties.getProperty( USER_PARAM );
-      final String pass = properties.getProperty( PASS_PARAM );
-      final boolean isValidUser = UmlsUserApprover.isValidUMLSUser( umlsUrl, vendor, user,
pass );
+      final boolean isValidUser = UmlsUserApprover.isValidUMLSUser( uimaContext, properties
);
       if ( !isValidUser ) {
-         LOGGER.error( "UMLS Account at " + umlsUrl + " is not valid for user " + user +
" with " + pass );
          throw new SQLException( "Invalid User for UMLS dictionary " + name );
       }
-      LOGGER.info( "UMLS Account at " + umlsUrl + " for user " + user + " has been validated"
);
       _delegateDictionary = new JdbcRareWordDictionary( name, uimaContext, properties );
    }
 

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=1630589&r1=1630588&r2=1630589&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
Thu Oct  9 20:30:08 2014
@@ -21,12 +21,12 @@ package org.apache.ctakes.dictionary.loo
 import org.apache.ctakes.utils.env.EnvironmentVariable;
 import org.apache.log4j.Logger;
 import org.apache.uima.UimaContext;
-import org.apache.uima.resource.ResourceInitializationException;
 
 import java.io.*;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.util.Properties;
 
 
 /**
@@ -39,65 +39,79 @@ import java.net.URLEncoder;
  */
 final public class UmlsUserApprover {
 
-
+   // environment, matches old
    private final static String UMLSADDR_PARAM = "ctakes.umlsaddr";
    private final static String UMLSVENDOR_PARAM = "ctakes.umlsvendor";
    private final static String UMLSUSER_PARAM = "ctakes.umlsuser";
    private final static String UMLSPW_PARAM = "ctakes.umlspw";
 
+   // properties, matches new
+   private final static String URL_PARAM = "umlsUrl";
+   private final static String VENDOR_PARAM = "umlsVendor";
+   private final static String USER_PARAM = "umlsUser";
+   private final static String PASS_PARAM = "umlsPass";
+
+
    static final private Logger LOGGER = Logger.getLogger( "UmlsUserApprover" );
 
    private UmlsUserApprover() {
    }
 
    /**
-    * Silently validate the UMLS license / user
+    * validate the UMLS license / user
     *
-    * @param aContext contains information about the UMLS license / user
-    * @throws ResourceInitializationException if the validation does not pass
+    * @param uimaContext contains information about the UMLS license / user
+    * @param properties  -
+    * @return true if the server at umlsaddr approves of the vendor, user, password combination
     */
-   static public void validateUMLSUser( final UimaContext aContext ) throws ResourceInitializationException
{
-      final String umlsAddress = EnvironmentVariable.getEnv( UMLSADDR_PARAM, aContext );
-      final String umlsVendor = EnvironmentVariable.getEnv( UMLSVENDOR_PARAM, aContext );
-      final String umlsUser = EnvironmentVariable.getEnv( UMLSUSER_PARAM, aContext );
-      final String umlsPassword = EnvironmentVariable.getEnv( UMLSPW_PARAM, aContext );
-      LOGGER.info( "Using " + UMLSADDR_PARAM + ": " + umlsAddress + ": " + umlsUser );
-      if ( !isValidUMLSUser( umlsAddress, umlsVendor, umlsUser, umlsPassword ) ) {
-         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 ResourceInitializationException( new Exception( "Failed to initilize.
 Invalid UMLS License" ) );
+   public static boolean isValidUMLSUser( final UimaContext uimaContext, final Properties
properties ) {
+      String umlsUrl = EnvironmentVariable.getEnv( UMLSADDR_PARAM, uimaContext );
+      if ( umlsUrl == null || umlsUrl.equals( EnvironmentVariable.NOT_PRESENT ) ) {
+         umlsUrl = properties.getProperty( URL_PARAM );
+      }
+      String vendor = EnvironmentVariable.getEnv( UMLSVENDOR_PARAM, uimaContext );
+      if ( vendor == null || vendor.equals( EnvironmentVariable.NOT_PRESENT ) ) {
+         vendor = properties.getProperty( VENDOR_PARAM );
       }
+      String user = EnvironmentVariable.getEnv( UMLSUSER_PARAM, uimaContext );
+      if ( user == null || user.equals( EnvironmentVariable.NOT_PRESENT ) ) {
+         user = properties.getProperty( USER_PARAM );
+      }
+      String pass = EnvironmentVariable.getEnv( UMLSPW_PARAM, uimaContext );
+      if ( pass == null || pass.equals( EnvironmentVariable.NOT_PRESENT ) ) {
+         pass = properties.getProperty( PASS_PARAM );
+      }
+      return isValidUMLSUser( umlsUrl, vendor, user, pass );
    }
 
    /**
-    * @param umlsaddr -
-    * @param vendor   -
-    * @param username -
-    * @param password -
+    * validate the UMLS license / user
+    *
+    * @param umlsUrl -
+    * @param vendor  -
+    * @param user    -
+    * @param pass    -
     * @return true if the server at umlsaddr approves of the vendor, user, password combination
     */
-   public static boolean isValidUMLSUser( final String umlsaddr, final String vendor,
-                                          final String username, final String password )
{
+   public static boolean isValidUMLSUser( final String umlsUrl, final String vendor,
+                                          final String user, final String pass ) {
       String data;
       try {
          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" );
+         data += "&" + URLEncoder.encode( "user", "UTF-8" ) + "=" + URLEncoder.encode(
user, "UTF-8" );
+         data += "&" + URLEncoder.encode( "password", "UTF-8" ) + "=" + URLEncoder.encode(
pass, "UTF-8" );
       } catch ( UnsupportedEncodingException unseE ) {
-         LOGGER.error( "Could not encode URL for " + username + " with vendor license " +
vendor );
+         LOGGER.error( "Could not encode URL for " + user + " with vendor license " + vendor
);
          return false;
       }
       try {
-         final URL url = new URL( umlsaddr );
+         final URL url = new URL( umlsUrl );
          final URLConnection connection = url.openConnection();
          connection.setDoOutput( true );
          final OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream()
);
          writer.write( data );
          writer.flush();
-         boolean result = false;
+         boolean isValidUser = false;
          final BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream()
) );
          String line;
          while ( (line = reader.readLine()) != null ) {
@@ -105,11 +119,16 @@ final public class UmlsUserApprover {
             if ( trimline.isEmpty() ) {
                break;
             }
-            result = trimline.equalsIgnoreCase( "<Result>true</Result>" );
+            isValidUser = trimline.equalsIgnoreCase( "<Result>true</Result>"
);
          }
          writer.close();
          reader.close();
-         return result;
+         if ( isValidUser ) {
+            LOGGER.info( "UMLS Account at " + umlsUrl + " for user " + user + " has been
validated" );
+         } else {
+            LOGGER.error( "UMLS Account at " + umlsUrl + " is not valid for user " + user
+ " with " + pass );
+         }
+         return isValidUser;
       } catch ( IOException ioE ) {
          LOGGER.error( ioE.getMessage() );
          return false;



Mime
View raw message