001/* 002 * Copyright (c) 2011, 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.util.List; 027 028import org.apache.uima.UimaContext; 029import org.apache.uima.analysis_engine.AnalysisEngineDescription; 030import org.apache.uima.jcas.JCas; 031import org.apache.uima.resource.ResourceInitializationException; 032import org.cleartk.ml.feature.extractor.CoveredTextExtractor; 033import org.cleartk.ml.feature.extractor.FeatureExtractor1; 034import org.cleartk.ml.feature.extractor.TypePathExtractor; 035import org.cleartk.ml.liblinear.LibLinearStringOutcomeDataWriter; 036import org.cleartk.timeml.type.DocumentCreationTime; 037import org.cleartk.timeml.type.Event; 038import org.cleartk.timeml.util.CleartkInternalModelFactory; 039import org.cleartk.feature.FilteringExtractor; 040import org.cleartk.token.type.Sentence; 041import org.apache.uima.fit.factory.AnalysisEngineFactory; 042import org.apache.uima.fit.util.JCasUtil; 043 044import com.google.common.collect.Lists; 045 046/** 047 * <br> 048 * Copyright (c) 2011, Regents of the University of Colorado <br> 049 * All rights reserved. 050 * 051 * @author Steven Bethard 052 */ 053public class TemporalLinkEventToDocumentCreationTimeAnnotator extends 054 TemporalLinkAnnotator_ImplBase<Event, DocumentCreationTime> { 055 056 public static final CleartkInternalModelFactory FACTORY = new CleartkInternalModelFactory() { 057 @Override 058 public Class<?> getAnnotatorClass() { 059 return TemporalLinkEventToDocumentCreationTimeAnnotator.class; 060 } 061 062 @Override 063 public Class<?> getDataWriterClass() { 064 return LibLinearStringOutcomeDataWriter.class; 065 } 066 067 @Override 068 public AnalysisEngineDescription getBaseDescription() throws ResourceInitializationException { 069 return AnalysisEngineFactory.createEngineDescription(TemporalLinkEventToDocumentCreationTimeAnnotator.class); 070 } 071 }; 072 073 public TemporalLinkEventToDocumentCreationTimeAnnotator() { 074 super(Event.class, DocumentCreationTime.class, "BEFORE", "AFTER", "INCLUDES"); 075 } 076 077 @Override 078 public void initialize(UimaContext context) throws ResourceInitializationException { 079 super.initialize(context); 080 081 // I explored a ton of features here, and the following were the only ones that worked 082 // The only feature that I didn't try that seems like it might still have some promise 083 // would be to find any times within, say, 5 tokens, and do the time value comparison 084 // to see whether the nearby time is before, overlapping with or after the DCT 085 List<FeatureExtractor1<Event>> srcExtractors = Lists.newArrayList(); 086 srcExtractors.add(new TypePathExtractor<Event>(Event.class, "tense")); 087 srcExtractors.add(new TypePathExtractor<Event>(Event.class, "aspect")); 088 srcExtractors.add(new TypePathExtractor<Event>(Event.class, "eventClass")); 089 srcExtractors.add(new TypePathExtractor<Event>(Event.class, "polarity")); 090 srcExtractors.add(new TypePathExtractor<Event>(Event.class, "modality")); 091 // the word, but only if it's an aspectual event 092 srcExtractors.add( 093 new FilteringExtractor<Event>(Event.class, new CoveredTextExtractor<Event>()) { 094 @Override 095 protected boolean accept(Event event) { 096 return event.getEventClass().equals("ASPECTUAL"); 097 } 098 }); 099 this.setSourceExtractors(srcExtractors); 100 } 101 102 @Override 103 protected List<SourceTargetPair> getSourceTargetPairs(JCas jCas) { 104 List<SourceTargetPair> pairs = Lists.newArrayList(); 105 DocumentCreationTime dct = JCasUtil.selectSingle(jCas, DocumentCreationTime.class); 106 for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) { 107 for (Event event : JCasUtil.selectCovered(jCas, Event.class, sentence)) { 108 pairs.add(new SourceTargetPair(event, dct)); 109 } 110 } 111 return pairs; 112 } 113}