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,6 +1,6 @@
1
1
  # Natural Language Toolkit: Punkt sentence tokenizer
2
2
  #
3
- # Copyright (C) 2001-2016 NLTK Project
3
+ # Copyright (C) 2001-2018 NLTK Project
4
4
  # Algorithm: Kiss & Strunk (2006)
5
5
  # Author: Willy <willy@csse.unimelb.edu.au> (original Python port)
6
6
  # Steven Bird <stevenbird1@gmail.com> (additions)
@@ -13,7 +13,7 @@
13
13
  r"""
14
14
  Punkt Sentence Tokenizer
15
15
 
16
- This tokenizer divides a text into a list of sentences,
16
+ This tokenizer divides a text into a list of sentences
17
17
  by using an unsupervised algorithm to build a model for abbreviation
18
18
  words, collocations, and words that start sentences. It must be
19
19
  trained on a large collection of plaintext in the target language
@@ -109,33 +109,35 @@ import re
109
109
  import math
110
110
  from collections import defaultdict
111
111
 
112
- from nltk.compat import unicode_repr, python_2_unicode_compatible, string_types
112
+ from six import string_types
113
+
114
+ from nltk.compat import unicode_repr, python_2_unicode_compatible
113
115
  from nltk.probability import FreqDist
114
116
  from nltk.tokenize.api import TokenizerI
115
117
 
116
118
  ######################################################################
117
- #{ Orthographic Context Constants
119
+ # { Orthographic Context Constants
118
120
  ######################################################################
119
121
  # The following constants are used to describe the orthographic
120
122
  # contexts in which a word can occur. BEG=beginning, MID=middle,
121
123
  # UNK=unknown, UC=uppercase, LC=lowercase, NC=no case.
122
124
 
123
- _ORTHO_BEG_UC = 1 << 1
125
+ _ORTHO_BEG_UC = 1 << 1
124
126
  """Orthographic context: beginning of a sentence with upper case."""
125
127
 
126
- _ORTHO_MID_UC = 1 << 2
128
+ _ORTHO_MID_UC = 1 << 2
127
129
  """Orthographic context: middle of a sentence with upper case."""
128
130
 
129
- _ORTHO_UNK_UC = 1 << 3
131
+ _ORTHO_UNK_UC = 1 << 3
130
132
  """Orthographic context: unknown position in a sentence with upper case."""
131
133
 
132
- _ORTHO_BEG_LC = 1 << 4
134
+ _ORTHO_BEG_LC = 1 << 4
133
135
  """Orthographic context: beginning of a sentence with lower case."""
134
136
 
135
- _ORTHO_MID_LC = 1 << 5
137
+ _ORTHO_MID_LC = 1 << 5
136
138
  """Orthographic context: middle of a sentence with lower case."""
137
139
 
138
- _ORTHO_UNK_LC = 1 << 6
140
+ _ORTHO_UNK_LC = 1 << 6
139
141
  """Orthographic context: unknown position in a sentence with lower case."""
140
142
 
141
143
  _ORTHO_UC = _ORTHO_BEG_UC + _ORTHO_MID_UC + _ORTHO_UNK_UC
@@ -145,21 +147,21 @@ _ORTHO_LC = _ORTHO_BEG_LC + _ORTHO_MID_LC + _ORTHO_UNK_LC
145
147
  """Orthographic context: occurs with lower case."""
146
148
 
147
149
  _ORTHO_MAP = {
148
- ('initial', 'upper'): _ORTHO_BEG_UC,
149
- ('internal', 'upper'): _ORTHO_MID_UC,
150
- ('unknown', 'upper'): _ORTHO_UNK_UC,
151
- ('initial', 'lower'): _ORTHO_BEG_LC,
152
- ('internal', 'lower'): _ORTHO_MID_LC,
153
- ('unknown', 'lower'): _ORTHO_UNK_LC,
150
+ ('initial', 'upper'): _ORTHO_BEG_UC,
151
+ ('internal', 'upper'): _ORTHO_MID_UC,
152
+ ('unknown', 'upper'): _ORTHO_UNK_UC,
153
+ ('initial', 'lower'): _ORTHO_BEG_LC,
154
+ ('internal', 'lower'): _ORTHO_MID_LC,
155
+ ('unknown', 'lower'): _ORTHO_UNK_LC,
154
156
  }
155
157
  """A map from context position and first-letter case to the
156
158
  appropriate orthographic context flag."""
157
159
 
158
- #} (end orthographic context constants)
160
+ # } (end orthographic context constants)
159
161
  ######################################################################
160
162
 
161
163
  ######################################################################
162
- #{ Decision reasons for debugging
164
+ # { Decision reasons for debugging
163
165
  ######################################################################
164
166
 
165
167
  REASON_DEFAULT_DECISION = 'default decision'
@@ -170,11 +172,12 @@ REASON_INITIAL_WITH_ORTHOGRAPHIC_HEURISTIC = 'initial + orthographic heuristic'
170
172
  REASON_NUMBER_WITH_ORTHOGRAPHIC_HEURISTIC = 'initial + orthographic heuristic'
171
173
  REASON_INITIAL_WITH_SPECIAL_ORTHOGRAPHIC_HEURISTIC = 'initial + special orthographic heuristic'
172
174
 
173
- #} (end decision reasons for debugging)
175
+
176
+ # } (end decision reasons for debugging)
174
177
  ######################################################################
175
178
 
176
179
  ######################################################################
177
- #{ Language-dependent variables
180
+ # { Language-dependent variables
178
181
  ######################################################################
179
182
 
180
183
  class PunktLanguageVars(object):
@@ -205,19 +208,19 @@ class PunktLanguageVars(object):
205
208
  def _re_sent_end_chars(self):
206
209
  return '[%s]' % re.escape(''.join(self.sent_end_chars))
207
210
 
208
- internal_punctuation = ',:;' # might want to extend this..
211
+ internal_punctuation = ',:;' # might want to extend this..
209
212
  """sentence internal punctuation, which indicates an abbreviation if
