You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/05/24 15:58:01 UTC

svn commit: r541304 - in /incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools: RunAE.java components/FileSystemCollectionReader.java components/InlineXmlCasConsumer.java

Author: eae
Date: Thu May 24 06:57:59 2007
New Revision: 541304

URL: http://svn.apache.org/viewvc?view=rev&rev=541304
Log:
UIMA-413

Modified:
    incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/RunAE.java
    incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/FileSystemCollectionReader.java
    incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/InlineXmlCasConsumer.java

Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/RunAE.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/RunAE.java?view=diff&rev=541304&r1=541303&r2=541304
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/RunAE.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/RunAE.java Thu May 24 06:57:59 2007
@@ -94,6 +94,8 @@
 
   private boolean xcasInput = false;
 
+  private boolean xmiInput = false;
+
   int docsProcessed;
 
   private CollectionProcessingEngine mCPE;
@@ -126,8 +128,11 @@
               .getAbsolutePath());
       crSettings.setParameterValue(FileSystemCollectionReader.PARAM_ENCODING, encoding);
       crSettings.setParameterValue(FileSystemCollectionReader.PARAM_LANGUAGE, language);
-      crSettings.setParameterValue(FileSystemCollectionReader.PARAM_XCAS, Boolean
-              .toString(xcasInput));
+      if (xcasInput) {
+        crSettings.setParameterValue(FileSystemCollectionReader.PARAM_XCAS, "XCAS");
+      } else if (xmiInput) {
+        crSettings.setParameterValue(FileSystemCollectionReader.PARAM_XCAS, "XMI");
+      }
 
       // if XML tag was specified, configure XmlDetagger annotator and add to CPE
       CpeCasProcessor xmlDetaggerCasProc = null;
@@ -159,8 +164,11 @@
         casCon.setConfigurationParameterSettings(consumerSettings);
         consumerSettings.setParameterValue(InlineXmlCasConsumer.PARAM_OUTPUTDIR, outputDir
                 .getAbsolutePath());
-        consumerSettings.setParameterValue(InlineXmlCasConsumer.PARAM_XCAS, Boolean
-                .toString(xcasInput));
+        if (xcasInput) {
+          consumerSettings.setParameterValue(InlineXmlCasConsumer.PARAM_XCAS, "XCAS");
+        } else if (xmiInput) {
+          consumerSettings.setParameterValue(InlineXmlCasConsumer.PARAM_XCAS, "XMI");
+        }
         casCon.setMaxErrorCount(0);
         cpeDesc.addCasProcessor(casCon);
       }
