Chronic (Ruby NLP date/time parser) for python?

末鹿安然 提交于 2019-12-19 04:07:48

问题


Does anyone know of a library like chronic but for python?

Thanks!


回答1:


Have you tried parsedatetime?




回答2:


You can try Stanford NLP's SUTime. Related Python bindings are here: https://github.com/FraBle/python-sutime

Make sure that all the Java dependencies are installed.




回答3:


I was talking to Stephen Russett at chronic. I came up with a Python example after he suggested tokenization.

Here is the Python example. You run the output into chronic.

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


来源:https://stackoverflow.com/questions/719088/chronic-ruby-nlp-date-time-parser-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!