210
213
  preceded by a period-final token."""
211
214
 
212
215
  re_boundary_realignment = re.compile(r'["\')\]}]+?(?:\s+|(?=--)|$)',
213
- re.MULTILINE)
216
+ re.MULTILINE)
214
217
  """Used to realign punctuation that should be included in a sentence
215
218
  although it follows the period (or ?, !)."""
216
219
 
217
- _re_word_start = r"[^\(\"\`{\[:;&\#\*@\)}\]\-,]"
220
+ _re_word_start = r"[^\(\"\`{\[:;&\#\*@\)}\]\-,]"
218
221
  """Excludes some characters from starting word tokens"""
219
222
 
220
- _re_non_word_chars = r"(?:[?!)\";}\]\*:@\'\({\[])"
223
+ _re_non_word_chars = r"(?:[?!)\";}\]\*:@\'\({\[])"
221
224
  """Characters that cannot appear within words"""
222
225
 
223
226
  _re_multi_char_punct = r"(?:\-{2,}|\.{2,}|(?:\.\s){2,}\.)"
@@ -247,7 +250,7 @@ class PunktLanguageVars(object):
247
250
  self._re_word_tokenizer = re.compile(
248
251
  self._word_tokenize_fmt %
249
252
  {
250
- 'NonWord': self._re_non_word_chars,
253
+ 'NonWord': self._re_non_word_chars,
251
254
  'MultiChar': self._re_multi_char_punct,
252
255
  'WordStart': self._re_word_start,
253
256
  },
@@ -280,7 +283,7 @@ class PunktLanguageVars(object):
280
283
  self._re_period_context = re.compile(
281
284
  self._period_context_fmt %
282
285
  {
283
- 'NonWord': self._re_non_word_chars,
286
+ 'NonWord': self._re_non_word_chars,
284
287
  'SentEndChars': self._re_sent_end_chars,
285
288
  },
286
289
  re.UNICODE | re.VERBOSE)
@@ -291,14 +294,14 @@ _re_non_punct = re.compile(r'[^\W\d]', re.UNICODE)
291
294
  """Matches token types that are not merely punctuation. (Types for
292
295
  numeric tokens are changed to ##number## and hence contain alpha.)"""
293
296
 
294
- #}
295
- ######################################################################
296
297
 
298
+ # }
299
+ ######################################################################
297
300
 
298
301
 
299
- #////////////////////////////////////////////////////////////
300
- #{ Helper Functions
301
- #////////////////////////////////////////////////////////////
302
+ # ////////////////////////////////////////////////////////////
303
+ # { Helper Functions
304
+ # ////////////////////////////////////////////////////////////
302
305
 
303
306
  def _pair_iter(it):
304
307
  """
@@ -313,8 +316,9 @@ def _pair_iter(it):
313
316
  prev = el
314
317
  yield (prev, None)
315
318
 
319
+
316
320
  ######################################################################
317
- #{ Punkt Parameters
321
+ # { Punkt Parameters
318
322
  ######################################################################
319
323
 
320
324
  class PunktParameters(object):
@@ -370,8 +374,9 @@ class PunktParameters(object):
370
374
  if c & _ORTHO_UNK_LC:
371
375
  yield 'UNK-LC'
372
376
 
377
+
373
378
  ######################################################################
374
- #{ PunktToken
379
+ # { PunktToken
375
380
  ######################################################################
376
381
 
377
382
  @python_2_unicode_compatible
@@ -395,18 +400,18 @@ class PunktToken(object):
395
400
  for k in params:
396
401
  setattr(self, k, params[k])
397
402
 
398
- #////////////////////////////////////////////////////////////
399
- #{ Regular expressions for properties
400
- #////////////////////////////////////////////////////////////
403
+ # ////////////////////////////////////////////////////////////
404
+ # { Regular expressions for properties
405
+ # ////////////////////////////////////////////////////////////
401
406
  # Note: [A-Za-z] is approximated by [^\W\d] in the general case.
402
407
  _RE_ELLIPSIS = re.compile(r'\.\.+$')
403
408
  _RE_NUMERIC = re.compile(r'^-?[\.,]?\d[\d,\.-]*\.?$')
404
409
  _RE_INITIAL = re.compile(r'[^\W\d]\.$', re.UNICODE)
405
410
  _RE_ALPHA = re.compile(r'[^\W\d]+$', re.UNICODE)
406
411
 
407
- #////////////////////////////////////////////////////////////
408
- #{ Derived properties
409
- #////////////////////////////////////////////////////////////
412
+ # ////////////////////////////////////////////////////////////
413
+ # { Derived properties
414
+ # ////////////////////////////////////////////////////////////
410
415
 
411
416
  def _get_type(self, tok):
412
417
  """Returns a case-normalized representation of the token."""
@@ -474,9 +479,9 @@ class PunktToken(object):
474
479
  """True if the token is either a number or is alphabetic."""
475
480
  return _re_non_punct.search(self.type)
476
481
 
477
- #////////////////////////////////////////////////////////////
478
- #{ String representation
479
- #////////////////////////////////////////////////////////////
482
+ # ////////////////////////////////////////////////////////////
483
+ # { String representation
484
+ # ////////////////////////////////////////////////////////////
480
485
 
481
486
  def __repr__(self):
482
487
  """
@@ -485,7 +490,7 @@ class PunktToken(object):
485
490
  annotations.
486
491
  """
487
492
  typestr = (' type=%s,' % unicode_repr(self.type)
488
- if self.type != self.tok else '')
493
+ if self.type != self.tok else '')
489
494
 
490
495
  propvals = ', '.join(
491
496
  '%s=%s' % (p, unicode_repr(getattr(self, p)))
@@ -494,7 +499,7 @@ class PunktToken(object):
494
499
  )
495
500
 
496
501
  return '%s(%s,%s %s)' % (self.__class__.__name__,
497
- unicode_repr(self.tok), typestr, propvals)
502
+ unicode_repr(self.tok), typestr, propvals)
498
503
 
499
504
  def __str__(self):
500
505
  """
@@ -509,8 +514,9 @@ class PunktToken(object):
509
514
  res += '<S>'
510
515
  return res
511
516
 
517
+
512
518
  ######################################################################
513
- #{ Punkt base class
519
+ # { Punkt base class
514
520
  ######################################################################
515
521
 
516
522
  class PunktBaseClass(object):
@@ -519,16 +525,18 @@ class PunktBaseClass(object):
519
525
  """
520
526
 
521
527
  def __init__(self, lang_vars=PunktLanguageVars(), token_cls=PunktToken,
522
- params=PunktParameters()):
528
+ params=None):
529
+ if params is None:
530
+ params = PunktParameters()
523
531
  self._params = params
524
532
  self._lang_vars = lang_vars
525
533
  self._Token = token_cls
526
534
  """The collection of parameters that determines the behavior
527
535
  of the punkt tokenizer."""
528
536
 
529
- #////////////////////////////////////////////////////////////
530
- #{ Word tokenization
531
- #////////////////////////////////////////////////////////////
537
+ # ////////////////////////////////////////////////////////////
538
+ # { Word tokenization
539
+ # ////////////////////////////////////////////////////////////
532
540
 
533
541
  def _tokenize_words(self, plaintext):
534
542
  """
@@ -544,7 +552,7 @@ class PunktBaseClass(object):
544
552
  line_toks = iter(self._lang_vars.word_tokenize(line))
545
553
 
546
554
  yield self._Token(next(line_toks),
547
- parastart=parastart, linestart=True)
555
+ parastart=parastart, linestart=True)
548
556
  parastart = False
