2012-12-29 10 views
11

私は、フリーフォームのテキストが解析されて特定の日付/時刻に変換される、Googleカレンダー(またはいくつかのGmailメッセージ)に沿って何かを考え出しています。フリーフォームのテキストからdatetimeを抽出するにはどうすればよいですか?

いくつかの例としては、(今は午前1時2013年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. 多く、N-見ベイジアンネットのいくつかの並べ替え「相対日付」、「相対曜日」、「特定の日付」、「日付と時刻」などのさまざまなシナリオに分類し、ルールエンジン(多分正規表現)を使用して実際の日付を把握します。
    2. あなたはこのライブラリを使用することができます
  • 答えて

    9

    (この1つは、おそらく現実的ではありません)、Googleの検索にそれを送信し、検索結果から意味のある情報を抽出しよう: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/

    +2

    うわー、これは私が望むすべてを持っています!ありがとう! – Paul

    関連する問題