ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1813226 - /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java
Date Tue, 24 Oct 2017 19:40:37 GMT
Author: seanfinan
Date: Tue Oct 24 19:40:37 2017
New Revision: 1813226

URL: http://svn.apache.org/viewvc?rev=1813226&view=rev
Log:
Set document count in patient note store

Modified:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java

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=1813226&r1=1813225&r2=1813226&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
Oct 24 19:40:37 2017
@@ -1,6 +1,7 @@
 package org.apache.ctakes.core.cr;
 
 import org.apache.ctakes.core.config.ConfigParameterConstants;
+import org.apache.ctakes.core.patient.PatientNoteStore;
 import org.apache.ctakes.core.pipeline.PipeBitInfo;
 import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.ctakes.typesystem.type.structured.DocumentID;
@@ -21,10 +22,7 @@ import org.apache.uima.util.ProgressImpl
 import java.io.*;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -84,10 +82,25 @@ final public class FileTreeReader extend
    )
    private String[] _explicitExtensions;
 
+   /**
+    * Name of optional configuration parameter that specifies the extensions
+    * of the files that the collection reader will read.  Values for this
+    * parameter should not begin with a dot <code>'.'</code>.
+    */
+   public static final String PATIENT_LEVEL = "PatientLevel";
+   @ConfigurationParameter(
+         name = PATIENT_LEVEL,
+         description = "The level in the directory hierarchy at which patient identifiers
exist."
+               + "Default value is 1; directly under root input directory.",
+         mandatory = false
+   )
+   private int _patientLevel = 1;
+
    private File _rootDir;
    private Collection<String> _validExtensions;
    private List<File> _files;
    private int _currentIndex;
+   private Map<String, Integer> _patientDocCounts = new HashMap<>();
 
    /**
     * {@inheritDoc}
@@ -102,7 +115,8 @@ final public class FileTreeReader extend
       }
       _validExtensions = createValidExtensions( _explicitExtensions );
       _currentIndex = 0;
-      _files = getDescendentFiles( _rootDir, _validExtensions );
+      _files = getDescendentFiles( _rootDir, _validExtensions, 0 );
+      _patientDocCounts.forEach( ( k, v ) -> PatientNoteStore.getInstance().setDocCount(
k, v ) );
    }
 
    /**
@@ -131,9 +145,10 @@ final public class FileTreeReader extend
    /**
     * @param parentDir       -
     * @param validExtensions collection of valid extensions or empty collection if all extensions
are valid
+    * @param level directory level beneath the root directory
     * @return List of files descending from the parent directory
     */
-   static private List<File> getDescendentFiles( final File parentDir, final Collection<String>
validExtensions ) {
+   private List<File> getDescendentFiles( final File parentDir, final Collection<String>
validExtensions, final int level ) {
       final File[] children = parentDir.listFiles();
       if ( children == null || children.length == 0 ) {
          return Collections.emptyList();
@@ -150,7 +165,12 @@ final public class FileTreeReader extend
          }
       }
       for ( File childDir : childDirs ) {
-         descendentFiles.addAll( getDescendentFiles( childDir, validExtensions ) );
+         descendentFiles.addAll( getDescendentFiles( childDir, validExtensions, level + 1
) );
+      }
+      if ( level == _patientLevel ) {
+         final String patientId = parentDir.getName();
+         final int count = _patientDocCounts.getOrDefault( patientId, 0 );
+         _patientDocCounts.put( patientId, count + descendentFiles.size() );
       }
       return descendentFiles;
    }



Mime
View raw message