2 from nltk
.wordnet
import N
,V
,ADJ
,ADV
4 from cache
import cached
6 parts
= [N
, V
, ADJ
, ADV
]
9 def find_definition(word
):
10 # TODO: do fuzzy matching for misspelled words and its variations
14 s
+= "[%s]\n" % part
.pos
15 for sense
in part
[word
]:
16 s
+= sense
.gloss
+ "\n"
20 pat_quoted
= re
.compile('("[^"]*")')
22 def find_definition_html(word
):
23 """This is much like `find_definition_html' except the returned
24 string is formatted as pretty HTML
29 s
+= "<p><b>[%s]</b><ol>" % part
.pos
30 for sense
in part
[word
]:
31 s
+= "<li>" + pat_quoted
.sub(r
'<i>\1</i>', sense
.gloss
)
36 if __name__
== '__main__':
37 print "dog:\n", find_definition("dog")
38 print "mitigate:\n", find_definition("mitigate")