549
557
 
550
558
  for t in line_toks:
@@ -552,10 +560,9 @@ class PunktBaseClass(object):
552
560
  else:
553
561
  parastart = True
554
562
 
555
-
556
- #////////////////////////////////////////////////////////////
557
- #{ Annotation Procedures
558
- #////////////////////////////////////////////////////////////
563
+ # ////////////////////////////////////////////////////////////
564
+ # { Annotation Procedures
565
+ # ////////////////////////////////////////////////////////////
559
566
 
560
567
  def _annotate_first_pass(self, tokens):
561
568
  """
@@ -591,7 +598,7 @@ class PunktBaseClass(object):
591
598
  aug_tok.ellipsis = True
592
599
  elif aug_tok.period_final and not tok.endswith('..'):
593
600
  if (tok[:-1].lower() in self._params.abbrev_types or
594
- tok[:-1].lower().split('-')[-1] in self._params.abbrev_types):
601
+ tok[:-1].lower().split('-')[-1] in self._params.abbrev_types):
595
602
 
596
603
  aug_tok.abbr = True
597
604
  else:
@@ -599,8 +606,9 @@ class PunktBaseClass(object):
599
606
 
600
607
  return
601
608
 
609
+
602
610
  ######################################################################
603
- #{ Punkt Trainer
611
+ # { Punkt Trainer
604
612
  ######################################################################
605
613
 
606
614
 
@@ -608,10 +616,10 @@ class PunktTrainer(PunktBaseClass):
608
616
  """Learns parameters used in Punkt sentence boundary detection."""
609
617
 
610
618
  def __init__(self, train_text=None, verbose=False,
611
- lang_vars=PunktLanguageVars(), token_cls=PunktToken):
619
+ lang_vars=PunktLanguageVars(), token_cls=PunktToken):
612
620
 
613
621
  PunktBaseClass.__init__(self, lang_vars=lang_vars,
614
- token_cls=token_cls)
622
+ token_cls=token_cls)
615
623
 
616
624
  self._type_fdist = FreqDist()
617
625
  """A frequency distribution giving the frequency of each
