Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.ctakes.temporal.duration;
 import java.util.List;
 import java.util.Map;
Analyze duration information for the relation arguments of CONTAINS relation.

dmitriy dligach
 public class EventEventDurationStatistics {
   static interface Options {
     @Option(longName = "xmi-dir")
     public File getInputDirectory();
     @Option(longName = "patients")
     @Option(longName = "output-file")
     public File getOutputFile();
   public static void main(String[] argsthrows Exception {
     Options options = CliFactory.parseArguments(Options.classargs);
     List<IntegerpatientSets = options.getPatients().getList();
     List<IntegertrainItems = THYMEData.getPatientSets(patientSets.);
     List<FiletrainFiles = Utils.getFilesFor(trainItemsoptions.getInputDirectory());
     CollectionReader collectionReader = Utils.getCollectionReader(trainFiles);
     AnalysisEngine annotationConsumer = AnalysisEngineFactory.createEngine(

Look at event-event relations whose event arguments have duration data.
   public static class AnalyseRelationArgumentDuration extends JCasAnnotator_ImplBase {                                               
         name = "OutputFile",
         mandatory = true,
         description = "path to the file that stores relation data")
     private String outputFile;
     public static final String GOLD_VIEW_NAME = "GoldView";
     public void process(JCas jCasthrows AnalysisEngineProcessException {                                                     
      File durationLookup = new File(.);                      
      Map<StringMap<StringFloat>> textToDistribution = null;                                                                 
      try {                                                                                                                      
        textToDistribution = Files.readLines( Utils.Callback());                                    
      } catch(IOException e) {                                                                                                   
      JCas goldView;                                                                                                           
      try {                                                                                                                    
        goldView = jCas.getView();                                                                               
      } catch (CASException e) {                                                                                               
        throw new AnalysisEngineProcessException(e);                                                                           
      // find event-time relations where both arguments have duration information
      for(BinaryTextRelation relation : Lists.newArrayList( {
        if(! relation.getCategory().equals("CONTAINS")) {
        RelationArgument arg1 = relation.getArg1();                                                                             
        RelationArgument arg2 = relation.getArg2(); 
        String event1Text;
        String event2Text;
        if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof EventMention) {
          event1Text = Utils.normalizeEventText(jCasarg1.getArgument());
          event2Text = Utils.normalizeEventText(jCasarg2.getArgument());
        } else {
          // this is not an event-event relation
        if(textToDistribution.containsKey(event1Text) && textToDistribution.containsKey(event2Text)) {
          // there is duration information for both arguments
          float event1ExpectedDuration = Utils.expectedDuration(textToDistribution.get(event1Text));
          float event2ExpectedDuration = Utils.expectedDuration(textToDistribution.get(event2Text));
          String context = Utils.getTextBetweenAnnotations(goldViewarg1.getArgument(), arg2.getArgument());
          String out = String.format("%s|%.5f|%s|%.5f|%s\n"
              event1Textevent1ExpectedDuration * 3650, 
              event2Textevent2ExpectedDuration * 3650, 
              context.length() < 80 ? context : "...");
          try {
            Files.append(outnew File(), .);
          } catch (IOException e) {
New to GrepCode? Check out our FAQ X