Skip to content

getRange() of SUTime.Temporal created with "this week" returns date with wrong year #235

Open
@mirosval

Description

@mirosval

Looks like an off-by-one error somewhere.

When I initialize a TimeExpression with strings containing "week" such as "this week", "last week", "next week", the TimeExpression itself is correct, but then when I try to get the beginning of the range (see code) I get the correct week, but a year earlier (i.e. now for 2016-07-26 when I say "this week" I get 2016-07-W30 from TimeExpression, but 2015-07-20 from TimeExpression.getRange.begin)

Please note that stuff like "next monday" "today" "tomorrow" "last wednesday" works as expected.

import java.time.LocalDate

import edu.stanford.nlp.ling.CoreAnnotations
import edu.stanford.nlp.pipeline.{Annotation, AnnotationPipeline, POSTaggerAnnotator, TokenizerAnnotator, WordsToSentencesAnnotator}
import edu.stanford.nlp.time.{TimeAnnotations, TimeAnnotator, TimeExpression}

import scala.collection.JavaConversions._

val annotationPipeline = new AnnotationPipeline()
annotationPipeline.addAnnotator(new TokenizerAnnotator(false))
annotationPipeline.addAnnotator(new WordsToSentencesAnnotator(false))
annotationPipeline.addAnnotator(new POSTaggerAnnotator(false))
annotationPipeline.addAnnotator(new TimeAnnotator())

val annotation = new Annotation("this week")
annotation.set(classOf[CoreAnnotations.DocDateAnnotation], LocalDate.now.toString)
annotationPipeline.annotate(annotation)

val timeAnnotations = annotation.get(classOf[TimeAnnotations.TimexAnnotations]).map { ann =>
  ann.get(classOf[TimeExpression.Annotation]).getTemporal
}

println(timeAnnotations) // <- correct
println(timeAnnotations.head.getRange.begin) // <- off by one year

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions