13

フリーフォームのテキストが解析され、特定の日付/時刻に変換される Google カレンダー (または一部の Gmail メッセージ) に沿ったものを考え出そうとしています。

いくつかの例 (簡単にするために、現在は 2013 年 1 月 1 日午前 1 時であると仮定します):

"I should call Mom tomorrow to wish her a happy birthday" -> "tomorrow" = "2013-01-02"
"The super bowl is on Feb 3rd at 6:30pm" -> "Feb 3rd at 6:30" => "2013-02-03T06:30:00Z"
"Remind me to take out the trash on Friday" => "Friday" => "2013-01-04"

まず第一に、これ (またはこれの一部) に関する既存のオープン ソース ライブラリはありますか? そうでない場合、どのようなアプローチを取るべきだと思いますか?

私はいくつかの異なる可能性を考えています:

  1. さまざまなユースケースごとに思いつく限りの多くの正規表現
  2. n-gram を見て、それらを「相対日付」、「相対曜日」、「特定の日付」、「日時」などのさまざまなシナリオに分類し、ルール エンジン (多分もっと正規表現) 実際の日付を把握します。
  3. Google 検索に送信し、検索結果から意味のある情報を抽出しようとします (これはおそらく現実的ではありません)。
4

1 に答える 1

11

このライブラリを使用できます: https://github.com/wanasit/chrono

デモ:

inputs = ["I should call Mom tomorrow to with her a happy birthday",
"The super bowl is on Feb 3rd at 6:30pm", "Remind me to take out the trash on Friday"];

for(var i = 0; i < inputs.length; i++) {
    var input = inputs[i];
    var parsed = chrono.parse(input);
    console.log(input + " parsed as: " + JSON.stringify(parsed.map(function(p) { return [p.text, p.startDate]; })));
}
​

出力:

I should call Mom tomorrow to with her a happy birthday parsed as: [["tomorrow","2012-12-31T06:30:00.000Z"]]
The super bowl is on Feb 3rd at 6:30pm parsed as: [["Feb 3rd at 6:30pm","2013-02-03T13:00:00.000Z"]]
Remind me to take out the trash on Friday parsed as: [["Friday","2013-01-04T06:30:00.000Z"]] 

http://jsfiddle.net/TXX3Z/

于 2012-12-29T19:05:04.190 に答える