@@ -232,7 +240,7 @@
     } else if (genProgressMessages) {
       // retreive the filename of the input file from the CAS
       // (it was put there by the FileSystemCollectionReader)
-      if (!xcasInput) {
+      if (!(xcasInput || xmiInput)) {
         Type fileLocType = aCas.getTypeSystem().getType(
                 "org.apache.uima.examples.SourceDocumentInformation");
         Feature fileNameFeat = fileLocType.getFeatureByBaseName("uri");
@@ -308,6 +316,7 @@
     System.err.println("-s<x> (Stats level) - determines the verboseness of "
             + "performance statistics.  s0=none, s1=brief, s2=full.  The default is brief.");
     System.err.println("-x - process input files as XCAS files.");
+    System.err.println("-xmi - process input files as XmiCas files.");
 
   }
 
@@ -354,6 +363,9 @@
       } else if (arg.equals("-x")) // XCAS file input
       {
         xcasInput = true;
+      } else if (arg.equals("-xmi")) // XMI file input
+      {
+        xmiInput = true;
       } else // one of the standard params - whichever we haven't read yet
       {
         if (aeSpecifierFile == null) {

Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/FileSystemCollectionReader.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/FileSystemCollectionReader.java?view=diff&rev=541304&r1=541303&r2=541304
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/FileSystemCollectionReader.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/FileSystemCollectionReader.java Thu May 24 06:57:59 2007
@@ -30,6 +30,7 @@
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.impl.XCASDeserializer;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
 import org.apache.uima.collection.CollectionException;
 import org.apache.uima.collection.CollectionReaderDescription;
 import org.apache.uima.collection.CollectionReader_ImplBase;
@@ -88,7 +89,9 @@
 
   private int mCurrentIndex;
 
-  private boolean mXCAS;
+  private boolean mTEXT;
+
+  private String mXCAS;
 
   /**
    * @see org.apache.uima.collection.CollectionReader_ImplBase#initialize()
@@ -98,8 +101,8 @@
     File directory = new File(dirPath);
     mEncoding = (String) getConfigParameterValue(PARAM_ENCODING);
     mLanguage = (String) getConfigParameterValue(PARAM_LANGUAGE);
-    String tempXCAS = (String) getConfigParameterValue(PARAM_XCAS);
-    mXCAS = "true".equalsIgnoreCase(tempXCAS);
+    mXCAS = (String) getConfigParameterValue(PARAM_XCAS);
+    mTEXT = !("xcas".equalsIgnoreCase(mXCAS) || "xmi".equalsIgnoreCase(mXCAS));
 
     mCurrentIndex = 0;
 
@@ -140,7 +143,7 @@
     // open input stream to file
     File file = (File) mFiles.get(mCurrentIndex++);
     FileInputStream fis = new FileInputStream(file);
-    if (!mXCAS) {
+    if (mTEXT) {
       try {
         // if there's a CAS Initializer, call it
         if (getCasInitializer() != null) {
@@ -176,7 +179,12 @@
     // XCAS input files
     else {
       try {
-        XCASDeserializer.deserialize(fis, aCAS);
+        if (mXCAS.equalsIgnoreCase("XCAS")) {
+          XCASDeserializer.deserialize(fis, aCAS);
+        }
+        else {
+          XmiCasDeserializer.deserialize(fis, aCAS);
+        }
       } catch (SAXException e) {
         throw new CollectionException(e);
       } finally {

Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/InlineXmlCasConsumer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/InlineXmlCasConsumer.java?view=diff&rev=541304&r1=541303&r2=541304
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/InlineXmlCasConsumer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/InlineXmlCasConsumer.java Thu May 24 06:57:59 2007
@@ -32,6 +32,7 @@
 import org.apache.uima.cas.CASRuntimeException;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.impl.XCASSerializer;
+import org.apache.uima.cas.impl.XmiCasSerializer;
 import org.apache.uima.collection.CasConsumerDescription;
 import org.apache.uima.collection.CasConsumer_ImplBase;
 import org.apache.uima.examples.SourceDocumentInformation;
@@ -81,7 +82,9 @@
 
   private int mDocNum;
 
-  private boolean mXCAS;
+  private String mXCAS;
+  
+  private boolean mTEXT;
 
   public void initialize() throws ResourceInitializationException {
     mDocNum = 0;
@@ -90,12 +93,8 @@
       mOutputDir.mkdirs();
     }
     cas2xml = new CasToInlineXml();
-    String tempXCAS = (String) getConfigParameterValue(PARAM_XCAS);
-    if (0 == tempXCAS.compareToIgnoreCase("true")) {
-      mXCAS = true;
-    } else {
-      mXCAS = false;
-    }
+    mXCAS = (String) getConfigParameterValue(PARAM_XCAS);
+    mTEXT = !("xcas".equalsIgnoreCase(mXCAS) || "xmi".equalsIgnoreCase(mXCAS));
   }
 
   /**
@@ -122,7 +121,7 @@
     File outFile = null;
     boolean hasDefaultView = false;
 
-    if (!mXCAS) {
+    if (mTEXT) {
       // get the default View if it exists
       try {
         jcas = aCAS.getView(CAS.NAME_DEFAULT_SOFA).getJCas();
@@ -158,9 +157,15 @@
         String xmlAnnotations = cas2xml.generateXML(aCAS);
         outStream.write(xmlAnnotations.getBytes("UTF-8"));
       } else {
-        XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem());
         XMLSerializer xmlSer = new XMLSerializer(outStream, false);
-        ser.serialize(aCAS, xmlSer.getContentHandler());
+        if (mXCAS.equalsIgnoreCase("xcas")) {
+          XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem());
+          ser.serialize(aCAS, xmlSer.getContentHandler());
+        }
+        else {
+          XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem());
+          ser.serialize(aCAS, xmlSer.getContentHandler());
+        }
       }
     } catch (CASException e) {
       throw new ResourceProcessException(e);