compromise
Version:
modest natural language processing
56 lines (51 loc) • 2.34 kB
JavaScript
export default [
// ==== Ambiguous numbers ====
// 'second'
{ match: `
//'a/an' can mean 1 - "a hour"
{
match: '!once? [(a|an)] (#Duration|hundred|thousand|million|billion|trillion)',
group: 0,
tag: 'Value',
reason: 'a-is-one',
},
// ==== PhoneNumber ====
//1 800 ...
{ match: '(1|+1) #Value #PhoneNumber', tag: 'PhoneNumber', reason: '1-800-Value' },
//(454) 232-9873
{ match: '#NumericValue #PhoneNumber', tag: 'PhoneNumber', reason: '(800) PhoneNumber' },
// ==== Currency ====
// chinese yuan
{ match: '#Demonym #Currency', tag: 'Currency', reason: 'demonym-currency' },
// ten bucks
{ match: '#Value [(buck|bucks|grand)]', group: 0, tag: 'Currency', reason: 'value-bucks' },
// ==== Money ====
{ match: '[#Value+] #Currency', group: 0, tag: 'Money', reason: '15 usd' },
// ==== Ordinal ====
{ match: '[second] #Noun', group: 0, tag: 'Ordinal', reason: 'second-noun' },
// ==== Units ====
//5 yan
{ match: '#Value+ [#Currency]', group: 0, tag: 'Unit', reason: '5-yan' },
{ match: '#Value [(foot|feet)]', group: 0, tag: 'Unit', reason: 'foot-unit' },
//5 kg.
{ match: '#Value [#Abbreviation]', group: 0, tag: 'Unit', reason: 'value-abbr' },
{ match: '#Value [k]', group: 0, tag: 'Unit', reason: 'value-k' },
{ match: '#Unit an hour', tag: 'Unit', reason: 'unit-an-hour' },
// ==== Magnitudes ====
//minus 7
{ match: '(minus|negative) #Value', tag: 'Value', reason: 'minus-value' },
//seven point five
{ match: '#Value (point|decimal) #Value', tag: 'Value', reason: 'value-point-value' },
//quarter million
{ match: '#Determiner [(half|quarter)] #Ordinal', group: 0, tag: 'Value', reason: 'half-ordinal' },
// thousand and two
{ match: `
// 5 miles per hour
{ match: '#Value #Unit [(per|an) (hr|hour|sec|second|min|minute)]', group: 0, tag: 'Unit', reason: '12-miles-per-second' },
// 5 square miles
{ match: '#Value [(square|cubic)] #Unit', group: 0, tag: 'Unit', reason: 'square-miles' },
//twelve percent
{ match: '#Cardinal percent', tag: '#Percent #Unit', reason: 'value-percent' },
// ambiguous units
{ match: '#Value [(gb|pa|ft|foot|feet|m)]', group: 0, tag: 'Unit', reason: 'ambiguous-unit' },
]