问题描述
我正在尝试将包含(自然语言)时间的字符串解析为 hh:mm 时间对象?例如:
I'm trying to parse strings containing (natural language) times to hh:mm time objects? For example:
"ten past five"
"quarter to three"
"half past noon"
"15 past 3"
"13:35"
"ten fourteen am"
我已经研究了慢性用于Ruby和 Natty for Java(以及其他一些库),但两者似乎都着重于解析日期.诸如十点五分"之类的字符串都无法正确解析.
I've looked into Chronic for Ruby and Natty for Java (as well as some other libraries) but both seem to focus on parsing dates. Strings like "ten past five" are not parsed correctly by either.
有人知道适合我需要的图书馆吗?还是我应该开始使用自己的解析器?
Does anyone know of a library which suit my needs? Or should I maybe start working on my own parser?
推荐答案
我不想延长解析时间,所以我决定使用 pyPEG (一种用于Python的解析器解释器框架),用于编写专用的时间解析器.对于感兴趣的人,第一个基本版本现在已经完成,可以很好地解析荷兰时间字符串.
I didn't feel like extending parsedatetime, so I decided to use pyPEG, a parser interpreter framework for Python, to write a dedicated time parser. For whoever's interested, the first basic version is now finished, and nicely parses Dutch time strings.
这篇关于自然语言时间解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!