ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1782993 - in /ctakes/trunk: ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/ ctakes-core/src/main/java/org/apache/ctakes/core/cc/ ctakes-core/src/main/java/org/apache/ctakes/core/config/ ctakes-core/src/ma...
Date Tue, 14 Feb 2017 17:38:41 GMT
Author: seanfinan
Date: Tue Feb 14 17:38:40 2017
New Revision: 1782993

URL: http://svn.apache.org/viewvc?rev=1782993&view=rev
Log:
Required change is the use of collectionreader desc instead of instance in core.pipeline.*
Refactoring changes are an update for sync
BagOfAnnotationsGenerator refactor to use ConfigParameterConst
AbstractOutputFileWriter refactor to use ConfigParameterConst
FileTreeXmiWriter refactor to use ConfigParameterConst
ConfigParameterConstants add description constants, javadoc
FilesInDirectoryCollectionReader refactor to use ConfigParameterConst
FileTreeReader refactored to UimaFit
PipelineBuilder use collection reader descriptor instead of instance
PiperFileReader use collection reader descriptor instead of instance
PiperFileRunner refactor to use ConfigParameterConst
ProcessLinesClinicalRunner use collection reader class instead of instance
RelationExtractorPipeline refactor to use ConfigParameterConst

Modified:
    ctakes/trunk/ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/BagOfAnnotationsGenerator.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/AbstractOutputFileWriter.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/FileTreeXmiWriter.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/config/ConfigParameterConstants.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FilesInDirectoryCollectionReader.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipelineBuilder.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileReader.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileRunner.java
    ctakes/trunk/ctakes-examples/src/main/java/org/apache/ctakes/examples/pipeline/ProcessLinesClinicalRunner.java
    ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationExtractorPipeline.java

Modified: ctakes/trunk/ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/BagOfAnnotationsGenerator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/BagOfAnnotationsGenerator.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/BagOfAnnotationsGenerator.java
(original)
+++ ctakes/trunk/ctakes-clinical-pipeline/src/main/java/org/apache/ctakes/clinicalpipeline/runtime/BagOfAnnotationsGenerator.java
Tue Feb 14 17:38:40 2017
@@ -18,14 +18,7 @@
  */
 package org.apache.ctakes.clinicalpipeline.runtime;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.lang.reflect.ParameterizedType;
-import java.util.Collection;
-
-import org.apache.ctakes.core.cr.FilesInDirectoryCollectionReader;
+import org.apache.ctakes.core.config.ConfigParameterConstants;
 import org.apache.ctakes.core.util.DocumentIDAnnotationUtil;
 import org.apache.uima.UIMAException;
 import org.apache.uima.analysis_engine.AnalysisEngine;
