如何在Python中使用nltk和WordNet获取单词的过去时态?

时间:2011-03-29 17:15:57

标签: python nltk wordnet

运行以下命令需要哪些软件包?

代码

import nltk
from nltk.corpus import wordnet
v = 'go'
present = present_tense(v)
I got an error saying-

错误消息

  

NameError:名称'present_tense'未定义

1 个答案:

答案 0 :(得分:3)

您可以尝试:import en
而不是:import nltk

您可以尝试:en.verb.present(v) 而不是:present_tense(v)

en包来自NodeBox English Linguistics library

演示网站:http://wnbot.com/wordnet/stackoverflow.py

草稿源代码清单:

#!/usr/bin/python

import en
import sys

went = 'went'
going = 'going'
gone = 'gone'
goes = 'goes'

print "Content-Type: text/html"
print
print "<html><head><title>Stack Overflow answer</title></head><body>"
print ' The present tense of <b>',going, '</b> is <i>',en.verb.present(going),'</i><br>'
print ' The present tense of <b>',goes, '</b> is <i>',en.verb.present(goes),'</i><br>'
print ' The present tense of <b>',gone, '</b> is <i>',en.verb.present(gone),'</i><br>'
print ' The present tense of <b>',went, '</b> is <i>',en.verb.present(went),'</i><br>'
print "</body></html>"

此源代码清单仅供教育和讨论之用。