我一直在尝试为SUTime添加自定义规则,而且我一直坚持使用其中一个。我尝试了各种方法,似乎没有一个能得到我想要的结果。
5 - 8 years returns the following.
{
'text' : '5 - 8 years',
'type' : 'DURATION',
'value' : 'P5Y/P8Y'
}
5-8 years return the following. (no space between the hyphens)
{
'text' : 'years',
'type' : 'DURATION',
'value' : 'PXY'
}
This is my understanding
- '5-8' and 'years' are the tokens it produces
- 5-8 is not mapped to anything and therefore is not considered relevant
我尝试了什么: -
These are results on running them on '5-8 years'
{ text: /(\d+)[-](\d+)[\s]+($TEUnits)(s)?/ =>
Duration( TIMEUNIT_MAP[Lowercase($3)], $2) }
gives 'value': 'P8Y' as expected. I want 'P5Y/P8Y' as the value.
Duration( $1, $2, TIMEUNIT_MAP[Lowercase($3)] )
,Duration( $1, $2, TIMEUNIT_MAP[Lowercase($3)], TIME_UNKNOWN, TIME_REF )
以及许多其他组合,即使它们没有意义。它们都导致规则被忽略,因此产生了同样的结果。如何从文本P5Y/P8Y
获取"I've been reading from the last 5-8 years"
表格的价值标签?
我已经做了一个诚实的努力,已经多次完成了大部分规则文件,随附的文档和其他3个Stack Overflow问题。我还有其他三条规则可供使用。