nltk 3.2.1__zip → 3.3__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. {nltk-3.2.1 → nltk-3.3}/LICENSE.txt +1 -1
  2. {nltk-3.2.1/nltk.egg-info → nltk-3.3}/PKG-INFO +13 -5
  3. nltk-3.3/README.md +49 -0
  4. nltk-3.3/nltk/VERSION +1 -0
  5. {nltk-3.2.1 → nltk-3.3}/nltk/__init__.py +3 -3
  6. {nltk-3.2.1 → nltk-3.3}/nltk/app/__init__.py +2 -3
  7. {nltk-3.2.1 → nltk-3.3}/nltk/app/chartparser_app.py +92 -92
  8. {nltk-3.2.1 → nltk-3.3}/nltk/app/chunkparser_app.py +11 -13
  9. {nltk-3.2.1 → nltk-3.3}/nltk/app/collocations_app.py +8 -11
  10. {nltk-3.2.1 → nltk-3.3}/nltk/app/concordance_app.py +9 -11
  11. {nltk-3.2.1 → nltk-3.3}/nltk/app/nemo_app.py +18 -17
  12. {nltk-3.2.1 → nltk-3.3}/nltk/app/rdparser_app.py +10 -12
  13. {nltk-3.2.1 → nltk-3.3}/nltk/app/srparser_app.py +16 -16
  14. {nltk-3.2.1 → nltk-3.3}/nltk/app/wordfreq_app.py +1 -1
  15. {nltk-3.2.1 → nltk-3.3}/nltk/app/wordnet_app.py +11 -11
  16. {nltk-3.2.1 → nltk-3.3}/nltk/book.py +2 -1
  17. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/__init__.py +1 -1
  18. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/api.py +67 -47
  19. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/chart.py +7 -5
  20. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/combinator.py +42 -11
  21. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/lexicon.py +1 -1
  22. {nltk-3.2.1 → nltk-3.3}/nltk/ccg/logic.py +1 -1
  23. {nltk-3.2.1 → nltk-3.3}/nltk/chat/__init__.py +1 -1
  24. {nltk-3.2.1 → nltk-3.3}/nltk/chat/eliza.py +1 -1
  25. {nltk-3.2.1 → nltk-3.3}/nltk/chat/iesha.py +1 -1
  26. {nltk-3.2.1 → nltk-3.3}/nltk/chat/rude.py +1 -1
  27. {nltk-3.2.1 → nltk-3.3}/nltk/chat/suntsu.py +1 -1
  28. {nltk-3.2.1 → nltk-3.3}/nltk/chat/util.py +12 -10
  29. {nltk-3.2.1 → nltk-3.3}/nltk/chat/zen.py +1 -1
  30. {nltk-3.2.1 → nltk-3.3}/nltk/chunk/__init__.py +1 -1
  31. {nltk-3.2.1 → nltk-3.3}/nltk/chunk/api.py +1 -1
  32. {nltk-3.2.1 → nltk-3.3}/nltk/chunk/named_entity.py +13 -13
  33. {nltk-3.2.1 → nltk-3.3}/nltk/chunk/regexp.py +9 -3
  34. {nltk-3.2.1 → nltk-3.3}/nltk/chunk/util.py +12 -12
  35. {nltk-3.2.1 → nltk-3.3}/nltk/classify/__init__.py +1 -1
  36. {nltk-3.2.1 → nltk-3.3}/nltk/classify/api.py +1 -1
  37. {nltk-3.2.1 → nltk-3.3}/nltk/classify/decisiontree.py +18 -18
  38. {nltk-3.2.1 → nltk-3.3}/nltk/classify/maxent.py +26 -8
  39. {nltk-3.2.1 → nltk-3.3}/nltk/classify/megam.py +5 -4
  40. {nltk-3.2.1 → nltk-3.3}/nltk/classify/naivebayes.py +29 -26
  41. {nltk-3.2.1 → nltk-3.3}/nltk/classify/rte_classify.py +58 -89
  42. {nltk-3.2.1 → nltk-3.3}/nltk/classify/scikitlearn.py +4 -2
  43. {nltk-3.2.1 → nltk-3.3}/nltk/classify/senna.py +24 -22
  44. {nltk-3.2.1 → nltk-3.3}/nltk/classify/svm.py +1 -1
  45. {nltk-3.2.1 → nltk-3.3}/nltk/classify/tadm.py +4 -3
  46. {nltk-3.2.1 → nltk-3.3}/nltk/classify/textcat.py +1 -1
  47. {nltk-3.2.1 → nltk-3.3}/nltk/classify/util.py +13 -1
  48. {nltk-3.2.1 → nltk-3.3}/nltk/classify/weka.py +7 -6
  49. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/__init__.py +1 -1
  50. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/api.py +9 -5
  51. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/em.py +1 -1
  52. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/gaac.py +3 -3
  53. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/kmeans.py +1 -1
  54. {nltk-3.2.1 → nltk-3.3}/nltk/cluster/util.py +35 -20
  55. nltk-3.3/nltk/collections.py +640 -0
  56. {nltk-3.2.1 → nltk-3.3}/nltk/collocations.py +2 -2
  57. nltk-3.3/nltk/compat.py +365 -0
  58. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/__init__.py +37 -16
  59. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/europarl_raw.py +1 -1
  60. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/__init__.py +4 -2
  61. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/aligned.py +4 -3
  62. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/api.py +12 -10
  63. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/bnc.py +1 -1
  64. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/bracket_parse.py +1 -1
  65. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/categorized_sents.py +4 -3
  66. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/chasen.py +5 -4
  67. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/childes.py +8 -9
  68. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/chunked.py +4 -4
  69. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/cmudict.py +4 -2
  70. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/comparative_sents.py +4 -2
  71. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/conll.py +19 -12
  72. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/crubadan.py +2 -2
  73. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/dependency.py +1 -1
  74. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/framenet.py +1085 -119
  75. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ieer.py +4 -3
  76. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/indian.py +4 -5
  77. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ipipan.py +6 -5
  78. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/knbc.py +2 -2
  79. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/lin.py +1 -1
  80. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/mte.py +5 -4
  81. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nkjp.py +4 -3
  82. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nombank.py +8 -8
  83. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nps_chat.py +1 -1
  84. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/opinion_lexicon.py +3 -3
  85. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/panlex_lite.py +1 -1
  86. nltk-3.3/nltk/corpus/reader/pl196x.py +292 -0
  87. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/plaintext.py +3 -4
  88. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ppattach.py +4 -3
  89. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/propbank.py +8 -10
  90. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/pros_cons.py +5 -3
  91. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/reviews.py +3 -1
  92. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/rte.py +5 -7
  93. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/semcor.py +1 -1
  94. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/senseval.py +4 -2
  95. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/sentiwordnet.py +3 -3
  96. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/sinica_treebank.py +1 -1
  97. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/string_category.py +4 -3
  98. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/switchboard.py +1 -1
  99. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/tagged.py +4 -3
  100. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/timit.py +10 -8
  101. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/toolbox.py +4 -4
  102. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/twitter.py +4 -6
  103. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/util.py +7 -3
  104. nltk-3.3/nltk/corpus/reader/verbnet.py +595 -0
  105. nltk-3.3/nltk/corpus/reader/wordlist.py +134 -0
  106. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/wordnet.py +357 -285
  107. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/xmldocs.py +10 -5
  108. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ycoe.py +25 -24
  109. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/util.py +22 -5
  110. {nltk-3.2.1 → nltk-3.3}/nltk/data.py +65 -29
  111. {nltk-3.2.1 → nltk-3.3}/nltk/decorators.py +5 -1
  112. {nltk-3.2.1 → nltk-3.3}/nltk/downloader.py +59 -55
  113. {nltk-3.2.1 → nltk-3.3}/nltk/draw/__init__.py +4 -4
  114. {nltk-3.2.1 → nltk-3.3}/nltk/draw/cfg.py +5 -8
  115. {nltk-3.2.1 → nltk-3.3}/nltk/draw/dispersion.py +1 -1
  116. {nltk-3.2.1 → nltk-3.3}/nltk/draw/table.py +4 -4
  117. {nltk-3.2.1 → nltk-3.3}/nltk/draw/tree.py +2 -5
  118. {nltk-3.2.1 → nltk-3.3}/nltk/draw/util.py +17 -17
  119. {nltk-3.2.1 → nltk-3.3}/nltk/featstruct.py +290 -173
  120. {nltk-3.2.1 → nltk-3.3}/nltk/grammar.py +87 -44
  121. {nltk-3.2.1 → nltk-3.3}/nltk/help.py +1 -1
  122. {nltk-3.2.1 → nltk-3.3}/nltk/inference/__init__.py +1 -1
  123. {nltk-3.2.1 → nltk-3.3}/nltk/inference/api.py +27 -19
  124. {nltk-3.2.1 → nltk-3.3}/nltk/inference/discourse.py +20 -16
  125. {nltk-3.2.1 → nltk-3.3}/nltk/inference/nonmonotonic.py +1 -1
  126. {nltk-3.2.1 → nltk-3.3}/nltk/inference/prover9.py +1 -1
  127. {nltk-3.2.1 → nltk-3.3}/nltk/inference/resolution.py +1 -1
  128. {nltk-3.2.1 → nltk-3.3}/nltk/inference/tableau.py +1 -1
  129. {nltk-3.2.1 → nltk-3.3}/nltk/internals.py +44 -44
  130. {nltk-3.2.1 → nltk-3.3}/nltk/jsontags.py +1 -1
  131. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/__init__.py +2 -1
  132. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/agreement.py +29 -9
  133. nltk-3.3/nltk/metrics/aline.py +607 -0
  134. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/association.py +8 -4
  135. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/confusionmatrix.py +1 -1
  136. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/distance.py +12 -7
  137. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/paice.py +1 -1
  138. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/scores.py +7 -7
  139. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/segmentation.py +4 -5
  140. {nltk-3.2.1 → nltk-3.3}/nltk/metrics/spearman.py +1 -1
  141. {nltk-3.2.1 → nltk-3.3}/nltk/misc/__init__.py +1 -1
  142. {nltk-3.2.1 → nltk-3.3}/nltk/misc/chomsky.py +4 -2
  143. {nltk-3.2.1 → nltk-3.3}/nltk/misc/minimalset.py +1 -1
  144. {nltk-3.2.1 → nltk-3.3}/nltk/misc/sort.py +1 -1
  145. {nltk-3.2.1 → nltk-3.3}/nltk/misc/wordfinder.py +1 -1
  146. {nltk-3.2.1 → nltk-3.3}/nltk/parse/__init__.py +2 -1
  147. {nltk-3.2.1 → nltk-3.3}/nltk/parse/api.py +1 -1
  148. {nltk-3.2.1 → nltk-3.3}/nltk/parse/bllip.py +1 -1
  149. {nltk-3.2.1 → nltk-3.3}/nltk/parse/chart.py +8 -7
  150. nltk-3.3/nltk/parse/corenlp.py +780 -0
  151. {nltk-3.2.1 → nltk-3.3}/nltk/parse/dependencygraph.py +4 -2
  152. {nltk-3.2.1 → nltk-3.3}/nltk/parse/earleychart.py +4 -3
  153. {nltk-3.2.1 → nltk-3.3}/nltk/parse/evaluate.py +1 -1
  154. {nltk-3.2.1 → nltk-3.3}/nltk/parse/featurechart.py +6 -4
  155. {nltk-3.2.1 → nltk-3.3}/nltk/parse/generate.py +15 -4
  156. {nltk-3.2.1 → nltk-3.3}/nltk/parse/malt.py +2 -2
  157. {nltk-3.2.1 → nltk-3.3}/nltk/parse/nonprojectivedependencyparser.py +3 -3
  158. {nltk-3.2.1 → nltk-3.3}/nltk/parse/pchart.py +1 -1
  159. {nltk-3.2.1 → nltk-3.3}/nltk/parse/projectivedependencyparser.py +6 -5
  160. {nltk-3.2.1 → nltk-3.3}/nltk/parse/recursivedescent.py +2 -3
  161. {nltk-3.2.1 → nltk-3.3}/nltk/parse/shiftreduce.py +2 -3
  162. {nltk-3.2.1 → nltk-3.3}/nltk/parse/stanford.py +53 -28
  163. {nltk-3.2.1 → nltk-3.3}/nltk/parse/transitionparser.py +11 -9
  164. {nltk-3.2.1 → nltk-3.3}/nltk/parse/util.py +1 -1
  165. {nltk-3.2.1 → nltk-3.3}/nltk/parse/viterbi.py +1 -1
  166. {nltk-3.2.1 → nltk-3.3}/nltk/probability.py +75 -20
  167. {nltk-3.2.1 → nltk-3.3}/nltk/sem/__init__.py +1 -1
  168. {nltk-3.2.1 → nltk-3.3}/nltk/sem/boxer.py +15 -15
  169. {nltk-3.2.1 → nltk-3.3}/nltk/sem/chat80.py +6 -6
  170. {nltk-3.2.1 → nltk-3.3}/nltk/sem/cooper_storage.py +1 -1
  171. {nltk-3.2.1 → nltk-3.3}/nltk/sem/drt.py +9 -8
  172. {nltk-3.2.1 → nltk-3.3}/nltk/sem/drt_glue_demo.py +5 -9
  173. {nltk-3.2.1 → nltk-3.3}/nltk/sem/evaluate.py +9 -3
  174. {nltk-3.2.1 → nltk-3.3}/nltk/sem/glue.py +8 -6
  175. {nltk-3.2.1 → nltk-3.3}/nltk/sem/hole.py +4 -2
  176. {nltk-3.2.1 → nltk-3.3}/nltk/sem/lfg.py +4 -2
  177. {nltk-3.2.1 → nltk-3.3}/nltk/sem/linearlogic.py +4 -2
  178. {nltk-3.2.1 → nltk-3.3}/nltk/sem/logic.py +14 -14
  179. {nltk-3.2.1 → nltk-3.3}/nltk/sem/relextract.py +11 -18
  180. {nltk-3.2.1 → nltk-3.3}/nltk/sem/skolemize.py +1 -1
  181. {nltk-3.2.1 → nltk-3.3}/nltk/sem/util.py +1 -1
  182. {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/__init__.py +1 -1
  183. {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/sentiment_analyzer.py +1 -1
  184. {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/util.py +14 -4
  185. {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/vader.py +41 -42
  186. {nltk-3.2.1 → nltk-3.3}/nltk/stem/__init__.py +1 -3
  187. {nltk-3.2.1 → nltk-3.3}/nltk/stem/api.py +7 -4
  188. nltk-3.3/nltk/stem/arlstem.py +369 -0
  189. {nltk-3.2.1 → nltk-3.3}/nltk/stem/isri.py +1 -1
  190. {nltk-3.2.1 → nltk-3.3}/nltk/stem/lancaster.py +39 -12
  191. nltk-3.3/nltk/stem/porter.py +710 -0
  192. {nltk-3.2.1 → nltk-3.3}/nltk/stem/regexp.py +2 -2
  193. {nltk-3.2.1 → nltk-3.3}/nltk/stem/rslp.py +1 -1
  194. {nltk-3.2.1 → nltk-3.3}/nltk/stem/snowball.py +537 -13
  195. {nltk-3.2.1 → nltk-3.3}/nltk/stem/util.py +11 -1
  196. {nltk-3.2.1 → nltk-3.3}/nltk/stem/wordnet.py +1 -1
  197. {nltk-3.2.1 → nltk-3.3}/nltk/tag/__init__.py +32 -7
  198. {nltk-3.2.1 → nltk-3.3}/nltk/tag/api.py +13 -8
  199. {nltk-3.2.1 → nltk-3.3}/nltk/tag/brill.py +4 -6
  200. {nltk-3.2.1 → nltk-3.3}/nltk/tag/crf.py +1 -1
  201. {nltk-3.2.1 → nltk-3.3}/nltk/tag/hmm.py +11 -11
  202. {nltk-3.2.1 → nltk-3.3}/nltk/tag/hunpos.py +4 -4
  203. {nltk-3.2.1 → nltk-3.3}/nltk/tag/mapping.py +1 -1
  204. {nltk-3.2.1 → nltk-3.3}/nltk/tag/perceptron.py +25 -10
  205. {nltk-3.2.1 → nltk-3.3}/nltk/tag/senna.py +25 -23
  206. {nltk-3.2.1 → nltk-3.3}/nltk/tag/sequential.py +19 -15
  207. {nltk-3.2.1 → nltk-3.3}/nltk/tag/stanford.py +59 -36
  208. {nltk-3.2.1 → nltk-3.3}/nltk/tag/tnt.py +11 -20
  209. {nltk-3.2.1 → nltk-3.3}/nltk/tag/util.py +1 -1
  210. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/__init__.py +1 -1
  211. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/demo.py +1 -1
  212. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/erroranalysis.py +1 -1
  213. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/feature.py +5 -7
  214. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/rule.py +6 -6
  215. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/template.py +18 -23
  216. {nltk-3.2.1 → nltk-3.3}/nltk/test/__init__.py +1 -1
  217. {nltk-3.2.1 → nltk-3.3}/nltk/test/all.py +7 -6
  218. {nltk-3.2.1 → nltk-3.3}/nltk/test/bnc.doctest +1 -1
  219. {nltk-3.2.1 → nltk-3.3}/nltk/test/ccg.doctest +1 -1
  220. {nltk-3.2.1 → nltk-3.3}/nltk/test/ccg_semantics.doctest +1 -1
  221. {nltk-3.2.1 → nltk-3.3}/nltk/test/chat80.doctest +1 -1
  222. {nltk-3.2.1 → nltk-3.3}/nltk/test/childes_fixt.py +1 -0
  223. {nltk-3.2.1 → nltk-3.3}/nltk/test/chunk.doctest +1 -1
  224. {nltk-3.2.1 → nltk-3.3}/nltk/test/classify.doctest +1 -1
  225. {nltk-3.2.1 → nltk-3.3}/nltk/test/classify_fixt.py +2 -1
  226. nltk-3.3/nltk/test/collections.doctest +20 -0
  227. {nltk-3.2.1 → nltk-3.3}/nltk/test/collocations.doctest +1 -1
  228. {nltk-3.2.1 → nltk-3.3}/nltk/test/compat.doctest +0 -4
  229. {nltk-3.2.1 → nltk-3.3}/nltk/test/compat_fixt.py +1 -0
  230. nltk-3.3/nltk/test/concordance.doctest +55 -0
  231. {nltk-3.2.1 → nltk-3.3}/nltk/test/corpus.doctest +38 -49
  232. {nltk-3.2.1 → nltk-3.3}/nltk/test/crubadan.doctest +1 -1
  233. {nltk-3.2.1 → nltk-3.3}/nltk/test/data.doctest +1 -1
  234. {nltk-3.2.1 → nltk-3.3}/nltk/test/dependency.doctest +1 -1
  235. {nltk-3.2.1 → nltk-3.3}/nltk/test/discourse.doctest +1 -1
  236. {nltk-3.2.1 → nltk-3.3}/nltk/test/discourse_fixt.py +1 -0
  237. {nltk-3.2.1 → nltk-3.3}/nltk/test/doctest_nose_plugin.py +8 -5
  238. {nltk-3.2.1 → nltk-3.3}/nltk/test/drt.doctest +1 -1
  239. {nltk-3.2.1 → nltk-3.3}/nltk/test/featgram.doctest +1 -1
  240. {nltk-3.2.1 → nltk-3.3}/nltk/test/featstruct.doctest +2 -3
  241. {nltk-3.2.1 → nltk-3.3}/nltk/test/framenet.doctest +82 -33
  242. {nltk-3.2.1 → nltk-3.3}/nltk/test/generate.doctest +1 -1
  243. {nltk-3.2.1 → nltk-3.3}/nltk/test/gensim.doctest +6 -7
  244. {nltk-3.2.1 → nltk-3.3}/nltk/test/gensim_fixt.py +1 -0
  245. {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics.doctest +13 -15
  246. {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics_malt.doctest +1 -1
  247. {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics_malt_fixt.py +1 -0
  248. {nltk-3.2.1 → nltk-3.3}/nltk/test/grammar.doctest +1 -1
  249. {nltk-3.2.1 → nltk-3.3}/nltk/test/grammartestsuites.doctest +1 -1
  250. {nltk-3.2.1 → nltk-3.3}/nltk/test/index.doctest +1 -1
  251. {nltk-3.2.1 → nltk-3.3}/nltk/test/inference.doctest +1 -1
  252. {nltk-3.2.1 → nltk-3.3}/nltk/test/inference_fixt.py +1 -0
  253. {nltk-3.2.1 → nltk-3.3}/nltk/test/internals.doctest +1 -1
  254. {nltk-3.2.1 → nltk-3.3}/nltk/test/japanese.doctest +1 -1
  255. {nltk-3.2.1 → nltk-3.3}/nltk/test/logic.doctest +1 -1
  256. {nltk-3.2.1 → nltk-3.3}/nltk/test/metrics.doctest +3 -3
  257. {nltk-3.2.1 → nltk-3.3}/nltk/test/misc.doctest +1 -1
  258. {nltk-3.2.1 → nltk-3.3}/nltk/test/nonmonotonic.doctest +1 -1
  259. {nltk-3.2.1 → nltk-3.3}/nltk/test/nonmonotonic_fixt.py +1 -0
  260. {nltk-3.2.1 → nltk-3.3}/nltk/test/parse.doctest +1 -1
  261. {nltk-3.2.1 → nltk-3.3}/nltk/test/portuguese_en.doctest +1 -1
  262. {nltk-3.2.1 → nltk-3.3}/nltk/test/probability.doctest +1 -1
  263. {nltk-3.2.1 → nltk-3.3}/nltk/test/probability_fixt.py +2 -1
  264. {nltk-3.2.1 → nltk-3.3}/nltk/test/propbank.doctest +1 -1
  265. {nltk-3.2.1 → nltk-3.3}/nltk/test/relextract.doctest +1 -1
  266. {nltk-3.2.1 → nltk-3.3}/nltk/test/resolution.doctest +1 -1
  267. {nltk-3.2.1 → nltk-3.3}/nltk/test/runtests.py +35 -13
  268. {nltk-3.2.1 → nltk-3.3}/nltk/test/semantics.doctest +1 -1
  269. {nltk-3.2.1 → nltk-3.3}/nltk/test/sentiment.doctest +3 -3
  270. {nltk-3.2.1 → nltk-3.3}/nltk/test/sentiwordnet.doctest +1 -1
  271. {nltk-3.2.1 → nltk-3.3}/nltk/test/simple.doctest +1 -1
  272. {nltk-3.2.1 → nltk-3.3}/nltk/test/stem.doctest +2 -2
  273. {nltk-3.2.1 → nltk-3.3}/nltk/test/tag.doctest +1 -1
  274. {nltk-3.2.1 → nltk-3.3}/nltk/test/tokenize.doctest +109 -2
  275. {nltk-3.2.1 → nltk-3.3}/nltk/test/toolbox.doctest +1 -1
  276. {nltk-3.2.1 → nltk-3.3}/nltk/test/translate.doctest +1 -1
  277. {nltk-3.2.1 → nltk-3.3}/nltk/test/tree.doctest +1 -1
  278. {nltk-3.2.1 → nltk-3.3}/nltk/test/treeprettyprinter.doctest +1 -1
  279. {nltk-3.2.1 → nltk-3.3}/nltk/test/treetransforms.doctest +1 -1
  280. nltk-3.3/nltk/test/unit/test_aline.py +52 -0
  281. nltk-3.3/nltk/test/unit/test_chunk.py +56 -0
  282. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_classify.py +20 -18
  283. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_collocations.py +16 -7
  284. nltk-3.3/nltk/test/unit/test_concordance.py +98 -0
  285. nltk-3.3/nltk/test/unit/test_corenlp.py +1000 -0
  286. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_corpora.py +18 -1
  287. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_json2csv_corpus.py +4 -3
  288. nltk-3.3/nltk/test/unit/test_rte_classify.py +86 -0
  289. nltk-3.3/nltk/test/unit/test_senna.py +74 -0
  290. nltk-3.3/nltk/test/unit/test_stem.py +121 -0
  291. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_tgrep.py +4 -2
  292. nltk-3.3/nltk/test/unit/test_tokenize.py +168 -0
  293. nltk-3.3/nltk/test/unit/test_wordnet.py +134 -0
  294. nltk-3.3/nltk/test/unit/translate/test_bleu.py +244 -0
  295. nltk-3.3/nltk/test/unit/translate/test_gdfa.py +57 -0
  296. nltk-3.3/nltk/test/unit/translate/test_nist.py +37 -0
  297. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_stack_decoder.py +1 -1
  298. {nltk-3.2.1 → nltk-3.3}/nltk/test/util.doctest +1 -1
  299. {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet.doctest +17 -3
  300. {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet_fixt.py +1 -0
  301. {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet_lch.doctest +1 -1
  302. {nltk-3.2.1 → nltk-3.3}/nltk/test/wsd.doctest +1 -1
  303. {nltk-3.2.1 → nltk-3.3}/nltk/text.py +92 -39
  304. {nltk-3.2.1 → nltk-3.3}/nltk/tgrep.py +8 -7
  305. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/__init__.py +37 -15
  306. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/api.py +3 -4
  307. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/casual.py +10 -9
  308. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/mwe.py +2 -2
  309. nltk-3.3/nltk/tokenize/nist.py +173 -0
  310. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/punkt.py +186 -167
  311. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/regexp.py +13 -7
  312. nltk-3.3/nltk/tokenize/repp.py +151 -0
  313. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/sexpr.py +4 -6
  314. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/simple.py +7 -5
  315. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/stanford.py +18 -14
  316. nltk-3.3/nltk/tokenize/stanford_segmenter.py +246 -0
  317. {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/texttiling.py +43 -45
  318. nltk-3.3/nltk/tokenize/toktok.py +155 -0
  319. nltk-3.3/nltk/tokenize/treebank.py +363 -0
  320. nltk-3.3/nltk/tokenize/util.py +261 -0
  321. {nltk-3.2.1 → nltk-3.3}/nltk/toolbox.py +4 -2
  322. {nltk-3.2.1 → nltk-3.3}/nltk/translate/__init__.py +1 -1
  323. {nltk-3.2.1 → nltk-3.3}/nltk/translate/api.py +50 -40
  324. {nltk-3.2.1 → nltk-3.3}/nltk/translate/bleu_score.py +221 -156
  325. nltk-3.3/nltk/translate/chrf_score.py +137 -0
  326. {nltk-3.2.1 → nltk-3.3}/nltk/translate/gale_church.py +32 -19
  327. {nltk-3.2.1 → nltk-3.3}/nltk/translate/gdfa.py +14 -10
  328. nltk-3.3/nltk/translate/gleu_score.py +193 -0
  329. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm1.py +17 -8
  330. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm2.py +4 -4
  331. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm4.py +1 -1
  332. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm5.py +1 -1
  333. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm_model.py +4 -1
  334. {nltk-3.2.1 → nltk-3.3}/nltk/translate/metrics.py +1 -1
  335. nltk-3.3/nltk/translate/nist_score.py +178 -0
  336. {nltk-3.2.1 → nltk-3.3}/nltk/translate/phrase_based.py +1 -1
  337. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ribes_score.py +1 -1
  338. {nltk-3.2.1 → nltk-3.3}/nltk/translate/stack_decoder.py +5 -1
  339. {nltk-3.2.1 → nltk-3.3}/nltk/tree.py +10 -8
  340. {nltk-3.2.1 → nltk-3.3}/nltk/treeprettyprinter.py +6 -6
  341. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/__init__.py +1 -1
  342. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/api.py +8 -3
  343. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/common.py +9 -3
  344. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/twitter_demo.py +1 -1
  345. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/twitterclient.py +1 -1
  346. {nltk-3.2.1 → nltk-3.3}/nltk/twitter/util.py +5 -4
  347. {nltk-3.2.1 → nltk-3.3}/nltk/util.py +41 -654
  348. {nltk-3.2.1 → nltk-3.3}/nltk/wsd.py +2 -2
  349. {nltk-3.2.1 → nltk-3.3/nltk.egg-info}/PKG-INFO +13 -5
  350. {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/SOURCES.txt +23 -1
  351. nltk-3.3/nltk.egg-info/requires.txt +31 -0
  352. {nltk-3.2.1 → nltk-3.3}/setup.cfg +0 -1
  353. {nltk-3.2.1 → nltk-3.3}/setup.py +32 -5
  354. nltk-3.2.1/nltk/VERSION +0 -1
  355. nltk-3.2.1/nltk/compat.py +0 -706
  356. nltk-3.2.1/nltk/corpus/reader/pl196x.py +0 -278
  357. nltk-3.2.1/nltk/corpus/reader/verbnet.py +0 -408
  358. nltk-3.2.1/nltk/corpus/reader/wordlist.py +0 -37
  359. nltk-3.2.1/nltk/six.py +0 -868
  360. nltk-3.2.1/nltk/stem/porter.py +0 -692
  361. nltk-3.2.1/nltk/test/unit/test_stem.py +0 -36
  362. nltk-3.2.1/nltk/test/unit/test_tokenize.py +0 -23
  363. nltk-3.2.1/nltk/test/unit/translate/test_bleu.py +0 -138
  364. nltk-3.2.1/nltk/tokenize/stanford_segmenter.py +0 -157
  365. nltk-3.2.1/nltk/tokenize/treebank.py +0 -124
  366. nltk-3.2.1/nltk/tokenize/util.py +0 -90
  367. {nltk-3.2.1 → nltk-3.3}/INSTALL.txt +0 -0
  368. {nltk-3.2.1 → nltk-3.3}/MANIFEST.in +0 -0
  369. {nltk-3.2.1 → nltk-3.3}/nltk/classify/positivenaivebayes.py +0 -0
  370. {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/udhr.py +0 -0
  371. {nltk-3.2.1 → nltk-3.3}/nltk/inference/mace.py +0 -0
  372. {nltk-3.2.1 → nltk-3.3}/nltk/lazyimport.py +0 -0
  373. {nltk-3.2.1 → nltk-3.3}/nltk/misc/babelfish.py +0 -0
  374. {nltk-3.2.1 → nltk-3.3}/nltk/tag/brill_trainer.py +0 -0
  375. {nltk-3.2.1 → nltk-3.3}/nltk/tbl/api.py +0 -0
  376. {nltk-3.2.1 → nltk-3.3}/nltk/test/bleu.doctest +0 -0
  377. {nltk-3.2.1 → nltk-3.3}/nltk/test/childes.doctest +0 -0
  378. {nltk-3.2.1 → nltk-3.3}/nltk/test/corpus_fixt.py +0 -0
  379. {nltk-3.2.1 → nltk-3.3}/nltk/test/paice.doctest +0 -0
  380. {nltk-3.2.1 → nltk-3.3}/nltk/test/portuguese_en_fixt.py +0 -0
  381. {nltk-3.2.1 → nltk-3.3}/nltk/test/segmentation_fixt.py +0 -0
  382. {nltk-3.2.1 → nltk-3.3}/nltk/test/semantics_fixt.py +0 -0
  383. {nltk-3.2.1 → nltk-3.3}/nltk/test/translate_fixt.py +0 -0
  384. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/__init__.py +0 -0
  385. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_2x_compat.py +0 -0
  386. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_corpus_views.py +0 -0
  387. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_hmm.py +0 -0
  388. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_naivebayes.py +0 -0
  389. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_seekable_unicode_stream_reader.py +0 -0
  390. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_tag.py +0 -0
  391. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_twitter_auth.py +0 -0
  392. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/__init__.py +0 -0
  393. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm1.py +0 -0
  394. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm2.py +0 -0
  395. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm3.py +0 -0
  396. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm4.py +0 -0
  397. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm5.py +0 -0
  398. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm_model.py +0 -0
  399. {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/utils.py +0 -0
  400. {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm3.py +0 -0
  401. {nltk-3.2.1 → nltk-3.3}/nltk/treetransforms.py +0 -0
  402. {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/dependency_links.txt +0 -0
  403. {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/not-zip-safe +0 -0
  404. {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Natural Language Toolkit: WordNet
3
3
  #
4
- # Copyright (C) 2001-2016 NLTK Project
4
+ # Copyright (C) 2001-2018 NLTK Project
5
5
  # Author: Steven Bethard <Steven.Bethard@colorado.edu>
6
6
  # Steven Bird <stevenbird1@gmail.com>
7
7
  # Edward Loper <edloper@gmail.com>
@@ -23,7 +23,7 @@ such as hypernyms, hyponyms, synonyms, antonyms etc.
23
23
  For details about WordNet see:
24
24
  http://wordnet.princeton.edu/
25
25
 
26
- This module also allows you to find lemmas in languages
26
+ This module also allows you to find lemmas in languages
27
27
  other than English from the Open Multilingual Wordnet
28
28
  http://compling.hss.ntu.edu.sg/omw/
29
29
 
@@ -34,42 +34,46 @@ from __future__ import print_function, unicode_literals
34
34
  import math
35
35
  import re
36
36
  from itertools import islice, chain
37
- from operator import itemgetter, attrgetter
37
+ from functools import total_ordering
38
+ from operator import itemgetter
38
39
  from collections import defaultdict, deque
39
40
 
41
+ from six import iteritems
42
+ from six.moves import range
43
+
40
44
  from nltk.corpus.reader import CorpusReader
41
45
  from nltk.util import binary_search_file as _binary_search_file
42
46
  from nltk.probability import FreqDist
43
- from nltk.compat import (iteritems, python_2_unicode_compatible,
44
- total_ordering, xrange)
47
+ from nltk.compat import python_2_unicode_compatible
48
+ from nltk.internals import deprecated
45
49
 
46
50
  ######################################################################
47
- ## Table of Contents
51
+ # Table of Contents
48
52
  ######################################################################
49
- ## - Constants
50
- ## - Data Classes
51
- ## - WordNetError
52
- ## - Lemma
53
- ## - Synset
54
- ## - WordNet Corpus Reader
55
- ## - WordNet Information Content Corpus Reader
56
- ## - Similarity Metrics
57
- ## - Demo
53
+ # - Constants
54
+ # - Data Classes
55
+ # - WordNetError
56
+ # - Lemma
57
+ # - Synset
58
+ # - WordNet Corpus Reader
59
+ # - WordNet Information Content Corpus Reader
60
+ # - Similarity Metrics
61
+ # - Demo
58
62
 
59
63
  ######################################################################
60
- ## Constants
64
+ # Constants
61
65
  ######################################################################
62
66
 
63
67
  #: Positive infinity (for similarity functions)
64
68
  _INF = 1e300
65
69
 
66
- #{ Part-of-speech constants
70
+ # { Part-of-speech constants
67
71
  ADJ, ADJ_SAT, ADV, NOUN, VERB = 'a', 's', 'r', 'n', 'v'
68
- #}
72
+ # }
69
73
 
70
74
  POS_LIST = [NOUN, VERB, ADJ, ADV]
71
75
 
72
- #: A table of strings that are used to express verb frames.
76
+ # A table of strings that are used to express verb frames.
73
77
  VERB_FRAME_STRINGS = (
74
78
  None,
75
79
  "Something %s",
@@ -108,12 +112,14 @@ VERB_FRAME_STRINGS = (
108
112
  "It %s that CLAUSE",
109
113
  "Something %s INFINITIVE")
110
114
 
111
- SENSENUM_RE = re.compile(r'\.\d\d\.')
115
+ SENSENUM_RE = re.compile(r'\.[\d]+\.')
116
+
112
117
 
113
118
  ######################################################################
114
- ## Data Classes
119
+ # Data Classes
115
120
  ######################################################################
116
121
 
122
+
117
123
  class WordNetError(Exception):
118
124
  """An exception class for wordnet-related errors."""
119
125
 
@@ -126,13 +132,13 @@ class _WordNetObject(object):
126
132
  return self._related('@')
127
133
 
128
134
  def _hypernyms(self):
129
- return self._related('@', sort=False)
135
+ return self._related('@')
130
136
 
131
137
  def instance_hypernyms(self):
132
138
  return self._related('@i')
133
139
 
134
140
  def _instance_hypernyms(self):
135
- return self._related('@i', sort=False)
141
+ return self._related('@i')
136
142
 
137
143
  def hyponyms(self):
138
144
  return self._related('~')
@@ -263,7 +269,7 @@ class Lemma(_WordNetObject):
263
269
  self._lex_id = lex_id
264
270
  self._lang = 'eng'
265
271
 
266
- self._key = None # gets set later.
272
+ self._key = None # gets set later.
267
273
 
268
274
  def name(self):
269
275
  return self._name
@@ -291,10 +297,12 @@ class Lemma(_WordNetObject):
291
297
  return "%s('%s.%s')" % tup
292
298
 
293
299
  def _related(self, relation_symbol):
294
- get_synset = self._wordnet_corpus_reader._synset_from_pos_and_offset
295
- return sorted([get_synset(pos, offset)._lemmas[lemma_index]
296
- for pos, offset, lemma_index
297
- in self._synset._lemma_pointers[self._name, relation_symbol]])
300
+ get_synset = self._wordnet_corpus_reader.synset_from_pos_and_offset
301
+ return [
302
+ get_synset(pos, offset)._lemmas[lemma_index]
303
+ for pos, offset, lemma_index
304
+ in self._synset._lemma_pointers[self._name, relation_symbol]
305
+ ]
298
306
 
299
307
  def count(self):
300
308
  """Return the frequency count for this Lemma"""
@@ -383,11 +391,11 @@ class Synset(_WordNetObject):
383
391
  self._lemma_names = []
384
392
  self._definition = None
385
393
  self._examples = []
386
- self._lexname = None # lexicographer name
394
+ self._lexname = None # lexicographer name
387
395
  self._all_hypernyms = None
388
396
 
389
397
  self._pointers = defaultdict(set)
390
- self._lemma_pointers = defaultdict(set)
398
+ self._lemma_pointers = defaultdict(list)
391
399
 
392
400
  def pos(self):
393
401
  return self._pos
@@ -421,7 +429,7 @@ class Synset(_WordNetObject):
421
429
 
422
430
  def lemma_names(self, lang='eng'):
423
431
  '''Return all the lemma_names associated with the synset'''
424
- if lang=='eng':
432
+ if lang == 'eng':
425
433
  return self._lemma_names
426
434
  else:
427
435
  self._wordnet_corpus_reader._load_lang_data(lang)
@@ -431,21 +439,30 @@ class Synset(_WordNetObject):
431
439
  return self._wordnet_corpus_reader._lang_data[lang][0][i]
432
440
  else:
433
441
  return []
434
-
442
+
435
443
  def lemmas(self, lang='eng'):
436
444
  '''Return all the lemma objects associated with the synset'''
437
- if lang=='eng':
445
+ if lang == 'eng':
438
446
  return self._lemmas
439
447
  else:
440
448
  self._wordnet_corpus_reader._load_lang_data(lang)
441
449
  lemmark = []
442
450
  lemmy = self.lemma_names(lang)
443
451
  for lem in lemmy:
444
- temp= Lemma(self._wordnet_corpus_reader, self, lem, self._wordnet_corpus_reader._lexnames.index(self.lexname()), 0, None)
445
- temp._lang=lang
452
+ temp = Lemma(
453
+ self._wordnet_corpus_reader,
454
+ self,
455
+ lem,
456
+ self._wordnet_corpus_reader._lexnames.index(
457
+ self.lexname()
458
+ ),
459
+ 0,
460
+ None
461
+ )
462
+ temp._lang = lang
446
463
  lemmark.append(temp)
447
464
  return lemmark
448
-
465
+
449
466
  def root_hypernyms(self):
450
467
  """Get the topmost hypernyms of this synset in WordNet."""
451
468
 
@@ -555,32 +572,40 @@ class Synset(_WordNetObject):
555
572
  :return: The synsets that are hypernyms of both synsets.
556
573
  """
557
574
  if not self._all_hypernyms:
558
- self._all_hypernyms = set(self_synset
559
- for self_synsets in self._iter_hypernym_lists()
560
- for self_synset in self_synsets)
575
+ self._all_hypernyms = set(
576
+ self_synset
577
+ for self_synsets in self._iter_hypernym_lists()
578
+ for self_synset in self_synsets
579
+ )
561
580
  if not other._all_hypernyms:
562
- other._all_hypernyms = set(other_synset
563
- for other_synsets in other._iter_hypernym_lists()
564
- for other_synset in other_synsets)
581
+ other._all_hypernyms = set(
582
+ other_synset
583
+ for other_synsets in other._iter_hypernym_lists()
584
+ for other_synset in other_synsets
585
+ )
565
586
  return list(self._all_hypernyms.intersection(other._all_hypernyms))
566
587
 
567
- def lowest_common_hypernyms(self, other, simulate_root=False, use_min_depth=False):
588
+ def lowest_common_hypernyms(
589
+ self, other, simulate_root=False, use_min_depth=False
590
+ ):
568
591
  """
569
592
  Get a list of lowest synset(s) that both synsets have as a hypernym.
570
- When `use_min_depth == False` this means that the synset which appears as a
571
- hypernym of both `self` and `other` with the lowest maximum depth is returned
572
- or if there are multiple such synsets at the same depth they are all returned
593
+ When `use_min_depth == False` this means that the synset which appears
594
+ as a hypernym of both `self` and `other` with the lowest maximum depth
595
+ is returned or if there are multiple such synsets at the same depth
596
+ they are all returned
573
597
 
574
- However, if `use_min_depth == True` then the synset(s) which has/have the lowest
575
- minimum depth and appear(s) in both paths is/are returned.
598
+ However, if `use_min_depth == True` then the synset(s) which has/have
599
+ the lowest minimum depth and appear(s) in both paths is/are returned.
576
600
 
577
- By setting the use_min_depth flag to True, the behavior of NLTK2 can be preserved.
578
- This was changed in NLTK3 to give more accurate results in a small set of cases,
579
- generally with synsets concerning people. (eg: 'chef.n.01', 'fireman.n.01', etc.)
601
+ By setting the use_min_depth flag to True, the behavior of NLTK2 can be
602
+ preserved. This was changed in NLTK3 to give more accurate results in a
603
+ small set of cases, generally with synsets concerning people. (eg:
604
+ 'chef.n.01', 'fireman.n.01', etc.)
580
605
 
581
- This method is an implementation of Ted Pedersen's "Lowest Common Subsumer" method
582
- from the Perl Wordnet module. It can return either "self" or "other" if they are a
583
- hypernym of the other.
606
+ This method is an implementation of Ted Pedersen's "Lowest Common
607
+ Subsumer" method from the Perl Wordnet module. It can return either
608
+ "self" or "other" if they are a hypernym of the other.
584
609
 
585
610
  :type other: Synset
586
611
  :param other: other input synset
@@ -594,11 +619,13 @@ class Synset(_WordNetObject):
594
619
  If you are using wordnet 1.6, a fake root will need to be added
595
620
  for nouns as well.
596
621
  :type use_min_depth: bool
597
- :param use_min_depth: This setting mimics older (v2) behavior of NLTK wordnet
598
- If True, will use the min_depth function to calculate the lowest common
599
- hypernyms. This is known to give strange results for some synset pairs
600
- (eg: 'chef.n.01', 'fireman.n.01') but is retained for backwards compatibility
601
- :return: The synsets that are the lowest common hypernyms of both synsets
622
+ :param use_min_depth: This setting mimics older (v2) behavior of NLTK
623
+ wordnet If True, will use the min_depth function to calculate the
624
+ lowest common hypernyms. This is known to give strange results for
625
+ some synset pairs (eg: 'chef.n.01', 'fireman.n.01') but is retained
626
+ for backwards compatibility
627
+ :return: The synsets that are the lowest common hypernyms of both
628
+ synsets
602
629
  """
603
630
  synsets = self.common_hypernyms(other)
604
631
  if simulate_root:
@@ -611,10 +638,14 @@ class Synset(_WordNetObject):
611
638
  try:
612
639
  if use_min_depth:
613
640
  max_depth = max(s.min_depth() for s in synsets)
614
- unsorted_lch = [s for s in synsets if s.min_depth() == max_depth]
641
+ unsorted_lch = [
642
+ s for s in synsets if s.min_depth() == max_depth
643
+ ]
615
644
  else:
616
645
  max_depth = max(s.max_depth() for s in synsets)
617
- unsorted_lch = [s for s in synsets if s.max_depth() == max_depth]
646
+ unsorted_lch = [
647
+ s for s in synsets if s.max_depth() == max_depth
648
+ ]
618
649
  return sorted(unsorted_lch)
619
650
  except ValueError:
620
651
  return []
@@ -633,7 +664,10 @@ class Synset(_WordNetObject):
633
664
  """
634
665
  distances = set([(self, distance)])
635
666
  for hypernym in self._hypernyms() + self._instance_hypernyms():
636
- distances |= hypernym.hypernym_distances(distance+1, simulate_root=False)
667
+ distances |= hypernym.hypernym_distances(
668
+ distance+1,
669
+ simulate_root=False
670
+ )
637
671
  if simulate_root:
638
672
  fake_synset = Synset(None)
639
673
  fake_synset._name = '*ROOT*'
@@ -762,7 +796,10 @@ class Synset(_WordNetObject):
762
796
  itself.
763
797
  """
764
798
 
765
- distance = self.shortest_path_distance(other, simulate_root=simulate_root and self._needs_root())
799
+ distance = self.shortest_path_distance(
800
+ other,
801
+ simulate_root=simulate_root and self._needs_root()
802
+ )
766
803
  if distance is None or distance < 0:
767
804
  return None
768
805
  return 1.0 / (distance + 1)
@@ -795,18 +832,25 @@ class Synset(_WordNetObject):
795
832
  """
796
833
 
797
834
  if self._pos != other._pos:
798
- raise WordNetError('Computing the lch similarity requires ' + \
799
- '%s and %s to have the same part of speech.' % \
800
- (self, other))
835
+ raise WordNetError(
836
+ 'Computing the lch similarity requires '
837
+ '%s and %s to have the same part of speech.' %
838
+ (self, other)
839
+ )
801
840
 
802
841
  need_root = self._needs_root()
803
842
 
804
843
  if self._pos not in self._wordnet_corpus_reader._max_depth:
805
- self._wordnet_corpus_reader._compute_max_depth(self._pos, need_root)
844
+ self._wordnet_corpus_reader._compute_max_depth(
845
+ self._pos, need_root
846
+ )
806
847
 
807
848
  depth = self._wordnet_corpus_reader._max_depth[self._pos]
808
849
 
809
- distance = self.shortest_path_distance(other, simulate_root=simulate_root and need_root)
850
+ distance = self.shortest_path_distance(
851
+ other,
852
+ simulate_root=simulate_root and need_root
853
+ )
810
854
 
811
855
  if distance is None or distance < 0 or depth == 0:
812
856
  return None
@@ -842,9 +886,9 @@ class Synset(_WordNetObject):
842
886
  there is usually a default root except for WordNet version 1.6.
843
887
  If you are using wordnet 1.6, a fake root will be added for nouns
844
888
  as well.
845
- :return: A float score denoting the similarity of the two ``Synset`` objects,
846
- normally greater than zero. If no connecting path between the two
847
- senses can be found, None is returned.
889
+ :return: A float score denoting the similarity of the two ``Synset``
890
+ objects, normally greater than zero. If no connecting path between
891
+ the two senses can be found, None is returned.
848
892
 
849
893
  """
850
894
 
@@ -852,13 +896,16 @@ class Synset(_WordNetObject):
852
896
  # Note that to preserve behavior from NLTK2 we set use_min_depth=True
853
897
  # It is possible that more accurate results could be obtained by
854
898
  # removing this setting and it should be tested later on
855
- subsumers = self.lowest_common_hypernyms(other, simulate_root=simulate_root and need_root, use_min_depth=True)
899
+ subsumers = self.lowest_common_hypernyms(
900
+ other,
901
+ simulate_root=simulate_root and need_root, use_min_depth=True
902
+ )
856
903
 
857
904
  # If no LCS was found return None
858
905
  if len(subsumers) == 0:
859
906
  return None
860
907
 
861
- subsumer = subsumers[0]
908
+ subsumer = self if self in subsumers else subsumers[0]
862
909
 
863
910
  # Get the longest path from the LCS to the root,
864
911
  # including a correction:
@@ -867,16 +914,22 @@ class Synset(_WordNetObject):
867
914
  depth = subsumer.max_depth() + 1
868
915
 
869
916
  # Note: No need for an additional add-one correction for non-nouns
870
- # to account for an imaginary root node because that is now automatically
871
- # handled by simulate_root
917
+ # to account for an imaginary root node because that is now
918
+ # automatically handled by simulate_root
872
919
  # if subsumer._pos != NOUN:
873
920
  # depth += 1
874
921
 
875
922
  # Get the shortest path from the LCS to each of the synsets it is
876
923
  # subsuming. Add this to the LCS path length to get the path
877
924
  # length from each synset to the root.
878
- len1 = self.shortest_path_distance(subsumer, simulate_root=simulate_root and need_root)
879
- len2 = other.shortest_path_distance(subsumer, simulate_root=simulate_root and need_root)
925
+ len1 = self.shortest_path_distance(
926
+ subsumer,
927
+ simulate_root=simulate_root and need_root
928
+ )
929
+ len2 = other.shortest_path_distance(
930
+ subsumer,
931
+ simulate_root=simulate_root and need_root
932
+ )
880
933
  if len1 is None or len2 is None:
881
934
  return None
882
935
  len1 += depth
@@ -893,10 +946,11 @@ class Synset(_WordNetObject):
893
946
  :type other: Synset
894
947
  :param other: The ``Synset`` that this ``Synset`` is being compared to.
895
948
  :type ic: dict
896
- :param ic: an information content object (as returned by ``nltk.corpus.wordnet_ic.ic()``).
897
- :return: A float score denoting the similarity of the two ``Synset`` objects.
898
- Synsets whose LCS is the root node of the taxonomy will have a
899
- score of 0 (e.g. N['dog'][0] and N['table'][0]).
949
+ :param ic: an information content object (as returned by
950
+ ``nltk.corpus.wordnet_ic.ic()``).
951
+ :return: A float score denoting the similarity of the two ``Synset``
952
+ objects. Synsets whose LCS is the root node of the taxonomy will
953
+ have a score of 0 (e.g. N['dog'][0] and N['table'][0]).
900
954
  """
901
955
 
902
956
  ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
@@ -913,8 +967,10 @@ class Synset(_WordNetObject):
913
967
  :type other: Synset
914
968
  :param other: The ``Synset`` that this ``Synset`` is being compared to.
915
969
  :type ic: dict
916
- :param ic: an information content object (as returned by ``nltk.corpus.wordnet_ic.ic()``).
917
- :return: A float score denoting the similarity of the two ``Synset`` objects.
970
+ :param ic: an information content object (as returned by
971
+ ``nltk.corpus.wordnet_ic.ic()``).
972
+ :return: A float score denoting the similarity of the two ``Synset``
973
+ objects.
918
974
  """
919
975
 
920
976
  if self == other:
@@ -945,9 +1001,10 @@ class Synset(_WordNetObject):
945
1001
  :type other: Synset
946
1002
  :param other: The ``Synset`` that this ``Synset`` is being compared to.
947
1003
  :type ic: dict
948
- :param ic: an information content object (as returned by ``nltk.corpus.wordnet_ic.ic()``).
949
- :return: A float score denoting the similarity of the two ``Synset`` objects,
950
- in the range 0 to 1.
1004
+ :param ic: an information content object (as returned by
1005
+ ``nltk.corpus.wordnet_ic.ic()``).
1006
+ :return: A float score denoting the similarity of the two ``Synset``
1007
+ objects, in the range 0 to 1.
951
1008
  """
952
1009
 
953
1010
  ic1, ic2, lcs_ic = _lcs_ic(self, other, ic)
@@ -966,15 +1023,16 @@ class Synset(_WordNetObject):
966
1023
  yield todo
967
1024
  todo = [hypernym
968
1025
  for synset in todo
969
- for hypernym in (synset.hypernyms() +
970
- synset.instance_hypernyms())
1026
+ for hypernym in (
1027
+ synset.hypernyms() + synset.instance_hypernyms()
1028
+ )
971
1029
  if hypernym not in seen]
972
1030
 
973
1031
  def __repr__(self):
974
1032
  return "%s('%s')" % (type(self).__name__, self._name)
975
1033
 
976
1034
  def _related(self, relation_symbol, sort=True):
977
- get_synset = self._wordnet_corpus_reader._synset_from_pos_and_offset
1035
+ get_synset = self._wordnet_corpus_reader.synset_from_pos_and_offset
978
1036
  pointer_tuples = self._pointers[relation_symbol]
979
1037
  r = [get_synset(pos, offset) for pos, offset in pointer_tuples]
980
1038
  if sort:
@@ -983,7 +1041,7 @@ class Synset(_WordNetObject):
983
1041
 
984
1042
 
985
1043
  ######################################################################
986
- ## WordNet Corpus Reader
1044
+ # WordNet Corpus Reader
987
1045
  ######################################################################
988
1046
 
989
1047
  class WordNetCorpusReader(CorpusReader):
@@ -993,18 +1051,18 @@ class WordNetCorpusReader(CorpusReader):
993
1051
 
994
1052
  _ENCODING = 'utf8'
995
1053
 
996
- #{ Part-of-speech constants
1054
+ # { Part-of-speech constants
997
1055
  ADJ, ADJ_SAT, ADV, NOUN, VERB = 'a', 's', 'r', 'n', 'v'
998
- #}
1056
+ # }
999
1057
 
1000
- #{ Filename constants
1058
+ # { Filename constants
1001
1059
  _FILEMAP = {ADJ: 'adj', ADV: 'adv', NOUN: 'noun', VERB: 'verb'}
1002
- #}
1060
+ # }
1003
1061
 
1004
- #{ Part of speech constants
1062
+ # { Part of speech constants
1005
1063
  _pos_numbers = {NOUN: 1, VERB: 2, ADJ: 3, ADV: 4, ADJ_SAT: 5}
1006
1064
  _pos_names = dict(tup[::-1] for tup in _pos_numbers.items())
1007
- #}
1065
+ # }
1008
1066
 
1009
1067
  #: A list of file identifiers for all the fileids used by this
1010
1068
  #: corpus reader.
@@ -1062,48 +1120,38 @@ class WordNetCorpusReader(CorpusReader):
1062
1120
 
1063
1121
  def of2ss(self, of):
1064
1122
  ''' take an id and return the synsets '''
1065
- return self._synset_from_pos_and_offset(of[-1], int(of[:8]))
1123
+ return self.synset_from_pos_and_offset(of[-1], int(of[:8]))
1066
1124
 
1067
1125
  def ss2of(self, ss):
1068
1126
  ''' return the ID of the synset '''
1069
1127
  return ("{:08d}-{}".format(ss.offset(), ss.pos()))
1070
-
1071
- def _load_lang_data(self, lang):
1072
- ''' load the wordnet data of the requested language from the file to the cache, _lang_data '''
1073
1128
 
1074
- if lang not in self.langs():
1075
- raise WordNetError("Language is not supported.")
1129
+ def _load_lang_data(self, lang):
1130
+ ''' load the wordnet data of the requested language from the file to
1131
+ the cache, _lang_data '''
1076
1132
 
1077
1133
  if lang in self._lang_data.keys():
1078
1134
  return
1079
1135
 
1080
- f = self._omw_reader.open('{0:}/wn-data-{0:}.tab'.format(lang))
1136
+ if lang not in self.langs():
1137
+ raise WordNetError("Language is not supported.")
1081
1138
 
1082
- self._lang_data[lang].append(defaultdict(list))
1083
- self._lang_data[lang].append(defaultdict(list))
1084
-
1085
- for l in f.readlines():
1086
- l = l.replace('\n', '')
1087
- l = l.replace(' ', '_')
1088
- if l[0] != '#':
1089
- word = l.split('\t')
1090
- self._lang_data[lang][0][word[0]].append(word[2])
1091
- self._lang_data[lang][1][word[2]].append(word[0])
1139
+ f = self._omw_reader.open('{0:}/wn-data-{0:}.tab'.format(lang))
1140
+ self.custom_lemmas(f, lang)
1092
1141
  f.close()
1093
1142
 
1094
1143
  def langs(self):
1095
1144
  ''' return a list of languages supported by Multilingual Wordnet '''
1096
1145
  import os
1097
- langs = [ 'eng' ]
1146
+ langs = ['eng']
1098
1147
  fileids = self._omw_reader.fileids()
1099
1148
  for fileid in fileids:
1100
1149
  file_name, file_extension = os.path.splitext(fileid)
1101
1150
  if file_extension == '.tab':
1102
1151
  langs.append(file_name.split('-')[-1])
1103
-
1152
+
1104
1153
  return langs
1105
1154
 
1106
-
1107
1155
  def _load_lemma_pos_offset_map(self):
1108
1156
  for suffix in self._FILEMAP.values():
1109
1157
 
@@ -1113,7 +1161,9 @@ class WordNetCorpusReader(CorpusReader):
1113
1161
  continue
1114
1162
 
1115
1163
  _iter = iter(line.split())
1116
- _next_token = lambda: next(_iter)
1164
+
1165
+ def _next_token(): return next(_iter)
1166
+
1117
1167
  try:
1118
1168
 
1119
1169
  # get the lemma and part-of-speech
@@ -1124,19 +1174,23 @@ class WordNetCorpusReader(CorpusReader):
1124
1174
  n_synsets = int(_next_token())
1125
1175
  assert n_synsets > 0
1126
1176
 
1127
- # get the pointer symbols for all synsets of this lemma
1177
+ # get and ignore the pointer symbols for all synsets of
1178
+ # this lemma
1128
1179
  n_pointers = int(_next_token())
1129
- _ = [_next_token() for _ in xrange(n_pointers)]
1180
+ [_next_token() for _ in range(n_pointers)]
1130
1181
 
1131
1182
  # same as number of synsets
1132
1183
  n_senses = int(_next_token())
1133
1184
  assert n_synsets == n_senses
1134
1185
 
1135
- # get number of senses ranked according to frequency
1136
- _ = int(_next_token())
1186
+ # get and ignore number of senses ranked according to
1187
+ # frequency
1188
+ _next_token()
1137
1189
 
1138
1190
  # get synset offsets
1139
- synset_offsets = [int(_next_token()) for _ in xrange(n_synsets)]
1191
+ synset_offsets = [
1192
+ int(_next_token()) for _ in range(n_synsets)
1193
+ ]
1140
1194
 
1141
1195
  # raise more informative error with file name and line number
1142
1196
  except (AssertionError, ValueError) as e:
@@ -1181,15 +1235,22 @@ class WordNetCorpusReader(CorpusReader):
1181
1235
  fh.seek(0)
1182
1236
  return version
1183
1237
 
1184
- #////////////////////////////////////////////////////////////
1238
+ #############################################################
1185
1239
  # Loading Lemmas
1186
- #////////////////////////////////////////////////////////////
1240
+ #############################################################
1187
1241
 
1188
1242
  def lemma(self, name, lang='eng'):
1189
1243
  '''Return lemma object that matches the name'''
1190
- # cannot simply split on first '.', e.g.: '.45_caliber.a.01..45_caliber'
1244
+ # cannot simply split on first '.',
1245
+ # e.g.: '.45_caliber.a.01..45_caliber'
1191
1246
  separator = SENSENUM_RE.search(name).start()
1192
- synset_name, lemma_name = name[:separator+3], name[separator+4:]
1247
+
1248
+ leadingZero = int(name[separator+1]) == 0
1249
+ if (leadingZero):
1250
+ synset_name, lemma_name = name[:separator+3], name[separator+4:]
1251
+ else:
1252
+ synset_name, lemma_name = name[:separator+2], name[separator+3:]
1253
+
1193
1254
  synset = self.synset(synset_name)
1194
1255
  for lemma in synset.lemmas(lang):
1195
1256
  if lemma._name == lemma_name:
@@ -1213,7 +1274,7 @@ class WordNetCorpusReader(CorpusReader):
1213
1274
  if not synset_line:
1214
1275
  raise WordNetError("No synset found for key %r" % key)
1215
1276
  offset = int(synset_line.split()[1])
1216
- synset = self._synset_from_pos_and_offset(pos, offset)
1277
+ synset = self.synset_from_pos_and_offset(pos, offset)
1217
1278
 
1218
1279
  # return the corresponding lemma
1219
1280
  for lemma in synset._lemmas:
@@ -1221,9 +1282,9 @@ class WordNetCorpusReader(CorpusReader):
1221
1282
  return lemma
1222
1283
  raise WordNetError("No lemma found for for key %r" % key)
1223
1284
 
1224
- #////////////////////////////////////////////////////////////
1285
+ #############################################################
1225
1286
  # Loading Synsets
1226
- #////////////////////////////////////////////////////////////
1287
+ #############################################################
1227
1288
  def synset(self, name):
1228
1289
  # split name into lemma, part of speech and synset number
1229
1290
  lemma, pos, synset_index_str = name.lower().rsplit('.', 2)
@@ -1245,7 +1306,7 @@ class WordNetCorpusReader(CorpusReader):
1245
1306
  raise WordNetError(message % tup)
1246
1307
 
1247
1308
  # load synset information from the appropriate file
1248
- synset = self._synset_from_pos_and_offset(pos, offset)
1309
+ synset = self.synset_from_pos_and_offset(pos, offset)
1249
1310
 
1250
1311
  # some basic sanity checks on loaded attributes
1251
1312
  if pos == 's' and synset._pos == 'a':
@@ -1269,7 +1330,7 @@ class WordNetCorpusReader(CorpusReader):
1269
1330
  self._data_file_map[pos] = self.open(fileid)
1270
1331
  return self._data_file_map[pos]
1271
1332
 
1272
- def _synset_from_pos_and_offset(self, pos, offset):
1333
+ def synset_from_pos_and_offset(self, pos, offset):
1273
1334
  # Check to see if the synset is in the cache
1274
1335
  if offset in self._synset_offset_cache[pos]:
1275
1336
  return self._synset_offset_cache[pos][offset]
@@ -1282,6 +1343,15 @@ class WordNetCorpusReader(CorpusReader):
1282
1343
  self._synset_offset_cache[pos][offset] = synset
1283
1344
  return synset
1284
1345
 
1346
+ @deprecated('Use public method synset_from_pos_and_offset() instead')
1347
+ def _synset_from_pos_and_offset(self, *args, **kwargs):
1348
+ """
1349
+ Hack to help people like the readers of
1350
+ http://stackoverflow.com/a/27145655/1709587
1351
+ who were using this function before it was officially a public method
1352
+ """
1353
+ return self.synset_from_pos_and_offset(*args, **kwargs)
1354
+
1285
1355
  def _synset_from_pos_and_line(self, pos, data_file_line):
1286
1356
  # Construct a new (empty) synset.
1287
1357
  synset = Synset(self)
@@ -1303,7 +1373,8 @@ class WordNetCorpusReader(CorpusReader):
1303
1373
 
1304
1374
  # split the other info into fields
1305
1375
  _iter = iter(columns_str.split())
1306
- _next_token = lambda: next(_iter)
1376
+
1377
+ def _next_token(): return next(_iter)
1307
1378
 
1308
1379
  # get the offset
1309
1380
  synset._offset = int(_next_token())
@@ -1317,7 +1388,7 @@ class WordNetCorpusReader(CorpusReader):
1317
1388
 
1318
1389
  # create Lemma objects for each lemma
1319
1390
  n_lemmas = int(_next_token(), 16)
1320
- for _ in xrange(n_lemmas):
1391
+ for _ in range(n_lemmas):
1321
1392
  # get the lemma name
1322
1393
  lemma_name = _next_token()
1323
1394
  # get the lex_id (used for sense_keys)
@@ -1333,7 +1404,7 @@ class WordNetCorpusReader(CorpusReader):
1333
1404
 
1334
1405
  # collect the pointer tuples
1335
1406
  n_pointers = int(_next_token())
1336
- for _ in xrange(n_pointers):
1407
+ for _ in range(n_pointers):
1337
1408
  symbol = _next_token()
1338
1409
  offset = int(_next_token())
1339
1410
  pos = _next_token()
@@ -1346,7 +1417,7 @@ class WordNetCorpusReader(CorpusReader):
1346
1417
  source_lemma_name = synset._lemmas[source_index]._name
1347
1418
  lemma_pointers = synset._lemma_pointers
1348
1419
  tups = lemma_pointers[source_lemma_name, symbol]
1349
- tups.add((pos, offset, target_index))
1420
+ tups.append((pos, offset, target_index))
1350
1421
 
1351
1422
  # read the verb frames
1352
1423
  try:
@@ -1354,7 +1425,7 @@ class WordNetCorpusReader(CorpusReader):
1354
1425
  except StopIteration:
1355
1426
  pass
1356
1427
  else:
1357
- for _ in xrange(frame_count):
1428
+ for _ in range(frame_count):
1358
1429
  # read the plus sign
1359
1430
  plus = _next_token()
1360
1431
  assert plus == '+'
@@ -1367,14 +1438,16 @@ class WordNetCorpusReader(CorpusReader):
1367
1438
  synset._frame_ids.append(frame_number)
1368
1439
  for lemma in synset._lemmas:
1369
1440
  lemma._frame_ids.append(frame_number)
1370
- lemma._frame_strings.append(frame_string_fmt %
1371
- lemma._name)
1441
+ lemma._frame_strings.append(
1442
+ frame_string_fmt % lemma._name
1443
+ )
1372
1444
  # only a specific word in the synset
1373
1445
  else:
1374
1446
  lemma = synset._lemmas[lemma_number - 1]
1375
1447
  lemma._frame_ids.append(frame_number)
1376
- lemma._frame_strings.append(frame_string_fmt %
1377
- lemma._name)
1448
+ lemma._frame_strings.append(
1449
+ frame_string_fmt % lemma._name
1450
+ )
1378
1451
 
1379
1452
  # raise a more informative error with line text
1380
1453
  except ValueError as e:
@@ -1402,27 +1475,71 @@ class WordNetCorpusReader(CorpusReader):
1402
1475
 
1403
1476
  return synset
1404
1477
 
1405
- #////////////////////////////////////////////////////////////
1478
+ def synset_from_sense_key(self, sense_key):
1479
+ """
1480
+ Retrieves synset based on a given sense_key. Sense keys can be
1481
+ obtained from lemma.key()
1482
+
1483
+ From https://wordnet.princeton.edu/wordnet/man/senseidx.5WN.html:
1484
+ A sense_key is represented as:
1485
+ lemma % lex_sense (e.g. 'dog%1:18:01::')
1486
+ where lex_sense is encoded as:
1487
+ ss_type:lex_filenum:lex_id:head_word:head_id
1488
+
1489
+ lemma: ASCII text of word/collocation, in lower case
1490
+ ss_type: synset type for the sense (1 digit int)
1491
+ The synset type is encoded as follows:
1492
+ 1 NOUN
1493
+ 2 VERB
1494
+ 3 ADJECTIVE
1495
+ 4 ADVERB
1496
+ 5 ADJECTIVE SATELLITE
1497
+ lex_filenum: name of lexicographer file containing the synset for the sense (2 digit int)
1498
+ lex_id: when paired with lemma, uniquely identifies a sense in the lexicographer file (2 digit int)
1499
+ head_word: lemma of the first word in satellite's head synset
1500
+ Only used if sense is in an adjective satellite synset
1501
+ head_id: uniquely identifies sense in a lexicographer file when paired with head_word
1502
+ Only used if head_word is present (2 digit int)
1503
+ """
1504
+ sense_key_regex = re.compile(r"(.*)\%(.*):(.*):(.*):(.*):(.*)")
1505
+ synset_types = {1:NOUN, 2:VERB, 3:ADJ, 4:ADV, 5:ADJ_SAT}
1506
+ lemma, ss_type, _, lex_id, _, _ = sense_key_regex.match(sense_key).groups()
1507
+
1508
+ # check that information extracted from sense_key is valid
1509
+ error = None
1510
+ if not lemma:
1511
+ error = "lemma"
1512
+ elif int(ss_type) not in synset_types:
1513
+ error = "ss_type"
1514
+ elif int(lex_id) < 0 or int(lex_id) > 99:
1515
+ error = "lex_id"
1516
+ if error:
1517
+ raise WordNetError("valid {} could not be extracted from the sense key".format(error))
1518
+
1519
+ synset_id = '.'.join([lemma, synset_types[int(ss_type)], lex_id])
1520
+ return self.synset(synset_id)
1521
+
1522
+ #############################################################
1406
1523
  # Retrieve synsets and lemmas.
1407
- #////////////////////////////////////////////////////////////
1524
+ #############################################################
1408
1525
 
1409
- def synsets(self, lemma, pos=None, lang='eng'):
1526
+ def synsets(self, lemma, pos=None, lang='eng', check_exceptions=True):
1410
1527
  """Load all synsets with a given lemma and part of speech tag.
1411
1528
  If no pos is specified, all synsets for all parts of speech
1412
- will be loaded.
1529
+ will be loaded.
1413
1530
  If lang is specified, all the synsets associated with the lemma name
1414
1531
  of that language will be returned.
1415
1532
  """
1416
1533
  lemma = lemma.lower()
1417
-
1534
+
1418
1535
  if lang == 'eng':
1419
- get_synset = self._synset_from_pos_and_offset
1536
+ get_synset = self.synset_from_pos_and_offset
1420
1537
  index = self._lemma_pos_offset_map
1421
1538
  if pos is None:
1422
1539
  pos = POS_LIST
1423
1540
  return [get_synset(p, offset)
1424
1541
  for p in pos
1425
- for form in self._morphy(lemma, p)
1542
+ for form in self._morphy(lemma, p, check_exceptions)
1426
1543
  for offset in index[form].get(p, [])]
1427
1544
 
1428
1545
  else:
@@ -1439,8 +1556,8 @@ class WordNetCorpusReader(CorpusReader):
1439
1556
  name and part of speech tag. Matches any part of speech tag if none is
1440
1557
  specified."""
1441
1558
 
1559
+ lemma = lemma.lower()
1442
1560
  if lang == 'eng':
1443
- lemma = lemma.lower()
1444
1561
  return [lemma_obj
1445
1562
  for synset in self.synsets(lemma, pos)
1446
1563
  for lemma_obj in synset.lemmas()
@@ -1453,23 +1570,25 @@ class WordNetCorpusReader(CorpusReader):
1453
1570
  for s in syn:
1454
1571
  if pos is not None and s.pos() != pos:
1455
1572
  continue
1456
- a = Lemma(self, s, lemma, self._lexnames.index(s.lexname()), 0, None)
1457
- a._lang = lang
1458
- lemmas.append(a)
1573
+ for lemma_obj in s.lemmas(lang=lang):
1574
+ if lemma_obj.name().lower() == lemma:
1575
+ lemmas.append(lemma_obj)
1459
1576
  return lemmas
1460
1577
 
1461
1578
  def all_lemma_names(self, pos=None, lang='eng'):
1462
1579
  """Return all lemma names for all synsets for the given
1463
- part of speech tag and language or languages. If pos is not specified, all synsets
1464
- for all parts of speech will be used."""
1580
+ part of speech tag and language or languages. If pos is
1581
+ not specified, all synsets for all parts of speech will
1582
+ be used."""
1465
1583
 
1466
1584
  if lang == 'eng':
1467
1585
  if pos is None:
1468
1586
  return iter(self._lemma_pos_offset_map)
1469
1587
  else:
1470
- return (lemma
1471
- for lemma in self._lemma_pos_offset_map
1472
- if pos in self._lemma_pos_offset_map[lemma])
1588
+ return (
1589
+ lemma for lemma in self._lemma_pos_offset_map
1590
+ if pos in self._lemma_pos_offset_map[lemma]
1591
+ )
1473
1592
  else:
1474
1593
  self._load_lang_data(lang)
1475
1594
  lemma = []
@@ -1477,10 +1596,10 @@ class WordNetCorpusReader(CorpusReader):
1477
1596
  if pos is not None and i[-1] != pos:
1478
1597
  continue
1479
1598
  lemma.extend(self._lang_data[lang][0][i])
1480
-
1599
+
1481
1600
  lemma = list(set(lemma))
1482
1601
  return lemma
1483
-
1602
+
1484
1603
  def all_synsets(self, pos=None):
1485
1604
  """Iterate over all synsets with a given part of speech tag.
1486
1605
  If no pos is specified, all synsets for all parts of speech
@@ -1551,11 +1670,15 @@ class WordNetCorpusReader(CorpusReader):
1551
1670
  elif lang in self.langs():
1552
1671
  return self._omw_reader.open("{}/LICENSE".format(lang)).read()
1553
1672
  elif lang == 'omw':
1554
- ### under the not unreasonable assumption you don't mean Omwunra-Toqura
1673
+ # under the assumption you don't mean Omwunra-Toqura
1555
1674
  return self._omw_reader.open("LICENSE").read()
1675
+ elif lang in self._lang_data:
1676
+ raise WordNetError(
1677
+ "Cannot determine license for user-provided tab file"
1678
+ )
1556
1679
  else:
1557
1680
  raise WordNetError("Language is not supported.")
1558
-
1681
+
1559
1682
  def readme(self, lang='omw'):
1560
1683
  """Return the contents of README (for omw)
1561
1684
  use lang=lang to get the readme for an individual language"""
@@ -1564,8 +1687,10 @@ class WordNetCorpusReader(CorpusReader):
1564
1687
  elif lang in self.langs():
1565
1688
  return self._omw_reader.open("{}/README".format(lang)).read()
1566
1689
  elif lang == 'omw':
1567
- ### under the not unreasonable assumption you don't mean Omwunra-Toqura
1690
+ # under the assumption you don't mean Omwunra-Toqura
1568
1691
  return self._omw_reader.open("README").read()
1692
+ elif lang in self._lang_data:
1693
+ raise WordNetError("No README for user-provided tab file")
1569
1694
  else:
1570
1695
  raise WordNetError("Language is not supported.")
1571
1696
 
@@ -1577,16 +1702,16 @@ class WordNetCorpusReader(CorpusReader):
1577
1702
  elif lang in self.langs():
1578
1703
  return self._omw_reader.open("{}/citation.bib".format(lang)).read()
1579
1704
  elif lang == 'omw':
1580
- ### under the not unreasonable assumption you don't mean Omwunra-Toqura
1705
+ # under the assumption you don't mean Omwunra-Toqura
1581
1706
  return self._omw_reader.open("citation.bib").read()
1707
+ elif lang in self._lang_data:
1708
+ raise WordNetError("citation not known for user-provided tab file")
1582
1709
  else:
1583
1710
  raise WordNetError("Language is not supported.")
1584
1711
 
1585
-
1586
-
1587
- #////////////////////////////////////////////////////////////
1712
+ #############################################################
1588
1713
  # Misc
1589
- #////////////////////////////////////////////////////////////
1714
+ #############################################################
1590
1715
  def lemma_count(self, lemma):
1591
1716
  """Return the frequency count for this Lemma"""
1592
1717
  # Currently, count is only work for English
@@ -1602,15 +1727,21 @@ class WordNetCorpusReader(CorpusReader):
1602
1727
  else:
1603
1728
  return 0
1604
1729
 
1605
- def path_similarity(self, synset1, synset2, verbose=False, simulate_root=True):
1730
+ def path_similarity(
1731
+ self, synset1, synset2, verbose=False, simulate_root=True
1732
+ ):
1606
1733
  return synset1.path_similarity(synset2, verbose, simulate_root)
1607
1734
  path_similarity.__doc__ = Synset.path_similarity.__doc__
1608
1735
 
1609
- def lch_similarity(self, synset1, synset2, verbose=False, simulate_root=True):
1736
+ def lch_similarity(
1737
+ self, synset1, synset2, verbose=False, simulate_root=True
1738
+ ):
1610
1739
  return synset1.lch_similarity(synset2, verbose, simulate_root)
1611
1740
  lch_similarity.__doc__ = Synset.lch_similarity.__doc__
1612
1741
 
1613
- def wup_similarity(self, synset1, synset2, verbose=False, simulate_root=True):
1742
+ def wup_similarity(
1743
+ self, synset1, synset2, verbose=False, simulate_root=True
1744
+ ):
1614
1745
  return synset1.wup_similarity(synset2, verbose, simulate_root)
1615
1746
  wup_similarity.__doc__ = Synset.wup_similarity.__doc__
1616
1747
 
@@ -1626,11 +1757,11 @@ class WordNetCorpusReader(CorpusReader):
1626
1757
  return synset1.lin_similarity(synset2, ic, verbose)
1627
1758
  lin_similarity.__doc__ = Synset.lin_similarity.__doc__
1628
1759
 
1629
- #////////////////////////////////////////////////////////////
1760
+ #############################################################
1630
1761
  # Morphy
1631
- #////////////////////////////////////////////////////////////
1762
+ #############################################################
1632
1763
  # Morphy, adapted from Oliver Steele's pywordnet
1633
- def morphy(self, form, pos=None):
1764
+ def morphy(self, form, pos=None, check_exceptions=True):
1634
1765
  """
1635
1766
  Find a possible base form for the given form, with the given
1636
1767
  part of speech, by checking WordNet's list of exceptional
@@ -1656,7 +1787,7 @@ class WordNetCorpusReader(CorpusReader):
1656
1787
  morphy = self._morphy
1657
1788
  analyses = chain(a for p in POS_LIST for a in morphy(form, p))
1658
1789
  else:
1659
- analyses = self._morphy(form, pos)
1790
+ analyses = self._morphy(form, pos, check_exceptions)
1660
1791
 
1661
1792
  # get the first one we find
1662
1793
  first = list(islice(analyses, 1))
@@ -1676,7 +1807,7 @@ class WordNetCorpusReader(CorpusReader):
1676
1807
 
1677
1808
  MORPHOLOGICAL_SUBSTITUTIONS[ADJ_SAT] = MORPHOLOGICAL_SUBSTITUTIONS[ADJ]
1678
1809
 
1679
- def _morphy(self, form, pos):
1810
+ def _morphy(self, form, pos, check_exceptions=True):
1680
1811
  # from jordanbg:
1681
1812
  # Given an original string x
1682
1813
  # 1. Apply rules once to the input to get y1, y2, y3, etc.
@@ -1705,8 +1836,9 @@ class WordNetCorpusReader(CorpusReader):
1705
1836
  return result
1706
1837
 
1707
1838
  # 0. Check the exception lists
1708
- if form in exceptions:
1709
- return filter_forms([form] + exceptions[form])
1839
+ if check_exceptions:
1840
+ if form in exceptions:
1841
+ return filter_forms([form] + exceptions[form])
1710
1842
 
1711
1843
  # 1. Apply rules once to the input to get y1, y2, y3, etc.
1712
1844
  forms = apply_rules([form])
@@ -1726,10 +1858,10 @@ class WordNetCorpusReader(CorpusReader):
1726
1858
  # Return an empty list if we can't find anything
1727
1859
  return []
1728
1860
 
1729
- #////////////////////////////////////////////////////////////
1861
+ #############################################################
1730
1862
  # Create information content from corpus
1731
- #////////////////////////////////////////////////////////////
1732
- def ic(self, corpus, weight_senses_equally = False, smoothing = 1.0):
1863
+ #############################################################
1864
+ def ic(self, corpus, weight_senses_equally=False, smoothing=1.0):
1733
1865
  """
1734
1866
  Creates an information content lookup dictionary from a corpus.
1735
1867
 
@@ -1783,9 +1915,37 @@ class WordNetCorpusReader(CorpusReader):
1783
1915
  ic[pos][0] += weight
1784
1916
  return ic
1785
1917
 
1918
+ def custom_lemmas(self, tab_file, lang):
1919
+ """
1920
+ Reads a custom tab file containing mappings of lemmas in the given
1921
+ language to Princeton WordNet 3.0 synset offsets, allowing NLTK's
1922
+ WordNet functions to then be used with that language.
1923
+
1924
+ See the "Tab files" section at http://compling.hss.ntu.edu.sg/omw/ for
1925
+ documentation on the Multilingual WordNet tab file format.
1926
+
1927
+ :param tab_file: Tab file as a file or file-like object
1928
+ :type lang str
1929
+ :param lang ISO 639-3 code of the language of the tab file
1930
+ """
1931
+ if len(lang) != 3:
1932
+ raise ValueError('lang should be a (3 character) ISO 639-3 code')
1933
+ self._lang_data[lang] = [defaultdict(list), defaultdict(list)]
1934
+ for l in tab_file.readlines():
1935
+ if isinstance(l, bytes):
1936
+ # Support byte-stream files (e.g. as returned by Python 2's
1937
+ # open() function) as well as text-stream ones
1938
+ l = l.decode('utf-8')
1939
+ l = l.replace('\n', '')
1940
+ l = l.replace(' ', '_')
1941
+ if l[0] != '#':
1942
+ word = l.split('\t')
1943
+ self._lang_data[lang][0][word[0]].append(word[2])
1944
+ self._lang_data[lang][1][word[2].lower()].append(word[0])
1945
+
1786
1946
 
1787
1947
  ######################################################################
1788
- ## WordNet Information Content Corpus Reader
1948
+ # WordNet Information Content Corpus Reader
1789
1949
  ######################################################################
1790
1950
 
1791
1951
  class WordNetICCorpusReader(CorpusReader):
@@ -1815,7 +1975,7 @@ class WordNetICCorpusReader(CorpusReader):
1815
1975
  ic[NOUN] = defaultdict(float)
1816
1976
  ic[VERB] = defaultdict(float)
1817
1977
  for num, line in enumerate(self.open(icfile)):
1818
- if num == 0: # skip the header
1978
+ if num == 0: # skip the header
1819
1979
  continue
1820
1980
  fields = line.split()
1821
1981
  offset = int(fields[0][:-1])
@@ -1841,31 +2001,33 @@ class WordNetICCorpusReader(CorpusReader):
1841
2001
 
1842
2002
  def path_similarity(synset1, synset2, verbose=False, simulate_root=True):
1843
2003
  return synset1.path_similarity(synset2, verbose, simulate_root)
1844
- path_similarity.__doc__ = Synset.path_similarity.__doc__
1845
2004
 
1846
2005
 
1847
2006
  def lch_similarity(synset1, synset2, verbose=False, simulate_root=True):
1848
2007
  return synset1.lch_similarity(synset2, verbose, simulate_root)
1849
- lch_similarity.__doc__ = Synset.lch_similarity.__doc__
1850
2008
 
1851
2009
 
1852
2010
  def wup_similarity(synset1, synset2, verbose=False, simulate_root=True):
1853
2011
  return synset1.wup_similarity(synset2, verbose, simulate_root)
1854
- wup_similarity.__doc__ = Synset.wup_similarity.__doc__
1855
2012
 
1856
2013
 
1857
2014
  def res_similarity(synset1, synset2, ic, verbose=False):
1858
2015
  return synset1.res_similarity(synset2, verbose)
1859
- res_similarity.__doc__ = Synset.res_similarity.__doc__
1860
2016
 
1861
2017
 
1862
2018
  def jcn_similarity(synset1, synset2, ic, verbose=False):
1863
2019
  return synset1.jcn_similarity(synset2, verbose)
1864
- jcn_similarity.__doc__ = Synset.jcn_similarity.__doc__
1865
2020
 
1866
2021
 
1867
2022
  def lin_similarity(synset1, synset2, ic, verbose=False):
1868
2023
  return synset1.lin_similarity(synset2, verbose)
2024
+
2025
+
2026
+ path_similarity.__doc__ = Synset.path_similarity.__doc__
2027
+ lch_similarity.__doc__ = Synset.lch_similarity.__doc__
2028
+ wup_similarity.__doc__ = Synset.wup_similarity.__doc__
2029
+ res_similarity.__doc__ = Synset.res_similarity.__doc__
2030
+ jcn_similarity.__doc__ = Synset.jcn_similarity.__doc__
1869
2031
  lin_similarity.__doc__ = Synset.lin_similarity.__doc__
1870
2032
 
1871
2033
 
@@ -1887,9 +2049,11 @@ def _lcs_ic(synset1, synset2, ic, verbose=False):
1887
2049
  informative subsumer
1888
2050
  """
1889
2051
  if synset1._pos != synset2._pos:
1890
- raise WordNetError('Computing the least common subsumer requires ' + \
1891
- '%s and %s to have the same part of speech.' % \
1892
- (synset1, synset2))
2052
+ raise WordNetError(
2053
+ 'Computing the least common subsumer requires '
2054
+ '%s and %s to have the same part of speech.' %
2055
+ (synset1, synset2)
2056
+ )
1893
2057
 
1894
2058
  ic1 = information_content(synset1, ic)
1895
2059
  ic2 = information_content(synset2, ic)
@@ -1930,7 +2094,10 @@ def _get_pos(field):
1930
2094
  elif field[-1] == 'v':
1931
2095
  return VERB
1932
2096
  else:
1933
- msg = "Unidentified part of speech in WordNet Information Content file for field %s" % field
2097
+ msg = (
2098
+ "Unidentified part of speech in WordNet Information Content file "
2099
+ "for field %s" % field
2100
+ )
1934
2101
  raise ValueError(msg)
1935
2102
 
1936
2103
 
@@ -1939,98 +2106,3 @@ def teardown_module(module=None):
1939
2106
  from nltk.corpus import wordnet
1940
2107
  wordnet._unload()
1941
2108
 
1942
-
1943
- ######################################################################
1944
- # Demo
1945
- ######################################################################
1946
-
1947
- def demo():
1948
- import nltk
1949
- print('loading wordnet')
1950
- wn = WordNetCorpusReader(nltk.data.find('corpora/wordnet'), None)
1951
- print('done loading')
1952
- S = wn.synset
1953
- L = wn.lemma
1954
-
1955
- print('getting a synset for go')
1956
- move_synset = S('go.v.21')
1957
- print(move_synset.name(), move_synset.pos(), move_synset.lexname())
1958
- print(move_synset.lemma_names())
1959
- print(move_synset.definition())
1960
- print(move_synset.examples())
1961
-
1962
- zap_n = ['zap.n.01']
1963
- zap_v = ['zap.v.01', 'zap.v.02', 'nuke.v.01', 'microwave.v.01']
1964
-
1965
- def _get_synsets(synset_strings):
1966
- return [S(synset) for synset in synset_strings]
1967
-
1968
- zap_n_synsets = _get_synsets(zap_n)
1969
- zap_v_synsets = _get_synsets(zap_v)
1970
-
1971
- print(zap_n_synsets)
1972
- print(zap_v_synsets)
1973
-
1974
- print("Navigations:")
1975
- print(S('travel.v.01').hypernyms())
1976
- print(S('travel.v.02').hypernyms())
1977
- print(S('travel.v.03').hypernyms())
1978
-
1979
- print(L('zap.v.03.nuke').derivationally_related_forms())
1980
- print(L('zap.v.03.atomize').derivationally_related_forms())
1981
- print(L('zap.v.03.atomise').derivationally_related_forms())
1982
- print(L('zap.v.03.zap').derivationally_related_forms())
1983
-
1984
- print(S('dog.n.01').member_holonyms())
1985
- print(S('dog.n.01').part_meronyms())
1986
-
1987
- print(S('breakfast.n.1').hypernyms())
1988
- print(S('meal.n.1').hyponyms())
1989
- print(S('Austen.n.1').instance_hypernyms())
1990
- print(S('composer.n.1').instance_hyponyms())
1991
-
1992
- print(S('faculty.n.2').member_meronyms())
1993
- print(S('copilot.n.1').member_holonyms())
1994
-
1995
- print(S('table.n.2').part_meronyms())
1996
- print(S('course.n.7').part_holonyms())
1997
-
1998
- print(S('water.n.1').substance_meronyms())
1999
- print(S('gin.n.1').substance_holonyms())
2000
-
2001
- print(L('leader.n.1.leader').antonyms())
2002
- print(L('increase.v.1.increase').antonyms())
2003
-
2004
- print(S('snore.v.1').entailments())
2005
- print(S('heavy.a.1').similar_tos())
2006
- print(S('light.a.1').attributes())
2007
- print(S('heavy.a.1').attributes())
2008
-
2009
- print(L('English.a.1.English').pertainyms())
2010
-
2011
- print(S('person.n.01').root_hypernyms())
2012
- print(S('sail.v.01').root_hypernyms())
2013
- print(S('fall.v.12').root_hypernyms())
2014
-
2015
- print(S('person.n.01').lowest_common_hypernyms(S('dog.n.01')))
2016
- print(S('woman.n.01').lowest_common_hypernyms(S('girlfriend.n.02')))
2017
-
2018
- print(S('dog.n.01').path_similarity(S('cat.n.01')))
2019
- print(S('dog.n.01').lch_similarity(S('cat.n.01')))
2020
- print(S('dog.n.01').wup_similarity(S('cat.n.01')))
2021
-
2022
- wnic = WordNetICCorpusReader(nltk.data.find('corpora/wordnet_ic'),
2023
- '.*\.dat')
2024
- ic = wnic.ic('ic-brown.dat')
2025
- print(S('dog.n.01').jcn_similarity(S('cat.n.01'), ic))
2026
-
2027
- ic = wnic.ic('ic-semcor.dat')
2028
- print(S('dog.n.01').lin_similarity(S('cat.n.01'), ic))
2029
-
2030
- print(S('code.n.03').topic_domains())
2031
- print(S('pukka.a.01').region_domains())
2032
- print(S('freaky.a.01').usage_domains())
2033
-
2034
-
2035
- if __name__ == '__main__':
2036
- demo()