@@ -656,9 +664,9 @@ class PunktTrainer(PunktBaseClass):
656
664
  self.finalize_training()
657
665
  return self._params
658
666
 
659
- #////////////////////////////////////////////////////////////
660
- #{ Customization Variables
661
- #////////////////////////////////////////////////////////////
667
+ # ////////////////////////////////////////////////////////////
668
+ # { Customization Variables
669
+ # ////////////////////////////////////////////////////////////
662
670
 
663
671
  ABBREV = 0.3
664
672
  """cut-off value whether a 'token' is an abbreviation"""
@@ -697,9 +705,9 @@ class PunktTrainer(PunktBaseClass):
697
705
  appear before it can be considered a collocation, in addition to log
698
706
  likelihood statistics. This is useful when INCLUDE_ALL_COLLOCS is True."""
699
707
 
700
- #////////////////////////////////////////////////////////////
701
- #{ Training..
702
- #////////////////////////////////////////////////////////////
708
+ # ////////////////////////////////////////////////////////////
709
+ # { Training..
710
+ # ////////////////////////////////////////////////////////////
703
711
 
704
712
  def train(self, text, verbose=False, finalize=True):
705
713
  """
@@ -800,19 +808,19 @@ class PunktTrainer(PunktBaseClass):
800
808
 
801
809
  self._params.clear_collocations()
802
810
  for (typ1, typ2), ll in self._find_collocations():
803
- self._params.collocations.add( (typ1,typ2) )
811
+ self._params.collocations.add((typ1, typ2))
804
812
  if verbose:
805
813
  print((' Collocation: [%6.4f] %r+%r' %
806
814
  (ll, typ1, typ2)))
807
815
 
808
816
  self._finalized = True
809
817
 
810
- #////////////////////////////////////////////////////////////
811
- #{ Overhead reduction
812
- #////////////////////////////////////////////////////////////
818
+ # ////////////////////////////////////////////////////////////
819
+ # { Overhead reduction
820
+ # ////////////////////////////////////////////////////////////
813
821
 
814
822
  def freq_threshold(self, ortho_thresh=2, type_thresh=2, colloc_thres=2,
815
- sentstart_thresh=2):
823
+ sentstart_thresh=2):
816
824
  """
817
825
  Allows memory use to be reduced after much training by removing data
818
826
  about rare tokens that are unlikely to have a statistical effect with
@@ -829,9 +837,9 @@ class PunktTrainer(PunktBaseClass):
829
837
 
830
838
  self._type_fdist = self._freq_threshold(self._type_fdist, type_thresh)
831
839
  self._collocation_fdist = self._freq_threshold(
832
- self._collocation_fdist, colloc_thres)
840
+ self._collocation_fdist, colloc_thres)
833
841
  self._sent_starter_fdist = self._freq_threshold(
834
- self._sent_starter_fdist, sentstart_thresh)
842
+ self._sent_starter_fdist, sentstart_thresh)
835
843
 
836
844
  def _freq_threshold(self, fdist, threshold):
837
845
  """
@@ -851,9 +859,9 @@ class PunktTrainer(PunktBaseClass):
851
859
  res[None] += num_removed
852
860
  return res
853
861
 
854
- #////////////////////////////////////////////////////////////
855
- #{ Orthographic data
856
- #////////////////////////////////////////////////////////////
862
+ # ////////////////////////////////////////////////////////////
863
+ # { Orthographic data
864
+ # ////////////////////////////////////////////////////////////
857
865
 
858
866
  def _get_orthography_data(self, tokens):
859
867
  """
@@ -899,9 +907,9 @@ class PunktTrainer(PunktBaseClass):
899
907
  else:
900
908
  context = 'internal'
901
909
 
902
- #////////////////////////////////////////////////////////////
903
- #{ Abbreviations
904
- #////////////////////////////////////////////////////////////
910
+ # ////////////////////////////////////////////////////////////
911
+ # { Abbreviations
912
+ # ////////////////////////////////////////////////////////////
905
913
 
906
914
  def _reclassify_abbrev_types(self, types):
907
915
  """
@@ -962,7 +970,7 @@ class PunktTrainer(PunktBaseClass):
962
970
  f_length = math.exp(-num_nonperiods)
963
971
  f_periods = num_periods
964
972
  f_penalty = (int(self.IGNORE_ABBREV_PENALTY)
965
- or math.pow(num_nonperiods, -count_without_period))
973
+ or math.pow(num_nonperiods, -count_without_period))
966
974
  score = ll * f_length * f_periods * f_penalty
967
975
 
968
976
  yield typ, score, is_add
@@ -1020,13 +1028,13 @@ class PunktTrainer(PunktBaseClass):
1020
1028
  elif next_tok.first_lower:
1021
1029
  typ2 = next_tok.type_no_sentperiod
1022
1030
  typ2ortho_context = self._params.ortho_context[typ2]
1023
- if ( (typ2ortho_context & _ORTHO_BEG_UC) and
1024
- not (typ2ortho_context & _ORTHO_MID_UC) ):
1031
+ if ((typ2ortho_context & _ORTHO_BEG_UC) and
1032
+ not (typ2ortho_context & _ORTHO_MID_UC)):
1025
1033
  return True
1026
1034
 
