Author: seanfinan
Date: Tue Nov 17 16:35:10 2020
New Revision: 1883545
URL: http://svn.apache.org/viewvc?rev=1883545&view=rev
Log:
PipelineBuilder add run( jcas )
UmlsUserApprover point to new DotLogger package
Modified:
ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java
ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/UmlsUserApprover.java
Modified:
ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java
URL:
http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java?rev=1883545&r1=1883544&r2=1883545&view=diff
==============================================================================
---
ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java
(original)
+++
ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java
Tue Nov 17 16:35:10 2020
@@ -433,8 +433,26 @@ final public class PipelineBuilder {
}
final JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText( text );
+ return run( jcas );
+ }
+
+ /**
+ * Run the pipeline on the given jcas.
+ * Use of this method is order-specific.
+ * This method will call {@link #build()} if the pipeline has not already
been initialized.
+ *
+ * @param jCas ye olde ...
+ * @return this PipelineBuilder
+ * @throws IOException if the pipeline could not be run
+ * @throws UIMAException if the pipeline could not be run
+ */
+ public PipelineBuilder run( final JCas jCas ) throws IOException,
UIMAException {
+ if ( _readerDesc != null ) {
+ LOGGER.error( "Collection Reader specified, ignoring." );
+ return this;
+ }
build();
- SimplePipeline.runPipeline( jcas, _analysisEngineDesc );
+ SimplePipeline.runPipeline( jCas, _analysisEngineDesc );
return this;
}
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=1883545&r1=1883544&r2=1883545&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 Nov 17 16:35:10 2020
@@ -19,16 +19,17 @@
package org.apache.ctakes.dictionary.lookup2.util;
import org.apache.ctakes.core.ae.UmlsEnvironmentConfiguration;
-import org.apache.ctakes.core.util.DotLogger;
+import org.apache.ctakes.core.util.log.DotLogger;
import org.apache.ctakes.utils.env.EnvironmentVariable;
import org.apache.log4j.Logger;
import org.apache.uima.UimaContext;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
@@ -71,10 +72,10 @@ public enum UmlsUserApprover {
static final private String CHANGE_ME = "CHANGE_ME";
// forget about copies of this URL sprinkled around the other libraries
static final private String UTS_APIKEY_URL =
"https://utslogin.nlm.nih.gov/cas/v1/api-key";
-
+
// cache of valid users
- static private final Collection<String> _validUsers = new
ArrayList<String>();
+ static private final Collection<String> _validUsers = new ArrayList<>();
/**
* validate the UMLS license / user
@@ -95,27 +96,28 @@ public enum UmlsUserApprover {
if (umlsApiKey == null) {
// emulate U&P style
- String user = getUser(uimaContext, properties);
- if (user == null || !user.equals(API_KEY_LABEL)) {
- LOGGER.error("USER AND PASSWORD MUST BE
umls_api_key and your <umls_api_key>");
+ String user = getUser( uimaContext, properties );
+ if ( user == null || !user.equals( API_KEY_LABEL ) ) {
+ LOGGER.error( "USER AND PASSWORD MUST BE
umls_api_key and your <umls_api_key>" );
return false;
}
-
- String pass = getPassOrKey(uimaContext, properties);
- if (pass == null || pass.indexOf("CHANGE") != -1 ||
pass.length() <= 24) {
- LOGGER.error("Upgrade to a UMLS API KEY.
Password no longer accepted");
+
+ String pass = getPassOrKey( uimaContext, properties );
+ if ( pass == null || pass.contains( "CHANGE" ) ||
pass.length() <= 24 ) {
+ LOGGER.error( "Upgrade to a UMLS API KEY.
Password no longer accepted" );
return false;
}
- return isValidUMLSUser(apiUrl, pass);
+ return isValidUMLSUser( apiUrl, pass );
}
return isValidUMLSUser(apiUrl, umlsApiKey);
}
/**
* See if the user has simply supplied the API key using its own
property name
- * @param properties
- * @param uimaContext
- * @return
+ *
+ * @param properties -
+ * @param uimaContext -
+ * @return -
*/
private String getSingleApiProp(final Properties properties,
UimaContext uimaContext) {
String umlsApiKey = EnvironmentVariable.getEnv(API_KEY_PROP,
uimaContext);
@@ -150,23 +152,24 @@ public enum UmlsUserApprover {
}
private String getPassOrKey(final UimaContext uimaContext,
- final Properties properties) {
+ final Properties properties ) {
String where = "environment";
String pass = EnvironmentVariable.getEnv(
UmlsEnvironmentConfiguration.PASSWORD.toString(),
- uimaContext);
- if (pass == null ||
pass.equals(EnvironmentVariable.NOT_PRESENT)
- || pass.indexOf("CHANGE") != -1) {
- pass = EnvironmentVariable.getEnv(PASS_PARAM,
uimaContext);
- if (pass == null
- ||
pass.equals(EnvironmentVariable.NOT_PRESENT)
- || pass.indexOf("CHANGE") != -1) {
- pass = properties.getProperty(PASS_PARAM);
+ uimaContext );
+ if ( pass == null || pass.equals(
EnvironmentVariable.NOT_PRESENT )
+ || pass.contains( "CHANGE" ) ) {
+ pass = EnvironmentVariable.getEnv( PASS_PARAM,
uimaContext );
+ if ( pass == null
+ || pass.equals(
EnvironmentVariable.NOT_PRESENT )
+ || pass.contains( "CHANGE" ) ) {
+ pass = properties.getProperty( PASS_PARAM );
where = "properties";
}
}
- if (pass != null)
- LOGGER.debug("ApiKey value found via: " + where);
+ if ( pass != null ) {
+ LOGGER.debug( "ApiKey value found via: " + where );
+ }
return pass;
}
@@ -177,11 +180,11 @@ public enum UmlsUserApprover {
UmlsEnvironmentConfiguration.USER.toString(),
uimaContext);
if (user == null || user.equals(EnvironmentVariable.NOT_PRESENT)
|| user.equals(CHANGEME) ||
user.equals(CHANGE_ME)) {
- user = EnvironmentVariable.getEnv(USER_PARAM,
uimaContext);
- if (user == null
- ||
user.equals(EnvironmentVariable.NOT_PRESENT)
- || user.indexOf("CHANGE") != -1) {
- user = properties.getProperty(USER_PARAM);
+ user = EnvironmentVariable.getEnv( USER_PARAM,
uimaContext );
+ if ( user == null
+ || user.equals(
EnvironmentVariable.NOT_PRESENT )
+ || user.contains( "CHANGE" ) ) {
+ user = properties.getProperty( USER_PARAM );
where = "properties";
}
}
@@ -192,15 +195,15 @@ public enum UmlsUserApprover {
/**
* New UTS authentication method
- * @param umlsUrl
- * @param umlsApiKey
- * @return
+ * @param umlsUrl -
+ * @param umlsApiKey -
+ * @return -
*/
private boolean isValidUMLSUser(String umlsUrl, String umlsApiKey) {
if (_validUsers.contains(umlsApiKey)) {
return true;
}
- return doAuth(umlsUrl, umlsApiKey);
+ return doAuth(umlsUrl, umlsApiKey );
}
/**
@@ -213,17 +216,17 @@ public enum UmlsUserApprover {
* -
* @param user NOW needs to be the value "umls_api_key"
* -
- * @param pass THE API KEY
+ * @param apikey THE API KEY
* -
* @return true if the server at umlsaddr approves of the vendor, user,
* password combination
*/
public boolean isValidUMLSUser(String umlsUrl, final String vendor,
- final String user, final String apikey) {
+ final String user, final String apikey ) {
- if (user == null || user.trim().isEmpty() ||
- !user.equals(this.API_KEY_LABEL)) {
- LOGGER.error("The user property must now be set to
\'umls_api_key\' ");
+ if ( user == null || user.trim().isEmpty() ||
+ !user.equals( API_KEY_LABEL ) ) {
+ LOGGER.error( "The user property must now be set to
\'umls_api_key\' " );
logCheckUser();
return false;
}
@@ -272,17 +275,17 @@ public enum UmlsUserApprover {
return doAuth(umlsUrl, apikey);
}
- private boolean doAuth(final String umlsUrl, String apiKey) {
- try (org.apache.ctakes.core.util.DotLogger dotter = new
org.apache.ctakes.core.util.DotLogger()) {
+ private boolean doAuth( final String umlsUrl, String apiKey ) {
+ try ( DotLogger dotter = new DotLogger() ) {
apiKey = apiKey.trim();
- LOGGER.info("Checking UMLS Account at " + umlsUrl +
":");
- String data = "apikey="+apiKey;
- final URL url = new URL(umlsUrl);
+ LOGGER.info( "Checking UMLS Account at " + umlsUrl +
":" );
+ String data = "apikey=" + apiKey;
+ final URL url = new URL( umlsUrl );
final HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- connection.setDoOutput(true);
+ connection.setRequestMethod( "POST" );
+ connection.setDoOutput( true );
final OutputStreamWriter writer = new
OutputStreamWriter(
- connection.getOutputStream());
+ connection.getOutputStream() );
writer.write(data);
writer.flush();
boolean isValidUser = false;