001/** 002 * Copyright (c) 2007-2008, Regents of the University of Colorado 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without 006 * modification, are permitted provided that the following conditions are met: 007 * 008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 010 * Neither the name of the University of Colorado at Boulder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 011 * 012 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 013 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 014 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 015 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 016 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 017 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 018 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 019 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 020 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 021 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 022 * POSSIBILITY OF SUCH DAMAGE. 023 */ 024package org.cleartk.timeml.tlink; 025 026import java.io.File; 027import java.util.Arrays; 028 029import org.apache.uima.collection.CollectionReader; 030import org.apache.uima.util.Level; 031import org.apache.uima.util.Logger; 032import org.cleartk.opennlp.tools.ParserAnnotator; 033import org.cleartk.opennlp.tools.PosTaggerAnnotator; 034import org.cleartk.opennlp.tools.SentenceAnnotator; 035import org.cleartk.corpus.timeml.TempEval2007Writer; 036import org.cleartk.snowball.DefaultSnowballStemmer; 037import org.cleartk.token.tokenizer.TokenAnnotator; 038import org.cleartk.util.ae.UriToDocumentTextAnnotator; 039import org.cleartk.util.cr.UriCollectionReader; 040import org.apache.uima.fit.factory.UimaContextFactory; 041import org.apache.uima.fit.pipeline.SimplePipeline; 042 043/** 044 * <br> 045 * Copyright (c) 2007-2008, Regents of the University of Colorado <br> 046 * All rights reserved. 047 * 048 * @author Steven Bethard 049 */ 050public class VerbClauseTemporalAnnotate { 051 052 private static void error(String message) throws Exception { 053 Logger logger = UimaContextFactory.createUimaContext().getLogger(); 054 logger.log(Level.SEVERE, String.format("%s\nusage: " 055 + "VerbClauseTemporalAnnotate input-file-or-dir [output-dir]", message)); 056 System.exit(1); 057 } 058 059 public static void main(String[] args) throws Exception { 060 // check arguments 061 if (args.length != 1 && args.length != 2) { 062 error("wrong number of arguments"); 063 } else if (!new File(args[0]).exists()) { 064 error("file or directory not found: " + args[0]); 065 } 066 067 // parse arguments 068 File inputFileOrDir = new File(args[0]); 069 File outputDir; 070 if (args.length == 2) { 071 outputDir = new File(args[1]); 072 } else { 073 outputDir = new File("."); 074 } 075 if (!outputDir.exists()) { 076 outputDir.mkdirs(); 077 } 078 079 CollectionReader uriReader = (inputFileOrDir.isDirectory()) 080 ? UriCollectionReader.getCollectionReaderFromDirectory(inputFileOrDir) 081 : UriCollectionReader.getCollectionReaderFromFiles(Arrays.asList(inputFileOrDir)); 082 083 // run the components on the selected documents 084 SimplePipeline.runPipeline( 085 uriReader, 086 UriToDocumentTextAnnotator.getDescription(), 087 SentenceAnnotator.getDescription(), 088 TokenAnnotator.getDescription(), 089 PosTaggerAnnotator.getDescription(), 090 DefaultSnowballStemmer.getDescription("English"), 091 ParserAnnotator.getDescription(), 092 VerbClauseTemporalAnnotator.FACTORY.getAnnotatorDescription(), 093 TempEval2007Writer.getDescription(outputDir.getPath())); 094 } 095}