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.
- {nltk-3.2.1 → nltk-3.3}/LICENSE.txt +1 -1
- {nltk-3.2.1/nltk.egg-info → nltk-3.3}/PKG-INFO +13 -5
- nltk-3.3/README.md +49 -0
- nltk-3.3/nltk/VERSION +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/__init__.py +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/app/__init__.py +2 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/app/chartparser_app.py +92 -92
- {nltk-3.2.1 → nltk-3.3}/nltk/app/chunkparser_app.py +11 -13
- {nltk-3.2.1 → nltk-3.3}/nltk/app/collocations_app.py +8 -11
- {nltk-3.2.1 → nltk-3.3}/nltk/app/concordance_app.py +9 -11
- {nltk-3.2.1 → nltk-3.3}/nltk/app/nemo_app.py +18 -17
- {nltk-3.2.1 → nltk-3.3}/nltk/app/rdparser_app.py +10 -12
- {nltk-3.2.1 → nltk-3.3}/nltk/app/srparser_app.py +16 -16
- {nltk-3.2.1 → nltk-3.3}/nltk/app/wordfreq_app.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/app/wordnet_app.py +11 -11
- {nltk-3.2.1 → nltk-3.3}/nltk/book.py +2 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/api.py +67 -47
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/chart.py +7 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/combinator.py +42 -11
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/lexicon.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/ccg/logic.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/eliza.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/iesha.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/rude.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/suntsu.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/util.py +12 -10
- {nltk-3.2.1 → nltk-3.3}/nltk/chat/zen.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chunk/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chunk/api.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/chunk/named_entity.py +13 -13
- {nltk-3.2.1 → nltk-3.3}/nltk/chunk/regexp.py +9 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/chunk/util.py +12 -12
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/api.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/decisiontree.py +18 -18
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/maxent.py +26 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/megam.py +5 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/naivebayes.py +29 -26
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/rte_classify.py +58 -89
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/scikitlearn.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/senna.py +24 -22
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/svm.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/tadm.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/textcat.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/util.py +13 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/weka.py +7 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/api.py +9 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/em.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/gaac.py +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/kmeans.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/cluster/util.py +35 -20
- nltk-3.3/nltk/collections.py +640 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/collocations.py +2 -2
- nltk-3.3/nltk/compat.py +365 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/__init__.py +37 -16
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/europarl_raw.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/__init__.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/aligned.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/api.py +12 -10
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/bnc.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/bracket_parse.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/categorized_sents.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/chasen.py +5 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/childes.py +8 -9
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/chunked.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/cmudict.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/comparative_sents.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/conll.py +19 -12
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/crubadan.py +2 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/dependency.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/framenet.py +1085 -119
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ieer.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/indian.py +4 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ipipan.py +6 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/knbc.py +2 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/lin.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/mte.py +5 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nkjp.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nombank.py +8 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/nps_chat.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/opinion_lexicon.py +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/panlex_lite.py +1 -1
- nltk-3.3/nltk/corpus/reader/pl196x.py +292 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/plaintext.py +3 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ppattach.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/propbank.py +8 -10
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/pros_cons.py +5 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/reviews.py +3 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/rte.py +5 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/semcor.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/senseval.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/sentiwordnet.py +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/sinica_treebank.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/string_category.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/switchboard.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/tagged.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/timit.py +10 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/toolbox.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/twitter.py +4 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/util.py +7 -3
- nltk-3.3/nltk/corpus/reader/verbnet.py +595 -0
- nltk-3.3/nltk/corpus/reader/wordlist.py +134 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/wordnet.py +357 -285
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/xmldocs.py +10 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/ycoe.py +25 -24
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/util.py +22 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/data.py +65 -29
- {nltk-3.2.1 → nltk-3.3}/nltk/decorators.py +5 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/downloader.py +59 -55
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/__init__.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/cfg.py +5 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/dispersion.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/table.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/tree.py +2 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/draw/util.py +17 -17
- {nltk-3.2.1 → nltk-3.3}/nltk/featstruct.py +290 -173
- {nltk-3.2.1 → nltk-3.3}/nltk/grammar.py +87 -44
- {nltk-3.2.1 → nltk-3.3}/nltk/help.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/api.py +27 -19
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/discourse.py +20 -16
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/nonmonotonic.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/prover9.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/resolution.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/tableau.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/internals.py +44 -44
- {nltk-3.2.1 → nltk-3.3}/nltk/jsontags.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/__init__.py +2 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/agreement.py +29 -9
- nltk-3.3/nltk/metrics/aline.py +607 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/association.py +8 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/confusionmatrix.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/distance.py +12 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/paice.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/scores.py +7 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/segmentation.py +4 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/metrics/spearman.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/chomsky.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/minimalset.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/sort.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/wordfinder.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/__init__.py +2 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/api.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/bllip.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/chart.py +8 -7
- nltk-3.3/nltk/parse/corenlp.py +780 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/dependencygraph.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/earleychart.py +4 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/evaluate.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/featurechart.py +6 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/generate.py +15 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/malt.py +2 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/nonprojectivedependencyparser.py +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/pchart.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/projectivedependencyparser.py +6 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/recursivedescent.py +2 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/shiftreduce.py +2 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/stanford.py +53 -28
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/transitionparser.py +11 -9
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/util.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/parse/viterbi.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/probability.py +75 -20
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/boxer.py +15 -15
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/chat80.py +6 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/cooper_storage.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/drt.py +9 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/drt_glue_demo.py +5 -9
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/evaluate.py +9 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/glue.py +8 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/hole.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/lfg.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/linearlogic.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/logic.py +14 -14
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/relextract.py +11 -18
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/skolemize.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sem/util.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/sentiment_analyzer.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/util.py +14 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/sentiment/vader.py +41 -42
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/__init__.py +1 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/api.py +7 -4
- nltk-3.3/nltk/stem/arlstem.py +369 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/isri.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/lancaster.py +39 -12
- nltk-3.3/nltk/stem/porter.py +710 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/regexp.py +2 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/rslp.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/snowball.py +537 -13
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/util.py +11 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/stem/wordnet.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/__init__.py +32 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/api.py +13 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/brill.py +4 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/crf.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/hmm.py +11 -11
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/hunpos.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/mapping.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/perceptron.py +25 -10
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/senna.py +25 -23
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/sequential.py +19 -15
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/stanford.py +59 -36
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/tnt.py +11 -20
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/util.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/demo.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/erroranalysis.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/feature.py +5 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/rule.py +6 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/template.py +18 -23
- {nltk-3.2.1 → nltk-3.3}/nltk/test/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/all.py +7 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/test/bnc.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/ccg.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/ccg_semantics.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/chat80.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/childes_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/chunk.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/classify.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/classify_fixt.py +2 -1
- nltk-3.3/nltk/test/collections.doctest +20 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/collocations.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/compat.doctest +0 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/test/compat_fixt.py +1 -0
- nltk-3.3/nltk/test/concordance.doctest +55 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/corpus.doctest +38 -49
- {nltk-3.2.1 → nltk-3.3}/nltk/test/crubadan.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/data.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/dependency.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/discourse.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/discourse_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/doctest_nose_plugin.py +8 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/test/drt.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/featgram.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/featstruct.doctest +2 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/test/framenet.doctest +82 -33
- {nltk-3.2.1 → nltk-3.3}/nltk/test/generate.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/gensim.doctest +6 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/test/gensim_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics.doctest +13 -15
- {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics_malt.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/gluesemantics_malt_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/grammar.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/grammartestsuites.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/index.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/inference.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/inference_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/internals.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/japanese.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/logic.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/metrics.doctest +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/test/misc.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/nonmonotonic.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/nonmonotonic_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/parse.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/portuguese_en.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/probability.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/probability_fixt.py +2 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/propbank.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/relextract.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/resolution.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/runtests.py +35 -13
- {nltk-3.2.1 → nltk-3.3}/nltk/test/semantics.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/sentiment.doctest +3 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/test/sentiwordnet.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/simple.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/stem.doctest +2 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/test/tag.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/tokenize.doctest +109 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/test/toolbox.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/translate.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/tree.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/treeprettyprinter.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/treetransforms.doctest +1 -1
- nltk-3.3/nltk/test/unit/test_aline.py +52 -0
- nltk-3.3/nltk/test/unit/test_chunk.py +56 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_classify.py +20 -18
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_collocations.py +16 -7
- nltk-3.3/nltk/test/unit/test_concordance.py +98 -0
- nltk-3.3/nltk/test/unit/test_corenlp.py +1000 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_corpora.py +18 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_json2csv_corpus.py +4 -3
- nltk-3.3/nltk/test/unit/test_rte_classify.py +86 -0
- nltk-3.3/nltk/test/unit/test_senna.py +74 -0
- nltk-3.3/nltk/test/unit/test_stem.py +121 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_tgrep.py +4 -2
- nltk-3.3/nltk/test/unit/test_tokenize.py +168 -0
- nltk-3.3/nltk/test/unit/test_wordnet.py +134 -0
- nltk-3.3/nltk/test/unit/translate/test_bleu.py +244 -0
- nltk-3.3/nltk/test/unit/translate/test_gdfa.py +57 -0
- nltk-3.3/nltk/test/unit/translate/test_nist.py +37 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_stack_decoder.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/util.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet.doctest +17 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet_fixt.py +1 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/wordnet_lch.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/test/wsd.doctest +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/text.py +92 -39
- {nltk-3.2.1 → nltk-3.3}/nltk/tgrep.py +8 -7
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/__init__.py +37 -15
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/api.py +3 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/casual.py +10 -9
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/mwe.py +2 -2
- nltk-3.3/nltk/tokenize/nist.py +173 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/punkt.py +186 -167
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/regexp.py +13 -7
- nltk-3.3/nltk/tokenize/repp.py +151 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/sexpr.py +4 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/simple.py +7 -5
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/stanford.py +18 -14
- nltk-3.3/nltk/tokenize/stanford_segmenter.py +246 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/tokenize/texttiling.py +43 -45
- nltk-3.3/nltk/tokenize/toktok.py +155 -0
- nltk-3.3/nltk/tokenize/treebank.py +363 -0
- nltk-3.3/nltk/tokenize/util.py +261 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/toolbox.py +4 -2
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/api.py +50 -40
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/bleu_score.py +221 -156
- nltk-3.3/nltk/translate/chrf_score.py +137 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/gale_church.py +32 -19
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/gdfa.py +14 -10
- nltk-3.3/nltk/translate/gleu_score.py +193 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm1.py +17 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm2.py +4 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm4.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm5.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm_model.py +4 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/metrics.py +1 -1
- nltk-3.3/nltk/translate/nist_score.py +178 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/phrase_based.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ribes_score.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/stack_decoder.py +5 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/tree.py +10 -8
- {nltk-3.2.1 → nltk-3.3}/nltk/treeprettyprinter.py +6 -6
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/__init__.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/api.py +8 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/common.py +9 -3
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/twitter_demo.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/twitterclient.py +1 -1
- {nltk-3.2.1 → nltk-3.3}/nltk/twitter/util.py +5 -4
- {nltk-3.2.1 → nltk-3.3}/nltk/util.py +41 -654
- {nltk-3.2.1 → nltk-3.3}/nltk/wsd.py +2 -2
- {nltk-3.2.1 → nltk-3.3/nltk.egg-info}/PKG-INFO +13 -5
- {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/SOURCES.txt +23 -1
- nltk-3.3/nltk.egg-info/requires.txt +31 -0
- {nltk-3.2.1 → nltk-3.3}/setup.cfg +0 -1
- {nltk-3.2.1 → nltk-3.3}/setup.py +32 -5
- nltk-3.2.1/nltk/VERSION +0 -1
- nltk-3.2.1/nltk/compat.py +0 -706
- nltk-3.2.1/nltk/corpus/reader/pl196x.py +0 -278
- nltk-3.2.1/nltk/corpus/reader/verbnet.py +0 -408
- nltk-3.2.1/nltk/corpus/reader/wordlist.py +0 -37
- nltk-3.2.1/nltk/six.py +0 -868
- nltk-3.2.1/nltk/stem/porter.py +0 -692
- nltk-3.2.1/nltk/test/unit/test_stem.py +0 -36
- nltk-3.2.1/nltk/test/unit/test_tokenize.py +0 -23
- nltk-3.2.1/nltk/test/unit/translate/test_bleu.py +0 -138
- nltk-3.2.1/nltk/tokenize/stanford_segmenter.py +0 -157
- nltk-3.2.1/nltk/tokenize/treebank.py +0 -124
- nltk-3.2.1/nltk/tokenize/util.py +0 -90
- {nltk-3.2.1 → nltk-3.3}/INSTALL.txt +0 -0
- {nltk-3.2.1 → nltk-3.3}/MANIFEST.in +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/classify/positivenaivebayes.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/corpus/reader/udhr.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/inference/mace.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/lazyimport.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/misc/babelfish.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/tag/brill_trainer.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/tbl/api.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/bleu.doctest +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/childes.doctest +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/corpus_fixt.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/paice.doctest +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/portuguese_en_fixt.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/segmentation_fixt.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/semantics_fixt.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/translate_fixt.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/__init__.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_2x_compat.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_corpus_views.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_hmm.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_naivebayes.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_seekable_unicode_stream_reader.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_tag.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/test_twitter_auth.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/__init__.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm1.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm2.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm3.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm4.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm5.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/translate/test_ibm_model.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/test/unit/utils.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/translate/ibm3.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk/treetransforms.py +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/dependency_links.txt +0 -0
- {nltk-3.2.1 → nltk-3.3}/nltk.egg-info/not-zip-safe +0 -0
- {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-
|
|
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
|
|
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
|
|
125
|
+
_ORTHO_BEG_UC = 1 << 1
|
|
124
126
|
"""Orthographic context: beginning of a sentence with upper case."""
|
|
125
127
|
|
|
126
|
-
_ORTHO_MID_UC
|
|
128
|
+
_ORTHO_MID_UC = 1 << 2
|
|
127
129
|
"""Orthographic context: middle of a sentence with upper case."""
|
|
128
130
|
|
|
129
|
-
_ORTHO_UNK_UC
|
|
131
|
+
_ORTHO_UNK_UC = 1 << 3
|
|
130
132
|
"""Orthographic context: unknown position in a sentence with upper case."""
|
|
131
133
|
|
|
132
|
-
_ORTHO_BEG_LC
|
|
134
|
+
_ORTHO_BEG_LC = 1 << 4
|
|
133
135
|
"""Orthographic context: beginning of a sentence with lower case."""
|
|
134
136
|
|
|
135
|
-
_ORTHO_MID_LC
|
|
137
|
+
_ORTHO_MID_LC = 1 << 5
|
|
136
138
|
"""Orthographic context: middle of a sentence with lower case."""
|
|
137
139
|
|
|
138
|
-
_ORTHO_UNK_LC
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
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 = ',:;'
|
|
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
|
-
|
|
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
|
|
220
|
+
_re_word_start = r"[^\(\"\`{\[:;&\#\*@\)}\]\-,]"
|
|
218
221
|
"""Excludes some characters from starting word tokens"""
|
|
219
222
|
|
|
220
|
-
_re_non_word_chars
|
|
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':
|
|
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':
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
-
|
|
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
|
-
|
|
619
|
+
lang_vars=PunktLanguageVars(), token_cls=PunktToken):
|
|
612
620
|
|
|
613
621
|
PunktBaseClass.__init__(self, lang_vars=lang_vars,
|
|
614
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
840
|
+
self._collocation_fdist, colloc_thres)
|
|
833
841
|
self._sent_starter_fdist = self._freq_threshold(
|
|
834
|
-
|
|
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
|
-
|
|
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 (
|
|
1024
|
-
|
|
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
|
|
1045
|
-
|
|
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
|
-
|
|
1071
|
+
try:
|
|
1072
|
+
p2 = (count_b - count_ab) / (N - count_a)
|
|
1073
|
+
except ZeroDivisionError as e:
|
|
1074
|
+
p2 = 1
|
|
1066
1075
|
|
|
1067
|
-
|
|
1068
|
-
|
|
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
|
-
|
|
1071
|
-
|
|
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
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1130
|
-
|
|
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 (
|
|
1146
|
-
|
|
1147
|
-
|
|
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
|
-
|
|
1180
|
+
typ_at_break_count,
|
|
1166
1181
|
self._type_fdist.N())
|
|
1167
1182
|
|
|
1168
1183
|
if (ll >= self.SENT_STARTER and
|
|
1169
|
-
|
|
1170
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
1498
|
-
|
|
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 (
|
|
1512
|
-
|
|
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 (
|
|
1538
|
-
|
|
1539
|
-
|
|
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 (
|
|
1560
|
-
|
|
1561
|
-
|
|
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 (
|
|
1569
|
-
|
|
1570
|
-
|
|
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
|
-
|