0

I am using the Stanford NLPCore SU time libraries to build a temporal parser. I am having issues with setting the reference time. Here is my code :

public static String dateFormatString = "yyyy-MM-dd HH:mm";
private static void setup() {
    try {
        String defs_sutime = rulesFiles + "/defs.sutime.txt";
        String holiday_sutime = rulesFiles + "/english.holidays.sutime.txt";
        String _sutime = rulesFiles + "/english.sutime.txt";
        pipeline = new AnnotationPipeline();
        Properties props = new Properties();
        String sutimeRules = defs_sutime + "," + holiday_sutime
                + "," + _sutime;
        props.setProperty("sutime.rules", sutimeRules);
        props.setProperty("sutime.binders", "0");
        props.setProperty("sutime.markTimeRanges", "true");
        props.setProperty("sutime.includeRange", "true");
        pipeline.addAnnotator(new TokenizerAnnotator(false));
        pipeline.addAnnotator(new TimeAnnotator("sutime", props));
     } catch (Exception e) {
        e.printStackTrace();
     }
}
public void annotateText(String text, String referenceDate) {
    try {
        if (pipeline != null) {
            Annotation annotation = new Annotation(text);
            annotation.set(CoreAnnotations.DocDateAnnotation.class, referenceDate);
            pipeline.annotate(annotation);
            List<CoreMap> timexAnnsAll = annotation.get(TimeAnnotations.TimexAnnotations.class);
            for (CoreMap cm : timexAnnsAll) {
                try {
                    Temporal temporal = cm.get(TimeExpression.Annotation.class).getTemporal();

                    System.out.println("Token text : " + cm.toString());
                    System.out.println("Temporal Value : " + temporal.toString());
                    System.out.println("Timex : " + temporal.getTimexValue());

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            System.out.println("Annotation Pipeline object is NULL");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
} 

public static void main (String [] args) {
    UnderstandTime time = new UnderstandTime();
    setup();
    time.annotateText("20 minutes from now", "2015-07-20 10:00");
}

The output shows :

Token text : 20 minutes from now

Temporal Value : 2015-07-20T00:20

Timex : 2015-07-20T00:20

The reference time it picks is 00:00. Same output when I input "20 minutes later"

Belphegor
  • 4,456
  • 11
  • 34
  • 59
Shreya Bhat
  • 311
  • 2
  • 3
  • 13

1 Answers1

0

The datetime string you provide needs to be in an ISO format accepted in the date parser code. Try separating the date and time with a T rather than a space (not tested):

time.annotateText("20 minutes from now", "2015-07-20T10:00");
Jon Gauthier
  • 25,202
  • 6
  • 63
  • 69
  • I ran this example myself with Jon's suggestion and got the desired result: Token text : 20 minutes from now Temporal Value : 2015-07-20T10:20 Timex : 2015-07-20T10:20 – StanfordNLPHelp Nov 02 '15 at 10:10