Public
Edited
Nov 8, 2023
Insert cell
Insert cell
Insert cell
{
let doc = nlp(input)
// find and interpret each date in the text
let dates = doc.dates()
// reformat each one
//dates.format('{month} {date-ordinal}')
// return the text
return dates
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nlp(`we met on June 1st 1992 at 8pm, then got married 1998-03-28.`).dates().out('array')
Insert cell
Insert cell
nlp(`it was two weeks after christmas.`).dates().json()[0]
Insert cell
Insert cell
nlp(`see you in three days`).dates().get()[0]
Insert cell
Insert cell
doc =nlp(`i was born September 5th, 1993. March 4th, 2022`).dates().get()[1].start
Insert cell
match= {
var date = "";
let m;
const regex = /^\w*-\w*-[0-9]*/gm;
while ((m = regex.exec(doc)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
date = match;
});
}
return date
}
Insert cell
Insert cell
nlp('four days and seven hours passed').durations().get()[0]
Insert cell
Insert cell
nlp('30mins tuesday').durations().json()[0]
Insert cell
Insert cell
nlp('it was 3 in the morning').times().get()[0]
Insert cell
nlp('meet at 5pm PST').times().get()[0]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more