Examples of TimeMention


Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

      } else if ("SECTIONTIME".equals(annotation.type)) {
        // TODO

      } else if ("TIMEX3".equals(annotation.type)) {
        String timexClass = stringSlots.remove("class");
        TimeMention timeMention = new TimeMention(jCas, coveringSpan.begin, coveringSpan.end);
        timeMention.addToIndexes();
        idAnnotationMap.put(annotation.id, timeMention);
        // TODO

      } else if ("generic_class".equals(annotation.type)) {
        // TODO: there's currently no Generic in the type system
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  @Override
  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    ArrayList<Feature> feats = new ArrayList<>();
    EventMention event = null;
    TimeMention time = null;

    if(arg1 instanceof EventMention){
      event = JCasUtil.selectCovering(jCas, EventMention.class, arg1.getBegin(), arg1.getEnd()).get(0);
      if( event != null && event.getEvent() !=null ){
        feats.add(new Feature("Arg1-Event-Modality", event.getEvent().getProperties().getContextualModality()));
      }
    }else if(arg1 instanceof TimeMention){
      time = (TimeMention) arg1;
      if( time != null){
        feats.add(new Feature("Arg1-Timex-", time.getTimeClass()));
      }     
    }

    if(arg2 instanceof TimeMention){
      time = (TimeMention) arg2;
      if(time != null){
        feats.add(new Feature("Arg2-Timex-", time.getTimeClass()));
      }
    }else if(arg2 instanceof EventMention){
      event = JCasUtil.selectCovering(jCas, EventMention.class, arg2.getBegin(), arg2.getEnd()).get(0);
      if(event !=null && event.getEvent() !=null ){
        feats.add(new Feature("Arg2-Event-Modality", event.getEvent().getProperties().getContextualModality()));
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  @Override
  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    ArrayList<Feature> feats = new ArrayList<Feature>();
    EventMention event = null;
    TimeMention time = null;
   
    // swap the order if necessary:
    if(arg2.getBegin() <= arg1.getBegin() && arg2.getEnd() <= arg1.getEnd()){
      IdentifiedAnnotation temp = arg1;
      arg1 = arg2;
      arg2 = temp;
    }

    if(arg1 instanceof EventMention){
      event = (EventMention) arg1;
      time = (TimeMention) arg2;
    }else{
      time = (TimeMention) arg1;
      event = (EventMention) arg2;
    }
   
    //1 get covering sentence:
    Map<EventMention, Collection<Sentence>> eventCoveringMap =
        JCasUtil.indexCovering(jCas, EventMention.class, Sentence.class);
    Collection<Sentence> eventSentList = eventCoveringMap.get(event);
    Map<TimeMention, Collection<Sentence>> timeCoveringMap =
        JCasUtil.indexCovering(jCas, TimeMention.class, Sentence.class);
    Collection<Sentence> timeSentList = timeCoveringMap.get(time);

    //2 get TimeX
    Map<Integer, TimeMention> timeDistMap = null;
    Map<Integer, EventMention> eventDistMap = null;
   
    if (eventSentList != null && !eventSentList.isEmpty()){
      timeDistMap = new TreeMap<Integer, TimeMention>();

      for(Sentence sent : eventSentList) {
        for (TimeMention atime : JCasUtil.selectCovered(jCas, TimeMention.class, sent)) {
          timeDistMap.put(Math.abs(atime.getBegin() - event.getBegin()), atime);
        }
      }

      //get the closest Time Expression feature
      for (Map.Entry<Integer, TimeMention> entry : timeDistMap.entrySet()) {
        if( entry.getValue().equals(time)){
          Feature indicator = new Feature("ClosestPair", "ClosestPair");
          feats.add(indicator);
          return feats;
        }
        break;
      }
    }

    if (timeSentList != null && !timeSentList.isEmpty()){
      eventDistMap = new TreeMap<Integer, EventMention>();

      for(Sentence sent : timeSentList) {
        for (EventMention aEvent : JCasUtil.selectCovered(jCas, EventMention.class, sent)) {
          eventDistMap.put(Math.abs(aEvent.getBegin() - time.getBegin()), aEvent);
        }
      }

      //get the closest Event feature
      for (Map.Entry<Integer, EventMention> entry : eventDistMap.entrySet()) {
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  @Override
  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    ArrayList<Feature> feats = new ArrayList<>();
    EventMention event = null;
    TimeMention time = null;

    // swap the order if necessary:
//    if(arg2.getBegin() <= arg1.getBegin() && arg2.getEnd() <= arg1.getEnd()){
//      IdentifiedAnnotation temp = arg1;
//      arg1 = arg2;
//      arg2 = temp;
//    }

    if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
      event = JCasUtil.selectCovering(jCas, EventMention.class, arg1.getBegin(), arg1.getEnd()).get(0);
      time = (TimeMention)arg2;
      if(event!=null && event.getEvent()!=null)
        feats.add(new Feature("Event-Modality-", event.getEvent().getProperties().getContextualModality()));
      feats.add(new Feature("Time-Class-", time.getTimeClass()));
    }else if(arg2 instanceof EventMention && arg1 instanceof TimeMention){
      time = (TimeMention)arg1;
      event = JCasUtil.selectCovering(jCas, EventMention.class, arg2.getBegin(), arg2.getEnd()).get(0);
      feats.add(new Feature("Timex-Class-", time.getTimeClass()));
      if(event!=null && event.getEvent()!=null)
        feats.add(new Feature("Event-Modality-", event.getEvent().getProperties().getContextualModality()));
    }
   
   
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  @Override
  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    ArrayList<Feature> feats = new ArrayList<Feature>();
    EventMention event = null;
    TimeMention time = null;
   
    if(arg1 instanceof EventMention){
      event = (EventMention) arg1;
      time = (TimeMention) arg2;
    }else{
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  }

  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    //get discharge Time id: T1:
    TimeMention admissionTime = null;
    //TODO
    //may need better way to identify Discharge Time other than relative span information:
    for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, 15, 30)) {
      if(time.getTimeClass().equals("DATE")){
        admissionTime = time;
        break;
      }
    }
    if (admissionTime != null){
      //get event-time1 relations:
      Map<List<Annotation>, TemporalTextRelation> dischargeTimeRelationLookup;
        dischargeTimeRelationLookup = new HashMap<>();
        if (this.isTraining()) {
          dischargeTimeRelationLookup = new HashMap<>();
          for (TemporalTextRelation relation : JCasUtil.select(jCas, TemporalTextRelation.class)) {
            Annotation arg1 = relation.getArg1().getArgument();
            Annotation arg2 = relation.getArg2().getArgument();
            // The key is a list of args so we can do bi-directional lookup
            if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
              if( arg1==admissionTime){
                dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
                continue;
              }
            }else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
              if( arg2==admissionTime ){
                dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
                continue;
              }
            }
           
          }
        }
       
      for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
        if (eventMention.getEvent() != null) {
          List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
          features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add nearby verb POS pattern feature
          features.addAll(this.sectionIDExtractor.extract(jCas, eventMention)); //add section heading
          features.addAll(this.closestVerbExtractor.extract(jCas, eventMention)); //add closest verb
          features.addAll(this.timeXExtractor.extract(jCas, eventMention)); //add the closest time expression types
          features.addAll(this.genericExtractor.extract(jCas, eventMention)); //add the closest time expression types
          features.addAll(this.dateExtractor.extract(jCas, eventMention)); //add the closest NE type
          features.addAll(this.umlsExtractor.extract(jCas, eventMention)); //add umls features
          //        features.addAll(this.durationExtractor.extract(jCas, eventMention)); //add duration feature
          //        features.addAll(this.disSemExtractor.extract(jCas, eventMention)); //add distributional semantic features
          if (this.isTraining()) {
            TemporalTextRelation relation = dischargeTimeRelationLookup.get(Arrays.asList(eventMention, admissionTime));
            String category = null;
            if (relation != null) {
              category = relation.getCategory();
            } else {
              relation = dischargeTimeRelationLookup.get(Arrays.asList(admissionTime, eventMention));
              if (relation != null) {
                if(relation.getCategory().equals("OVERLAP")){
                  category = relation.getCategory();
                }else if (relation.getCategory().equals("BEFORE")){
                  category = "AFTER";
                }else if (relation.getCategory().equals("AFTER")){
                  category = "BEFORE";
                }
              }
            }
            if(category!=null){
              this.dataWriter.write(new Instance<>(category, features));
            }
          } else {
            String outcome = this.classifier.classify(features);
            if(outcome!=null){
              // add the relation to the CAS
                RelationArgument relArg1 = new RelationArgument(jCas);
                relArg1.setArgument(eventMention);
                relArg1.setRole("Argument");
                relArg1.addToIndexes();
                RelationArgument relArg2 = new RelationArgument(jCas);
                relArg2.setArgument(admissionTime);
                relArg2.setRole("Related_to");
                relArg2.addToIndexes();
                TemporalTextRelation relation = new TemporalTextRelation(jCas);
                relation.setArg1(relArg1);
                relation.setArg2(relArg2);
                relation.setCategory(outcome);
                relation.addToIndexes();
            }else{
              System.out.println("cannot classify "+ eventMention.getCoveredText()+" and " + admissionTime.getCoveredText());
            }
          }
        }
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

        if(mention.getCoveredText().equals(mentionText)) {
          if(isNegated(jCas, mention) || isMedicationPattern(jCas, mention)) {
            continue;
          }

          TimeMention nearestTimeMention = getNearestTimeMention(jCas, mention);
          if(nearestTimeMention == null) {
            continue;
          }
         
          // try to parse this timex with Bethard normalizer
          HashSet<String> timeUnits = Utils.getTimeUnits(nearestTimeMention.getCoveredText());
          if(timeUnits.size() > 0) {
            for(String timeUnit : timeUnits) {
              durationDistribution.add(timeUnit);
            }
          } else {
            // could be an abbreviation e.g. "wks"
            Matcher matcher = pattern.matcher(nearestTimeMention.getCoveredText());
            // need a loop to handle things like 'several days/weeks'
            while(matcher.find()) {
              String matchedTimeUnit = matcher.group(); // e.g. "wks"
              String normalizedTimeUnit = abbreviationToTimeUnit.get(matchedTimeUnit);
              durationDistribution.add(normalizedTimeUnit);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

        return null;
      }
     
      assert timeMentions.size() == 1;
     
      TimeMention nearestTimeMention = timeMentions.get(0);
      int distance = JCasUtil.selectBetween(jCas, BaseToken.class, mention, nearestTimeMention).size();
      if(distance > MAXDISTANCE) {
        return null;
      }
     
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

  }

  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    //get discharge Time id: T1:
    TimeMention dischargeTime = null;
    //TODO
    //may need better way to identify Discharge Time other than relative span information:
    for (TimeMention time : JCasUtil.selectCovered(jCas, TimeMention.class, 40, 60)) {
      if(time.getTimeClass().equals("DATE")){
        dischargeTime = time;
        break;
      }
    }
    if (dischargeTime != null){
      //get event-time1 relations:
      Map<List<Annotation>, TemporalTextRelation> dischargeTimeRelationLookup;
        dischargeTimeRelationLookup = new HashMap<>();
        if (this.isTraining()) {
          dischargeTimeRelationLookup = new HashMap<>();
          for (TemporalTextRelation relation : JCasUtil.select(jCas, TemporalTextRelation.class)) {
            Annotation arg1 = relation.getArg1().getArgument();
            Annotation arg2 = relation.getArg2().getArgument();
            // The key is a list of args so we can do bi-directional lookup
            if(arg1 instanceof TimeMention && arg2 instanceof EventMention ){
              if( arg1==dischargeTime){
                dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
                continue;
              }
            }else if(arg1 instanceof EventMention && arg2 instanceof TimeMention){
              if( arg2==dischargeTime ){
                dischargeTimeRelationLookup.put(Arrays.asList(arg1, arg2), relation);
                continue;
              }
            }
           
          }
        }
       
      for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
        if (eventMention.getEvent() != null) {
          List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
          features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add nearby verb POS pattern feature
          features.addAll(this.sectionIDExtractor.extract(jCas, eventMention)); //add section heading
          features.addAll(this.closestVerbExtractor.extract(jCas, eventMention)); //add closest verb
          features.addAll(this.timeXExtractor.extract(jCas, eventMention)); //add the closest time expression types
          features.addAll(this.genericExtractor.extract(jCas, eventMention)); //add the closest time expression types
          features.addAll(this.dateExtractor.extract(jCas, eventMention)); //add the closest NE type
          features.addAll(this.umlsExtractor.extract(jCas, eventMention)); //add umls features
          //        features.addAll(this.durationExtractor.extract(jCas, eventMention)); //add duration feature
          //        features.addAll(this.disSemExtractor.extract(jCas, eventMention)); //add distributional semantic features
          if (this.isTraining()) {
            TemporalTextRelation relation = dischargeTimeRelationLookup.get(Arrays.asList(eventMention, dischargeTime));
            String category = null;
            if (relation != null) {
              category = relation.getCategory();
            } else {
              relation = dischargeTimeRelationLookup.get(Arrays.asList(dischargeTime, eventMention));
              if (relation != null) {
                if(relation.getCategory().equals("OVERLAP")){
                  category = relation.getCategory();
                }else if (relation.getCategory().equals("BEFORE")){
                  category = "AFTER";
                }else if (relation.getCategory().equals("AFTER")){
                  category = "BEFORE";
                }
              }
            }
            if(category!=null){
              this.dataWriter.write(new Instance<>(category, features));
            }
          } else {
            String outcome = this.classifier.classify(features);
            if(outcome!=null){
              // add the relation to the CAS
                RelationArgument relArg1 = new RelationArgument(jCas);
                relArg1.setArgument(eventMention);
                relArg1.setRole("Argument");
                relArg1.addToIndexes();
                RelationArgument relArg2 = new RelationArgument(jCas);
                relArg2.setArgument(dischargeTime);
                relArg2.setRole("Related_to");
                relArg2.addToIndexes();
                TemporalTextRelation relation = new TemporalTextRelation(jCas);
                relation.setArg1(relArg1);
                relation.setArg2(relArg2);
                relation.setCategory(outcome);
                relation.addToIndexes();
            }else{
              System.out.println("cannot classify "+ eventMention.getCoveredText()+" and " + dischargeTime.getCoveredText());
            }           
          }
        }
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.TimeMention

          timexCas = jCas.getView(timexView);
        } catch (CASException e) {
          throw new AnalysisEngineProcessException(e);
        }

        TimeMention mention = new TimeMention(timexCas, node.getBegin(), node.getEnd());
        mention.setConfidence((float)score);
        mention.addToIndexes();
      }else{
        score = 1 - score;
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.