python的慢性(Ruby NLP日期/时间解析器)?

时间:2009-04-05 15:12:39

标签: chronic

有没有人知道像慢性但是对于python这样的库?

谢谢!

3 个答案:

答案 0 :(得分:4)

您是否尝试过parsedatetime

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

我在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
相关问题