-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #833 from spencermountain/dev
Dev
- Loading branch information
Showing
51 changed files
with
941 additions
and
616 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "compromise-dates", | ||
"description": "plugin for nlp-compromise", | ||
"version": "2.0.3", | ||
"version": "2.2.0", | ||
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)", | ||
"main": "./builds/compromise-dates.js", | ||
"unpkg": "./builds/compromise-dates.min.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const split = require('./split') | ||
|
||
const findDate = function (doc) { | ||
if (doc.world.isVerbose() === 'date') { | ||
doc.debug() | ||
console.log(' ---') | ||
} | ||
let dates = doc.match('#Date+') | ||
// ignore only-durations like '20 minutes' | ||
dates = dates.filter((m) => { | ||
let isDuration = m.has('^#Duration+$') || m.has('^#Value #Duration+$') | ||
// allow 'q4', etc | ||
if (isDuration === true && m.has('(#FinancialQuarter|quarter)')) { | ||
return true | ||
} | ||
return isDuration === false | ||
}) | ||
// 30 minutes on tuesday | ||
let m = dates.match('[#Cardinal #Duration (in|on|this|next|during|for)] #Date', 0) | ||
if (m.found) { | ||
dates = dates.not(m) | ||
} | ||
// 30 minutes tuesday | ||
m = dates.match('[#Cardinal #Duration] #WeekDay', 0) | ||
if (m.found) { | ||
dates = dates.not(m) | ||
} | ||
// tuesday for 30 mins | ||
m = dates.match('#Date [for #Value #Duration]$', 0) | ||
if (m.found) { | ||
dates = dates.not(m) | ||
} | ||
// '20 minutes june 5th' | ||
m = dates.match('[#Cardinal #Duration] #Date', 0) //but allow '20 minutes ago' | ||
if (m.found && !dates.has('#Cardinal #Duration] (ago|from|before|after|back)')) { | ||
dates = dates.not(m) | ||
} | ||
// for 20 minutes | ||
m = dates.match('for #Cardinal #Duration') | ||
if (m.found) { | ||
dates = dates.not(m) | ||
} | ||
// 'one saturday' | ||
dates = dates.notIf('^one (#WeekDay|#Month)$') | ||
// tokenize the dates | ||
dates = split(dates) | ||
return dates | ||
} | ||
module.exports = findDate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// chop things up into bite-size pieces | ||
const split = function (dates) { | ||
let m = null | ||
// don't split anything if it looks like a range | ||
if (dates.has('^(between|within) #Date')) { | ||
return dates | ||
} | ||
|
||
if (dates.has('#Month')) { | ||
// 'june 5, june 10' | ||
m = dates.match('[#Month #Value] and? #Month', 0).ifNo('@hasDash$') | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
|
||
// '5 june, 10 june' | ||
m = dates.match('[#Value #Month] and? #Value #Month', 0) | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
|
||
// 'june, august' | ||
m = dates.match('^[#Month] and? #Month #Ordinal?$', 0) | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
|
||
// 'june 5th, june 10th' | ||
m = dates.match('[#Month #Value] #Month', 0).ifNo('@hasDash$') | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
} | ||
|
||
if (dates.has('#WeekDay')) { | ||
// 'tuesday, wednesday' | ||
m = dates.match('^[#WeekDay] and? #WeekDay$', 0).ifNo('@hasDash$') | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
|
||
// 'tuesday, wednesday, and friday' | ||
m = dates.match('#WeekDay #WeekDay and? #WeekDay') | ||
if (m.found) { | ||
dates = dates.splitOn('#WeekDay') | ||
} | ||
|
||
// monday, wednesday | ||
m = dates.match('[#WeekDay] (and|or|this|next)? #WeekDay', 0).ifNo('@hasDash$') | ||
if (m.found) { | ||
dates = dates.splitAfter('#WeekDay') | ||
} | ||
} | ||
|
||
// next week tomorrow | ||
m = dates.match('(this|next) #Duration [(today|tomorrow|yesterday)]', 0) | ||
if (m.found) { | ||
dates = dates.splitBefore(m) | ||
} | ||
// tomorrow 15 march | ||
m = dates.match('[(today|tomorrow|yesterday)] #Value #Month', 0) | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
// tomorrow yesterday | ||
m = dates.match('[(today|tomorrow|yesterday)] (today|tomorrow|yesterday|#WeekDay)', 0).ifNo('@hasDash$') | ||
if (m.found) { | ||
dates = dates.splitAfter(m) | ||
} | ||
// cleanup any splits | ||
dates = dates.not('^and') | ||
return dates | ||
} | ||
module.exports = split |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.