ruby/rails 的自然语言日期解析器 [英] Natural language date parser for ruby/rails

查看:24
本文介绍了ruby/rails 的自然语言日期解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道 Ruby 中类似于 Date.js 的东西吗?能够从诸如从今天起两周"返回日期对象的东西.记住牛奶网络应用程序将此功能整合到他们的系统中,使用起来非常简单.

Does anybody know of something similar to Date.js in Ruby? Something that would be able to return a date object from something like: "two weeks from today". The Remember the Milk webapp incorporates this feature into their system and it is incredibly easy to use.

我会使用 Date.js 库本身,但因为它位于客户端,所以有其局限性.如果用户没有启用 javascript,则该功能将丢失.这会影响到理想情况下通过短信 (sms) 使用我们系统的手机用户.

I would use the Date.js library itself but because it is on the client side it has its limitations. If the user doesn't have javascript enabled the functionality would be lost. This would affect mobile phone users who would, ideally, use our system via text message (sms).

我很想使用已经存在的解决方案,但如果不是,将这段代码移植到 Ruby 会有多难?我真的不太了解自然语言解释,但似乎需要一些时间.

I would love to use a solution that's already out there but if not how hard would it be to port this code into Ruby? I really don't know much about natural language interpretation but it seems like it would take some time.

谢谢.

推荐答案

不要忘记在 Ruby 中一切都是对象,您已经从语言本身获得了一些非常可读的语句:

Do not forget that everything being an object in Ruby, you have already some pretty readable statement from the language itself:

2.weeks.from_now.utc

相当于从今天起两周".

would be the equivalent of "two weeks from today".

然而,对于真实自然语言,可能是chronic 可能是 rubyforge.

However, for real natural language, may be chronic might be a more specialized library at rubyforge.

Chronic.parse('this tuesday 5:00')
#=> Tue Aug 29 17:00:00 PDT 2006

这篇关于ruby/rails 的自然语言日期解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