【问题标题】:Chronic (Ruby NLP date/time parser) for python?python的慢性(Ruby NLP日期/时间解析器)?
【发布时间】:2009-04-05 15:12:39
【问题描述】:

有没有人知道像chronic这样的库,但只用于python?

谢谢!

【问题讨论】:

    标签: chronic


    【解决方案1】:

    你试过parsedatetime吗?

    【讨论】:

      【解决方案2】:

      你可以试试斯坦福 NLP 的 SUTime。相关的 Python 绑定在这里:https://github.com/FraBle/python-sutime

      确保已安装所有 Java 依赖项。

      【讨论】:

        【解决方案3】:

        我在chronic 与 Stephen Russett 交谈。在他建议标记化之后,我想出了一个 Python 示例。

        这是 Python 示例。您将输出运行为慢性。

        import nltk
        import MySQLdb
        import time
        import string
        import re
        
        #tokenize
        sentence = 'Available June 9 -- August first week'
        tokens = nltk.word_tokenize(sentence)
        
        parts_of_speech = nltk.pos_tag(tokens)
        print parts_of_speech
        
        #allow white list
        white_list = ['first']
        
        #allow only prepositions
        #NNP, CD
        approved_prepositions = ['NNP', 'CD']
        filtered = []
        for word in parts_of_speech:
        
            if any(x in word[1] for x in approved_prepositions):
                filtered.append(word[0])
            elif any(x in word[0] for x in white_list):
                #if word in white list, append it
                filtered.append(word[0])
        
        print filtered
        
        #normalize to alphanumeric only
        normalized = re.sub(r'\s\W+', ' ', ' '.join(filtered))
        print filtered
        

        【讨论】:

          猜你喜欢
          • 2015-07-22
          • 1970-01-01
          • 1970-01-01
          • 2016-01-01
          • 1970-01-01
          • 2017-08-20
          • 1970-01-01
          • 2012-09-04
          • 1970-01-01
          相关资源
          最近更新 更多