1027
- #////////////////////////////////////////////////////////////
1028
- #{ Log Likelihoods
1029
- #////////////////////////////////////////////////////////////
1035
+ # ////////////////////////////////////////////////////////////
1036
+ # { Log Likelihoods
1037
+ # ////////////////////////////////////////////////////////////
1030
1038
 
1031
1039
  # helper for _reclassify_abbrev_types:
1032
1040
  @staticmethod
@@ -1041,8 +1049,8 @@ class PunktTrainer(PunktBaseClass):
1041
1049
 
1042
1050
  null_hypo = (count_ab * math.log(p1) +
1043
1051
  (count_a - count_ab) * math.log(1.0 - p1))
1044
- alt_hypo = (count_ab * math.log(p2) +
1045
- (count_a - count_ab) * math.log(1.0 - p2))
1052
+ alt_hypo = (count_ab * math.log(p2) +
1053
+ (count_a - count_ab) * math.log(1.0 - p2))
1046
1054
 
1047
1055
  likelihood = null_hypo - alt_hypo
1048
1056
 
@@ -1058,25 +1066,32 @@ class PunktTrainer(PunktBaseClass):
1058
1066
  unlike the previous log_l function where it used modified
1059
1067
  Dunning log-likelihood values
1060
1068
  """
1061
- import math
1062
-
1063
1069
  p = count_b / N
1064
1070
  p1 = count_ab / count_a
1065
- p2 = (count_b - count_ab) / (N - count_a)
1071
+ try:
1072
+ p2 = (count_b - count_ab) / (N - count_a)
1073
+ except ZeroDivisionError as e:
1074
+ p2 = 1
1066
1075
 
1067
- summand1 = (count_ab * math.log(p) +
1068
- (count_a - count_ab) * math.log(1.0 - p))
1076
+ try:
1077
+ summand1 = (count_ab * math.log(p) +
1078
+ (count_a - count_ab) * math.log(1.0 - p))
1079
+ except ValueError as e:
1080
+ summand1 = 0
1069
1081
 
1070
- summand2 = ((count_b - count_ab) * math.log(p) +
1071
- (N - count_a - count_b + count_ab) * math.log(1.0 - p))
1082
+ try:
1083
+ summand2 = ((count_b - count_ab) * math.log(p) +
1084
+ (N - count_a - count_b + count_ab) * math.log(1.0 - p))
1085
+ except ValueError as e:
1086
+ summand2 = 0
1072
1087
 
1073
- if count_a == count_ab:
1088
+ if count_a == count_ab or p1 <= 0 or p1 >= 1:
1074
1089
  summand3 = 0
1075
1090
  else:
1076
1091
  summand3 = (count_ab * math.log(p1) +
1077
1092
  (count_a - count_ab) * math.log(1.0 - p1))
1078
1093
 
1079
- if count_b == count_ab:
1094
+ if count_b == count_ab or p2 <= 0 or p2 >= 1:
1080
1095
  summand4 = 0
1081
1096
  else:
1082
1097
  summand4 = ((count_b - count_ab) * math.log(p2) +
@@ -1086,9 +1101,9 @@ class PunktTrainer(PunktBaseClass):
1086
1101
 
1087
1102
  return (-2.0 * likelihood)
1088
1103
 
1089
- #////////////////////////////////////////////////////////////
1090
- #{ Collocation Finder
1091
- #////////////////////////////////////////////////////////////
1104
+ # ////////////////////////////////////////////////////////////
1105
+ # { Collocation Finder
1106
+ # ////////////////////////////////////////////////////////////
1092
1107
 
1093
1108
  def _is_potential_collocation(self, aug_tok1, aug_tok2):
1094
1109
  """
@@ -1096,9 +1111,9 @@ class PunktTrainer(PunktBaseClass):
1096
1111
  log-likelihood statistics.
1097
1112
  """
1098
1113
  return ((self.INCLUDE_ALL_COLLOCS or
1099
- (self.INCLUDE_ABBREV_COLLOCS and aug_tok1.abbr) or
1100
- (aug_tok1.sentbreak and
1101
- (aug_tok1.is_number or aug_tok1.is_initial)))
1114
+ (self.INCLUDE_ABBREV_COLLOCS and aug_tok1.abbr) or
1115
+ (aug_tok1.sentbreak and
1116
+ (aug_tok1.is_number or aug_tok1.is_initial)))
1102
1117
  and aug_tok1.is_non_punct
1103
1118
  and aug_tok2.is_non_punct)
1104
1119
 
@@ -1116,23 +1131,23 @@ class PunktTrainer(PunktBaseClass):
1116
1131
  continue
1117
1132
 
1118
1133
  col_count = self._collocation_fdist[types]
1119
- typ1_count = self._type_fdist[typ1]+self._type_fdist[typ1+'.']
1120
- typ2_count = self._type_fdist[typ2]+self._type_fdist[typ2+'.']
1134
+ typ1_count = self._type_fdist[typ1] + self._type_fdist[typ1 + '.']
1135
+ typ2_count = self._type_fdist[typ2] + self._type_fdist[typ2 + '.']
1121
1136
  if (typ1_count > 1 and typ2_count > 1
1122
1137
  and self.MIN_COLLOC_FREQ <
1123
- col_count <= min(typ1_count, typ2_count)):
1138
+ col_count <= min(typ1_count, typ2_count)):
1124
1139
 
1125
1140
  ll = self._col_log_likelihood(typ1_count, typ2_count,
1126
1141
  col_count, self._type_fdist.N())
1127
1142
  # Filter out the not-so-collocative
1128
1143
  if (ll >= self.COLLOCATION and
1129
- (self._type_fdist.N()/typ1_count >
1130
- typ2_count/col_count)):
1144
+ (self._type_fdist.N() / typ1_count >
1145
+ typ2_count / col_count)):
1131
1146
  yield (typ1, typ2), ll
1132
1147
 
1133
- #////////////////////////////////////////////////////////////
1134
- #{ Sentence-Starter Finder
1135
- #////////////////////////////////////////////////////////////
1148
+ # ////////////////////////////////////////////////////////////
1149
+ # { Sentence-Starter Finder
1150
+ # ////////////////////////////////////////////////////////////
1136
1151
 
1137
1152
  def _is_potential_sent_starter(self, cur_tok, prev_tok):
1138
1153
  """
