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
nltk-3.2.1/nltk/compat.py
DELETED
|
@@ -1,706 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# Natural Language Toolkit: Compatibility
|
|
3
|
-
#
|
|
4
|
-
# Copyright (C) 2001-2016 NLTK Project
|
|
5
|
-
#
|
|
6
|
-
# URL: <http://nltk.org/>
|
|
7
|
-
# For license information, see LICENSE.TXT
|
|
8
|
-
|
|
9
|
-
from __future__ import absolute_import, print_function
|
|
10
|
-
import os
|
|
11
|
-
import sys
|
|
12
|
-
import types
|
|
13
|
-
from functools import wraps
|
|
14
|
-
import fractions
|
|
15
|
-
|
|
16
|
-
# Python 2/3 compatibility layer. Based on six.
|
|
17
|
-
|
|
18
|
-
PY3 = sys.version_info[0] == 3
|
|
19
|
-
PY26 = sys.version_info[:2] == (2, 6)
|
|
20
|
-
|
|
21
|
-
if PY3:
|
|
22
|
-
def b(s):
|
|
23
|
-
return s.encode("latin-1")
|
|
24
|
-
|
|
25
|
-
def u(s):
|
|
26
|
-
return s
|
|
27
|
-
|
|
28
|
-
string_types = str,
|
|
29
|
-
integer_types = int,
|
|
30
|
-
class_types = type,
|
|
31
|
-
text_type = str
|
|
32
|
-
binary_type = bytes
|
|
33
|
-
|
|
34
|
-
MAXSIZE = sys.maxsize
|
|
35
|
-
get_im_class = lambda meth: meth.__self__.__class__
|
|
36
|
-
xrange = range
|
|
37
|
-
_iterkeys = "keys"
|
|
38
|
-
_itervalues = "values"
|
|
39
|
-
_iteritems = "items"
|
|
40
|
-
from imp import reload
|
|
41
|
-
raw_input = input
|
|
42
|
-
|
|
43
|
-
imap = map
|
|
44
|
-
izip = zip
|
|
45
|
-
|
|
46
|
-
import io
|
|
47
|
-
StringIO = io.StringIO
|
|
48
|
-
BytesIO = io.BytesIO
|
|
49
|
-
|
|
50
|
-
import html.entities as htmlentitydefs
|
|
51
|
-
from urllib.request import (urlopen, ProxyHandler, build_opener,
|
|
52
|
-
install_opener, getproxies, HTTPPasswordMgrWithDefaultRealm,
|
|
53
|
-
ProxyBasicAuthHandler, ProxyDigestAuthHandler, Request,
|
|
54
|
-
url2pathname)
|
|
55
|
-
from urllib.error import HTTPError, URLError
|
|
56
|
-
from urllib.parse import quote_plus, unquote_plus, urlencode
|
|
57
|
-
|
|
58
|
-
from collections import Counter
|
|
59
|
-
|
|
60
|
-
from datetime import timezone
|
|
61
|
-
UTC = timezone.utc
|
|
62
|
-
|
|
63
|
-
from tempfile import TemporaryDirectory
|
|
64
|
-
|
|
65
|
-
unichr = chr
|
|
66
|
-
if sys.version_info[1] <= 1:
|
|
67
|
-
def int2byte(i):
|
|
68
|
-
return bytes((i,))
|
|
69
|
-
else:
|
|
70
|
-
# This is about 2x faster than the implementation above on 3.2+
|
|
71
|
-
import operator
|
|
72
|
-
int2byte = operator.methodcaller("to_bytes", 1, "big")
|
|
73
|
-
|
|
74
|
-
else:
|
|
75
|
-
def b(s):
|
|
76
|
-
return s
|
|
77
|
-
|
|
78
|
-
def u(s):
|
|
79
|
-
return unicode(s, "unicode_escape")
|
|
80
|
-
|
|
81
|
-
string_types = basestring,
|
|
82
|
-
integer_types = (int, long)
|
|
83
|
-
class_types = (type, types.ClassType)
|
|
84
|
-
text_type = unicode
|
|
85
|
-
binary_type = str
|
|
86
|
-
get_im_class = lambda meth: meth.im_class
|
|
87
|
-
xrange = xrange
|
|
88
|
-
_iterkeys = "iterkeys"
|
|
89
|
-
_itervalues = "itervalues"
|
|
90
|
-
_iteritems = "iteritems"
|
|
91
|
-
reload = reload
|
|
92
|
-
raw_input = raw_input
|
|
93
|
-
|
|
94
|
-
from itertools import imap, izip
|
|
95
|
-
|
|
96
|
-
try:
|
|
97
|
-
from cStringIO import StringIO
|
|
98
|
-
except ImportError:
|
|
99
|
-
from StringIO import StringIO
|
|
100
|
-
BytesIO = StringIO
|
|
101
|
-
|
|
102
|
-
import htmlentitydefs
|
|
103
|
-
from urllib2 import (urlopen, HTTPError, URLError,
|
|
104
|
-
ProxyHandler, build_opener, install_opener,
|
|
105
|
-
HTTPPasswordMgrWithDefaultRealm, ProxyBasicAuthHandler,
|
|
106
|
-
ProxyDigestAuthHandler, Request)
|
|
107
|
-
from urllib import getproxies, quote_plus, unquote_plus, urlencode, url2pathname
|
|
108
|
-
|
|
109
|
-
# Maps py2 tkinter package structure to py3 using import hook (PEP 302)
|
|
110
|
-
class TkinterPackage(object):
|
|
111
|
-
def __init__(self):
|
|
112
|
-
self.mod = __import__("Tkinter")
|
|
113
|
-
self.__path__ = ["nltk_py2_tkinter_package_path"]
|
|
114
|
-
|
|
115
|
-
def __getattr__(self, name):
|
|
116
|
-
return getattr(self.mod, name)
|
|
117
|
-
|
|
118
|
-
class TkinterLoader(object):
|
|
119
|
-
def __init__(self):
|
|
120
|
-
# module name mapping from py3 to py2
|
|
121
|
-
self.module_map = {
|
|
122
|
-
"tkinter": "Tkinter",
|
|
123
|
-
"tkinter.filedialog": "tkFileDialog",
|
|
124
|
-
"tkinter.font": "tkFont",
|
|
125
|
-
"tkinter.messagebox": "tkMessageBox",
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
def find_module(self, name, path=None):
|
|
129
|
-
# we are only interested in tkinter modules listed
|
|
130
|
-
# in self.module_map
|
|
131
|
-
if name in self.module_map:
|
|
132
|
-
return self
|
|
133
|
-
|
|
134
|
-
def load_module(self, name):
|
|
135
|
-
if name not in sys.modules:
|
|
136
|
-
if name == 'tkinter':
|
|
137
|
-
mod = TkinterPackage()
|
|
138
|
-
else:
|
|
139
|
-
mod = __import__(self.module_map[name])
|
|
140
|
-
sys.modules[name] = mod
|
|
141
|
-
return sys.modules[name]
|
|
142
|
-
|
|
143
|
-
sys.meta_path.insert(0, TkinterLoader())
|
|
144
|
-
|
|
145
|
-
from datetime import tzinfo, timedelta
|
|
146
|
-
|
|
147
|
-
ZERO = timedelta(0)
|
|
148
|
-
HOUR = timedelta(hours=1)
|
|
149
|
-
|
|
150
|
-
# A UTC class for python 2.7
|
|
151
|
-
class UTC(tzinfo):
|
|
152
|
-
"""UTC"""
|
|
153
|
-
|
|
154
|
-
def utcoffset(self, dt):
|
|
155
|
-
return ZERO
|
|
156
|
-
|
|
157
|
-
def tzname(self, dt):
|
|
158
|
-
return "UTC"
|
|
159
|
-
|
|
160
|
-
def dst(self, dt):
|
|
161
|
-
return ZERO
|
|
162
|
-
|
|
163
|
-
UTC = UTC()
|
|
164
|
-
|
|
165
|
-
unichr = unichr
|
|
166
|
-
int2byte = chr
|
|
167
|
-
|
|
168
|
-
import csv
|
|
169
|
-
import codecs
|
|
170
|
-
import cStringIO
|
|
171
|
-
|
|
172
|
-
class UnicodeWriter:
|
|
173
|
-
"""
|
|
174
|
-
A CSV writer which will write rows to CSV file "f",
|
|
175
|
-
which is encoded in the given encoding.
|
|
176
|
-
see https://docs.python.org/2/library/csv.html
|
|
177
|
-
"""
|
|
178
|
-
|
|
179
|
-
def __init__(self, f, dialect=csv.excel, encoding="utf-8", errors='replace', **kwds):
|
|
180
|
-
# Redirect output to a queue
|
|
181
|
-
self.queue = cStringIO.StringIO()
|
|
182
|
-
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
|
|
183
|
-
self.stream = f
|
|
184
|
-
encoder_cls = codecs.getincrementalencoder(encoding)
|
|
185
|
-
self.encoder = encoder_cls(errors=errors)
|
|
186
|
-
|
|
187
|
-
def encode(self, data):
|
|
188
|
-
if isinstance(data, basestring):
|
|
189
|
-
return data.encode("utf-8")
|
|
190
|
-
else:
|
|
191
|
-
return data
|
|
192
|
-
|
|
193
|
-
def writerow(self, row):
|
|
194
|
-
self.writer.writerow([self.encode(s) for s in row])
|
|
195
|
-
# Fetch UTF-8 output from the queue ...
|
|
196
|
-
data = self.queue.getvalue()
|
|
197
|
-
data = data.decode("utf-8")
|
|
198
|
-
# ... and reencode it into the target encoding
|
|
199
|
-
data = self.encoder.encode(data, 'replace')
|
|
200
|
-
# write to the target stream
|
|
201
|
-
self.stream.write(data)
|
|
202
|
-
# empty queue
|
|
203
|
-
self.queue.truncate(0)
|
|
204
|
-
|
|
205
|
-
import warnings as _warnings
|
|
206
|
-
import os as _os
|
|
207
|
-
from tempfile import mkdtemp
|
|
208
|
-
|
|
209
|
-
class TemporaryDirectory(object):
|
|
210
|
-
"""Create and return a temporary directory. This has the same
|
|
211
|
-
behavior as mkdtemp but can be used as a context manager. For
|
|
212
|
-
example:
|
|
213
|
-
|
|
214
|
-
with TemporaryDirectory() as tmpdir:
|
|
215
|
-
...
|
|
216
|
-
|
|
217
|
-
Upon exiting the context, the directory and everything contained
|
|
218
|
-
in it are removed.
|
|
219
|
-
|
|
220
|
-
http://stackoverflow.com/questions/19296146/tempfile-temporarydirectory-context-manager-in-python-2-7
|
|
221
|
-
"""
|
|
222
|
-
|
|
223
|
-
def __init__(self, suffix="", prefix="tmp", dir=None):
|
|
224
|
-
self._closed = False
|
|
225
|
-
self.name = None # Handle mkdtemp raising an exception
|
|
226
|
-
self.name = mkdtemp(suffix, prefix, dir)
|
|
227
|
-
|
|
228
|
-
def __repr__(self):
|
|
229
|
-
return "<{} {!r}>".format(self.__class__.__name__, self.name)
|
|
230
|
-
|
|
231
|
-
def __enter__(self):
|
|
232
|
-
return self.name
|
|
233
|
-
|
|
234
|
-
def cleanup(self, _warn=False):
|
|
235
|
-
if self.name and not self._closed:
|
|
236
|
-
try:
|
|
237
|
-
self._rmtree(self.name)
|
|
238
|
-
except (TypeError, AttributeError) as ex:
|
|
239
|
-
# Issue #10188: Emit a warning on stderr
|
|
240
|
-
# if the directory could not be cleaned
|
|
241
|
-
# up due to missing globals
|
|
242
|
-
if "None" not in str(ex):
|
|
243
|
-
raise
|
|
244
|
-
print("ERROR: {!r} while cleaning up {!r}".format(ex, self,),
|
|
245
|
-
file=sys.stderr)
|
|
246
|
-
return
|
|
247
|
-
self._closed = True
|
|
248
|
-
if _warn:
|
|
249
|
-
self._warn("Implicitly cleaning up {!r}".format(self),
|
|
250
|
-
ResourceWarning)
|
|
251
|
-
|
|
252
|
-
def __exit__(self, exc, value, tb):
|
|
253
|
-
self.cleanup()
|
|
254
|
-
|
|
255
|
-
def __del__(self):
|
|
256
|
-
# Issue a ResourceWarning if implicit cleanup needed
|
|
257
|
-
self.cleanup(_warn=True)
|
|
258
|
-
|
|
259
|
-
# XXX (ncoghlan): The following code attempts to make
|
|
260
|
-
# this class tolerant of the module nulling out process
|
|
261
|
-
# that happens during CPython interpreter shutdown
|
|
262
|
-
# Alas, it doesn't actually manage it. See issue #10188
|
|
263
|
-
_listdir = staticmethod(_os.listdir)
|
|
264
|
-
_path_join = staticmethod(_os.path.join)
|
|
265
|
-
_isdir = staticmethod(_os.path.isdir)
|
|
266
|
-
_islink = staticmethod(_os.path.islink)
|
|
267
|
-
_remove = staticmethod(_os.remove)
|
|
268
|
-
_rmdir = staticmethod(_os.rmdir)
|
|
269
|
-
_warn = _warnings.warn
|
|
270
|
-
|
|
271
|
-
def _rmtree(self, path):
|
|
272
|
-
# Essentially a stripped down version of shutil.rmtree. We can't
|
|
273
|
-
# use globals because they may be None'ed out at shutdown.
|
|
274
|
-
for name in self._listdir(path):
|
|
275
|
-
fullname = self._path_join(path, name)
|
|
276
|
-
try:
|
|
277
|
-
isdir = self._isdir(fullname) and not self._islink(fullname)
|
|
278
|
-
except OSError:
|
|
279
|
-
isdir = False
|
|
280
|
-
if isdir:
|
|
281
|
-
self._rmtree(fullname)
|
|
282
|
-
else:
|
|
283
|
-
try:
|
|
284
|
-
self._remove(fullname)
|
|
285
|
-
except OSError:
|
|
286
|
-
pass
|
|
287
|
-
try:
|
|
288
|
-
self._rmdir(path)
|
|
289
|
-
except OSError:
|
|
290
|
-
pass
|
|
291
|
-
|
|
292
|
-
if PY26:
|
|
293
|
-
from operator import itemgetter
|
|
294
|
-
from heapq import nlargest
|
|
295
|
-
from itertools import repeat, ifilter
|
|
296
|
-
|
|
297
|
-
class Counter(dict):
|
|
298
|
-
'''Dict subclass for counting hashable objects. Sometimes called a bag
|
|
299
|
-
or multiset. Elements are stored as dictionary keys and their counts
|
|
300
|
-
are stored as dictionary values.
|
|
301
|
-
|
|
302
|
-
>>> Counter('zyzygy')
|
|
303
|
-
Counter({'y': 3, 'z': 2, 'g': 1})
|
|
304
|
-
|
|
305
|
-
'''
|
|
306
|
-
|
|
307
|
-
def __init__(self, iterable=None, **kwds):
|
|
308
|
-
'''Create a new, empty Counter object. And if given, count elements
|
|
309
|
-
from an input iterable. Or, initialize the count from another mapping
|
|
310
|
-
of elements to their counts.
|
|
311
|
-
|
|
312
|
-
>>> Counter() # a new, empty counter
|
|
313
|
-
>>> Counter('gallahad') # a new counter from an iterable
|
|
314
|
-
>>> Counter({'a': 4, 'b': 2}) # a new counter from a mapping
|
|
315
|
-
>>> Counter(a=4, b=2) # a new counter from keyword args
|
|
316
|
-
|
|
317
|
-
'''
|
|
318
|
-
self.update(iterable, **kwds)
|
|
319
|
-
|
|
320
|
-
def __missing__(self, key):
|
|
321
|
-
return 0
|
|
322
|
-
|
|
323
|
-
def most_common(self, n=None):
|
|
324
|
-
'''List the n most common elements and their counts from the most
|
|
325
|
-
common to the least. If n is None, then list all element counts.
|
|
326
|
-
|
|
327
|
-
>>> Counter('abracadabra').most_common(3)
|
|
328
|
-
[('a', 5), ('r', 2), ('b', 2)]
|
|
329
|
-
|
|
330
|
-
'''
|
|
331
|
-
if n is None:
|
|
332
|
-
return sorted(self.iteritems(), key=itemgetter(1), reverse=True)
|
|
333
|
-
return nlargest(n, self.iteritems(), key=itemgetter(1))
|
|
334
|
-
|
|
335
|
-
def elements(self):
|
|
336
|
-
'''Iterator over elements repeating each as many times as its count.
|
|
337
|
-
|
|
338
|
-
>>> c = Counter('ABCABC')
|
|
339
|
-
>>> sorted(c.elements())
|
|
340
|
-
['A', 'A', 'B', 'B', 'C', 'C']
|
|
341
|
-
|
|
342
|
-
If an element's count has been set to zero or is a negative number,
|
|
343
|
-
elements() will ignore it.
|
|
344
|
-
|
|
345
|
-
'''
|
|
346
|
-
for elem, count in self.iteritems():
|
|
347
|
-
for _ in repeat(None, count):
|
|
348
|
-
yield elem
|
|
349
|
-
|
|
350
|
-
# Override dict methods where the meaning changes for Counter
|
|
351
|
-
# objects.
|
|
352
|
-
|
|
353
|
-
@classmethod
|
|
354
|
-
def fromkeys(cls, iterable, v=None):
|
|
355
|
-
raise NotImplementedError(
|
|
356
|
-
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
|
357
|
-
|
|
358
|
-
def update(self, iterable=None, **kwds):
|
|
359
|
-
'''Like dict.update() but add counts instead of replacing them.
|
|
360
|
-
|
|
361
|
-
Source can be an iterable, a dictionary, or another Counter instance.
|
|
362
|
-
|
|
363
|
-
>>> c = Counter('which')
|
|
364
|
-
>>> c.update('witch') # add elements from another iterable
|
|
365
|
-
>>> d = Counter('watch')
|
|
366
|
-
>>> c.update(d) # add elements from another counter
|
|
367
|
-
>>> c['h'] # four 'h' in which, witch, and watch
|
|
368
|
-
4
|
|
369
|
-
|
|
370
|
-
'''
|
|
371
|
-
if iterable is not None:
|
|
372
|
-
if hasattr(iterable, 'iteritems'):
|
|
373
|
-
if self:
|
|
374
|
-
self_get = self.get
|
|
375
|
-
for elem, count in iterable.iteritems():
|
|
376
|
-
self[elem] = self_get(elem, 0) + count
|
|
377
|
-
else:
|
|
378
|
-
# fast path when counter is empty
|
|
379
|
-
dict.update(self, iterable)
|
|
380
|
-
else:
|
|
381
|
-
self_get = self.get
|
|
382
|
-
for elem in iterable:
|
|
383
|
-
self[elem] = self_get(elem, 0) + 1
|
|
384
|
-
if kwds:
|
|
385
|
-
self.update(kwds)
|
|
386
|
-
|
|
387
|
-
def copy(self):
|
|
388
|
-
'Like dict.copy() but returns a Counter instance instead of a dict.'
|
|
389
|
-
return Counter(self)
|
|
390
|
-
|
|
391
|
-
def __delitem__(self, elem):
|
|
392
|
-
'Like dict.__delitem__() but does not raise KeyError for missing values.'
|
|
393
|
-
if elem in self:
|
|
394
|
-
dict.__delitem__(self, elem)
|
|
395
|
-
|
|
396
|
-
def __repr__(self):
|
|
397
|
-
if not self:
|
|
398
|
-
return '%s()' % self.__class__.__name__
|
|
399
|
-
items = ', '.join(map('%r: %r'.__mod__, self.most_common()))
|
|
400
|
-
return '%s({%s})' % (self.__class__.__name__, items)
|
|
401
|
-
|
|
402
|
-
# Multiset-style mathematical operations discussed in:
|
|
403
|
-
# Knuth TAOCP Volume II section 4.6.3 exercise 19
|
|
404
|
-
# and at http://en.wikipedia.org/wiki/Multiset
|
|
405
|
-
#
|
|
406
|
-
# Outputs guaranteed to only include positive counts.
|
|
407
|
-
#
|
|
408
|
-
# To strip negative and zero counts, add-in an empty counter:
|
|
409
|
-
# c += Counter()
|
|
410
|
-
|
|
411
|
-
def __add__(self, other):
|
|
412
|
-
'''Add counts from two counters.
|
|
413
|
-
|
|
414
|
-
>>> Counter('abbb') + Counter('bcc')
|
|
415
|
-
Counter({'b': 4, 'c': 2, 'a': 1})
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
'''
|
|
419
|
-
if not isinstance(other, Counter):
|
|
420
|
-
return NotImplemented
|
|
421
|
-
result = Counter()
|
|
422
|
-
for elem in set(self) | set(other):
|
|
423
|
-
newcount = self[elem] + other[elem]
|
|
424
|
-
if newcount > 0:
|
|
425
|
-
result[elem] = newcount
|
|
426
|
-
return result
|
|
427
|
-
|
|
428
|
-
def __sub__(self, other):
|
|
429
|
-
''' Subtract count, but keep only results with positive counts.
|
|
430
|
-
|
|
431
|
-
>>> Counter('abbbc') - Counter('bccd')
|
|
432
|
-
Counter({'b': 2, 'a': 1})
|
|
433
|
-
|
|
434
|
-
'''
|
|
435
|
-
if not isinstance(other, Counter):
|
|
436
|
-
return NotImplemented
|
|
437
|
-
result = Counter()
|
|
438
|
-
for elem in set(self) | set(other):
|
|
439
|
-
newcount = self[elem] - other[elem]
|
|
440
|
-
if newcount > 0:
|
|
441
|
-
result[elem] = newcount
|
|
442
|
-
return result
|
|
443
|
-
|
|
444
|
-
def __or__(self, other):
|
|
445
|
-
'''Union is the maximum of value in either of the input counters.
|
|
446
|
-
|
|
447
|
-
>>> Counter('abbb') | Counter('bcc')
|
|
448
|
-
Counter({'b': 3, 'c': 2, 'a': 1})
|
|
449
|
-
|
|
450
|
-
'''
|
|
451
|
-
if not isinstance(other, Counter):
|
|
452
|
-
return NotImplemented
|
|
453
|
-
_max = max
|
|
454
|
-
result = Counter()
|
|
455
|
-
for elem in set(self) | set(other):
|
|
456
|
-
newcount = _max(self[elem], other[elem])
|
|
457
|
-
if newcount > 0:
|
|
458
|
-
result[elem] = newcount
|
|
459
|
-
return result
|
|
460
|
-
|
|
461
|
-
def __and__(self, other):
|
|
462
|
-
''' Intersection is the minimum of corresponding counts.
|
|
463
|
-
|
|
464
|
-
>>> Counter('abbb') & Counter('bcc')
|
|
465
|
-
Counter({'b': 1})
|
|
466
|
-
|
|
467
|
-
'''
|
|
468
|
-
if not isinstance(other, Counter):
|
|
469
|
-
return NotImplemented
|
|
470
|
-
_min = min
|
|
471
|
-
result = Counter()
|
|
472
|
-
if len(self) < len(other):
|
|
473
|
-
self, other = other, self
|
|
474
|
-
for elem in ifilter(self.__contains__, other):
|
|
475
|
-
newcount = _min(self[elem], other[elem])
|
|
476
|
-
if newcount > 0:
|
|
477
|
-
result[elem] = newcount
|
|
478
|
-
return result
|
|
479
|
-
|
|
480
|
-
else:
|
|
481
|
-
from collections import Counter
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
def iterkeys(d):
|
|
485
|
-
"""Return an iterator over the keys of a dictionary."""
|
|
486
|
-
return getattr(d, _iterkeys)()
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
def itervalues(d):
|
|
490
|
-
"""Return an iterator over the values of a dictionary."""
|
|
491
|
-
return getattr(d, _itervalues)()
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
def iteritems(d):
|
|
495
|
-
"""Return an iterator over the (key, value) pairs of a dictionary."""
|
|
496
|
-
return getattr(d, _iteritems)()
|
|
497
|
-
|
|
498
|
-
try:
|
|
499
|
-
from functools import total_ordering
|
|
500
|
-
except ImportError: # python 2.6
|
|
501
|
-
def total_ordering(cls):
|
|
502
|
-
"""Class decorator that fills in missing ordering methods"""
|
|
503
|
-
convert = {
|
|
504
|
-
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
|
|
505
|
-
('__le__', lambda self, other: self < other or self == other),
|
|
506
|
-
('__ge__', lambda self, other: not self < other)],
|
|
507
|
-
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
|
|
508
|
-
('__lt__', lambda self, other: self <= other and not self == other),
|
|
509
|
-
('__gt__', lambda self, other: not self <= other)],
|
|
510
|
-
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
|
|
511
|
-
('__ge__', lambda self, other: self > other or self == other),
|
|
512
|
-
('__le__', lambda self, other: not self > other)],
|
|
513
|
-
'__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
|
|
514
|
-
('__gt__', lambda self, other: self >= other and not self == other),
|
|
515
|
-
('__lt__', lambda self, other: not self >= other)]
|
|
516
|
-
}
|
|
517
|
-
roots = set(dir(cls)) & set(convert)
|
|
518
|
-
if not roots:
|
|
519
|
-
raise ValueError(
|
|
520
|
-
'must define at least one ordering operation: < > <= >=')
|
|
521
|
-
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
|
|
522
|
-
for opname, opfunc in convert[root]:
|
|
523
|
-
if opname not in roots:
|
|
524
|
-
opfunc.__name__ = opname
|
|
525
|
-
opfunc.__doc__ = getattr(int, opname).__doc__
|
|
526
|
-
setattr(cls, opname, opfunc)
|
|
527
|
-
return cls
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
# ======= Compatibility for datasets that care about Python versions ========
|
|
531
|
-
|
|
532
|
-
# The following datasets have a /PY3 subdirectory containing
|
|
533
|
-
# a full copy of the data which has been re-encoded or repickled.
|
|
534
|
-
|
|
535
|
-
import os.path
|
|
536
|
-
|
|
537
|
-
DATA_UPDATES = [("chunkers", "maxent_ne_chunker"),
|
|
538
|
-
("help", "tagsets"),
|
|
539
|
-
("taggers", "maxent_treebank_pos_tagger"),
|
|
540
|
-
("tokenizers", "punkt")]
|
|
541
|
-
|
|
542
|
-
_PY3_DATA_UPDATES = [os.path.join(*path_list) for path_list in DATA_UPDATES]
|
|
543
|
-
|
|
544
|
-
def add_py3_data(path):
|
|
545
|
-
if PY3:
|
|
546
|
-
for item in _PY3_DATA_UPDATES:
|
|
547
|
-
if item in str(path) and "/PY3" not in str(path):
|
|
548
|
-
pos = path.index(item) + len(item)
|
|
549
|
-
if path[pos:pos + 4] == ".zip":
|
|
550
|
-
pos += 4
|
|
551
|
-
path = path[:pos] + "/PY3" + path[pos:]
|
|
552
|
-
break
|
|
553
|
-
return path
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
# for use in adding /PY3 to the second (filename) argument
|
|
557
|
-
# of the file pointers in data.py
|
|
558
|
-
def py3_data(init_func):
|
|
559
|
-
def _decorator(*args, **kwargs):
|
|
560
|
-
args = (args[0], add_py3_data(args[1])) + args[2:]
|
|
561
|
-
return init_func(*args, **kwargs)
|
|
562
|
-
return wraps(init_func)(_decorator)
|
|
563
|
-
|
|
564
|
-
# ======= Compatibility layer for __str__ and __repr__ ==========
|
|
565
|
-
|
|
566
|
-
import unicodedata
|
|
567
|
-
import functools
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
def remove_accents(text):
|
|
571
|
-
|
|
572
|
-
if isinstance(text, bytes):
|
|
573
|
-
text = text.decode('ascii')
|
|
574
|
-
|
|
575
|
-
category = unicodedata.category # this gives a small (~10%) speedup
|
|
576
|
-
return ''.join(
|
|
577
|
-
c for c in unicodedata.normalize('NFKD', text) if category(c) != 'Mn'
|
|
578
|
-
)
|
|
579
|
-
|
|
580
|
-
# Select the best transliteration method:
|
|
581
|
-
try:
|
|
582
|
-
# Older versions of Unidecode are licensed under Artistic License;
|
|
583
|
-
# assume an older version is installed.
|
|
584
|
-
from unidecode import unidecode as transliterate
|
|
585
|
-
except ImportError:
|
|
586
|
-
try:
|
|
587
|
-
# text-unidecode implementation is worse than Unidecode
|
|
588
|
-
# implementation so Unidecode is preferred.
|
|
589
|
-
from text_unidecode import unidecode as transliterate
|
|
590
|
-
except ImportError:
|
|
591
|
-
# This transliteration method should be enough
|
|
592
|
-
# for many Western languages.
|
|
593
|
-
transliterate = remove_accents
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
def python_2_unicode_compatible(klass):
|
|
597
|
-
"""
|
|
598
|
-
This decorator defines __unicode__ method and fixes
|
|
599
|
-
__repr__ and __str__ methods under Python 2.
|
|
600
|
-
|
|
601
|
-
To support Python 2 and 3 with a single code base,
|
|
602
|
-
define __str__ and __repr__ methods returning unicode
|
|
603
|
-
text and apply this decorator to the class.
|
|
604
|
-
|
|
605
|
-
Original __repr__ and __str__ would be available
|
|
606
|
-
as unicode_repr and __unicode__ (under both Python 2
|
|
607
|
-
and Python 3).
|
|
608
|
-
"""
|
|
609
|
-
|
|
610
|
-
if not issubclass(klass, object):
|
|
611
|
-
raise ValueError("This decorator doesn't work for old-style classes")
|
|
612
|
-
|
|
613
|
-
# both __unicode__ and unicode_repr are public because they
|
|
614
|
-
# may be useful in console under Python 2.x
|
|
615
|
-
|
|
616
|
-
# if __str__ or __repr__ are not overriden in a subclass,
|
|
617
|
-
# they may be already fixed by this decorator in a parent class
|
|
618
|
-
# and we shouldn't them again
|
|
619
|
-
|
|
620
|
-
if not _was_fixed(klass.__str__):
|
|
621
|
-
klass.__unicode__ = klass.__str__
|
|
622
|
-
if not PY3:
|
|
623
|
-
klass.__str__ = _7bit(_transliterated(klass.__unicode__))
|
|
624
|
-
|
|
625
|
-
if not _was_fixed(klass.__repr__):
|
|
626
|
-
klass.unicode_repr = klass.__repr__
|
|
627
|
-
if not PY3:
|
|
628
|
-
klass.__repr__ = _7bit(klass.unicode_repr)
|
|
629
|
-
|
|
630
|
-
return klass
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
def unicode_repr(obj):
|
|
634
|
-
"""
|
|
635
|
-
For classes that was fixed with @python_2_unicode_compatible
|
|
636
|
-
``unicode_repr`` returns ``obj.unicode_repr()``; for unicode strings
|
|
637
|
-
the result is returned without "u" letter (to make output the
|
|
638
|
-
same under Python 2.x and Python 3.x); for other variables
|
|
639
|
-
it is the same as ``repr``.
|
|
640
|
-
"""
|
|
641
|
-
if PY3:
|
|
642
|
-
return repr(obj)
|
|
643
|
-
|
|
644
|
-
# Python 2.x
|
|
645
|
-
if hasattr(obj, 'unicode_repr'):
|
|
646
|
-
return obj.unicode_repr()
|
|
647
|
-
|
|
648
|
-
if isinstance(obj, unicode):
|
|
649
|
-
return repr(obj)[1:] # strip "u" letter from output
|
|
650
|
-
|
|
651
|
-
return repr(obj)
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
def _transliterated(method):
|
|
655
|
-
def wrapper(self):
|
|
656
|
-
return transliterate(method(self))
|
|
657
|
-
|
|
658
|
-
functools.update_wrapper(wrapper, method, ["__name__", "__doc__"])
|
|
659
|
-
if hasattr(method, "_nltk_compat_7bit"):
|
|
660
|
-
wrapper._nltk_compat_7bit = method._nltk_compat_7bit
|
|
661
|
-
|
|
662
|
-
wrapper._nltk_compat_transliterated = True
|
|
663
|
-
return wrapper
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
def _7bit(method):
|
|
667
|
-
def wrapper(self):
|
|
668
|
-
return method(self).encode('ascii', 'backslashreplace')
|
|
669
|
-
|
|
670
|
-
functools.update_wrapper(wrapper, method, ["__name__", "__doc__"])
|
|
671
|
-
|
|
672
|
-
if hasattr(method, "_nltk_compat_transliterated"):
|
|
673
|
-
wrapper._nltk_compat_transliterated = method._nltk_compat_transliterated
|
|
674
|
-
|
|
675
|
-
wrapper._nltk_compat_7bit = True
|
|
676
|
-
return wrapper
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
def _was_fixed(method):
|
|
680
|
-
return (getattr(method, "_nltk_compat_7bit", False) or
|
|
681
|
-
getattr(method, "_nltk_compat_transliterated", False))
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
class Fraction(fractions.Fraction):
|
|
685
|
-
"""
|
|
686
|
-
This is a simplified backwards compatible version of fractions.Fraction from
|
|
687
|
-
Python >=3.5. It adds the `_normalize` parameter such that it does
|
|
688
|
-
not normalize the denominator to the Greatest Common Divisor (gcd) when
|
|
689
|
-
the numerator is 0.
|
|
690
|
-
|
|
691
|
-
This is most probably only used by the nltk.translate.bleu_score.py where
|
|
692
|
-
numerator and denominator of the different ngram precisions are mutable.
|
|
693
|
-
But the idea of "mutable" fraction might not be applicable to other usages,
|
|
694
|
-
See http://stackoverflow.com/questions/34561265
|
|
695
|
-
|
|
696
|
-
This objects should be deprecated once NLTK stops supporting Python < 3.5
|
|
697
|
-
See https://github.com/nltk/nltk/issues/1330
|
|
698
|
-
"""
|
|
699
|
-
def __new__(cls, numerator=0, denominator=None, _normalize=True):
|
|
700
|
-
cls = super(Fraction, cls).__new__(cls, numerator, denominator)
|
|
701
|
-
# To emulate fraction.Fraction.from_float across Python >=2.7,
|
|
702
|
-
# check that numerator is an integer and denominator is not None.
|
|
703
|
-
if not _normalize and type(numerator) == int and denominator:
|
|
704
|
-
cls._numerator = numerator
|
|
705
|
-
cls._denominator = denominator
|
|
706
|
-
return cls
|