Natural language time parser

ⅰ亾dé卋堺 提交于 2019-12-17 19:06:09

问题


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"

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?


回答1:


parsedatetime looks promising. Credit.




回答2:


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.




回答3:


Just for anyone who is interested, I found this:

https://gist.github.com/akatzbreaker/5849024

This is the same as Bert's Anwser on Github, but it is in English... Just for anyone who is interested on this, and doesn't know Dutch :-P ...



来源:https://stackoverflow.com/questions/11340963/natural-language-time-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!