【问题标题】:How to get the past tense of a word using nltk and WordNet in Python?如何在 Python 中使用 nltk 和 WordNet 获取单词的过去式?
【发布时间】:2015-04-12 23:19:05
【问题描述】:

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

代码

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

错误信息

NameError:名称“present_tense”未定义

【问题讨论】:

标签: python nltk wordnet


【解决方案1】:

你可以试试: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>"

此源代码清单仅用于教育和讨论目的的草稿。

【讨论】:

  • 你好,这个信息现在对python 3+没有用了吗
猜你喜欢
  • 2013-02-26
  • 2011-04-14
  • 2013-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
相关资源
最近更新 更多