@@ -1142,9 +1157,9 @@ class PunktTrainer(PunktBaseClass):
1142
1157
  # If a token (i) is preceded by a sentece break that is
1143
1158
  # not a potential ordinal number or initial, and (ii) is
1144
1159
  # alphabetic, then it is a a sentence-starter.
1145
- return ( prev_tok.sentbreak and
1146
- not (prev_tok.is_number or prev_tok.is_initial) and
1147
- cur_tok.is_alpha )
1160
+ return (prev_tok.sentbreak and
1161
+ not (prev_tok.is_number or prev_tok.is_initial) and
1162
+ cur_tok.is_alpha)
1148
1163
 
1149
1164
  def _find_sent_starters(self):
1150
1165
  """
@@ -1156,19 +1171,18 @@ class PunktTrainer(PunktBaseClass):
1156
1171
  continue
1157
1172
 
1158
1173
  typ_at_break_count = self._sent_starter_fdist[typ]
1159
- typ_count = self._type_fdist[typ]+self._type_fdist[typ+'.']
1174
+ typ_count = self._type_fdist[typ] + self._type_fdist[typ + '.']
1160
1175
  if typ_count < typ_at_break_count:
1161
1176
  # needed after freq_threshold
1162
1177
  continue
1163
1178
 
1164
1179
  ll = self._col_log_likelihood(self._sentbreak_count, typ_count,
1165
- typ_at_break_count,
1180
+ typ_at_break_count,
1166
1181
  self._type_fdist.N())
1167
1182
 
1168
1183
  if (ll >= self.SENT_STARTER and
1169
- self._type_fdist.N()/self._sentbreak_count >
1170
- typ_count/typ_at_break_count):
1171
-
1184
+ self._type_fdist.N() / self._sentbreak_count >
1185
+ typ_count / typ_at_break_count):
1172
1186
  yield typ, ll
1173
1187
 
1174
1188
  def _get_sentbreak_count(self, tokens):
@@ -1180,11 +1194,11 @@ class PunktTrainer(PunktBaseClass):
1180
1194
 
1181
1195
 
1182
1196
  ######################################################################
1183
- #{ Punkt Sentence Tokenizer
1197
+ # { Punkt Sentence Tokenizer
1184
1198
  ######################################################################
1185
1199
 
1186
1200
 
1187
- class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1201
+ class PunktSentenceTokenizer(PunktBaseClass, TokenizerI):
1188
1202
  """
1189
1203
  A sentence tokenizer which uses an unsupervised algorithm to build
1190
1204
  a model for abbreviation words, collocations, and words that start
@@ -1192,14 +1206,15 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1192
1206
  This approach has been shown to work well for many European
1193
1207
  languages.
1194
1208
  """
1209
+
1195
1210
  def __init__(self, train_text=None, verbose=False,
1196
- lang_vars=PunktLanguageVars(), token_cls=PunktToken):
1211
+ lang_vars=PunktLanguageVars(), token_cls=PunktToken):
1197
1212
  """
1198
1213
  train_text can either be the sole training text for this sentence
1199
1214
  boundary detector, or can be a PunktParameters object.
1200
1215
  """
1201
1216
  PunktBaseClass.__init__(self, lang_vars=lang_vars,
1202
- token_cls=token_cls)
1217
+ token_cls=token_cls)
1203
1218
 
1204
1219
  if train_text:
1205
1220
  self._params = self.train(train_text, verbose)
@@ -1213,11 +1228,11 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1213
1228
  if not isinstance(train_text, string_types):
1214
1229
  return train_text
1215
1230
  return PunktTrainer(train_text, lang_vars=self._lang_vars,
1216
- token_cls=self._Token).get_params()
1231
+ token_cls=self._Token).get_params()
1217
1232
 
1218
- #////////////////////////////////////////////////////////////
1219
- #{ Tokenization
1220
- #////////////////////////////////////////////////////////////
1233
+ # ////////////////////////////////////////////////////////////
1234
+ # { Tokenization
1235
+ # ////////////////////////////////////////////////////////////
1221
1236
 
1222
1237
  def tokenize(self, text, realign_boundaries=True):
1223
1238
  """
