【发布时间】:2015-05-09 15:58:15
【问题描述】:
关于过去发生的事件,我有成千上万的句子。例如
sentence1 = 'The Knights Templar are founded to protect Christian pilgrims in Jerusalem.'
sentence2 = 'Alfonso VI of Castile captures the Moorish Muslim city of Toledo, Spain.'
sentence3 = 'The Hindu Medang kingdom flourishes and declines.'
我想将它们转换为以下形式的问题:
question1 = 'When were the Knights Templar founded to protect Christian pilgrims in Jerusalem?'
question2 = 'When did Alfonso VI of Castile capture the Moorish Muslim city of Toledo, Spain?'
question3 = 'When did the Hindu Medang kingdom flourish and decline?'
我意识到这是一个复杂的问题,并且成功率达到了 80%。
据我在网络上的搜索了解,NTLK 是解决此类问题的方法。 我开始尝试一些东西,但这是我第一次使用这个库,我不能走得更远:
import nltk
question = 'The Knights Templar are founded to protect Christian pilgrims in Jerusalem.'
tokens = nltk.word_tokenize(question)
tagged = nltk.pos_tag(tokens)
这听起来是很多人一定遇到并解决的问题。 有什么建议吗?
【问题讨论】:
标签: python string text nlp nltk