You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by dl...@apache.org on 2013/04/29 17:45:51 UTC

svn commit: r1477161 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis: EventContextAnalysisConsumer.java EventContextAnalysisPipeline.java

Author: dligach
Date: Mon Apr 29 15:45:44 2013
New Revision: 1477161

URL: http://svn.apache.org/r1477161
Log:
use configuration parameters instead of hard-coded values

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisConsumer.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisPipeline.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisConsumer.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisConsumer.java?rev=1477161&r1=1477160&r2=1477161&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisConsumer.java (original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisConsumer.java Mon Apr 29 15:45:44 2013
@@ -29,6 +29,7 @@ import org.apache.uima.cas.CASException;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
 import org.uimafit.util.JCasUtil;
 
 /**
@@ -39,12 +40,27 @@ import org.uimafit.util.JCasUtil;
  */
 public class EventContextAnalysisConsumer extends JCasAnnotator_ImplBase {
 
-  String tokenFile = "event-context/tokens.txt";
-  String eventFile = "event-context/events.txt";
+  @ConfigurationParameter(
+      name = "TokenOutputFile",
+      mandatory = true,
+      description = "path to the file that stores token contexts")
+  private String tokenOutputFile;
+
+  @ConfigurationParameter(
+      name = "EventOutputFile",
+      mandatory = true,
+      description = "path to the file that stores event contexts")
+  private String eventOutputFile;
+  
+  @ConfigurationParameter(
+      name = "ContextSize",
+      mandatory = true,
+      description = "context size in characters")
+  private int contextSize;
   
 	@Override
   public void process(JCas jCas) throws AnalysisEngineProcessException {
-
+	  
     JCas goldView;
     try {
       goldView = jCas.getView("GoldView");
@@ -59,12 +75,12 @@ public class EventContextAnalysisConsume
       throw new AnalysisEngineProcessException(e);
     }
 
-    BufferedWriter tokenWriter = getWriter(tokenFile, true);
-    BufferedWriter eventWriter = getWriter(eventFile, true);
+    BufferedWriter tokenWriter = getWriter(tokenOutputFile, true);
+    BufferedWriter eventWriter = getWriter(eventOutputFile, true);
       
     for(BaseToken baseToken : JCasUtil.select(systemView, BaseToken.class)) {
       String tokenText = baseToken.getCoveredText().toLowerCase();
-      String output = String.format("%s|%s\n", tokenText, getAnnotationContext(baseToken, 40));
+      String output = String.format("%s|%s\n", tokenText, getAnnotationContext(baseToken, contextSize));
       
       try {
         tokenWriter.write(output);
@@ -75,7 +91,7 @@ public class EventContextAnalysisConsume
 
     for(EventMention eventMention : JCasUtil.select(goldView, EventMention.class)) {
       String eventText = eventMention.getCoveredText().toLowerCase();
-      String output = String.format("%s|%s\n", eventText, getAnnotationContext(eventMention, 40));
+      String output = String.format("%s|%s\n", eventText, getAnnotationContext(eventMention, contextSize));
       
       try {
         eventWriter.write(output);

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisPipeline.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisPipeline.java?rev=1477161&r1=1477160&r2=1477161&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisPipeline.java (original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/EventContextAnalysisPipeline.java Mon Apr 29 15:45:44 2013
@@ -45,6 +45,24 @@ public class EventContextAnalysisPipelin
         usage = "specify the path to the directory containing the clinical notes to be processed",
         required = true)
     public File inputDirectory;
+
+    @Option(
+        name = "--token-output-file",
+        usage = "specify the path to the directory containing the clinical notes to be processed",
+        required = true)
+    public File tokenOutputFile;
+
+    @Option(
+        name = "--event-output-file",
+        usage = "specify the path to the directory containing the clinical notes to be processed",
+        required = true)
+    public File eventOutputFile;
+    
+    @Option(
+        name = "--context-size",
+        usage = "specify the number of characters to include on both sides",
+        required = false)
+    public int contextSize = 50;
   }
   
 	public static void main(String[] args) throws Exception {
@@ -55,10 +73,16 @@ public class EventContextAnalysisPipelin
 		List<File> trainFiles = Arrays.asList(options.inputDirectory.listFiles());
     CollectionReader collectionReader = getCollectionReader(trainFiles);
 		
-    AnalysisEngine relationExtractorConsumer = AnalysisEngineFactory.createPrimitive(
-    		EventContextAnalysisConsumer.class);
+    AnalysisEngine annotationConsumer = AnalysisEngineFactory.createPrimitive(
+    		EventContextAnalysisConsumer.class,
+    		"TokenOutputFile",
+    		options.tokenOutputFile,
+    		"EventOutputFile",
+    		options.eventOutputFile,
+    		"ContextSize",
+    		options.contextSize);
     		
-		SimplePipeline.runPipeline(collectionReader, relationExtractorConsumer);
+		SimplePipeline.runPipeline(collectionReader, annotationConsumer);
 	}
 	
   private static CollectionReader getCollectionReader(List<File> inputFiles) throws Exception {