我一直在尝试向 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
Duration( $1, $2, TIMEUNIT_MAP[Lowercase($3)] )
和Duration( $1, $2, TIMEUNIT_MAP[Lowercase($3)], TIME_UNKNOWN, TIME_REF )
许多其他组合,即使它们没有意义。它们都导致规则被忽略,因此给出了相同的结果。 - 我尝试通过将 (digit-digit) 替换为 (digit - digit) 来清理数据,但这会导致检测日期出现问题。
要旨
如何P5Y/P8Y
从文本中获取表单的值标签"I've been reading from the last 5-8 years"
?
我已经付出了诚实的努力,并多次阅读了大部分规则文件、随附的文档和 3 个其他 Stack Overflow 问题。我还有其他三个规则可以工作。