Note that there are some explanatory texts on larger screens.

plurals
  1. POfinding dates and their position within a string using stanford nlp
    primarykey
    data
    text
    <p>I need to find the dates within a string and their positions. Consider the example string</p> <p>"The interesting date is 4 days from today and it is 20th july of this year, another date is 18th Feb 1997" </p> <p>I need the output (Assuming today is 2013-07-14)<br> 2013-07-17, position 25<br> 2013-07-20, position 56<br> 1997-02-18, position 93 </p> <p>I have managed to write the code to get the various parts of the string that is recognized as date. Need to enhance/change this to achieve the above output. Any hints or help is appreciated:</p> <pre><code> Properties props = new Properties(); AnnotationPipeline pipeline = new AnnotationPipeline(); pipeline.addAnnotator(new PTBTokenizerAnnotator(false)); pipeline.addAnnotator(new WordsToSentencesAnnotator(false)); pipeline.addAnnotator(new POSTaggerAnnotator(false)); pipeline.addAnnotator(new TimeAnnotator("sutime", props)); Annotation annotation = new Annotation("The interesting date is 4 days from today and it is 20th july of this year, another date is 18th Feb 1997"); annotation.set(CoreAnnotations.DocDateAnnotation.class, "2013-07-14"); pipeline.annotate(annotation); List&lt;CoreMap&gt; timexAnnsAll = annotation.get(TimeAnnotations.TimexAnnotations.class); timexAnnsAll.each(){ println it } </code></pre> <p>With the above code I get the output as:<br> 4 days from today<br> 20th july of this year<br> 18th Feb 1997 </p> <p>EDIT::<br> Managed to get the date part, with the following change</p> <pre><code>timexAnnsAll.each(){it -&gt; Timex timex = it.get(TimeAnnotations.TimexAnnotation.class); println timex.val + " from : $it" } </code></pre> <p>Now the output is:<br> 2013-07-18 from : 4 days from today<br> 2013-07-20 from : 20th july of this year<br> 1997-02-18 from : 18th Feb 1997 </p> <p>All I need to solve now is to find the position of the date within the original string.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload