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: Tokenizers
|
|
2
2
|
#
|
|
3
|
-
# Copyright (C) 2001-
|
|
3
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
4
4
|
# Author: Edward Loper <edloper@gmail.com>
|
|
5
5
|
# Steven Bird <stevenbird1@gmail.com>
|
|
6
6
|
# Trevor Cohn <tacohn@csse.unimelb.edu.au>
|
|
@@ -73,6 +73,7 @@ from nltk.tokenize.api import TokenizerI
|
|
|
73
73
|
from nltk.tokenize.util import regexp_span_tokenize
|
|
74
74
|
from nltk.compat import python_2_unicode_compatible
|
|
75
75
|
|
|
76
|
+
|
|
76
77
|
@python_2_unicode_compatible
|
|
77
78
|
class RegexpTokenizer(TokenizerI):
|
|
78
79
|
"""
|
|
@@ -100,6 +101,7 @@ class RegexpTokenizer(TokenizerI):
|
|
|
100
101
|
used: `re.UNICODE | re.MULTILINE | re.DOTALL`.
|
|
101
102
|
|
|
102
103
|
"""
|
|
104
|
+
|
|
103
105
|
def __init__(self, pattern, gaps=False, discard_empty=True,
|
|
104
106
|
flags=re.UNICODE | re.MULTILINE | re.DOTALL):
|
|
105
107
|
# If they gave us a regexp object, extract the pattern.
|
|
@@ -110,11 +112,11 @@ class RegexpTokenizer(TokenizerI):
|
|
|
110
112
|
self._discard_empty = discard_empty
|
|
111
113
|
self._flags = flags
|
|
112
114
|
self._regexp = None
|
|
113
|
-
|
|
115
|
+
|
|
114
116
|
def _check_regexp(self):
|
|
115
117
|
if self._regexp is None:
|
|
116
118
|
self._regexp = re.compile(self._pattern, self._flags)
|
|
117
|
-
|
|
119
|
+
|
|
118
120
|
def tokenize(self, text):
|
|
119
121
|
self._check_regexp()
|
|
120
122
|
# If our regexp matches gaps, use re.split:
|
|
@@ -144,6 +146,7 @@ class RegexpTokenizer(TokenizerI):
|
|
|
144
146
|
(self.__class__.__name__, self._pattern, self._gaps,
|
|
145
147
|
self._discard_empty, self._flags))
|
|
146
148
|
|
|
149
|
+
|
|
147
150
|
class WhitespaceTokenizer(RegexpTokenizer):
|
|
148
151
|
r"""
|
|
149
152
|
Tokenize a string on whitespace (space, tab, newline).
|
|
@@ -159,15 +162,18 @@ class WhitespaceTokenizer(RegexpTokenizer):
|
|
|
159
162
|
def __init__(self):
|
|
160
163
|
RegexpTokenizer.__init__(self, r'\s+', gaps=True)
|
|
161
164
|
|
|
165
|
+
|
|
162
166
|
class BlanklineTokenizer(RegexpTokenizer):
|
|
163
167
|
"""
|
|
164
168
|
Tokenize a string, treating any sequence of blank lines as a delimiter.
|
|
165
169
|
Blank lines are defined as lines containing no characters, except for
|
|
166
170
|
space or tab characters.
|
|
167
171
|
"""
|
|
172
|
+
|
|
168
173
|
def __init__(self):
|
|
169
174
|
RegexpTokenizer.__init__(self, r'\s*\n\s*\n\s*', gaps=True)
|
|
170
175
|
|
|
176
|
+
|
|
171
177
|
class WordPunctTokenizer(RegexpTokenizer):
|
|
172
178
|
"""
|
|
173
179
|
Tokenize a text into a sequence of alphabetic and
|
|
@@ -179,11 +185,13 @@ class WordPunctTokenizer(RegexpTokenizer):
|
|
|
179
185
|
['Good', 'muffins', 'cost', '$', '3', '.', '88', 'in', 'New', 'York',
|
|
180
186
|
'.', 'Please', 'buy', 'me', 'two', 'of', 'them', '.', 'Thanks', '.']
|
|
181
187
|
"""
|
|
188
|
+
|
|
182
189
|
def __init__(self):
|
|
183
190
|
RegexpTokenizer.__init__(self, r'\w+|[^\w\s]+')
|
|
184
191
|
|
|
192
|
+
|
|
185
193
|
######################################################################
|
|
186
|
-
#{ Tokenization Functions
|
|
194
|
+
# { Tokenization Functions
|
|
187
195
|
######################################################################
|
|
188
196
|
|
|
189
197
|
def regexp_tokenize(text, pattern, gaps=False, discard_empty=True,
|
|
@@ -195,8 +203,6 @@ def regexp_tokenize(text, pattern, gaps=False, discard_empty=True,
|
|
|
195
203
|
tokenizer = RegexpTokenizer(pattern, gaps, discard_empty, flags)
|
|
196
204
|
return tokenizer.tokenize(text)
|
|
197
205
|
|
|
206
|
+
|
|
198
207
|
blankline_tokenize = BlanklineTokenizer().tokenize
|
|
199
208
|
wordpunct_tokenize = WordPunctTokenizer().tokenize
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Natural Language Toolkit: Interface to the Repp Tokenizer
|
|
3
|
+
#
|
|
4
|
+
# Copyright (C) 2001-2015 NLTK Project
|
|
5
|
+
# Authors: Rebecca Dridan and Stephan Oepen
|
|
6
|
+
# Contributors: Liling Tan
|
|
7
|
+
#
|
|
8
|
+
# URL: <http://nltk.org/>
|
|
9
|
+
# For license information, see LICENSE.TXT
|
|
10
|
+
|
|
11
|
+
from __future__ import unicode_literals, print_function
|
|
12
|
+
from six import text_type
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import sys
|
|
17
|
+
import subprocess
|
|
18
|
+
import tempfile
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from nltk.data import ZipFilePathPointer
|
|
22
|
+
from nltk.internals import find_dir
|
|
23
|
+
|
|
24
|
+
from nltk.tokenize.api import TokenizerI
|
|
25
|
+
|
|
26
|
+
class ReppTokenizer(TokenizerI):
|
|
27
|
+
"""
|
|
28
|
+
A class for word tokenization using the REPP parser described in
|
|
29
|
+
Rebecca Dridan and Stephan Oepen (2012) Tokenization: Returning to a
|
|
30
|
+
Long Solved Problem - A Survey, Contrastive Experiment, Recommendations,
|
|
31
|
+
and Toolkit. In ACL. http://anthology.aclweb.org/P/P12/P12-2.pdf#page=406
|
|
32
|
+
|
|
33
|
+
>>> sents = ['Tokenization is widely regarded as a solved problem due to the high accuracy that rulebased tokenizers achieve.' ,
|
|
34
|
+
... 'But rule-based tokenizers are hard to maintain and their rules language specific.' ,
|
|
35
|
+
... 'We evaluated our method on three languages and obtained error rates of 0.27% (English), 0.35% (Dutch) and 0.76% (Italian) for our best models.'
|
|
36
|
+
... ]
|
|
37
|
+
>>> tokenizer = ReppTokenizer('/home/alvas/repp/') # doctest: +SKIP
|
|
38
|
+
>>> for sent in sents: # doctest: +SKIP
|
|
39
|
+
... tokenizer.tokenize(sent) # doctest: +SKIP
|
|
40
|
+
...
|
|
41
|
+
(u'Tokenization', u'is', u'widely', u'regarded', u'as', u'a', u'solved', u'problem', u'due', u'to', u'the', u'high', u'accuracy', u'that', u'rulebased', u'tokenizers', u'achieve', u'.')
|
|
42
|
+
(u'But', u'rule-based', u'tokenizers', u'are', u'hard', u'to', u'maintain', u'and', u'their', u'rules', u'language', u'specific', u'.')
|
|
43
|
+
(u'We', u'evaluated', u'our', u'method', u'on', u'three', u'languages', u'and', u'obtained', u'error', u'rates', u'of', u'0.27', u'%', u'(', u'English', u')', u',', u'0.35', u'%', u'(', u'Dutch', u')', u'and', u'0.76', u'%', u'(', u'Italian', u')', u'for', u'our', u'best', u'models', u'.')
|
|
44
|
+
|
|
45
|
+
>>> for sent in tokenizer.tokenize_sents(sents): # doctest: +SKIP
|
|
46
|
+
... print sent # doctest: +SKIP
|
|
47
|
+
...
|
|
48
|
+
(u'Tokenization', u'is', u'widely', u'regarded', u'as', u'a', u'solved', u'problem', u'due', u'to', u'the', u'high', u'accuracy', u'that', u'rulebased', u'tokenizers', u'achieve', u'.')
|
|
49
|
+
(u'But', u'rule-based', u'tokenizers', u'are', u'hard', u'to', u'maintain', u'and', u'their', u'rules', u'language', u'specific', u'.')
|
|
50
|
+
(u'We', u'evaluated', u'our', u'method', u'on', u'three', u'languages', u'and', u'obtained', u'error', u'rates', u'of', u'0.27', u'%', u'(', u'English', u')', u',', u'0.35', u'%', u'(', u'Dutch', u')', u'and', u'0.76', u'%', u'(', u'Italian', u')', u'for', u'our', u'best', u'models', u'.')
|
|
51
|
+
>>> for sent in tokenizer.tokenize_sents(sents, keep_token_positions=True): # doctest: +SKIP
|
|
52
|
+
... print sent # doctest: +SKIP
|
|
53
|
+
...
|
|
54
|
+
[(u'Tokenization', 0, 12), (u'is', 13, 15), (u'widely', 16, 22), (u'regarded', 23, 31), (u'as', 32, 34), (u'a', 35, 36), (u'solved', 37, 43), (u'problem', 44, 51), (u'due', 52, 55), (u'to', 56, 58), (u'the', 59, 62), (u'high', 63, 67), (u'accuracy', 68, 76), (u'that', 77, 81), (u'rulebased', 82, 91), (u'tokenizers', 92, 102), (u'achieve', 103, 110), (u'.', 110, 111)]
|
|
55
|
+
[(u'But', 0, 3), (u'rule-based', 4, 14), (u'tokenizers', 15, 25), (u'are', 26, 29), (u'hard', 30, 34), (u'to', 35, 37), (u'maintain', 38, 46), (u'and', 47, 50), (u'their', 51, 56), (u'rules', 57, 62), (u'language', 63, 71), (u'specific', 72, 80), (u'.', 80, 81)]
|
|
56
|
+
[(u'We', 0, 2), (u'evaluated', 3, 12), (u'our', 13, 16), (u'method', 17, 23), (u'on', 24, 26), (u'three', 27, 32), (u'languages', 33, 42), (u'and', 43, 46), (u'obtained', 47, 55), (u'error', 56, 61), (u'rates', 62, 67), (u'of', 68, 70), (u'0.27', 71, 75), (u'%', 75, 76), (u'(', 77, 78), (u'English', 78, 85), (u')', 85, 86), (u',', 86, 87), (u'0.35', 88, 92), (u'%', 92, 93), (u'(', 94, 95), (u'Dutch', 95, 100), (u')', 100, 101), (u'and', 102, 105), (u'0.76', 106, 110), (u'%', 110, 111), (u'(', 112, 113), (u'Italian', 113, 120), (u')', 120, 121), (u'for', 122, 125), (u'our', 126, 129), (u'best', 130, 134), (u'models', 135, 141), (u'.', 141, 142)]
|
|
57
|
+
"""
|
|
58
|
+
def __init__(self, repp_dir, encoding='utf8'):
|
|
59
|
+
self.repp_dir = self.find_repptokenizer(repp_dir)
|
|
60
|
+
# Set a directory to store the temporary files.
|
|
61
|
+
self.working_dir = tempfile.gettempdir()
|
|
62
|
+
# Set an encoding for the input strings.
|
|
63
|
+
self.encoding = encoding
|
|
64
|
+
|
|
65
|
+
def tokenize(self, sentence):
|
|
66
|
+
"""
|
|
67
|
+
Use Repp to tokenize a single sentence.
|
|
68
|
+
|
|
69
|
+
:param sentence: A single sentence string.
|
|
70
|
+
:type sentence: str
|
|
71
|
+
:return: A tuple of tokens.
|
|
72
|
+
:rtype: tuple(str)
|
|
73
|
+
"""
|
|
74
|
+
return next(self.tokenize_sents([sentence]))
|
|
75
|
+
|
|
76
|
+
def tokenize_sents(self, sentences, keep_token_positions=False):
|
|
77
|
+
"""
|
|
78
|
+
Tokenize multiple sentences using Repp.
|
|
79
|
+
|
|
80
|
+
:param sentences: A list of sentence strings.
|
|
81
|
+
:type sentences: list(str)
|
|
82
|
+
:return: A list of tuples of tokens
|
|
83
|
+
:rtype: iter(tuple(str))
|
|
84
|
+
"""
|
|
85
|
+
with tempfile.NamedTemporaryFile(prefix='repp_input.',
|
|
86
|
+
dir=self.working_dir, mode='w', delete=False) as input_file:
|
|
87
|
+
# Write sentences to temporary input file.
|
|
88
|
+
for sent in sentences:
|
|
89
|
+
input_file.write(text_type(sent) + '\n')
|
|
90
|
+
input_file.close()
|
|
91
|
+
# Generate command to run REPP.
|
|
92
|
+
cmd =self.generate_repp_command(input_file.name)
|
|
93
|
+
# Decode the stdout and strips the ending newline.
|
|
94
|
+
repp_output = self._execute(cmd).decode(self.encoding).strip()
|
|
95
|
+
for tokenized_sent in self.parse_repp_outputs(repp_output):
|
|
96
|
+
if not keep_token_positions:
|
|
97
|
+
# Removes token position information.
|
|
98
|
+
tokenized_sent, starts, ends = zip(*tokenized_sent)
|
|
99
|
+
yield tokenized_sent
|
|
100
|
+
|
|
101
|
+
def generate_repp_command(self, inputfilename):
|
|
102
|
+
"""
|
|
103
|
+
This module generates the REPP command to be used at the terminal.
|
|
104
|
+
|
|
105
|
+
:param inputfilename: path to the input file
|
|
106
|
+
:type inputfilename: str
|
|
107
|
+
"""
|
|
108
|
+
cmd = [self.repp_dir + '/src/repp']
|
|
109
|
+
cmd+= ['-c', self.repp_dir + '/erg/repp.set']
|
|
110
|
+
cmd+= ['--format', 'triple']
|
|
111
|
+
cmd+= [inputfilename]
|
|
112
|
+
return cmd
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def _execute(cmd):
|
|
116
|
+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
117
|
+
stdout, stderr = p.communicate()
|
|
118
|
+
return stdout
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def parse_repp_outputs(repp_output):
|
|
122
|
+
"""
|
|
123
|
+
This module parses the tri-tuple format that REPP outputs using the
|
|
124
|
+
"--format triple" option and returns an generator with tuple of string
|
|
125
|
+
tokens.
|
|
126
|
+
|
|
127
|
+
:param repp_output:
|
|
128
|
+
:type repp_output: type
|
|
129
|
+
:return: an iterable of the tokenized sentences as tuples of strings
|
|
130
|
+
:rtype: iter(tuple)
|
|
131
|
+
"""
|
|
132
|
+
line_regex = re.compile('^\((\d+), (\d+), (.+)\)$', re.MULTILINE)
|
|
133
|
+
for section in repp_output.split('\n\n'):
|
|
134
|
+
words_with_positions = [(token, int(start), int(end))
|
|
135
|
+
for start, end, token in
|
|
136
|
+
line_regex.findall(section)]
|
|
137
|
+
words = tuple(t[2] for t in words_with_positions)
|
|
138
|
+
yield words_with_positions
|
|
139
|
+
|
|
140
|
+
def find_repptokenizer(self, repp_dirname):
|
|
141
|
+
"""
|
|
142
|
+
A module to find REPP tokenizer binary and its *repp.set* config file.
|
|
143
|
+
"""
|
|
144
|
+
if os.path.exists(repp_dirname): # If a full path is given.
|
|
145
|
+
_repp_dir = repp_dirname
|
|
146
|
+
else: # Try to find path to REPP directory in environment variables.
|
|
147
|
+
_repp_dir = find_dir(repp_dirname, env_vars=('REPP_TOKENIZER',))
|
|
148
|
+
# Checks for the REPP binary and erg/repp.set config file.
|
|
149
|
+
assert os.path.exists(_repp_dir+'/src/repp')
|
|
150
|
+
assert os.path.exists(_repp_dir+'/erg/repp.set')
|
|
151
|
+
return _repp_dir
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Natural Language Toolkit: Tokenizers
|
|
2
2
|
#
|
|
3
|
-
# Copyright (C) 2001-
|
|
3
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
4
4
|
# Author: Yoav Goldberg <yoavg@cs.bgu.ac.il>
|
|
5
5
|
# Steven Bird <stevenbird1@gmail.com> (minor edits)
|
|
6
6
|
# URL: <http://nltk.sourceforge.net>
|
|
@@ -53,6 +53,7 @@ import re
|
|
|
53
53
|
|
|
54
54
|
from nltk.tokenize.api import TokenizerI
|
|
55
55
|
|
|
56
|
+
|
|
56
57
|
class SExprTokenizer(TokenizerI):
|
|
57
58
|
"""
|
|
58
59
|
A tokenizer that divides strings into s-expressions.
|
|
@@ -125,7 +126,7 @@ class SExprTokenizer(TokenizerI):
|
|
|
125
126
|
if self._strict and depth == 0:
|
|
126
127
|
raise ValueError('Un-matched close paren at char %d'
|
|
127
128
|
% m.start())
|
|
128
|
-
depth = max(0, depth-1)
|
|
129
|
+
depth = max(0, depth - 1)
|
|
129
130
|
if depth == 0:
|
|
130
131
|
result.append(text[pos:m.end()])
|
|
131
132
|
pos = m.end()
|
|
@@ -135,8 +136,5 @@ class SExprTokenizer(TokenizerI):
|
|
|
135
136
|
result.append(text[pos:])
|
|
136
137
|
return result
|
|
137
138
|
|
|
138
|
-
sexpr_tokenize = SExprTokenizer().tokenize
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
139
|
|
|
140
|
+
sexpr_tokenize = SExprTokenizer().tokenize
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Natural Language Toolkit: Simple Tokenizers
|
|
2
2
|
#
|
|
3
|
-
# Copyright (C) 2001-
|
|
3
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
4
4
|
# Author: Edward Loper <edloper@gmail.com>
|
|
5
5
|
# Steven Bird <stevenbird1@gmail.com>
|
|
6
6
|
# URL: <http://nltk.sourceforge.net>
|
|
@@ -38,6 +38,7 @@ from __future__ import unicode_literals
|
|
|
38
38
|
from nltk.tokenize.api import TokenizerI, StringTokenizer
|
|
39
39
|
from nltk.tokenize.util import string_span_tokenize, regexp_span_tokenize
|
|
40
40
|
|
|
41
|
+
|
|
41
42
|
class SpaceTokenizer(StringTokenizer):
|
|
42
43
|
r"""Tokenize a string using the space character as a delimiter,
|
|
43
44
|
which is the same as ``s.split(' ')``.
|
|
@@ -51,6 +52,7 @@ class SpaceTokenizer(StringTokenizer):
|
|
|
51
52
|
|
|
52
53
|
_string = ' '
|
|
53
54
|
|
|
55
|
+
|
|
54
56
|
class TabTokenizer(StringTokenizer):
|
|
55
57
|
r"""Tokenize a string use the tab character as a delimiter,
|
|
56
58
|
the same as ``s.split('\t')``.
|
|
@@ -62,6 +64,7 @@ class TabTokenizer(StringTokenizer):
|
|
|
62
64
|
|
|
63
65
|
_string = '\t'
|
|
64
66
|
|
|
67
|
+
|
|
65
68
|
class CharTokenizer(StringTokenizer):
|
|
66
69
|
"""Tokenize a string into individual characters. If this functionality
|
|
67
70
|
is ever required directly, use ``for char in string``.
|
|
@@ -74,6 +77,7 @@ class CharTokenizer(StringTokenizer):
|
|
|
74
77
|
for i, j in enumerate(range(1, len(s) + 1)):
|
|
75
78
|
yield i, j
|
|
76
79
|
|
|
80
|
+
|
|
77
81
|
class LineTokenizer(TokenizerI):
|
|
78
82
|
r"""Tokenize a string into its lines, optionally discarding blank lines.
|
|
79
83
|
This is similar to ``s.split('\n')``.
|
|
@@ -124,13 +128,11 @@ class LineTokenizer(TokenizerI):
|
|
|
124
128
|
for span in regexp_span_tokenize(s, r'\n(\s+\n)*'):
|
|
125
129
|
yield span
|
|
126
130
|
|
|
131
|
+
|
|
127
132
|
######################################################################
|
|
128
|
-
#{ Tokenization Functions
|
|
133
|
+
# { Tokenization Functions
|
|
129
134
|
######################################################################
|
|
130
135
|
# XXX: it is stated in module docs that there is no function versions
|
|
131
136
|
|
|
132
137
|
def line_tokenize(text, blanklines='discard'):
|
|
133
138
|
return LineTokenizer(blanklines).tokenize(text)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# Natural Language Toolkit: Interface to the Stanford Tokenizer
|
|
3
3
|
#
|
|
4
|
-
# Copyright (C) 2001-
|
|
4
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
5
5
|
# Author: Steven Xu <xxu@student.unimelb.edu.au>
|
|
6
6
|
#
|
|
7
7
|
# URL: <http://nltk.org/>
|
|
@@ -13,19 +13,22 @@ import tempfile
|
|
|
13
13
|
import os
|
|
14
14
|
import json
|
|
15
15
|
from subprocess import PIPE
|
|
16
|
+
import warnings
|
|
16
17
|
|
|
17
|
-
from
|
|
18
|
-
from nltk.internals import find_jar, config_java, java, _java_options, find_jars_within_path
|
|
18
|
+
from six import text_type
|
|
19
19
|
|
|
20
|
+
from nltk.internals import find_jar, config_java, java, _java_options
|
|
20
21
|
from nltk.tokenize.api import TokenizerI
|
|
22
|
+
from nltk.parse.corenlp import CoreNLPParser
|
|
23
|
+
|
|
24
|
+
_stanford_url = 'https://nlp.stanford.edu/software/tokenizer.shtml'
|
|
21
25
|
|
|
22
|
-
_stanford_url = 'http://nlp.stanford.edu/software/tokenizer.shtml'
|
|
23
26
|
|
|
24
27
|
class StanfordTokenizer(TokenizerI):
|
|
25
28
|
r"""
|
|
26
29
|
Interface to the Stanford Tokenizer
|
|
27
30
|
|
|
28
|
-
>>> from nltk.tokenize import StanfordTokenizer
|
|
31
|
+
>>> from nltk.tokenize.stanford import StanfordTokenizer
|
|
29
32
|
>>> s = "Good muffins cost $3.88\nin New York. Please buy me\ntwo of them.\nThanks."
|
|
30
33
|
>>> StanfordTokenizer().tokenize(s)
|
|
31
34
|
['Good', 'muffins', 'cost', '$', '3.88', 'in', 'New', 'York', '.', 'Please', 'buy', 'me', 'two', 'of', 'them', '.', 'Thanks', '.']
|
|
@@ -37,17 +40,19 @@ class StanfordTokenizer(TokenizerI):
|
|
|
37
40
|
_JAR = 'stanford-postagger.jar'
|
|
38
41
|
|
|
39
42
|
def __init__(self, path_to_jar=None, encoding='utf8', options=None, verbose=False, java_options='-mx1000m'):
|
|
43
|
+
# Raise deprecation warning.
|
|
44
|
+
warnings.warn(str("\nThe StanfordTokenizer will "
|
|
45
|
+
"be deprecated in version 3.2.5.\n"
|
|
46
|
+
"Please use \033[91mnltk.parse.corenlp.CoreNLPParser\033[0m instead.'"),
|
|
47
|
+
DeprecationWarning, stacklevel=2)
|
|
48
|
+
|
|
40
49
|
self._stanford_jar = find_jar(
|
|
41
50
|
self._JAR, path_to_jar,
|
|
42
51
|
env_vars=('STANFORD_POSTAGGER',),
|
|
43
52
|
searchpath=(), url=_stanford_url,
|
|
44
53
|
verbose=verbose
|
|
45
54
|
)
|
|
46
|
-
|
|
47
|
-
# Adding logging jar files to classpath
|
|
48
|
-
stanford_dir = os.path.split(self._stanford_jar)[0]
|
|
49
|
-
self._stanford_jar = tuple(find_jars_within_path(stanford_dir))
|
|
50
|
-
|
|
55
|
+
|
|
51
56
|
self._encoding = encoding
|
|
52
57
|
self.java_options = java_options
|
|
53
58
|
|
|
@@ -82,7 +87,7 @@ class StanfordTokenizer(TokenizerI):
|
|
|
82
87
|
# Windows is incompatible with NamedTemporaryFile() without passing in delete=False.
|
|
83
88
|
with tempfile.NamedTemporaryFile(mode='wb', delete=False) as input_file:
|
|
84
89
|
# Write the actual sentences to the temporary input file
|
|
85
|
-
if isinstance(input_,
|
|
90
|
+
if isinstance(input_, text_type) and encoding:
|
|
86
91
|
input_ = input_.encode(encoding)
|
|
87
92
|
input_file.write(input_)
|
|
88
93
|
input_file.flush()
|
|
@@ -108,6 +113,5 @@ def setup_module(module):
|
|
|
108
113
|
try:
|
|
109
114
|
StanfordTokenizer()
|
|
110
115
|
except LookupError:
|
|
111
|
-
raise SkipTest(
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
raise SkipTest(
|
|
117
|
+
'doctests from nltk.tokenize.stanford are skipped because the stanford postagger jar doesn\'t exist')
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Natural Language Toolkit: Interface to the Stanford Segmenter
|
|
4
|
+
# for Chinese and Arabic
|
|
5
|
+
#
|
|
6
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
7
|
+
# Author: 52nlp <52nlpcn@gmail.com>
|
|
8
|
+
# Casper Lehmann-Strøm <casperlehmann@gmail.com>
|
|
9
|
+
# Alex Constantin <alex@keyworder.ch>
|
|
10
|
+
#
|
|
11
|
+
# URL: <http://nltk.org/>
|
|
12
|
+
# For license information, see LICENSE.TXT
|
|
13
|
+
|
|
14
|
+
from __future__ import unicode_literals, print_function
|
|
15
|
+
|
|
16
|
+
import tempfile
|
|
17
|
+
import os
|
|
18
|
+
import json
|
|
19
|
+
from subprocess import PIPE
|
|
20
|
+
import warnings
|
|
21
|
+
|
|
22
|
+
from nltk import compat
|
|
23
|
+
from nltk.internals import find_jar, find_file, find_dir, \
|
|
24
|
+
config_java, java, _java_options
|
|
25
|
+
from nltk.tokenize.api import TokenizerI
|
|
26
|
+
|
|
27
|
+
from six import text_type
|
|
28
|
+
|
|
29
|
+
_stanford_url = 'https://nlp.stanford.edu/software'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class StanfordSegmenter(TokenizerI):
|
|
33
|
+
"""Interface to the Stanford Segmenter
|
|
34
|
+
|
|
35
|
+
If stanford-segmenter version is older than 2016-10-31, then path_to_slf4j
|
|
36
|
+
should be provieded, for example::
|
|
37
|
+
|
|
38
|
+
seg = StanfordSegmenter(path_to_slf4j='/YOUR_PATH/slf4j-api.jar')
|
|
39
|
+
|
|
40
|
+
>>> from nltk.tokenize.stanford_segmenter import StanfordSegmenter
|
|
41
|
+
>>> seg = StanfordSegmenter()
|
|
42
|
+
>>> seg.default_config('zh')
|
|
43
|
+
>>> sent = u'这是斯坦福中文分词器测试'
|
|
44
|
+
>>> print(seg.segment(sent))
|
|
45
|
+
\u8fd9 \u662f \u65af\u5766\u798f \u4e2d\u6587 \u5206\u8bcd\u5668 \u6d4b\u8bd5
|
|
46
|
+
<BLANKLINE>
|
|
47
|
+
>>> seg.default_config('ar')
|
|
48
|
+
>>> sent = u'هذا هو تصنيف ستانفورد العربي للكلمات'
|
|
49
|
+
>>> print(seg.segment(sent.split()))
|
|
50
|
+
\u0647\u0630\u0627 \u0647\u0648 \u062a\u0635\u0646\u064a\u0641 \u0633\u062a\u0627\u0646\u0641\u0648\u0631\u062f \u0627\u0644\u0639\u0631\u0628\u064a \u0644 \u0627\u0644\u0643\u0644\u0645\u0627\u062a
|
|
51
|
+
<BLANKLINE>
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
_JAR = 'stanford-segmenter.jar'
|
|
55
|
+
|
|
56
|
+
def __init__(self,
|
|
57
|
+
path_to_jar=None,
|
|
58
|
+
path_to_slf4j=None,
|
|
59
|
+
java_class=None,
|
|
60
|
+
path_to_model=None,
|
|
61
|
+
path_to_dict=None,
|
|
62
|
+
path_to_sihan_corpora_dict=None,
|
|
63
|
+
sihan_post_processing='false',
|
|
64
|
+
keep_whitespaces='false',
|
|
65
|
+
encoding='UTF-8', options=None,
|
|
66
|
+
verbose=False, java_options='-mx2g'):
|
|
67
|
+
# Raise deprecation warning.
|
|
68
|
+
warnings.simplefilter('always', DeprecationWarning)
|
|
69
|
+
warnings.warn(str("\nThe StanfordTokenizer will "
|
|
70
|
+
"be deprecated in version 3.2.5.\n"
|
|
71
|
+
"Please use \033[91mnltk.parse.corenlp.CoreNLPTokenizer\033[0m instead.'"),
|
|
72
|
+
DeprecationWarning, stacklevel=2)
|
|
73
|
+
warnings.simplefilter('ignore', DeprecationWarning)
|
|
74
|
+
|
|
75
|
+
stanford_segmenter = find_jar(
|
|
76
|
+
self._JAR, path_to_jar,
|
|
77
|
+
env_vars=('STANFORD_SEGMENTER',),
|
|
78
|
+
searchpath=(), url=_stanford_url,
|
|
79
|
+
verbose=verbose)
|
|
80
|
+
if path_to_slf4j is not None:
|
|
81
|
+
slf4j = find_jar(
|
|
82
|
+
'slf4j-api.jar', path_to_slf4j,
|
|
83
|
+
env_vars=('SLF4J', 'STANFORD_SEGMENTER',),
|
|
84
|
+
searchpath=(), url=_stanford_url,
|
|
85
|
+
verbose=verbose)
|
|
86
|
+
else:
|
|
87
|
+
slf4j = None
|
|
88
|
+
|
|
89
|
+
# This is passed to java as the -cp option, the old version of segmenter needs slf4j.
|
|
90
|
+
# The new version of stanford-segmenter-2016-10-31 doesn't need slf4j
|
|
91
|
+
self._stanford_jar = os.pathsep.join(
|
|
92
|
+
_ for _ in [stanford_segmenter, slf4j] if _ is not None
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
self._java_class = java_class
|
|
96
|
+
self._model = path_to_model
|
|
97
|
+
self._sihan_corpora_dict = path_to_sihan_corpora_dict
|
|
98
|
+
self._sihan_post_processing = sihan_post_processing
|
|
99
|
+
self._keep_whitespaces = keep_whitespaces
|
|
100
|
+
self._dict = path_to_dict
|
|
101
|
+
|
|
102
|
+
self._encoding = encoding
|
|
103
|
+
self.java_options = java_options
|
|
104
|
+
options = {} if options is None else options
|
|
105
|
+
self._options_cmd = ','.join('{0}={1}'.format(key, json.dumps(val)) for key, val in options.items())
|
|
106
|
+
|
|
107
|
+
def default_config(self, lang):
|
|
108
|
+
"""
|
|
109
|
+
Attempt to intialize Stanford Word Segmenter for the specified language
|
|
110
|
+
using the STANFORD_SEGMENTER and STANFORD_MODELS environment variables
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
search_path = ()
|
|
114
|
+
if os.environ.get('STANFORD_SEGMENTER'):
|
|
115
|
+
search_path = {os.path.join(os.environ.get('STANFORD_SEGMENTER'), 'data')}
|
|
116
|
+
|
|
117
|
+
# init for Chinese-specific files
|
|
118
|
+
self._dict = None
|
|
119
|
+
self._sihan_corpora_dict = None
|
|
120
|
+
self._sihan_post_processing = 'false'
|
|
121
|
+
|
|
122
|
+
if lang == 'ar':
|
|
123
|
+
self._java_class = 'edu.stanford.nlp.international.arabic.process.ArabicSegmenter'
|
|
124
|
+
model = 'arabic-segmenter-atb+bn+arztrain.ser.gz'
|
|
125
|
+
|
|
126
|
+
elif lang == 'zh':
|
|
127
|
+
self._java_class = 'edu.stanford.nlp.ie.crf.CRFClassifier'
|
|
128
|
+
model = 'pku.gz'
|
|
129
|
+
self._sihan_post_processing = 'true'
|
|
130
|
+
|
|
131
|
+
path_to_dict = 'dict-chris6.ser.gz'
|
|
132
|
+
try:
|
|
133
|
+
self._dict = find_file(path_to_dict, searchpath=search_path,
|
|
134
|
+
url=_stanford_url, verbose=False,
|
|
135
|
+
env_vars=('STANFORD_MODELS',))
|
|
136
|
+
except LookupError:
|
|
137
|
+
raise LookupError("Could not find '%s' (tried using env. "
|
|
138
|
+
"variables STANFORD_MODELS and <STANFORD_SEGMENTER>/data/)" % path_to_dict)
|
|
139
|
+
|
|
140
|
+
sihan_dir = './data/'
|
|
141
|
+
try:
|
|
142
|
+
path_to_sihan_dir = find_dir(sihan_dir,
|
|
143
|
+
url=_stanford_url, verbose=False,
|
|
144
|
+
env_vars=('STANFORD_SEGMENTER',))
|
|
145
|
+
self._sihan_corpora_dict = os.path.join(path_to_sihan_dir, sihan_dir)
|
|
146
|
+
except LookupError:
|
|
147
|
+
raise LookupError("Could not find '%s' (tried using the "
|
|
148
|
+
"STANFORD_SEGMENTER environment variable)" % sihan_dir)
|
|
149
|
+
else:
|
|
150
|
+
raise LookupError("Unsupported language '%'" % lang)
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
self._model = find_file(model, searchpath=search_path,
|
|
154
|
+
url=_stanford_url, verbose=False,
|
|
155
|
+
env_vars=('STANFORD_MODELS', 'STANFORD_SEGMENTER',))
|
|
156
|
+
except LookupError:
|
|
157
|
+
raise LookupError("Could not find '%s' (tried using env. "
|
|
158
|
+
"variables STANFORD_MODELS and <STANFORD_SEGMENTER>/data/)" % model)
|
|
159
|
+
|
|
160
|
+
def tokenize(self, s):
|
|
161
|
+
super().tokenize(s)
|
|
162
|
+
|
|
163
|
+
def segment_file(self, input_file_path):
|
|
164
|
+
"""
|
|
165
|
+
"""
|
|
166
|
+
cmd = [
|
|
167
|
+
self._java_class,
|
|
168
|
+
'-loadClassifier', self._model,
|
|
169
|
+
'-keepAllWhitespaces', self._keep_whitespaces,
|
|
170
|
+
'-textFile', input_file_path
|
|
171
|
+
]
|
|
172
|
+
if self._sihan_corpora_dict is not None:
|
|
173
|
+
cmd.extend(['-serDictionary', self._dict,
|
|
174
|
+
'-sighanCorporaDict', self._sihan_corpora_dict,
|
|
175
|
+
'-sighanPostProcessing', self._sihan_post_processing])
|
|
176
|
+
|
|
177
|
+
stdout = self._execute(cmd)
|
|
178
|
+
|
|
179
|
+
return stdout
|
|
180
|
+
|
|
181
|
+
def segment(self, tokens):
|
|
182
|
+
return self.segment_sents([tokens])
|
|
183
|
+
|
|
184
|
+
def segment_sents(self, sentences):
|
|
185
|
+
"""
|
|
186
|
+
"""
|
|
187
|
+
encoding = self._encoding
|
|
188
|
+
# Create a temporary input file
|
|
189
|
+
_input_fh, self._input_file_path = tempfile.mkstemp(text=True)
|
|
190
|
+
|
|
191
|
+
# Write the actural sentences to the temporary input file
|
|
192
|
+
_input_fh = os.fdopen(_input_fh, 'wb')
|
|
193
|
+
_input = '\n'.join((' '.join(x) for x in sentences))
|
|
194
|
+
if isinstance(_input, text_type) and encoding:
|
|
195
|
+
_input = _input.encode(encoding)
|
|
196
|
+
_input_fh.write(_input)
|
|
197
|
+
_input_fh.close()
|
|
198
|
+
|
|
199
|
+
cmd = [
|
|
200
|
+
self._java_class,
|
|
201
|
+
'-loadClassifier', self._model,
|
|
202
|
+
'-keepAllWhitespaces', self._keep_whitespaces,
|
|
203
|
+
'-textFile', self._input_file_path
|
|
204
|
+
]
|
|
205
|
+
if self._sihan_corpora_dict is not None:
|
|
206
|
+
cmd.extend(['-serDictionary', self._dict,
|
|
207
|
+
'-sighanCorporaDict', self._sihan_corpora_dict,
|
|
208
|
+
'-sighanPostProcessing', self._sihan_post_processing])
|
|
209
|
+
|
|
210
|
+
stdout = self._execute(cmd)
|
|
211
|
+
|
|
212
|
+
# Delete the temporary file
|
|
213
|
+
os.unlink(self._input_file_path)
|
|
214
|
+
|
|
215
|
+
return stdout
|
|
216
|
+
|
|
217
|
+
def _execute(self, cmd, verbose=False):
|
|
218
|
+
encoding = self._encoding
|
|
219
|
+
cmd.extend(['-inputEncoding', encoding])
|
|
220
|
+
_options_cmd = self._options_cmd
|
|
221
|
+
if _options_cmd:
|
|
222
|
+
cmd.extend(['-options', self._options_cmd])
|
|
223
|
+
|
|
224
|
+
default_options = ' '.join(_java_options)
|
|
225
|
+
|
|
226
|
+
# Configure java.
|
|
227
|
+
config_java(options=self.java_options, verbose=verbose)
|
|
228
|
+
|
|
229
|
+
stdout, _stderr = java(cmd, classpath=self._stanford_jar, stdout=PIPE, stderr=PIPE)
|
|
230
|
+
stdout = stdout.decode(encoding)
|
|
231
|
+
|
|
232
|
+
# Return java configurations to their default values.
|
|
233
|
+
config_java(options=default_options, verbose=False)
|
|
234
|
+
|
|
235
|
+
return stdout
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def setup_module(module):
|
|
239
|
+
from nose import SkipTest
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
seg = StanfordSegmenter()
|
|
243
|
+
seg.default_config('ar')
|
|
244
|
+
seg.default_config('zh')
|
|
245
|
+
except LookupError as e:
|
|
246
|
+
raise SkipTest('Tests for nltk.tokenize.stanford_segmenter skipped: %s' % str(e))
|