@@ -37,6 +30,13 @@ import org.apache.uima.fit.util.JCasUtil
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.ParameterizedType;
+import java.util.Collection;
+
 public abstract class BagOfAnnotationsGenerator<T extends Annotation,K> {
 
 	private String outputDir = null;
@@ -46,8 +46,7 @@ public abstract class BagOfAnnotationsGe
 	private Class<T> classOfT;
 	
 	/**
-	 * @param args
-	 * @throws IOException 
+	 * @throws IOException
 	 * @throws UIMAException 
 	 */
 	public BagOfAnnotationsGenerator(String inputDir, String outputDir) throws UIMAException,
IOException{
@@ -55,9 +54,10 @@ public abstract class BagOfAnnotationsGe
 	}
 	
 	public BagOfAnnotationsGenerator(String inputDir, String outputDir, String aePath) throws
UIMAException, IOException {
-		reader = CollectionReaderFactory.createReaderFromPath("../ctakes-core/desc/collection_reader/FilesInDirectoryCollectionReader.xml",

-				FilesInDirectoryCollectionReader.PARAM_INPUTDIR, inputDir);
-		this.ae = AnalysisEngineFactory.createEngineFromPath(aePath == null ? defaultAEPath : aePath);
+		reader = CollectionReaderFactory
+				.createReaderFromPath( "../ctakes-core/desc/collection_reader/FilesInDirectoryCollectionReader.xml",
+						ConfigParameterConstants.PARAM_INPUTDIR, inputDir );
+		this.ae = AnalysisEngineFactory.createEngineFromPath( aePath == null ? defaultAEPath :
aePath );
 		this.outputDir = outputDir;
 		this.classOfT = getClassOfT();
 	}

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/AbstractOutputFileWriter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/AbstractOutputFileWriter.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/AbstractOutputFileWriter.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/AbstractOutputFileWriter.java
Tue Feb 14 17:38:40 2017
@@ -1,6 +1,7 @@
 package org.apache.ctakes.core.cc;
 
 
+import org.apache.ctakes.core.config.ConfigParameterConstants;
 import org.apache.ctakes.core.util.DocumentIDAnnotationUtil;
 import org.apache.ctakes.typesystem.type.structured.DocumentIdPrefix;
 import org.apache.ctakes.typesystem.type.structured.DocumentPath;
@@ -33,9 +34,10 @@ abstract public class AbstractOutputFile
     * Name of configuration parameter that must be set to the path of a directory into which
the
     * output files will be written.
     */
-   public static final String PARAM_OUTPUTDIR = "OutputDirectory";
-   @ConfigurationParameter( name = PARAM_OUTPUTDIR,
-         description = "Root output directory to write files" )
+   @ConfigurationParameter(
+         name = ConfigParameterConstants.PARAM_OUTPUTDIR,
+         description = ConfigParameterConstants.DESC_OUTPUTDIR
+   )
    private File _outputRootDir;
 
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/FileTreeXmiWriter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/FileTreeXmiWriter.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/FileTreeXmiWriter.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/FileTreeXmiWriter.java
Tue Feb 14 17:38:40 2017
@@ -1,5 +1,7 @@
 package org.apache.ctakes.core.cc;
 
+import org.apache.ctakes.core.config.ConfigParameterConstants;
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
 import org.apache.log4j.Logger;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.cas.CAS;
@@ -18,6 +20,14 @@ import java.io.*;
  * @version %I%
  * @since 2/12/2016
  */
+@PipeBitInfo(
+      name = "XMI Writer (Dir Tree)",
+      description = "Writes XMI files with full representation of input text and all extracted
information.",
+      role = PipeBitInfo.Role.WRITER,
+      input = PipeBitInfo.POPULATED_JCAS,
+      output = PipeBitInfo.NO_OUTPUT
+)
+// TODO Create and extend AbstractInputFileReader  a'la the abstract writer
 final public class FileTreeXmiWriter extends AbstractOutputFileWriter {
 
    static private final Logger LOGGER = Logger.getLogger( "FileTreeXmiWriter" );
@@ -50,7 +60,8 @@ final public class FileTreeXmiWriter ext
    }
 
    public static AnalysisEngine createEngine( final String outputDirectory ) throws ResourceInitializationException
{
-      return AnalysisEngineFactory.createEngine( FileTreeXmiWriter.class, PARAM_OUTPUTDIR,
outputDirectory );
+      return AnalysisEngineFactory
+            .createEngine( FileTreeXmiWriter.class, ConfigParameterConstants.PARAM_OUTPUTDIR,
outputDirectory );
    }
 
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/config/ConfigParameterConstants.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/config/ConfigParameterConstants.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/config/ConfigParameterConstants.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/config/ConfigParameterConstants.java
Tue Feb 14 17:38:40 2017
@@ -5,19 +5,26 @@ package org.apache.ctakes.core.config;
  * @version %I%
  * @since 9/28/2015
  */
-public interface ConfigParameterConstants {
+final public class ConfigParameterConstants {
 
+   private ConfigParameterConstants() {
+   }
 
+   /**
+    * Name of configuration parameter that can be set to the path of
+    * a directory containing input files.
+    */
    static public final String PARAM_INPUTDIR = "InputDirectory";
-   static public final String PARAM_OUTPUTDIR = "OutputDirectory";
-
-
    static public final String OPTION_INPUTDIR = "-i";
-   static public final String OPTION_OUTPUTDIR = "-o";
+   static public final String DESC_INPUTDIR = "Directory for all input files.";
 
-
-   static public final String DESC_INPUTDIR = "Directory for all input files";
-   static public final String DESC_OUTPUTDIR = "Directory for all output files";
+   /**
+    * Name of configuration parameter that can be set to the path of
+    * a directory containing output files.
+    */
+   static public final String PARAM_OUTPUTDIR = "OutputDirectory";
+   static public final String OPTION_OUTPUTDIR = "-o";
+   static public final String DESC_OUTPUTDIR = "Directory for all output files.";
 
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java (original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java Tue
Feb 14 17:38:40 2017
@@ -1,15 +1,17 @@
 package org.apache.ctakes.core.cr;
 
+import org.apache.ctakes.core.config.ConfigParameterConstants;
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.ctakes.typesystem.type.structured.DocumentID;
 import org.apache.ctakes.typesystem.type.structured.DocumentIdPrefix;
 import org.apache.ctakes.typesystem.type.structured.DocumentPath;
 import org.apache.log4j.Logger;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.CASException;
+import org.apache.uima.UimaContext;
 import org.apache.uima.collection.CollectionException;
 import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.collection.CollectionReader_ImplBase;
+import org.apache.uima.fit.component.JCasCollectionReader_ImplBase;
+import org.apache.uima.fit.descriptor.ConfigurationParameter;
 import org.apache.uima.fit.factory.CollectionReaderFactory;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -32,7 +34,13 @@ import java.util.List;
  * @version %I%
  * @since 2/10/2016
  */
-final public class FileTreeReader extends CollectionReader_ImplBase {
+@PipeBitInfo(
+      name = "Files in Dir Tree Reader",
+      description = "Reads document texts from text files in a directory tree.",
+      role = PipeBitInfo.Role.READER,
+      output = PipeBitInfo.NEW_JCAS
+)
+final public class FileTreeReader extends JCasCollectionReader_ImplBase {
 
    static private final Logger LOGGER = Logger.getLogger( "FileTreeReader" );
 
@@ -40,7 +48,11 @@ final public class FileTreeReader extend
     * Name of configuration parameter that must be set to the path of
     * a directory containing input files.
     */
-   public static final String PARAM_INPUTDIR = "InputDirectory";
+   @ConfigurationParameter(
+         name = ConfigParameterConstants.PARAM_INPUTDIR,
+         description = ConfigParameterConstants.DESC_INPUTDIR
+   )
+   private String _rootDirPath;
 
    /**
     * Name of configuration parameter that contains the character encoding used
@@ -48,6 +60,12 @@ final public class FileTreeReader extend
     * be used.
     */
    public static final String PARAM_ENCODING = "Encoding";
+   @ConfigurationParameter(
+         name = PARAM_ENCODING,
+         description = "The character encoding used by the input files.",
+         mandatory = false
+   )
+   private String _encoding;
 
    /**
     * Name of optional configuration parameter that specifies the extensions
@@ -55,26 +73,31 @@ final public class FileTreeReader extend
     * parameter should not begin with a dot <code>'.'</code>.
     */
    public static final String PARAM_EXTENSIONS = "Extensions";
+   @ConfigurationParameter(
+         name = PARAM_EXTENSIONS,
+         description = "The extensions of the files that the collection reader will read."
+
+                       "  Values for this parameter should not begin with a dot.",
+         mandatory = false
+   )
+   private String[] _explicitExtensions;
 
-   private List<File> _files;
-   private String _encoding;
-   private Collection<String> _validExtensions;
    private File _rootDir;
+   private Collection<String> _validExtensions;
+   private List<File> _files;
    private int _currentIndex;
 
    /**
     * {@inheritDoc}
     */
    @Override
-   public void initialize() throws ResourceInitializationException {
+   public void initialize( final UimaContext context ) throws ResourceInitializationException
{
+      super.initialize( context );
       try {
-         _rootDir = FileLocator.locateFile( (String)getConfigParameterValue( PARAM_INPUTDIR
) );
+         _rootDir = FileLocator.locateFile( _rootDirPath );
       } catch ( FileNotFoundException fnfE ) {
          throw new ResourceInitializationException( fnfE );
       }
-      _encoding = (String)getConfigParameterValue( PARAM_ENCODING );
-      final String[] explicitExtensions = (String[])getConfigParameterValue( PARAM_EXTENSIONS
);
-      _validExtensions = createValidExtensions( explicitExtensions );
+      _validExtensions = createValidExtensions( _explicitExtensions );
 
       _currentIndex = 0;
       _files = getDescendentFiles( _rootDir, _validExtensions );
@@ -213,14 +236,7 @@ final public class FileTreeReader extend
     * {@inheritDoc}
     */
    @Override
-   public void getNext( final CAS cas ) throws IOException, CollectionException {
-      JCas jcas;
-      try {
-         jcas = cas.getJCas();
-      } catch ( CASException casE ) {
-         _currentIndex++;
-         throw new IOException( casE );
-      }
+   public void getNext( final JCas jcas ) throws IOException, CollectionException {
       final File file = _files.get( _currentIndex );
       _currentIndex++;
       // Use 8KB as the default buffer size
@@ -274,9 +290,16 @@ final public class FileTreeReader extend
    }
 
 
+   /**
+    * Convenience method to create a reader with an input directory
+    *
+    * @param inputDirectory -
+    * @return new reader
+    * @throws ResourceInitializationException -
+    */
    public static CollectionReader createReader( final String inputDirectory ) throws ResourceInitializationException
{
       return CollectionReaderFactory.createReader( FileTreeReader.class,
-            FilesInDirectoryCollectionReader.PARAM_INPUTDIR,
+            ConfigParameterConstants.PARAM_INPUTDIR,
             inputDirectory );
    }
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FilesInDirectoryCollectionReader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FilesInDirectoryCollectionReader.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FilesInDirectoryCollectionReader.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FilesInDirectoryCollectionReader.java
Tue Feb 14 17:38:40 2017
@@ -39,6 +39,8 @@ package org.apache.ctakes.core.cr;
  * gather files in the directory from sub directories.    
  */
 
+import org.apache.ctakes.core.config.ConfigParameterConstants;
+import org.apache.ctakes.core.pipeline.PipeBitInfo;
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.ctakes.typesystem.type.structured.DocumentID;
 import org.apache.uima.cas.CAS;
@@ -57,14 +59,14 @@ import java.util.List;
 
 //import org.apache.uima.jcas.tcas.DocumentAnnotation;
 
-public class FilesInDirectoryCollectionReader extends CollectionReader_ImplBase 
+@PipeBitInfo(
+      name = "Files in Dir Reader",
+      description = "Reads document texts from text files in a directory.",
+      role = PipeBitInfo.Role.READER,
+      output = PipeBitInfo.NEW_JCAS
+)
+public class FilesInDirectoryCollectionReader extends CollectionReader_ImplBase
 {
-	/**
-	   * Name of configuration parameter that must be set to the path of
-	   * a directory containing input files.
-	   */
-	  public static final String PARAM_INPUTDIR = "InputDirectory";
-
 	  /**
 	   * Name of configuration parameter that contains the character encoding used
 	   * by the input files.  If not specified, the default system encoding will
@@ -105,16 +107,16 @@ public class FilesInDirectoryCollectionR
 	  @Override
 	public void initialize() throws ResourceInitializationException
 	{
-		final String inputDirPath = (String)getConfigParameterValue( PARAM_INPUTDIR );
-		File directory;
-		try {
+      final String inputDirPath = (String)getConfigParameterValue( ConfigParameterConstants.PARAM_INPUTDIR
);
+      File directory;
+      try {
 			directory = FileLocator.locateFile( inputDirPath );
 		} catch ( IOException ioE ) {
 			throw new ResourceInitializationException(
 					ResourceConfigurationException.DIRECTORY_NOT_FOUND,
-					new Object[] { PARAM_INPUTDIR, getMetaData().getName(), inputDirPath } );
-		}
-		iv_encoding = (String)getConfigParameterValue( PARAM_ENCODING );
+               new Object[] { ConfigParameterConstants.PARAM_INPUTDIR, getMetaData().getName(),
inputDirPath } );
+      }
+      iv_encoding = (String)getConfigParameterValue( PARAM_ENCODING );
 		iv_language = (String)getConfigParameterValue(PARAM_LANGUAGE);
 	    iv_extensions = (String[]) getConfigParameterValue(PARAM_EXTENSIONS);
 	    
@@ -131,11 +133,12 @@ public class FilesInDirectoryCollectionR
 		{
 			throw new ResourceInitializationException(
 				ResourceConfigurationException.DIRECTORY_NOT_FOUND,
-				new Object[]{PARAM_INPUTDIR, this.getMetaData().getName(), directory.getPath()});
-		}
-		
-		
-	    //get list of files (not subdirectories) in the specified directory
+               new Object[] { ConfigParameterConstants.PARAM_INPUTDIR, this.getMetaData().getName(),
+                              directory.getPath() } );
+      }
+
+
+      //get list of files (not subdirectories) in the specified directory
 	    iv_files = new ArrayList<File>();
 	    if(!iv_recurse)
 	    {

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=1782993&r1=1782992&r2=1782993&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 Feb 14 17:38:40 2017
@@ -8,11 +8,10 @@ import org.apache.ctakes.core.util.Prope
 import org.apache.log4j.Logger;
 import org.apache.uima.UIMAException;
 import org.apache.uima.analysis_component.AnalysisComponent;
-import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.collection.CollectionReader;
+import org.apache.uima.collection.CollectionReaderDescription;
 import org.apache.uima.fit.factory.AggregateBuilder;
-import org.apache.uima.fit.factory.AnalysisEngineFactory;
 import org.apache.uima.fit.factory.CollectionReaderFactory;
 import org.apache.uima.fit.factory.JCasFactory;
 import org.apache.uima.fit.pipeline.SimplePipeline;
@@ -37,13 +36,13 @@ final public class PipelineBuilder {
 
    static private final Logger LOGGER = Logger.getLogger( "PipelineBuilder" );
 
-   private CollectionReader _reader;
+   private CollectionReaderDescription _readerDesc;
    private final List<String> _aeNameList;
    private final List<AnalysisEngineDescription> _descList;
    private final List<String> _aeEndNameList;
    private final List<AnalysisEngineDescription> _descEndList;
    // Allow the pipeline to be changed even after it has been built once.
-   private AnalysisEngine _analysisEngine;
+   private AnalysisEngineDescription _analysisEngineDesc;
    private boolean _pipelineChanged;
 
 
@@ -69,11 +68,11 @@ final public class PipelineBuilder {
    /**
     * Use of this method is not order-specific
     *
-    * @param reader Collection Reader to place at the beginning of the pipeline
+    * @param description Collection Reader Description to place at the beginning of the pipeline
     * @return this PipelineBuilder
     */
-   public PipelineBuilder reader( final CollectionReader reader ) {
-      _reader = reader;
+   public PipelineBuilder reader( final CollectionReaderDescription description ) {
+      _readerDesc = description;
       _pipelineChanged = true;
       return this;
    }
@@ -87,7 +86,7 @@ final public class PipelineBuilder {
     */
    public PipelineBuilder reader( final Class<? extends CollectionReader> readerClass,
final Object... parameters )
          throws UIMAException {
-      reader( CollectionReaderFactory.createReader( readerClass, parameters ) );
+      reader( CollectionReaderFactory.createReaderDescription( readerClass, parameters )
);
       _pipelineChanged = true;
       return this;
    }
@@ -101,7 +100,7 @@ final public class PipelineBuilder {
     * @throws UIMAException if the collection reader cannot be created
     */
    public PipelineBuilder readFiles() throws UIMAException {
-      _reader = CollectionReaderFactory.createReader( FileTreeReader.class );
+      _readerDesc = CollectionReaderFactory.createReaderDescription( FileTreeReader.class
);
       _pipelineChanged = true;
       return this;
    }
@@ -115,17 +114,19 @@ final public class PipelineBuilder {
     * @throws UIMAException if the collection reader cannot be created
     */
    public PipelineBuilder readFiles( final String inputDirectory ) throws UIMAException {
-      _reader = FileTreeReader.createReader( inputDirectory );
+      _readerDesc = CollectionReaderFactory.createReaderDescription( FileTreeReader.class,
+            ConfigParameterConstants.PARAM_INPUTDIR,
+            inputDirectory );
       _pipelineChanged = true;
       return this;
    }
 
    /**
     *
-    * @return the CollectionReader for the pipeline or null if none has been specified
+    * @return the Collection Reader for the pipeline or null if none has been specified
     */
-   public CollectionReader getReader() {
-      return _reader;
+   public CollectionReaderDescription getReader() {
+      return _readerDesc;
    }
 
    /**
@@ -257,12 +258,11 @@ final public class PipelineBuilder {
     * @throws UIMAException if the pipeline could not be run
     */
    public PipelineBuilder build() throws IOException, UIMAException {
-      if ( _analysisEngine == null || _pipelineChanged ) {
+      if ( _analysisEngineDesc == null || _pipelineChanged ) {
          final AggregateBuilder builder = new AggregateBuilder();
          _descList.forEach( builder::add );
          _descEndList.forEach( builder::add );
-         final AnalysisEngineDescription description = builder.createAggregateDescription();
-         _analysisEngine = AnalysisEngineFactory.createEngine( description );
+         _analysisEngineDesc = builder.createAggregateDescription();
       }
       _pipelineChanged = false;
       return this;
@@ -278,12 +278,12 @@ final public class PipelineBuilder {
     * @throws UIMAException if the pipeline could not be run
     */
    public PipelineBuilder run() throws IOException, UIMAException {
-      if ( _reader == null ) {
+      if ( _readerDesc == null ) {
          LOGGER.error( "No Collection Reader specified." );
          return this;
       }
       build();
-      SimplePipeline.runPipeline( _reader, _analysisEngine );
+      SimplePipeline.runPipeline( _readerDesc, _analysisEngineDesc );
       return this;
    }
 
@@ -298,14 +298,14 @@ final public class PipelineBuilder {
     * @throws UIMAException if the pipeline could not be run
     */
    public PipelineBuilder run( final String text ) throws IOException, UIMAException {
-      if ( _reader != null ) {
+      if ( _readerDesc != null ) {
          LOGGER.error( "Collection Reader specified, ignoring." );
          return this;
       }
       final JCas jcas = JCasFactory.createJCas();
       jcas.setDocumentText( text );
       build();
-      SimplePipeline.runPipeline( jcas, _analysisEngine );
+      SimplePipeline.runPipeline( jcas, _analysisEngineDesc );
       return this;
    }
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileReader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileReader.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileReader.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileReader.java
Tue Feb 14 17:38:40 2017
@@ -2,7 +2,6 @@ package org.apache.ctakes.core.pipeline;
 
 
 import org.apache.ctakes.core.cc.XmiWriterCasConsumerCtakes;
-import org.apache.ctakes.core.cr.FilesInDirectoryCollectionReader;
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.log4j.Logger;
 import org.apache.uima.UIMAException;
@@ -14,7 +13,6 @@ import org.apache.uima.resource.Resource
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -34,7 +32,7 @@ import java.util.regex.Pattern;
  * reader <i>collection_reader_class_name</i>
  * readFiles <i>input_directory</i>
  *    <i>input_directory</i> can be empty if
- *    {@link FilesInDirectoryCollectionReader#PARAM_INPUTDIR} ("InputDirectory") was specified
+ *    {@link org.apache.ctakes.core.config.ConfigParameterConstants#PARAM_INPUTDIR} ("InputDirectory")
was specified
  * add <i>ae_or_cc_class_name ae_parameter_name=ae_parameter_value e_parameter_name<=ae_parameter_value</i>
...
  * addLogged <i>ae_or_cc_class_name ae_parameter_name=ae_parameter_value e_parameter_name=ae_parameter_value</i>
...
  * addDescription <i>ae_or_cc_class_name</i>
@@ -189,7 +187,14 @@ final public class PiperFileReader {
             _builder.set( getCliParameters( parameter ) );
             break;
          case "reader":
-            _builder.reader( createReader( parameter ) );
+            if ( hasParameters( parameter ) ) {
+               final String[] component_parameters = splitFromParameters( parameter );
+               final String component = component_parameters[ 0 ];
+               final Object[] parameters = splitParameters( component_parameters[ 1 ] );
+               _builder.reader( getReaderClass( component ), parameters );
+            } else {
+               _builder.reader( getReaderClass( parameter ) );
+            }
             break;
          case "readFiles":
             if ( parameter.isEmpty() ) {
@@ -371,11 +376,12 @@ final public class PiperFileReader {
 
    /**
     * @param className fully-specified or simple name of a cr Collection Reader class
-    * @return instantiated collection reader
+    * @return a class for the reader
     * @throws ResourceInitializationException if the class could not be found or instantiated
     */
-   private CollectionReader createReader( final String className ) throws ResourceInitializationException
{
-      Class<?> readerClass;
+   private Class<? extends CollectionReader> getReaderClass( final String className
)
+         throws ResourceInitializationException {
+      Class readerClass;
       try {
          readerClass = Class.forName( className );
       } catch ( ClassNotFoundException cnfE ) {
@@ -385,18 +391,7 @@ final public class PiperFileReader {
          throw new ResourceInitializationException( "No Collection Reader found for " + className,
EMPTY_OBJECT_ARRAY );
       }
       assertClassType( readerClass, CollectionReader.class );
-      final Constructor<?>[] constructors = readerClass.getConstructors();
-      for ( Constructor<?> constructor : constructors ) {
-         try {
-            if ( constructor.getParameterTypes().length == 0 ) {
-               return (CollectionReader)constructor.newInstance();
-            }
-         } catch ( InstantiationException | IllegalAccessException | InvocationTargetException
iniaitE ) {
-            throw new ResourceInitializationException(
-                  "Could not construct " + className, EMPTY_OBJECT_ARRAY, iniaitE );
-         }
-      }
-      throw new ResourceInitializationException( "No Constructor for " + className, EMPTY_OBJECT_ARRAY
);
+      return readerClass;
    }
 
    /**

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileRunner.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileRunner.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileRunner.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PiperFileRunner.java
Tue Feb 14 17:38:40 2017
@@ -2,6 +2,7 @@ package org.apache.ctakes.core.pipeline;
 
 
 import com.lexicalscope.jewel.cli.CliFactory;
+import org.apache.ctakes.core.config.ConfigParameterConstants;
 import org.apache.log4j.Logger;
 import org.apache.uima.UIMAException;
 
@@ -30,15 +31,15 @@ final public class PiperFileRunner {
          // set the input directory parameter if needed
          final String inputDir = options.getInputDirectory();
          if ( !inputDir.isEmpty() ) {
-            builder.set( "InputDirectory", inputDir );
+            builder.set( ConfigParameterConstants.PARAM_INPUTDIR, inputDir );
          }
          // set the output directory parameter if needed
          final String outputDir = options.getOutputDirectory();
          final String xmiOutDir = options.getXmiOutDirectory();
          if ( !outputDir.isEmpty() ) {
-            builder.set( "OutputDirectory", outputDir );
+            builder.set( ConfigParameterConstants.PARAM_OUTPUTDIR, outputDir );
          } else if ( !xmiOutDir.isEmpty() ) {
-            builder.set( "OutputDirectory", xmiOutDir );
+            builder.set( ConfigParameterConstants.PARAM_OUTPUTDIR, xmiOutDir );
          }
          // set the umls user and password parameters if needed
          final String umlsUser = options.getUmlsUserName();

Modified: ctakes/trunk/ctakes-examples/src/main/java/org/apache/ctakes/examples/pipeline/ProcessLinesClinicalRunner.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-examples/src/main/java/org/apache/ctakes/examples/pipeline/ProcessLinesClinicalRunner.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-examples/src/main/java/org/apache/ctakes/examples/pipeline/ProcessLinesClinicalRunner.java
(original)
+++ ctakes/trunk/ctakes-examples/src/main/java/org/apache/ctakes/examples/pipeline/ProcessLinesClinicalRunner.java
Tue Feb 14 17:38:40 2017
@@ -8,8 +8,6 @@ import org.apache.ctakes.core.pipeline.P
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.log4j.Logger;
 import org.apache.uima.UIMAException;
-import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.fit.factory.CollectionReaderFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -46,10 +44,8 @@ final public class ProcessLinesClinicalR
          final PipelineBuilder builder = reader.getBuilder();
          // Add the Lines from File reader
          final File inputFile = FileLocator.locateFile( INPUT_FILE_PATH );
-         final CollectionReader linesFromFileReader
-               = CollectionReaderFactory.createReader( LinesFromFileCollectionReader.class,
+         builder.reader( LinesFromFileCollectionReader.class,
                LinesFromFileCollectionReader.PARAM_INPUT_FILE_NAME, inputFile.getAbsolutePath()
);
-         builder.reader( linesFromFileReader );
          // Add the lines from the piper file
          reader.loadPipelineFile( PIPER_FILE_PATH );
          // Collect IdentifiedAnnotation object information for output - simple for examples

Modified: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationExtractorPipeline.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationExtractorPipeline.java?rev=1782993&r1=1782992&r2=1782993&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationExtractorPipeline.java
(original)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/pipelines/RelationExtractorPipeline.java
Tue Feb 14 17:38:40 2017
@@ -18,10 +18,7 @@
  */
 package org.apache.ctakes.relationextractor.pipelines;
 
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.ctakes.core.cr.FilesInDirectoryCollectionReader;
+import org.apache.ctakes.core.config.ConfigParameterConstants;
 import org.apache.uima.UIMAException;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.collection.CollectionReaderDescription;
@@ -34,6 +31,9 @@ import org.kohsuke.args4j.CmdLineExcepti
 import org.kohsuke.args4j.CmdLineParser;
 import org.kohsuke.args4j.Option;
 
+import java.io.File;
+import java.io.IOException;
+
 /**
  * A simple pipeline that runs relation extraction on all files in a directory and saves
  * the resulting annotations as XMI files. The core part of this pipeline is the aggregate
@@ -68,8 +68,8 @@ public class RelationExtractorPipeline {
 
 		CollectionReaderDescription collectionReader = CollectionReaderFactory.createReaderDescriptionFromPath(
 				"../ctakes-core/desc/collection_reader/FilesInDirectoryCollectionReader.xml",
-				FilesInDirectoryCollectionReader.PARAM_INPUTDIR,
-				options.inputDirectory);
+            ConfigParameterConstants.PARAM_INPUTDIR,
+            options.inputDirectory );
 
 		// make sure the model parameters match those used for training
 		AnalysisEngineDescription relationExtractor = AnalysisEngineFactory.createEngineDescriptionFromPath(



Mime
View raw message