Return-Path: X-Original-To: apmail-ctakes-commits-archive@www.apache.org Delivered-To: apmail-ctakes-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A90E5106F2 for ; Wed, 30 Oct 2013 16:13:13 +0000 (UTC) Received: (qmail 88115 invoked by uid 500); 30 Oct 2013 16:10:34 -0000 Delivered-To: apmail-ctakes-commits-archive@ctakes.apache.org Received: (qmail 88053 invoked by uid 500); 30 Oct 2013 16:10:32 -0000 Mailing-List: contact commits-help@ctakes.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ctakes.apache.org Delivered-To: mailing list commits@ctakes.apache.org Received: (qmail 88036 invoked by uid 99); 30 Oct 2013 16:10:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Oct 2013 16:10:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Oct 2013 16:10:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AD9562388994; Wed, 30 Oct 2013 16:10:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1537153 - in /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe: ./ CmdLineCpeRunner.java Date: Wed, 30 Oct 2013 16:10:06 -0000 To: commits@ctakes.apache.org From: seanfinan@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131030161006.AD9562388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: seanfinan Date: Wed Oct 30 16:10:06 2013 New Revision: 1537153 URL: http://svn.apache.org/r1537153 Log: Added simple CPE Command line interface. No JIRA item, dev@ topic "cTAKES user interface" Broke build (silly maven) Rather than adding uima to the ctakes-utils pom, I'm moving this to ctakes-core Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java (with props) Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java?rev=1537153&view=auto ============================================================================== --- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java (added) +++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java Wed Oct 30 16:10:06 2013 @@ -0,0 +1,151 @@ +package org.apache.ctakes.core.cpe; + +import org.apache.uima.UIMAFramework; +import org.apache.uima.cas.CAS; +import org.apache.uima.collection.CollectionProcessingEngine; +import org.apache.uima.collection.EntityProcessStatus; +import org.apache.uima.collection.StatusCallbackListener; +import org.apache.uima.collection.metadata.CpeDescription; +import org.apache.uima.resource.ResourceInitializationException; +import org.apache.uima.util.InvalidXMLException; +import org.apache.uima.util.XMLInputSource; + +import java.io.IOException; +import java.util.List; + +/** + * Author: SPF + * Affiliation: CHIP-NLP + * Date: 1/17/13 + */ +public class CmdLineCpeRunner { + + + public static void main( String[] args ) { + if ( args.length == 0 || args[0].isEmpty() ) { + System.err.println( "Please provide the path to a cpe.xml in the first argument.\n" + + "If you do not have a cpe.xml you can create one with the cpe gui." ); + System.exit( 1 ); + } + XMLInputSource xmlInputSource = null; + try { + xmlInputSource = new XMLInputSource( args[0] ); + } catch ( IOException ioE ) { + System.err.println( "Couldn't open cpe xml " + args[0] ); + System.err.println( " " + ioE.getLocalizedMessage() ); + System.exit( 1 ); + } + CpeDescription cpeDescription = null; + try { + cpeDescription = UIMAFramework.getXMLParser().parseCpeDescription( xmlInputSource ); + } catch ( InvalidXMLException ixmlE ) { + System.err.println( "Couldn't parse cpe xml " + args[0] ); + System.err.println( " " + ixmlE.getLocalizedMessage() ); + System.exit( 1 ); + } + CollectionProcessingEngine collectionProcessingEngine = null; + try { + collectionProcessingEngine = UIMAFramework.produceCollectionProcessingEngine( cpeDescription ); + } catch ( ResourceInitializationException riE ) { + System.err.println( "Couldn't initialize processing engine." ); + System.err.println( " " + riE.getLocalizedMessage() ); + System.exit( 1 ); + } + collectionProcessingEngine.addStatusCallbackListener( new MyStatusCallbackListener() ); + + try { + collectionProcessingEngine.process(); + } catch ( ResourceInitializationException riE ) { + System.err.println( "Couldn't Run processing engine." ); + System.err.println( " " + riE.getLocalizedMessage() ); + System.exit( 1 ); + } + } + + + /** + * Callback Listener. Receives event notifications from CPE. + */ + static private class MyStatusCallbackListener implements StatusCallbackListener { + /** + * Start time of CPE initialization + */ + private long mStartTime = System.currentTimeMillis(); + + /** + * Start time of the processing + */ + private long mInitCompleteTime; + + int entityCount = 0; + + long size = 0; + + public void initializationComplete() { + System.out.println("CPM Initialization Complete"); + mInitCompleteTime = System.currentTimeMillis(); + } + + public void batchProcessComplete() { + System.out.print("Completed " + entityCount + " documents"); + if (size > 0) { + System.out.print("; " + size + " characters"); + } + System.out.println(); + long elapsedTime = System.currentTimeMillis() - mStartTime; + System.out.println("Time Elapsed : " + elapsedTime + " ms "); + } + + public void collectionProcessComplete() { + long time = System.currentTimeMillis(); + System.out.print("Completed " + entityCount + " documents"); + if (size > 0) { + System.out.print("; " + size + " characters"); + } + System.out.println(); + long initTime = mInitCompleteTime - mStartTime; + long processingTime = time - mInitCompleteTime; + long elapsedTime = initTime + processingTime; + System.out.println("Total Time Elapsed: " + elapsedTime + " ms "); + System.out.println("Initialization Time: " + initTime + " ms"); + System.out.println("Processing Time: " + processingTime + " ms"); + + System.out.println("\n\n ------------------ PERFORMANCE REPORT ------------------\n"); +// System.out.println(mCPE.getPerformanceReport().toString()); + // stop the JVM. Otherwise main thread will still be blocked waiting for + // user to press Enter. +// System.exit(1); + } + + public void paused() { + System.out.println("Paused"); + } + + public void resumed() { + System.out.println("Resumed"); + } + + public void aborted() { + System.out.println("Aborted"); + // stop the JVM. Otherwise main thread will still be blocked waiting for + // user to press Enter. + System.exit(1); + } + + public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) { + if (aStatus.isException()) { + List exceptions = aStatus.getExceptions(); + for (Exception exception : exceptions ) { + exception.printStackTrace(); + } + return; + } + entityCount++; + String docText = aCas.getDocumentText(); + if (docText != null) { + size += docText.length(); + } + } + } + +} Propchange: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cpe/CmdLineCpeRunner.java ------------------------------------------------------------------------------ svn:eol-style = native