@@ -1240,29 +1255,31 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1240
1255
  while not tokens[0].period_final:
1241
1256
  tokens.pop(0)
1242
1257
  yield dict(period_index=match.end() - 1,
1243
- text=decision_text,
1244
- type1=tokens[0].type,
1245
- type2=tokens[1].type,
1246
- type1_in_abbrs=bool(tokens[0].abbr),
1247
- type1_is_initial=bool(tokens[0].is_initial),
1248
- type2_is_sent_starter=tokens[1].type_no_sentperiod in self._params.sent_starters,
1249
- type2_ortho_heuristic=self._ortho_heuristic(tokens[1]),
1250
- type2_ortho_contexts=set(self._params._debug_ortho_context(tokens[1].type_no_sentperiod)),
1251
- collocation=(tokens[0].type_no_sentperiod, tokens[1].type_no_sentperiod) in self._params.collocations,
1252
-
1253
- reason=self._second_pass_annotation(tokens[0], tokens[1]) or REASON_DEFAULT_DECISION,
1254
- break_decision=tokens[0].sentbreak,
1255
- )
1258
+ text=decision_text,
1259
+ type1=tokens[0].type,
1260
+ type2=tokens[1].type,
1261
+ type1_in_abbrs=bool(tokens[0].abbr),
1262
+ type1_is_initial=bool(tokens[0].is_initial),
1263
+ type2_is_sent_starter=tokens[1].type_no_sentperiod in self._params.sent_starters,
1264
+ type2_ortho_heuristic=self._ortho_heuristic(tokens[1]),
1265
+ type2_ortho_contexts=set(self._params._debug_ortho_context(tokens[1].type_no_sentperiod)),
1266
+ collocation=(tokens[0].type_no_sentperiod,
1267
+ tokens[1].type_no_sentperiod) in self._params.collocations,
1268
+
1269
+ reason=self._second_pass_annotation(tokens[0], tokens[1]) or REASON_DEFAULT_DECISION,
1270
+ break_decision=tokens[0].sentbreak,
1271
+ )
1256
1272
 
1257
1273
  def span_tokenize(self, text, realign_boundaries=True):
1258
1274
  """
1259
- Given a text, returns a list of the (start, end) spans of sentences
1275
+ Given a text, generates (start, end) spans of sentences
1260
1276
  in the text.
1261
1277
  """
1262
1278
  slices = self._slices_from_text(text)
1263
1279
  if realign_boundaries:
1264
1280
  slices = self._realign_boundaries(text, slices)
1265
- return [(sl.start, sl.stop) for sl in slices]
1281
+ for sl in slices:
1282
+ yield (sl.start, sl.stop)
1266
1283
 
1267
1284
  def sentences_from_text(self, text, realign_boundaries=True):
1268
1285
  """
@@ -1285,7 +1302,8 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1285
1302
  else:
1286
1303
  # next sentence starts at following punctuation
1287
1304
  last_break = match.end()
1288
- yield slice(last_break, len(text))
1305
+ # The last sentence should not contain trailing whitespace.
1306
+ yield slice(last_break, len(text.rstrip()))
1289
1307
 
1290
1308
  def _realign_boundaries(self, text, slices):
1291
1309
  """
@@ -1321,7 +1339,7 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1321
1339
  """
1322
1340
  Returns True if the given text includes a sentence break.
1323
1341
  """
1324
- found = False # used to ignore last token
1342
+ found = False # used to ignore last token
1325
1343
  for t in self._annotate_tokens(self._tokenize_words(text)):
1326
1344
  if found:
1327
1345
  return True
@@ -1369,8 +1387,8 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1369
1387
  tokens = self._annotate_second_pass(tokens)
1370
1388
 
1371
1389
  ## [XX] TESTING
1372
- #tokens = list(tokens)
1373
- #self.dump(tokens)
1390
+ # tokens = list(tokens)
1391
+ # self.dump(tokens)
1374
1392
 
1375
1393
  return tokens
1376
1394
 
@@ -1402,13 +1420,13 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1402
1420
  # that contain whitespace in the source text. If our
1403
1421
  # token doesn't match, see if adding whitespace helps.
1404
1422
  # If so, then use the version with whitespace.
1405
- if text[pos:pos+len(tok)] != tok:
1423
+ if text[pos:pos + len(tok)] != tok:
1406
1424
  pat = '\s*'.join(re.escape(c) for c in tok)
1407
- m = re.compile(pat).match(text,pos)
1425
+ m = re.compile(pat).match(text, pos)
1408
1426
  if m: tok = m.group()
1409
1427
 
1410
1428
  # Move our position pointer to the end of the token.
1411
- assert text[pos:pos+len(tok)] == tok
1429
+ assert text[pos:pos + len(tok)] == tok
1412
1430
  pos += len(tok)
1413
1431
 
1414
1432
  # Add this token. If it's not at the beginning of the
@@ -1441,15 +1459,15 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1441
1459
 
1442
1460
  outfile.write(str(aug_tok))
1443
1461
 
1444
- #////////////////////////////////////////////////////////////
1445
- #{ Customization Variables
1446
- #////////////////////////////////////////////////////////////
1462
+ # ////////////////////////////////////////////////////////////
1463
+ # { Customization Variables
1464
+ # ////////////////////////////////////////////////////////////
1447
1465
 
