All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.AdeptForumPostAnnotator Maven / Gradle / Ivy

The newest version!
package edu.stanford.nlp;

import edu.stanford.nlp.ling.CoreAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.Annotator;
import edu.stanford.nlp.util.*;

import java.util.*;

public class AdeptForumPostAnnotator implements Annotator {

  public static class AdeptForumPostDateInfoAnnotation implements CoreAnnotation {
    @Override
    public Class getType() {
      return HashMap.class;
    }
  }

  public AdeptForumPostAnnotator(String name, Properties props) {

  }

  public void annotate(Annotation annotation) {
    HashMap, String> forumPostDateInfo =
        annotation.get(AdeptForumPostDateInfoAnnotation.class);
    if (forumPostDateInfo != null) {
      // go through each sentence, find it's forum post, set to the section date of that forum post
      for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
        for (Pair forumPostOffsets : forumPostDateInfo.keySet()) {
          if (sentence.get(CoreAnnotations.TokenBeginAnnotation.class) >= forumPostOffsets.first() &&
              sentence.get(CoreAnnotations.TokenEndAnnotation.class) <= forumPostOffsets.second() + 1) {
            sentence.set(CoreAnnotations.SectionDateAnnotation.class,
                forumPostDateInfo.get(forumPostOffsets).split("T")[0]);
            System.err.println("Attaching date to forum post: "+forumPostDateInfo.get(forumPostOffsets));
            break;
          }
        }
      }
    }
  }

  @Override
  public Set> requires() {
    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
        CoreAnnotations.TextAnnotation.class,
        CoreAnnotations.TokensAnnotation.class,
        CoreAnnotations.SentencesAnnotation.class
    )));
  }

  @Override
  public Set> requirementsSatisfied() {
    return Collections.singleton(CoreAnnotations.SectionDateAnnotation.class);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy