ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1720023 - /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java
Date Mon, 14 Dec 2015 22:16:13 GMT
Author: clin
Date: Mon Dec 14 22:16:13 2015
New Revision: 1720023

URL: http://svn.apache.org/viewvc?rev=1720023&view=rev
Log:
add a fall back mechanism for getting document ID. If DocumentIDAnnotaionUtil.getDocumentID
gets null, try clearTK's ViewUriUtil.getURI

Modified:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java?rev=1720023&r1=1720022&r2=1720023&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/XmiWriterCasConsumerCtakes.java
Mon Dec 14 22:16:13 2015
@@ -74,146 +74,169 @@ import java.net.URL;
  * </ul>
  */
 public class XmiWriterCasConsumerCtakes extends CasConsumer_ImplBase {
-   /**
-    * 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 = "Output directory to write
xmi files", mandatory = true)
-   private File mOutputDir;
-
-   private int mDocNum;
-
-   @Override
-   public void initialize( UimaContext context ) throws ResourceInitializationException {
-      super.initialize( context );
-      mDocNum = 0;
-      if ( !mOutputDir.exists() ) {
-         mOutputDir.mkdirs();
-      }
-   }
-
-   /**
-    * Processes the CAS which was populated by the TextAnalysisEngines. <br>
-    * In this case, the CAS is converted to XMI and written into the output file .
-    *
-    * @param aCAS a CAS which has been populated by the TAEs
-    * @throws AnalysisEngineProcessException
-    * @see org.apache.uima.collection.base_cpm.CasObjectProcessor#processCas(org.apache.uima.cas.CAS)
-    */
-   @Override
-   public void process( CAS aCAS ) throws AnalysisEngineProcessException {
-      String modelFileName = null;
-
-      JCas jcas;
-      try {
-         jcas = aCAS.getJCas();
-      } catch ( CASException e1 ) {
-         e1.printStackTrace();
-         throw new AnalysisEngineProcessException( e1 );
-      }
-
-      String originalFileName = ViewUriUtil.getURI(jcas).toString();//DocumentIDAnnotationUtil.getDocumentID(
jcas );
-      File outFile = null;
-      if ( originalFileName != null
-           && !originalFileName.isEmpty()
-           && !originalFileName.equals( DocumentIDAnnotationUtil.NO_DOCUMENT_ID )
) {
-         File inFile;
-         try {
-            String outFileName = null;
-            if ( originalFileName.contains( "/" ) ) {
-               URI uri = UriUtils.quote( originalFileName );
-               inFile = new File( uri );
-               outFileName = inFile.getName();
-            } else {
-               outFileName = originalFileName;
-            }
-            outFileName += ".xmi";
-            outFile = new File( mOutputDir, outFileName );
-
-         } catch ( URISyntaxException e ) {
-            // bad URI, use default processing below
-         }
-
-      }
-      if ( outFile == null ) {
-         outFile = new File( mOutputDir, "doc" + mDocNum++ + ".xmi" ); // Jira UIMA-629
-      }
-      // serialize XCAS and write to output file
-      try {
-         writeXmi( jcas.getCas(), outFile, modelFileName );
-      } catch ( IOException e ) {
-         throw new AnalysisEngineProcessException( e );
-      } catch ( SAXException e ) {
-         throw new AnalysisEngineProcessException( e );
-      }
-   }
-
-   /**
-    * Serialize a CAS to a file in XMI format
-    *
-    * @param aCas CAS to serialize
-    * @param name output file
-    * @throws SAXException
-    * @throws Exception
-    * @throws ResourceProcessException
-    */
-   private void writeXmi( CAS aCas, File name ) throws IOException, SAXException {
-      FileOutputStream out = null;
-
-      try {
-         // write XMI
-         out = new FileOutputStream( name );
-         XmiCasSerializer ser = new XmiCasSerializer( aCas.getTypeSystem() );
-         XMLSerializer xmlSer = new XMLSerializer( out, false );
-         ser.serialize( aCas, xmlSer.getContentHandler() );
-      } finally {
-         if ( out != null ) {
-            out.close();
-         }
-      }
-   }
-
-   /**
-    * Serialize a CAS to a file in XMI format
-    *
-    * @param aCas CAS to serialize
-    * @param name output file
-    * @throws SAXException
-    * @throws Exception
-    * @throws ResourceProcessException
-    */
-   private void writeXmi( CAS aCas, File name, String modelFileName ) throws IOException,
SAXException {
-      FileOutputStream out = null;
-
-      try {
-         // write XMI
-         out = new FileOutputStream( name );
-         XmiCasSerializer ser = new XmiCasSerializer( aCas.getTypeSystem() );
-         XMLSerializer xmlSer = new XMLSerializer( out, false );
-         ser.serialize( aCas, xmlSer.getContentHandler() );
-      } finally {
-         if ( out != null ) {
-            out.close();
-         }
-      }
-   }
-
-   /**
-    * Parses and returns the descriptor for this collection reader. The descriptor is stored
in the
-    * uima.jar file and located using the ClassLoader.
-    *
-    * @return an object containing all of the information parsed from the descriptor.
-    * @throws InvalidXMLException if the descriptor is invalid or missing
-    */
-   public static CasConsumerDescription getDescription() throws InvalidXMLException {
-      InputStream descStream = XmiWriterCasConsumerCtakes.class
-            .getResourceAsStream( "XmiWriterCasConsumerCtakes.xml" );
-      return UIMAFramework.getXMLParser().parseCasConsumerDescription(
-            new XMLInputSource( descStream, null ) );
-   }
-
-   public static URL getDescriptorURL() {
-      return XmiWriterCasConsumerCtakes.class.getResource( "XmiWriterCasConsumerCtakes.xml"
);
-   }
+	/**
+	 * 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 = "Output directory to write
xmi files", mandatory = true)
+	private File mOutputDir;
+
+	private int mDocNum;
+
+	@Override
+	public void initialize( UimaContext context ) throws ResourceInitializationException {
+		super.initialize( context );
+		mDocNum = 0;
+		if ( !mOutputDir.exists() ) {
+			mOutputDir.mkdirs();
+		}
+	}
+
+	/**
+	 * Processes the CAS which was populated by the TextAnalysisEngines. <br>
+	 * In this case, the CAS is converted to XMI and written into the output file .
+	 *
+	 * @param aCAS a CAS which has been populated by the TAEs
+	 * @throws AnalysisEngineProcessException
+	 * @see org.apache.uima.collection.base_cpm.CasObjectProcessor#processCas(org.apache.uima.cas.CAS)
+	 */
+	@Override
+	public void process( CAS aCAS ) throws AnalysisEngineProcessException {
+		String modelFileName = null;
+
+		JCas jcas;
+		try {
+			jcas = aCAS.getJCas();
+		} catch ( CASException e1 ) {
+			e1.printStackTrace();
+			throw new AnalysisEngineProcessException( e1 );
+		}
+
+		String originalFileName = DocumentIDAnnotationUtil.getDocumentID( jcas );
+		File outFile = null;
+		if ( originalFileName != null
+				&& !originalFileName.isEmpty()
+				&& !originalFileName.equals( DocumentIDAnnotationUtil.NO_DOCUMENT_ID ) ) {
+			File inFile;
+			try {
+				String outFileName = null;
+				if ( originalFileName.contains( "/" ) ) {
+					URI uri = UriUtils.quote( originalFileName );
+					inFile = new File( uri );
+					outFileName = inFile.getName();
+				} else {
+					outFileName = originalFileName;
+				}
+				outFileName += ".xmi";
+				outFile = new File( mOutputDir, outFileName );
+
+			} catch ( URISyntaxException e ) {
+				// bad URI, use default processing below
+			}
+
+		}
+		if ( outFile == null ) {
+			originalFileName = ViewUriUtil.getURI(jcas).toString();
+			File inFile;
+			String outFileName = null;
+			if ( originalFileName != null
+					&& !originalFileName.isEmpty()
+					&& !originalFileName.equals( DocumentIDAnnotationUtil.NO_DOCUMENT_ID ) ) {
+				try {
+					if ( originalFileName.contains( "/" ) ) {
+						URI uri = UriUtils.quote( originalFileName );
+						inFile = new File( uri );
+						outFileName = inFile.getName();
+					} else {
+						outFileName = originalFileName;
+					}
+					outFileName += ".xmi";
+					outFile = new File( mOutputDir, outFileName );
+				} catch ( URISyntaxException e ) {
+					// bad URI, use default processing below
+				}
+			}
+		}
+
+		if ( outFile == null){
+			outFile = new File( mOutputDir, "doc" + mDocNum++ + ".xmi" ); // Jira UIMA-629
+		}
+		// serialize XCAS and write to output file
+		try {
+			writeXmi( jcas.getCas(), outFile, modelFileName );
+		} catch ( IOException e ) {
+			throw new AnalysisEngineProcessException( e );
+		} catch ( SAXException e ) {
+			throw new AnalysisEngineProcessException( e );
+		}
+	}
+
+	/**
+	 * Serialize a CAS to a file in XMI format
+	 *
+	 * @param aCas CAS to serialize
+	 * @param name output file
+	 * @throws SAXException
+	 * @throws Exception
+	 * @throws ResourceProcessException
+	 */
+	private void writeXmi( CAS aCas, File name ) throws IOException, SAXException {
+		FileOutputStream out = null;
+
+		try {
+			// write XMI
+			out = new FileOutputStream( name );
+			XmiCasSerializer ser = new XmiCasSerializer( aCas.getTypeSystem() );
+			XMLSerializer xmlSer = new XMLSerializer( out, false );
+			ser.serialize( aCas, xmlSer.getContentHandler() );
+		} finally {
+			if ( out != null ) {
+				out.close();
+			}
+		}
+	}
+
+	/**
+	 * Serialize a CAS to a file in XMI format
+	 *
+	 * @param aCas CAS to serialize
+	 * @param name output file
+	 * @throws SAXException
+	 * @throws Exception
+	 * @throws ResourceProcessException
+	 */
+	private void writeXmi( CAS aCas, File name, String modelFileName ) throws IOException, SAXException
{
+		FileOutputStream out = null;
+
+		try {
+			// write XMI
+			out = new FileOutputStream( name );
+			XmiCasSerializer ser = new XmiCasSerializer( aCas.getTypeSystem() );
+			XMLSerializer xmlSer = new XMLSerializer( out, false );
+			ser.serialize( aCas, xmlSer.getContentHandler() );
+		} finally {
+			if ( out != null ) {
+				out.close();
+			}
+		}
+	}
+
+	/**
+	 * Parses and returns the descriptor for this collection reader. The descriptor is stored
in the
+	 * uima.jar file and located using the ClassLoader.
+	 *
+	 * @return an object containing all of the information parsed from the descriptor.
+	 * @throws InvalidXMLException if the descriptor is invalid or missing
+	 */
+	public static CasConsumerDescription getDescription() throws InvalidXMLException {
+		InputStream descStream = XmiWriterCasConsumerCtakes.class
+				.getResourceAsStream( "XmiWriterCasConsumerCtakes.xml" );
+		return UIMAFramework.getXMLParser().parseCasConsumerDescription(
+				new XMLInputSource( descStream, null ) );
+	}
+
+	public static URL getDescriptorURL() {
+		return XmiWriterCasConsumerCtakes.class.getResource( "XmiWriterCasConsumerCtakes.xml" );
+	}
 }



Mime
View raw message