ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1777834 - /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/
Date Sat, 07 Jan 2017 18:23:50 GMT
Author: seanfinan
Date: Sat Jan  7 18:23:50 2017
New Revision: 1777834

URL: http://svn.apache.org/viewvc?rev=1777834&view=rev
Log:
PipeBitInfo : New annotation for pipeline bit (reader, annotator, writer) information
PipeBitInfoUtil : New util to handle PipeBitInfo
StandardOptions : Moved RunOptions from PiperFileRunner
CliOptionals : New non-standard, user-definable via piper cli character options
CliOptionalHandler : New util for CliOptionals
CuiCollector : Added PipeBitInfo
EntityCollector : Added PipeBitInfo
PiperFileReader : Added ability to use custom cli character options
PiperFileRunner : Moved RunOptions to StandardOptions, Added ability to use custom cli character
options

Added:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionals.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionalsHandler.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfo.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfoUtil.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/StandardOptions.java
Modified:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CuiCollector.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/EntityCollector.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

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionals.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionals.java?rev=1777834&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionals.java
(added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionals.java
Sat Jan  7 18:23:50 2017
@@ -0,0 +1,308 @@
+package org.apache.ctakes.core.pipeline;
+
+import com.lexicalscope.jewel.cli.Option;
+
+/**
+ * Defines command line interface single-character options that are not ctakes defaults.
+ * This allows -a SomeValue -b SomeValue -c SomeValue ... -1 SomeValue -2 SomeValue ... -A
SomeValue -B SomeValue ...
+ * Reserved option characters are -p (PiperFile), -i (InputDirectory), -o (OutputDirectory).
+ *
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/7/2017
+ */
+public interface CliOptionals extends StandardOptions {
+
+   @Option(
+         shortName = "a",
+         defaultValue = "" )
+   String getOption_a();
+
+   @Option(
+         shortName = "b",
+         defaultValue = "" )
+   String getOption_b();
+
+   @Option(
+         shortName = "c",
+         defaultValue = "" )
+   String getOption_c();
+
+   @Option(
+         shortName = "d",
+         defaultValue = "" )
+   String getOption_d();
+
+   @Option(
+         shortName = "e",
+         defaultValue = "" )
+   String getOption_e();
+
+   @Option(
+         shortName = "f",
+         defaultValue = "" )
+   String getOption_f();
+
+   @Option(
+         shortName = "g",
+         defaultValue = "" )
+   String getOption_g();
+
+   @Option(
+         shortName = "h",
+         defaultValue = "" )
+   String getOption_h();
+
+   // -i is reserved for common parameter "InputDirectory"
+
+   @Option(
+         shortName = "j",
+         defaultValue = "" )
+   String getOption_j();
+
+   @Option(
+         shortName = "k",
+         defaultValue = "" )
+   String getOption_k();
+
+   @Option(
+         shortName = "l",
+         defaultValue = "" )
+   String getOption_l();
+
+   @Option(
+         shortName = "m",
+         defaultValue = "" )
+   String getOption_m();
+
+   @Option(
+         shortName = "n",
+         defaultValue = "" )
+   String getOption_n();
+
+   // -o is reserved for common parameter "OutputDirectory"
+
+   // -p is reserved for common parameter "PiperFile"
+
+   @Option(
+         shortName = "q",
+         defaultValue = "" )
+   String getOption_q();
+
+   @Option(
+         shortName = "r",
+         defaultValue = "" )
+   String getOption_r();
+
+   @Option(
+         shortName = "s",
+         defaultValue = "" )
+   String getOption_s();
+
+   @Option(
+         shortName = "t",
+         defaultValue = "" )
+   String getOption_t();
+
+   @Option(
+         shortName = "u",
+         defaultValue = "" )
+   String getOption_u();
+
+   @Option(
+         shortName = "v",
+         defaultValue = "" )
+   String getOption_v();
+
+   @Option(
+         shortName = "w",
+         defaultValue = "" )
+   String getOption_w();
+
+   @Option(
+         shortName = "x",
+         defaultValue = "" )
+   String getOption_x();
+
+   @Option(
+         shortName = "y",
+         defaultValue = "" )
+   String getOption_y();
+
+   @Option(
+         shortName = "z",
+         defaultValue = "" )
+   String getOption_z();
+
+   @Option(
+         shortName = "0",
+         defaultValue = "" )
+   String getOption_0();
+
+   @Option(
+         shortName = "1",
+         defaultValue = "" )
+   String getOption_1();
+
+   @Option(
+         shortName = "2",
+         defaultValue = "" )
+   String getOption_2();
+
+   @Option(
+         shortName = "3",
+         defaultValue = "" )
+   String getOption_3();
+
+   @Option(
+         shortName = "4",
+         defaultValue = "" )
+   String getOption_4();
+
+   @Option(
+         shortName = "5",
+         defaultValue = "" )
+   String getOption_5();
+
+   @Option(
+         shortName = "6",
+         defaultValue = "" )
+   String getOption_6();
+
+   @Option(
+         shortName = "7",
+         defaultValue = "" )
+   String getOption_7();
+
+   @Option(
+         shortName = "8",
+         defaultValue = "" )
+   String getOption_8();
+
+   @Option(
+         shortName = "9",
+         defaultValue = "" )
+   String getOption_9();
+
+   @Option(
+         shortName = "A",
+         defaultValue = "" )
+   String getOption_A();
+
+   @Option(
+         shortName = "B",
+         defaultValue = "" )
+   String getOption_B();
+
+   @Option(
+         shortName = "C",
+         defaultValue = "" )
+   String getOption_C();
+
+   @Option(
+         shortName = "D",
+         defaultValue = "" )
+   String getOption_D();
+
+   @Option(
+         shortName = "E",
+         defaultValue = "" )
+   String getOption_E();
+
+   @Option(
+         shortName = "F",
+         defaultValue = "" )
+   String getOption_F();
+
+   @Option(
+         shortName = "G",
+         defaultValue = "" )
+   String getOption_G();
+
+   @Option(
+         shortName = "H",
+         defaultValue = "" )
+   String getOption_H();
+
+   // -i is reserved for common parameter "InputDirectory"
+
+   @Option(
+         shortName = "J",
+         defaultValue = "" )
+   String getOption_J();
+
+   @Option(
+         shortName = "K",
+         defaultValue = "" )
+   String getOption_K();
+
+   @Option(
+         shortName = "L",
+         defaultValue = "" )
+   String getOption_L();
+
+   @Option(
+         shortName = "M",
+         defaultValue = "" )
+   String getOption_M();
+
+   @Option(
+         shortName = "N",
+         defaultValue = "" )
+   String getOption_N();
+
+   // -o is reserved for common parameter "OutputDirectory"
+
+   // -p is reserved for common parameter "PiperFile"
+
+   @Option(
+         shortName = "Q",
+         defaultValue = "" )
+   String getOption_Q();
+
+   @Option(
+         shortName = "R",
+         defaultValue = "" )
+   String getOption_R();
+
+   @Option(
+         shortName = "S",
+         defaultValue = "" )
+   String getOption_S();
+
+   @Option(
+         shortName = "T",
+         defaultValue = "" )
+   String getOption_T();
+
+   @Option(
+         shortName = "U",
+         defaultValue = "" )
+   String getOption_U();
+
+   @Option(
+         shortName = "V",
+         defaultValue = "" )
+   String getOption_V();
+
+   @Option(
+         shortName = "W",
+         defaultValue = "" )
+   String getOption_W();
+
+   @Option(
+         shortName = "X",
+         defaultValue = "" )
+   String getOption_X();
+
+   @Option(
+         shortName = "Y",
+         defaultValue = "" )
+   String getOption_Y();
+
+   @Option(
+         shortName = "Z",
+         defaultValue = "" )
+   String getOption_Z();
+
+}
\ No newline at end of file

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionalsHandler.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionalsHandler.java?rev=1777834&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionalsHandler.java
(added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CliOptionalsHandler.java
Sat Jan  7 18:23:50 2017
@@ -0,0 +1,143 @@
+package org.apache.ctakes.core.pipeline;
+
+import java.util.logging.Logger;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/7/2017
+ */
+final public class CliOptionalsHandler {
+
+   static private final Logger LOGGER = Logger.getLogger( "CliOptionalsHandler" );
+
+   private CliOptionalsHandler() {
+   }
+
+   /**
+    * Brute force method to get option values
+    *
+    * @param optionals  -
+    * @param optionChar character option
+    * @return the value specified on the command line for the given character
+    */
+   static public String getCliOptionalValue( final CliOptionals optionals, final String optionChar
) {
+      switch ( optionChar ) {
+         case "a":
+            return optionals.getOption_a();
+         case "b":
+            return optionals.getOption_b();
+         case "c":
+            return optionals.getOption_c();
+         case "d":
+            return optionals.getOption_d();
+         case "e":
+            return optionals.getOption_e();
+         case "f":
+            return optionals.getOption_f();
+         case "g":
+            return optionals.getOption_g();
+         case "h":
+            return optionals.getOption_h();
+         case "j":
+            return optionals.getOption_j();
+         case "k":
+            return optionals.getOption_k();
+         case "l":
+            return optionals.getOption_l();
+         case "m":
+            return optionals.getOption_m();
+         case "n":
+            return optionals.getOption_n();
+         case "q":
+            return optionals.getOption_q();
+         case "r":
+            return optionals.getOption_r();
+         case "s":
+            return optionals.getOption_s();
+         case "t":
+            return optionals.getOption_t();
+         case "u":
+            return optionals.getOption_u();
+         case "v":
+            return optionals.getOption_v();
+         case "w":
+            return optionals.getOption_w();
+         case "x":
+            return optionals.getOption_x();
+         case "y":
+            return optionals.getOption_y();
+         case "z":
+            return optionals.getOption_z();
+         case "0":
+            return optionals.getOption_0();
+         case "1":
+            return optionals.getOption_1();
+         case "2":
+            return optionals.getOption_2();
+         case "3":
+            return optionals.getOption_3();
+         case "4":
+            return optionals.getOption_4();
+         case "5":
+            return optionals.getOption_5();
+         case "6":
+            return optionals.getOption_6();
+         case "7":
+            return optionals.getOption_7();
+         case "8":
+            return optionals.getOption_8();
+         case "9":
+            return optionals.getOption_9();
+         case "A":
+            return optionals.getOption_A();
+         case "B":
+            return optionals.getOption_B();
+         case "C":
+            return optionals.getOption_C();
+         case "D":
+            return optionals.getOption_D();
+         case "E":
+            return optionals.getOption_E();
+         case "F":
+            return optionals.getOption_F();
+         case "G":
+            return optionals.getOption_G();
+         case "H":
+            return optionals.getOption_H();
+         case "J":
+            return optionals.getOption_J();
+         case "K":
+            return optionals.getOption_K();
+         case "L":
+            return optionals.getOption_L();
+         case "M":
+            return optionals.getOption_M();
+         case "N":
+            return optionals.getOption_N();
+         case "Q":
+            return optionals.getOption_Q();
+         case "R":
+            return optionals.getOption_R();
+         case "S":
+            return optionals.getOption_S();
+         case "T":
+            return optionals.getOption_T();
+         case "U":
+            return optionals.getOption_U();
+         case "V":
+            return optionals.getOption_V();
+         case "W":
+            return optionals.getOption_W();
+         case "X":
+            return optionals.getOption_X();
+         case "Y":
+            return optionals.getOption_Y();
+         case "Z":
+            return optionals.getOption_Z();
+      }
+      LOGGER.warning( "No value specified on command line for " + optionChar );
+      return "";
+   }
+
+}

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CuiCollector.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CuiCollector.java?rev=1777834&r1=1777833&r2=1777834&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CuiCollector.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/CuiCollector.java
Sat Jan  7 18:23:50 2017
@@ -121,6 +121,13 @@ public enum CuiCollector {
    /**
     * Analysis Engine that stores collections of cuis by document id in the CuiCollector
     */
+   @PipeBitInfo(
+         name = "CUI Collector",
+         description = "Collects all CUIs generated during a run.",
+         role = PipeBitInfo.Role.SPECIAL,
+         input = "CUI " + PipeBitInfo.POPULATED_JCAS,
+         output = PipeBitInfo.NO_OUTPUT
+   )
    static public final class CuiCollectorEngine extends JCasAnnotator_ImplBase {
       @Override
       public void process( final JCas jCas ) {

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/EntityCollector.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/EntityCollector.java?rev=1777834&r1=1777833&r2=1777834&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/EntityCollector.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/EntityCollector.java
Sat Jan  7 18:23:50 2017
@@ -128,6 +128,13 @@ public enum EntityCollector {
    /**
     * Analysis Engine that stores collections of cuis by document id in the CuiCollector
     */
+   @PipeBitInfo(
+         name = "Entity Collector",
+         description = "Collects information on entities generated during a run.",
+         role = PipeBitInfo.Role.SPECIAL,
+         input = "IdentifiedAnnotation " + PipeBitInfo.POPULATED_JCAS,
+         output = PipeBitInfo.NO_OUTPUT
+   )
    static public final class EntityCollectorEngine extends JCasAnnotator_ImplBase {
       @Override
       public void process( final JCas jCas ) {

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfo.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfo.java?rev=1777834&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfo.java
(added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfo.java
Sat Jan  7 18:23:50 2017
@@ -0,0 +1,65 @@
+package org.apache.ctakes.core.pipeline;
+
+
+import java.lang.annotation.*;
+
+/**
+ * Annotation that should be used for Collection Readers, Annotators, and Cas Consumers (Writers).
+ * It may be useful for pipeline builder UIs and other human-pipeline interaction.
+ *
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 12/22/2016
+ */
+@Documented
+@Retention( RetentionPolicy.RUNTIME )
+@Target( ElementType.TYPE )
+@Inherited
+public @interface PipeBitInfo {
+   enum Role {
+      READER, ANNOTATOR, WRITER, SPECIAL
+   }
+
+   String NO_INPUT = "No Required Input.";
+   String NO_OUTPUT = "No Produced Output.";
+   String NO_PARAMETERS = "No Parameters.";
+   String NO_DEPENDENCIES = "No Dependencies.";
+   String NEW_JCAS = "New JCas.";
+   String POPULATED_JCAS = "Populated JCas.";
+
+   /**
+    * @return Human-readable name of the Reader, Annotator, or Writer
+    */
+   String name();
+
+   /**
+    * @return Role played within a pipeline
+    */
+   Role role() default Role.ANNOTATOR;
+
+   /**
+    * @return Human-readable description of the purpose of the Reader, Annotator, or Writer
+    */
+   String description();
+
+   /**
+    * @return Human-readable description of the input of the Reader, Annotator, or Writer
+    */
+   String input() default NO_INPUT;
+
+   /**
+    * @return Human-readable description of the output of the Reader, Annotator, or Writer
+    */
+   String output();
+
+   /**
+    * @return Human-readable names of Configuration Parameters
+    */
+   String[] parameters() default { NO_PARAMETERS };
+
+   /**
+    * @return Human-readable array of dependencies of the Reader, Annotator, or Writer
+    */
+   String[] dependencies() default { NO_DEPENDENCIES };
+
+}

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfoUtil.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfoUtil.java?rev=1777834&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfoUtil.java
(added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/PipeBitInfoUtil.java
Sat Jan  7 18:23:50 2017
@@ -0,0 +1,198 @@
+package org.apache.ctakes.core.pipeline;
+
+
+import org.apache.log4j.Logger;
+import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
+import org.apache.uima.collection.CasConsumer_ImplBase;
+import org.apache.uima.collection.CollectionReader_ImplBase;
+import org.apache.uima.fit.descriptor.ConfigurationParameter;
+
+import javax.annotation.concurrent.Immutable;
+import java.lang.reflect.Field;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 12/22/2016
+ */
+@Immutable
+final public class PipeBitInfoUtil {
+
+   static private final Logger LOGGER = Logger.getLogger( "PipeBitInfoUtil" );
+
+   private PipeBitInfoUtil() {
+   }
+
+   static public String getName( final Class<?> pipeBitClass ) {
+      return getInfo( pipeBitClass ).name();
+   }
+
+
+   /**
+    * @param pipeBitClass -
+    * @return If the class doesn't have explicitly declared PipeBitInfo then one is generated
automatically.
+    */
+   static public PipeBitInfo getInfo( final Class<?> pipeBitClass ) {
+      final PipeBitInfo info = pipeBitClass.getAnnotation( PipeBitInfo.class );
+      if ( info == null ) {
+         return new AutoPipeBitInfo( pipeBitClass );
+      }
+      return info;
+   }
+
+   /**
+    * @param pipeBitClass -
+    * @return all infos for the class and its parent classes.
+    * If the first class doesn't have explicitly declared PipeBitInfo then one is generated
automatically.
+    */
+   static public Collection<PipeBitInfo> getAllInfos( final Class<?> pipeBitClass
) {
+      final List<PipeBitInfo> infos = getSuperInfos( pipeBitClass.getSuperclass() );
+      infos.add( 0, getInfo( pipeBitClass ) );
+      return infos;
+   }
+
+   /**
+    * @param pipeBitClass -
+    * @return info for the given class and all of its parent classes
+    */
+   static private List<PipeBitInfo> getSuperInfos( final Class<?> pipeBitClass
) {
+      if ( pipeBitClass == null
+           || pipeBitClass.equals( CollectionReader_ImplBase.class )
+           || pipeBitClass.equals( JCasAnnotator_ImplBase.class )
+           || pipeBitClass.equals( CasConsumer_ImplBase.class ) ) {
+         return Collections.emptyList();
+      }
+      final List<PipeBitInfo> infos = new ArrayList<>();
+      final PipeBitInfo info = pipeBitClass.getAnnotation( PipeBitInfo.class );
+      if ( info != null ) {
+         infos.add( info );
+      }
+      infos.addAll( getSuperInfos( pipeBitClass.getSuperclass() ) );
+      return infos;
+   }
+
+   /**
+    * @param pipeBitClass -
+    * @return annotated parameters for the class and all of its parent classes
+    */
+   static public Collection<ConfigurationParameter> getAllParameters( final Class<?>
pipeBitClass ) {
+      if ( pipeBitClass == null
+           || pipeBitClass.equals( CollectionReader_ImplBase.class )
+           || pipeBitClass.equals( JCasAnnotator_ImplBase.class )
+           || pipeBitClass.equals( CasConsumer_ImplBase.class ) ) {
+         return Collections.emptyList();
+      }
+      final Field[] fields = pipeBitClass.getDeclaredFields();
+      final Collection<ConfigurationParameter> parameters = Arrays.stream( fields )
+            .map( f -> f.getAnnotation( ConfigurationParameter.class ) )
+            .filter( Objects::nonNull )
+            .collect( Collectors.toList() );
+      parameters.addAll( getAllParameters( pipeBitClass.getSuperclass() ) );
+      return parameters;
+   }
+
+   /**
+    * @param pipeBitClass -
+    * @return annotated parameters for the class and all of its parent classes
+    */
+   static private Collection<String> getParameterDescriptions( final Class<?>
pipeBitClass ) {
+      return getAllParameters( pipeBitClass ).stream()
+            .map( p -> p.name() + " : " + p.description() )
+            .collect( Collectors.toList() );
+   }
+
+
+   /**
+    * A PipeBitInfo built from information available via reflection
+    */
+   @Immutable
+   static private final class AutoPipeBitInfo implements PipeBitInfo {
+      private final Class<?> _pipeBitClass;
+
+      private AutoPipeBitInfo( final Class<?> pipeBitClass ) {
+         _pipeBitClass = pipeBitClass;
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String name() {
+         return _pipeBitClass.getSimpleName();
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String description() {
+         final String prefix = "Pipeline component that ";
+         String purpose = " has an unknown purpose.";
+         if ( CollectionReader_ImplBase.class.isAssignableFrom( _pipeBitClass ) ) {
+            purpose = "Reads or creates Text and provides it to a pipeline.";
+         } else if ( JCasAnnotator_ImplBase.class.isAssignableFrom( _pipeBitClass ) ) {
+            purpose = "Performs some Annotation task within a pipeline.";
+         } else if ( CasConsumer_ImplBase.class.isAssignableFrom( _pipeBitClass ) ) {
+            purpose = "Consumes Annotations and performs some task at the end of a pipeline.";
+         }
+         return name() + " : " + prefix + purpose;
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public Role role() {
+         if ( CollectionReader_ImplBase.class.isAssignableFrom( _pipeBitClass ) ) {
+            return Role.READER;
+         } else if ( CasConsumer_ImplBase.class.isAssignableFrom( _pipeBitClass ) ) {
+            return Role.WRITER;
+         }
+         return Role.ANNOTATOR;
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String input() {
+         return "Unknown Inputs.";
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String output() {
+         return "Unknown Outputs.";
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String[] parameters() {
+         final Collection<String> parameters = getParameterDescriptions( _pipeBitClass
);
+         return parameters.toArray( new String[ parameters.size() ] );
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public String[] dependencies() {
+         return new String[] { "Unknown Dependencies." };
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      @Override
+      public Class<? extends java.lang.annotation.Annotation> annotationType() {
+         return PipeBitInfo.class;
+      }
+   }
+
+}

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=1777834&r1=1777833&r2=1777834&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
Sat Jan  7 18:23:50 2017
@@ -92,7 +92,7 @@ final public class PiperFileReader {
    private PipelineBuilder _builder;
 
    private final Collection<String> _userPackages;
-
+   private CliOptionals _cliOptionals;
 
    /**
     * Create and empty PipelineReader
@@ -115,6 +115,24 @@ final public class PiperFileReader {
    }
 
    /**
+    * Create a PipelineReader and load a file with command parameter pairs for building a
pipeline
+    *
+    * @param filePath     path to the pipeline command file
+    * @param cliOptionals command line options pre-defined
+    * @throws UIMAException if the pipeline cannot be loaded
+    */
+   public PiperFileReader( final String filePath, final CliOptionals cliOptionals ) throws
UIMAException {
+      _builder = new PipelineBuilder();
+      _userPackages = new ArrayList<>();
+      setCliOptionals( cliOptionals );
+      loadPipelineFile( filePath );
+   }
+
+   public void setCliOptionals( final CliOptionals cliOptionals ) {
+      _cliOptionals = cliOptionals;
+   }
+
+   /**
     * Load a file with command parameter pairs for building a pipeline
     *
     * @param filePath path to the pipeline command file
@@ -166,6 +184,9 @@ final public class PiperFileReader {
          case "set":
             _builder.set( splitParameters( parameter ) );
             break;
+         case "cli":
+            _builder.set( getCliParameters( parameter ) );
+            break;
          case "reader":
             _builder.reader( createReader( parameter ) );
             break;
@@ -482,6 +503,8 @@ final public class PiperFileReader {
          keysAndValues[ i ] = keyAndValue[ 0 ];
          if ( keyAndValue.length == 1 ) {
             keysAndValues[ i + 1 ] = "";
+            i += 2;
+            continue;
          } else if ( keyAndValue.length > 2 ) {
             LOGGER.warn( "Multiple parameter values, using first of " + pair );
          }
@@ -491,6 +514,44 @@ final public class PiperFileReader {
       return keysAndValues;
    }
 
+   /**
+    * @param text -
+    * @return array created by splitting text ' ' and then at '=' characters
+    */
+   private Object[] getCliParameters( final String text ) {
+      if ( _cliOptionals == null ) {
+         LOGGER.error( "Attempting to set Parameter by Command-line options.  Command-line
options are not specified." );
+         return EMPTY_OBJECT_ARRAY;
+      }
+      if ( text == null || text.trim().isEmpty() ) {
+         return EMPTY_OBJECT_ARRAY;
+      }
+      final Matcher matcher = NAME_VALUE_PATTERN.matcher( text );
+      final List<String> pairList = new ArrayList<>();
+      while ( matcher.find() ) {
+         pairList.add( text.substring( matcher.start(), matcher.end() ) );
+      }
+      final String[] pairs = pairList.toArray( new String[ pairList.size() ] );
+      final Object[] keysAndValues = new Object[ pairs.length * 2 ];
+      int i = 0;
+      for ( String pair : pairs ) {
+         final String[] keyAndValue = KEY_VALUE_PATTERN.split( pair );
+         keysAndValues[ i ] = keyAndValue[ 0 ];
+         if ( keyAndValue.length == 1 ) {
+            keysAndValues[ i + 1 ] = "";
+            i += 2;
+            continue;
+         } else if ( keyAndValue.length > 2 ) {
+            LOGGER.warn( "Multiple parameter values, using first of " + pair );
+         }
+         keysAndValues[ i + 1 ] = getValueObject( CliOptionalsHandler
+               .getCliOptionalValue( _cliOptionals, keyAndValue[ 1 ] ) );
+         i += 2;
+      }
+      return keysAndValues;
+   }
+
+
    static private Object[] splitDescriptorValues( final String text ) {
       final Matcher matcher = QUOTE_VALUE_PATTERN.matcher( text );
       final List<String> valueList = new ArrayList<>();

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=1777834&r1=1777833&r2=1777834&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
Sat Jan  7 18:23:50 2017
@@ -2,7 +2,6 @@ package org.apache.ctakes.core.pipeline;
 
 
 import com.lexicalscope.jewel.cli.CliFactory;
-import com.lexicalscope.jewel.cli.Option;
 import org.apache.log4j.Logger;
 import org.apache.uima.UIMAException;
 
@@ -13,63 +12,18 @@ import java.io.IOException;
  * @version %I%
  * @since 10/13/2016
  */
-public class PiperFileRunner {
+final public class PiperFileRunner {
 
    static private final Logger LOGGER = Logger.getLogger( "PiperFileRunner" );
 
-   interface RunOptions {
-      @Option(
-            shortName = "p",
-            longName = "piper",
-            description = "path to the piper file containing commands and parameters for
pipeline configuration." )
-      String getPiperPath();
-
-      @Option(
-            shortName = "i",
-            longName = "inputDir",
-            description = "path to the directory containing the clinical notes to be processed.",
-            defaultValue = "" )
-      String getInputDirectory();
-
-      @Option(
-            shortName = "o",
-            longName = "outputDir",
-            description = "path to the directory where the output files are to be written.",
-            defaultValue = "" )
-      String getOutputDirectory();
-
-      @Option(
-            longName = "xmiOut",
-            description = "path to the directory where xmi files are to be written.  Adds
XmiWriter to pipeline.",
-            defaultValue = "" )
-      String getXmiOutDirectory();
-
-      @Option(
-            longName = "user",
-            description = "UMLS username.",
-            defaultValue = "" )
-      String getUmlsUserName();
-
-      @Option(
-            longName = "pass",
-            description = "UMLS user password.",
-            defaultValue = "" )
-      String getUmlsPassword();
-
-      @Option(
-            shortName = { "?", "h" },
-            longName = "help",
-            description = "print usage",
-            helpRequest = true )
-      boolean isHelpWanted();
-
+   private PiperFileRunner() {
    }
 
    /**
     * @param args general run options
     */
    public static void main( final String... args ) {
-      final RunOptions options = CliFactory.parseArguments( RunOptions.class, args );
+      final CliOptionals options = CliFactory.parseArguments( CliOptionals.class, args );
       try {
          final PiperFileReader reader = new PiperFileReader();
          final PipelineBuilder builder = reader.getBuilder();
@@ -98,6 +52,7 @@ public class PiperFileRunner {
             builder.set( "ctakes.umlspw", umlsPass );
          }
          // load the piper file
+         reader.setCliOptionals( options );
          reader.loadPipelineFile( options.getPiperPath() );
          // if an input directory was specified but the piper didn't add a collection reader,
add the default reader
          if ( !inputDir.isEmpty() && builder.getReader() == null ) {

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/StandardOptions.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/StandardOptions.java?rev=1777834&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/StandardOptions.java
(added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/pipeline/StandardOptions.java
Sat Jan  7 18:23:50 2017
@@ -0,0 +1,57 @@
+package org.apache.ctakes.core.pipeline;
+
+import com.lexicalscope.jewel.cli.Option;
+
+/**
+ * Standard Options for ctakes.  For instance; -p PiperFile, -i InputDir, -o OutputDir.
+ *
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 1/7/2017
+ */
+interface StandardOptions {
+   @Option(
+         shortName = "p",
+         longName = "piper",
+         description = "path to the piper file containing commands and parameters for pipeline
configuration." )
+   String getPiperPath();
+
+   @Option(
+         shortName = "i",
+         longName = "inputDir",
+         description = "path to the directory containing the clinical notes to be processed.",
+         defaultValue = "" )
+   String getInputDirectory();
+
+   @Option(
+         shortName = "o",
+         longName = "outputDir",
+         description = "path to the directory where the output files are to be written.",
+         defaultValue = "" )
+   String getOutputDirectory();
+
+   @Option(
+         longName = "xmiOut",
+         description = "path to the directory where xmi files are to be written.  Adds XmiWriter
to pipeline.",
+         defaultValue = "" )
+   String getXmiOutDirectory();
+
+   @Option(
+         longName = "user",
+         description = "UMLS username.",
+         defaultValue = "" )
+   String getUmlsUserName();
+
+   @Option(
+         longName = "pass",
+         description = "UMLS user password.",
+         defaultValue = "" )
+   String getUmlsPassword();
+
+   @Option(
+         shortName = "?",
+         longName = "help",
+         description = "print usage.",
+         helpRequest = true )
+   boolean isHelpWanted();
+}



Mime
View raw message