1448
1466
  PUNCTUATION = tuple(';:,.!?')
1449
1467
 
1450
- #////////////////////////////////////////////////////////////
1451
- #{ Annotation Procedures
1452
- #////////////////////////////////////////////////////////////
1468
+ # ////////////////////////////////////////////////////////////
1469
+ # { Annotation Procedures
1470
+ # ////////////////////////////////////////////////////////////
1453
1471
 
1454
1472
  def _annotate_second_pass(self, tokens):
1455
1473
  """
@@ -1494,8 +1512,8 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1494
1512
  # [4.2. Token-Based Reclassification of Abbreviations] If
1495
1513
  # the token is an abbreviation or an ellipsis, then decide
1496
1514
  # whether we should *also* classify it as a sentbreak.
1497
- if ( (aug_tok1.abbr or aug_tok1.ellipsis) and
1498
- (not tok_is_initial) ):
1515
+ if ((aug_tok1.abbr or aug_tok1.ellipsis) and
1516
+ (not tok_is_initial)):
1499
1517
  # [4.1.1. Orthographic Heuristic] Check if there's
1500
1518
  # orthogrpahic evidence about whether the next word
1501
1519
  # starts a sentence or not.
@@ -1508,8 +1526,8 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1508
1526
  # next word is capitalized, and is a member of the
1509
1527
  # frequent-sentence-starters list, then label tok as a
1510
1528
  # sentence break.
1511
- if ( aug_tok2.first_upper and
1512
- next_typ in self._params.sent_starters):
1529
+ if (aug_tok2.first_upper and
1530
+ next_typ in self._params.sent_starters):
1513
1531
  aug_tok1.sentbreak = True
1514
1532
  return REASON_ABBR_WITH_SENTENCE_STARTER
1515
1533
 
@@ -1534,9 +1552,9 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1534
1552
  # Special heuristic for initials: if orthogrpahic
1535
1553
  # heuristc is unknown, and next word is always
1536
1554
  # capitalized, then mark as abbrev (eg: J. Bach).
1537
- if ( is_sent_starter == 'unknown' and tok_is_initial and
1538
- aug_tok2.first_upper and
1539
- not (self._params.ortho_context[next_typ] & _ORTHO_LC) ):
1555
+ if (is_sent_starter == 'unknown' and tok_is_initial and
1556
+ aug_tok2.first_upper and
1557
+ not (self._params.ortho_context[next_typ] & _ORTHO_LC)):
1540
1558
  aug_tok1.sentbreak = False
1541
1559
  aug_tok1.abbr = True
1542
1560
  return REASON_INITIAL_WITH_SPECIAL_ORTHOGRAPHIC_HEURISTIC
@@ -1556,18 +1574,18 @@ class PunktSentenceTokenizer(PunktBaseClass,TokenizerI):
1556
1574
  # If the word is capitalized, occurs at least once with a
1557
1575
  # lower case first letter, and never occurs with an upper case
1558
1576
  # first letter sentence-internally, then it's a sentence starter.
1559
- if ( aug_tok.first_upper and
1560
- (ortho_context & _ORTHO_LC) and
1561
- not (ortho_context & _ORTHO_MID_UC) ):
1577
+ if (aug_tok.first_upper and
1578
+ (ortho_context & _ORTHO_LC) and
1579
+ not (ortho_context & _ORTHO_MID_UC)):
1562
1580
  return True
1563
1581
 
1564
1582
  # If the word is lower case, and either (a) we've seen it used
1565
1583
  # with upper case, or (b) we've never seen it used
1566
1584
  # sentence-initially with lower case, then it's not a sentence
1567
1585
  # starter.
1568
- if ( aug_tok.first_lower and
1569
- ((ortho_context & _ORTHO_UC) or
1570
- not (ortho_context & _ORTHO_BEG_LC)) ):
1586
+ if (aug_tok.first_lower and
1587
+ ((ortho_context & _ORTHO_UC) or
1588
+ not (ortho_context & _ORTHO_BEG_LC))):
1571
1589
  return False
1572
1590
 
1573
1591
  # Otherwise, we're not sure.
@@ -1585,9 +1603,12 @@ Collocation? %(collocation)s
1585
1603
  orthographic heuristic suggests is a sentence starter? %(type2_ortho_heuristic)s
1586
1604
  orthographic contexts in training: %(type2_ortho_contexts)s
1587
1605
  '''
1606
+
1607
+
1588
1608
  def format_debug_decision(d):
1589
1609
  return DEBUG_DECISION_FMT % d
1590
1610
 
1611
+
1591
1612
  def demo(text, tok_cls=PunktSentenceTokenizer, train_cls=PunktTrainer):
1592
1613
  """Builds a punkt model and applies it to the same text"""
1593
1614
  cleanup = lambda s: re.compile(r'(?:\r|^\s+)', re.MULTILINE).sub('', s).replace('\n', ' ')
@@ -1597,5 +1618,3 @@ def demo(text, tok_cls=PunktSentenceTokenizer, train_cls=PunktTrainer):
1597
1618
  sbd = tok_cls(trainer.get_params())
1598
1619
  for l in sbd.sentences_from_text(text):
1599
1620
  print(cleanup(l))
1600
-
1601
-