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 2022/12/20 03:14:01 UTC
[ctakes] branch main updated: Extracted PausableFileLoggerAE from CommandRunner and CtakesRunner Comments in StartFinishLogger and XmiCollectionReaderCtakes
This is an automated email from the ASF dual-hosted git repository.
seanfinan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ctakes.git
The following commit(s) were added to refs/heads/main by this push:
new b096dc1 Extracted PausableFileLoggerAE from CommandRunner and CtakesRunner Comments in StartFinishLogger and XmiCollectionReaderCtakes
b096dc1 is described below
commit b096dc12572d66b373b6fd63907d1b2a2525f301
Author: Sean Finan <se...@childrens.harvard.edu>
AuthorDate: Mon Dec 19 22:13:31 2022 -0500
Extracted PausableFileLoggerAE from CommandRunner and CtakesRunner
Comments in StartFinishLogger and XmiCollectionReaderCtakes
---
.../org/apache/ctakes/core/ae/CommandRunner.java | 53 ++++++--------------
.../org/apache/ctakes/core/ae/CtakesRunner.java | 46 ++++++-----------
.../java/org/apache/ctakes/core/ae/ExitForcer.java | 6 ++-
.../ctakes/core/ae/PausableFileLoggerAE.java | 58 ++++++++++++++++++++++
.../apache/ctakes/core/ae/StartFinishLogger.java | 2 +-
.../apache/ctakes/core/ae/inert/PausableAE.java | 17 ++-----
.../ctakes/core/cr/XmiCollectionReaderCtakes.java | 2 +
7 files changed, 101 insertions(+), 83 deletions(-)
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CommandRunner.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CommandRunner.java
index 094bb40..0c8e9b3 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CommandRunner.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CommandRunner.java
@@ -2,11 +2,9 @@ package org.apache.ctakes.core.ae;
import org.apache.ctakes.core.pipeline.PipeBitInfo;
import org.apache.ctakes.core.util.external.SystemUtil;
-import org.apache.ctakes.core.util.log.DotLogger;
import org.apache.log4j.Logger;
import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
-import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.descriptor.ConfigurationParameter;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
@@ -23,7 +21,7 @@ import java.io.IOException;
description = "Runs an external process.",
role = PipeBitInfo.Role.SPECIAL
)
-public class CommandRunner extends JCasAnnotator_ImplBase {
+public class CommandRunner extends PausableFileLoggerAE {
static private final Logger LOGGER = Logger.getLogger( "CommandRunner" );
@@ -65,15 +63,6 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
)
private String _perDoc;
- static public final String PAUSE_PARAM = "Pause";
- static public final String PAUSE_DESC = "Pause for some seconds after launching. Default is 0";
- @ConfigurationParameter(
- name = PAUSE_PARAM,
- description = PAUSE_DESC,
- mandatory = false
- )
- private int _pause = 0;
-
static public final String WAIT_PARAM = "Wait";
static public final String WAIT_DESC = "Wait for the launched command to finish. Default is no.";
@ConfigurationParameter(
@@ -94,15 +83,13 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
private String _logName;
- static public final String LOG_FILE_PARAM = "LogFile";
- static public final String LOG_FILE_DESC = "File to which the command's output should be sent. This overrides Log.";
- @ConfigurationParameter(
- name = LOG_FILE_PARAM,
- description = LOG_FILE_DESC,
- mandatory = false
- )
- private String _logFile;
+ boolean processPerDoc() {
+ return _perDoc.equalsIgnoreCase( "yes" ) || _perDoc.equalsIgnoreCase( "true" );
+ }
+ public void logInfo( final String info ) {
+ LOGGER.info( info );
+ }
/**
* {@inheritDoc}
@@ -119,7 +106,7 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
if ( _dir != null && !_dir.isEmpty() && !new File( _dir ).exists() ) {
LOGGER.warn( "Cannot find Directory " + _dir );
}
- if ( _perDoc.equalsIgnoreCase( "yes" ) || _perDoc.equalsIgnoreCase( "true" ) ) {
+ if ( processPerDoc() ) {
return;
}
try {
@@ -134,7 +121,7 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
*/
@Override
public void process( final JCas jcas ) throws AnalysisEngineProcessException {
- if ( !_perDoc.equalsIgnoreCase( "yes" ) && !_perDoc.equalsIgnoreCase( "true" ) ) {
+ if ( !processPerDoc() ) {
return;
}
try {
@@ -145,11 +132,12 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
}
- private void runCommand() throws IOException {
+ void runCommand() throws IOException {
final String command = ( _cmdDir == null || _cmdDir.isEmpty() ) ? _cmd : _cmdDir + File.separator + _cmd;
final SystemUtil.CommandRunner runner = new SystemUtil.CommandRunner( command );
- if ( _logFile != null && !_logFile.isEmpty() ) {
- runner.setLogFiles( _logFile );
+ final String logFile = getLogFile();
+ if ( logFile != null && !logFile.isEmpty() ) {
+ runner.setLogFiles( logFile );
} else {
final Logger logger = getRunLogger();
runner.setLogger( logger );
@@ -161,20 +149,11 @@ public class CommandRunner extends JCasAnnotator_ImplBase {
runner.setDirectory( _dir );
}
LOGGER.info( "Running " + command + " ..." );
- if ( _logFile != null && !_logFile.isEmpty() ) {
- LOGGER.info( "Log File is " + _logFile );
+ if ( logFile != null && !logFile.isEmpty() ) {
+ LOGGER.info( "Log File is " + logFile );
}
SystemUtil.run( runner );
- if ( _pause < 1 ) {
- return;
- }
- final long pause = _pause * 1000L;
- LOGGER.info( "Pausing " + _pause + " seconds ..." );
- try ( DotLogger dotter = new DotLogger() ) {
- Thread.sleep( pause );
- } catch ( IOException | InterruptedException multE ) {
- // do nothing
- }
+ pause();
}
private Logger getRunLogger() {
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CtakesRunner.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CtakesRunner.java
index c310fbb..39dbdee 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CtakesRunner.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/CtakesRunner.java
@@ -2,12 +2,10 @@ package org.apache.ctakes.core.ae;
import org.apache.ctakes.core.pipeline.PipeBitInfo;
import org.apache.ctakes.core.util.external.SystemUtil;
-import org.apache.ctakes.core.util.log.DotLogger;
import org.apache.log4j.Logger;
import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
-import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.descriptor.ConfigurationParameter;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.jcas.JCas;
@@ -25,7 +23,7 @@ import java.io.IOException;
description = "Starts a new instance of cTAKES with the given piper parameters.",
role = PipeBitInfo.Role.SPECIAL
)
-public class CtakesRunner extends JCasAnnotator_ImplBase {
+public class CtakesRunner extends PausableFileLoggerAE {
static private final Logger LOGGER = Logger.getLogger( "CtakesRunner" );
@@ -37,25 +35,19 @@ public class CtakesRunner extends JCasAnnotator_ImplBase {
)
private String _cli;
- static public final String LOG_FILE_PARAM = "LogFile";
- static public final String LOG_FILE_DESC = "File to which cTAKES output should be sent.";
- @ConfigurationParameter(
- name = LOG_FILE_PARAM,
- description = LOG_FILE_DESC,
- mandatory = false
- )
+
+ static private final String JAVA_CMD = "-Xms512M -Xmx3g org.apache.ctakes.core.pipeline.PiperFileRunner";
+
private String _logFile;
- static public final String PAUSE_PARAM = "Pause";
- static public final String PAUSE_DESC = "Pause for some seconds after launching. Default is 0";
- @ConfigurationParameter(
- name = PAUSE_PARAM,
- description = PAUSE_DESC,
- mandatory = false
- )
- private int _pause = 0;
+ boolean processPerDoc() {
+ return false;
+ }
+
+ public void logInfo( final String info ) {
+ LOGGER.info( info );
+ }
- static private final String JAVA_CMD = "-Xms512M -Xmx3g org.apache.ctakes.core.pipeline.PiperFileRunner";
/**
* {@inheritDoc}
@@ -66,7 +58,8 @@ public class CtakesRunner extends JCasAnnotator_ImplBase {
_cli = SystemUtil.subVariableParameters( _cli, context );
try {
final String piper = getPiper();
- if ( _logFile == null || _logFile.isEmpty() ) {
+ final String logFile = getLogFile();
+ if ( logFile == null || logFile.isEmpty() ) {
_logFile = "ctakes_" + piper + ".log";
}
runCommand();
@@ -104,7 +97,7 @@ public class CtakesRunner extends JCasAnnotator_ImplBase {
return piper;
}
- private void runCommand() throws IOException {
+ void runCommand() throws IOException {
final String java_home = System.getProperty( "java.home" );
final SystemUtil.CommandRunner runner =
new SystemUtil.CommandRunner( "\"" + java_home + File.separator + "bin" + File.separator
@@ -113,16 +106,7 @@ public class CtakesRunner extends JCasAnnotator_ImplBase {
// LOGGER.info( "Starting cTAKES with " + _cli + " ..." );
LOGGER.info( "Starting external cTAKES pipeline with " + _cli + " ..." );
SystemUtil.run( runner );
- if ( _pause < 1 ) {
- return;
- }
- final long pause = _pause * 1000L;
- LOGGER.info( "Pausing " + _pause + " seconds ..." );
- try ( DotLogger dotter = new DotLogger() ) {
- Thread.sleep( pause );
- } catch ( IOException | InterruptedException multE ) {
- // do nothing
- }
+ pause();
}
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/ExitForcer.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/ExitForcer.java
index 337daf3..aae6346 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/ExitForcer.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/ExitForcer.java
@@ -40,6 +40,10 @@ public class ExitForcer extends PausableAE {
// Do nothing
}
+ protected void logInfo( final String info ) {
+ LOGGER.info( info );
+ }
+
/**
* Forcibly exit. If ctakes happens to be running within a gui then a message dialog is displayed.
* {@inheritDoc}
@@ -47,7 +51,7 @@ public class ExitForcer extends PausableAE {
@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
super.collectionProcessComplete();
- pause( LOGGER );
+ pause();
final Frame[] frames = Frame.getFrames();
if ( frames != null && frames.length > 0 ) {
JOptionPane.showMessageDialog( null, "Processing Complete. Click OK to exit." );
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/PausableFileLoggerAE.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/PausableFileLoggerAE.java
new file mode 100644
index 0000000..f09aec1
--- /dev/null
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/PausableFileLoggerAE.java
@@ -0,0 +1,58 @@
+package org.apache.ctakes.core.ae;
+
+import org.apache.ctakes.core.ae.inert.PausableAE;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.descriptor.ConfigurationParameter;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+
+import java.io.IOException;
+
+/**
+ * @author SPF , chip-nlp
+ * @since {12/19/2022}
+ */
+abstract public class PausableFileLoggerAE extends PausableAE {
+
+ static public final String LOG_FILE_PARAM = "LogFile";
+ static public final String LOG_FILE_DESC = "File to which cTAKES output should be sent.";
+ @ConfigurationParameter(
+ name = LOG_FILE_PARAM,
+ description = LOG_FILE_DESC,
+ mandatory = false
+ )
+ private String _logFile;
+
+ abstract boolean processPerDoc();
+
+ abstract void runCommand() throws IOException;
+
+ final protected String getLogFile() {
+ return _logFile;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initialize( final UimaContext context ) throws ResourceInitializationException {
+ super.initialize( context );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void process( final JCas jcas ) throws AnalysisEngineProcessException {
+ if ( !processPerDoc() ) {
+ return;
+ }
+ try {
+ runCommand();
+ } catch ( IOException ioE ) {
+ throw new AnalysisEngineProcessException( ioE );
+ }
+ }
+
+}
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/StartFinishLogger.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/StartFinishLogger.java
index a34063a..b429f3e 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/StartFinishLogger.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/StartFinishLogger.java
@@ -14,7 +14,7 @@ import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
/**
- * All Annotation Engines should be logger their start and finish.
+ * All Annotation Engines should be logging their start and finish.
* Such logging not only keeps track of what is actually in the pipeline, but it also helps with debugging and profiling
*
* @author SPF , chip-nlp
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/inert/PausableAE.java b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/inert/PausableAE.java
index 4c725e6..bc6524c 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/ae/inert/PausableAE.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/ae/inert/PausableAE.java
@@ -14,11 +14,6 @@ import java.io.IOException;
* @author SPF , chip-nlp
* @since {7/29/2022}
*/
-@PipeBitInfo(
- name = "PausableAE",
- description = "Can be extended to add Pause capabilities to an Annotation Engine",
- role = PipeBitInfo.Role.ANNOTATOR
-)
abstract public class PausableAE extends JCasAnnotator_ImplBase {
static public final String PAUSE_PARAM = "Pause";
@@ -39,18 +34,14 @@ abstract public class PausableAE extends JCasAnnotator_ImplBase {
super.initialize( context );
}
- protected void pause() {
- pause( null );
- }
+ protected void logInfo( final String info ) {}
- protected void pause( final Logger logger ) {
- if ( _pause <= 0 ) {
+ final protected void pause() {
+ if ( _pause < 1 ) {
return;
}
final long pause = _pause * 1000L;
- if ( logger != null ) {
- logger.info( "Pausing " + _pause + " seconds ..." );
- }
+ logInfo( "Pausing " + _pause + " seconds ..." );
try ( DotLogger dotter = new DotLogger() ) {
Thread.sleep( pause );
} catch ( IOException | InterruptedException multE ) {
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/cr/XmiCollectionReaderCtakes.java b/ctakes-core/src/main/java/org/apache/ctakes/core/cr/XmiCollectionReaderCtakes.java
index 2058955..fd9efa7 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/cr/XmiCollectionReaderCtakes.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/cr/XmiCollectionReaderCtakes.java
@@ -37,6 +37,7 @@ import java.util.ArrayList;
/**
* A simple collection reader that reads CASes in XMI format from a directory in the filesystem.
+ * @deprecated use XmiTreeReader, with configuration parameter Extensions=xmi if necessary.
*/
@PipeBitInfo(
name = "XMI in Dir Reader (1)",
@@ -44,6 +45,7 @@ import java.util.ArrayList;
role = PipeBitInfo.Role.READER,
products = { PipeBitInfo.TypeProduct.DOCUMENT_ID }
)
+@Deprecated
public class XmiCollectionReaderCtakes extends CollectionReader_ImplBase {
/**
* Name of configuration parameter that must be set to the path of a directory containing the XMI