nltk 3.2__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 → nltk-3.3}/INSTALL.txt +6 -6
- {nltk-3.2 → nltk-3.3}/LICENSE.txt +13 -13
- {nltk-3.2 → nltk-3.3}/MANIFEST.in +6 -6
- {nltk-3.2/nltk.egg-info → nltk-3.3}/PKG-INFO +13 -5
- nltk-3.2/README.txt → nltk-3.3/README.md +49 -48
- nltk-3.3/nltk/VERSION +1 -0
- {nltk-3.2 → nltk-3.3}/nltk/__init__.py +185 -185
- {nltk-3.2 → nltk-3.3}/nltk/app/__init__.py +52 -53
- {nltk-3.2 → nltk-3.3}/nltk/app/chartparser_app.py +2276 -2276
- {nltk-3.2 → nltk-3.3}/nltk/app/chunkparser_app.py +1262 -1264
- {nltk-3.2 → nltk-3.3}/nltk/app/collocations_app.py +347 -350
- {nltk-3.2 → nltk-3.3}/nltk/app/concordance_app.py +568 -570
- {nltk-3.2 → nltk-3.3}/nltk/app/nemo_app.py +156 -155
- {nltk-3.2 → nltk-3.3}/nltk/app/rdparser_app.py +892 -894
- {nltk-3.2 → nltk-3.3}/nltk/app/srparser_app.py +809 -809
- {nltk-3.2 → nltk-3.3}/nltk/app/wordfreq_app.py +32 -32
- {nltk-3.2 → nltk-3.3}/nltk/app/wordnet_app.py +968 -968
- {nltk-3.2 → nltk-3.3}/nltk/book.py +91 -90
- {nltk-3.2 → nltk-3.3}/nltk/ccg/__init__.py +22 -22
- {nltk-3.2 → nltk-3.3}/nltk/ccg/api.py +359 -335
- {nltk-3.2 → nltk-3.3}/nltk/ccg/chart.py +394 -361
- {nltk-3.2 → nltk-3.3}/nltk/ccg/combinator.py +343 -312
- {nltk-3.2 → nltk-3.3}/nltk/ccg/lexicon.py +328 -290
- nltk-3.3/nltk/ccg/logic.py +46 -0
- {nltk-3.2 → nltk-3.3}/nltk/chat/__init__.py +49 -49
- {nltk-3.2 → nltk-3.3}/nltk/chat/eliza.py +244 -244
- {nltk-3.2 → nltk-3.3}/nltk/chat/iesha.py +140 -140
- {nltk-3.2 → nltk-3.3}/nltk/chat/rude.py +92 -92
- {nltk-3.2 → nltk-3.3}/nltk/chat/suntsu.py +117 -117
- {nltk-3.2 → nltk-3.3}/nltk/chat/util.py +122 -120
- {nltk-3.2 → nltk-3.3}/nltk/chat/zen.py +282 -282
- {nltk-3.2 → nltk-3.3}/nltk/chunk/__init__.py +190 -190
- {nltk-3.2 → nltk-3.3}/nltk/chunk/api.py +51 -51
- {nltk-3.2 → nltk-3.3}/nltk/chunk/named_entity.py +331 -331
- {nltk-3.2 → nltk-3.3}/nltk/chunk/regexp.py +1390 -1384
- {nltk-3.2 → nltk-3.3}/nltk/chunk/util.py +600 -600
- {nltk-3.2 → nltk-3.3}/nltk/classify/__init__.py +98 -98
- {nltk-3.2 → nltk-3.3}/nltk/classify/api.py +193 -193
- {nltk-3.2 → nltk-3.3}/nltk/classify/decisiontree.py +295 -295
- {nltk-3.2 → nltk-3.3}/nltk/classify/maxent.py +1510 -1492
- {nltk-3.2 → nltk-3.3}/nltk/classify/megam.py +179 -178
- {nltk-3.2 → nltk-3.3}/nltk/classify/naivebayes.py +245 -242
- {nltk-3.2 → nltk-3.3}/nltk/classify/positivenaivebayes.py +170 -170
- {nltk-3.2 → nltk-3.3}/nltk/classify/rte_classify.py +160 -191
- {nltk-3.2 → nltk-3.3}/nltk/classify/scikitlearn.py +153 -151
- {nltk-3.2 → nltk-3.3}/nltk/classify/senna.py +183 -181
- {nltk-3.2 → nltk-3.3}/nltk/classify/svm.py +15 -15
- {nltk-3.2 → nltk-3.3}/nltk/classify/tadm.py +113 -112
- {nltk-3.2 → nltk-3.3}/nltk/classify/textcat.py +193 -193
- {nltk-3.2 → nltk-3.3}/nltk/classify/util.py +324 -312
- {nltk-3.2 → nltk-3.3}/nltk/classify/weka.py +346 -345
- {nltk-3.2 → nltk-3.3}/nltk/cluster/__init__.py +86 -86
- {nltk-3.2 → nltk-3.3}/nltk/cluster/api.py +74 -70
- {nltk-3.2 → nltk-3.3}/nltk/cluster/em.py +247 -247
- {nltk-3.2 → nltk-3.3}/nltk/cluster/gaac.py +168 -168
- {nltk-3.2 → nltk-3.3}/nltk/cluster/kmeans.py +221 -221
- {nltk-3.2 → nltk-3.3}/nltk/cluster/util.py +304 -289
- nltk-3.3/nltk/collections.py +640 -0
- {nltk-3.2 → nltk-3.3}/nltk/collocations.py +388 -388
- nltk-3.3/nltk/compat.py +365 -0
- {nltk-3.2 → nltk-3.3}/nltk/corpus/__init__.py +341 -320
- {nltk-3.2 → nltk-3.3}/nltk/corpus/europarl_raw.py +44 -44
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/__init__.py +147 -145
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/aligned.py +115 -114
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/api.py +448 -446
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/bnc.py +252 -252
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/bracket_parse.py +227 -227
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/categorized_sents.py +179 -178
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/chasen.py +140 -139
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/childes.py +522 -494
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/chunked.py +212 -212
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/cmudict.py +97 -95
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/comparative_sents.py +280 -278
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/conll.py +528 -521
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/crubadan.py +116 -116
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/dependency.py +101 -101
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/framenet.py +3059 -2093
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/ieer.py +112 -111
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/indian.py +85 -86
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/ipipan.py +332 -331
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/knbc.py +187 -187
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/lin.py +156 -156
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/mte.py +311 -310
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/nkjp.py +429 -428
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/nombank.py +421 -421
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/nps_chat.py +73 -73
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/opinion_lexicon.py +115 -115
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/panlex_lite.py +165 -165
- nltk-3.3/nltk/corpus/reader/pl196x.py +292 -0
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/plaintext.py +232 -233
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/ppattach.py +96 -95
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/propbank.py +479 -481
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/pros_cons.py +128 -126
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/reviews.py +330 -328
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/rte.py +144 -146
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/semcor.py +256 -256
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/senseval.py +203 -201
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/sentiwordnet.py +137 -137
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/sinica_treebank.py +75 -75
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/string_category.py +60 -59
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/switchboard.py +119 -119
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/tagged.py +295 -294
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/timit.py +452 -450
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/toolbox.py +68 -68
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/twitter.py +155 -157
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/udhr.py +80 -80
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/util.py +804 -800
- nltk-3.3/nltk/corpus/reader/verbnet.py +595 -0
- nltk-3.3/nltk/corpus/reader/wordlist.py +134 -0
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/wordnet.py +2108 -2036
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/xmldocs.py +392 -387
- {nltk-3.2 → nltk-3.3}/nltk/corpus/reader/ycoe.py +243 -242
- {nltk-3.2 → nltk-3.3}/nltk/corpus/util.py +144 -127
- {nltk-3.2 → nltk-3.3}/nltk/data.py +1487 -1451
- {nltk-3.2 → nltk-3.3}/nltk/decorators.py +219 -215
- {nltk-3.2 → nltk-3.3}/nltk/downloader.py +2278 -2274
- {nltk-3.2 → nltk-3.3}/nltk/draw/__init__.py +27 -27
- {nltk-3.2 → nltk-3.3}/nltk/draw/cfg.py +774 -777
- {nltk-3.2 → nltk-3.3}/nltk/draw/dispersion.py +58 -58
- {nltk-3.2 → nltk-3.3}/nltk/draw/table.py +1098 -1098
- {nltk-3.2 → nltk-3.3}/nltk/draw/tree.py +963 -966
- {nltk-3.2 → nltk-3.3}/nltk/draw/util.py +2356 -2356
- {nltk-3.2 → nltk-3.3}/nltk/featstruct.py +2617 -2500
- {nltk-3.2 → nltk-3.3}/nltk/grammar.py +1559 -1516
- {nltk-3.2 → nltk-3.3}/nltk/help.py +56 -56
- {nltk-3.2 → nltk-3.3}/nltk/inference/__init__.py +20 -20
- {nltk-3.2 → nltk-3.3}/nltk/inference/api.py +597 -589
- {nltk-3.2 → nltk-3.3}/nltk/inference/discourse.py +612 -608
- {nltk-3.2 → nltk-3.3}/nltk/inference/mace.py +311 -311
- {nltk-3.2 → nltk-3.3}/nltk/inference/nonmonotonic.py +509 -509
- {nltk-3.2 → nltk-3.3}/nltk/inference/prover9.py +431 -431
- {nltk-3.2 → nltk-3.3}/nltk/inference/resolution.py +687 -687
- {nltk-3.2 → nltk-3.3}/nltk/inference/tableau.py +607 -607
- {nltk-3.2 → nltk-3.3}/nltk/internals.py +982 -982
- {nltk-3.2 → nltk-3.3}/nltk/jsontags.py +63 -63
- {nltk-3.2 → nltk-3.3}/nltk/lazyimport.py +142 -142
- {nltk-3.2 → nltk-3.3}/nltk/metrics/__init__.py +30 -29
- {nltk-3.2 → nltk-3.3}/nltk/metrics/agreement.py +421 -401
- nltk-3.3/nltk/metrics/aline.py +607 -0
- {nltk-3.2 → nltk-3.3}/nltk/metrics/association.py +414 -410
- {nltk-3.2 → nltk-3.3}/nltk/metrics/confusionmatrix.py +206 -206
- {nltk-3.2 → nltk-3.3}/nltk/metrics/distance.py +207 -202
- {nltk-3.2 → nltk-3.3}/nltk/metrics/paice.py +381 -381
- {nltk-3.2 → nltk-3.3}/nltk/metrics/scores.py +228 -228
- {nltk-3.2 → nltk-3.3}/nltk/metrics/segmentation.py +231 -232
- {nltk-3.2 → nltk-3.3}/nltk/metrics/spearman.py +69 -69
- {nltk-3.2 → nltk-3.3}/nltk/misc/__init__.py +11 -11
- {nltk-3.2 → nltk-3.3}/nltk/misc/babelfish.py +10 -10
- {nltk-3.2 → nltk-3.3}/nltk/misc/chomsky.py +135 -133
- {nltk-3.2 → nltk-3.3}/nltk/misc/minimalset.py +83 -83
- {nltk-3.2 → nltk-3.3}/nltk/misc/sort.py +157 -157
- {nltk-3.2 → nltk-3.3}/nltk/misc/wordfinder.py +129 -129
- {nltk-3.2 → nltk-3.3}/nltk/parse/__init__.py +81 -80
- {nltk-3.2 → nltk-3.3}/nltk/parse/api.py +66 -66
- {nltk-3.2 → nltk-3.3}/nltk/parse/bllip.py +282 -282
- {nltk-3.2 → nltk-3.3}/nltk/parse/chart.py +1682 -1681
- nltk-3.3/nltk/parse/corenlp.py +780 -0
- {nltk-3.2 → nltk-3.3}/nltk/parse/dependencygraph.py +760 -758
- {nltk-3.2 → nltk-3.3}/nltk/parse/earleychart.py +452 -451
- {nltk-3.2 → nltk-3.3}/nltk/parse/evaluate.py +129 -129
- {nltk-3.2 → nltk-3.3}/nltk/parse/featurechart.py +580 -578
- {nltk-3.2 → nltk-3.3}/nltk/parse/generate.py +87 -76
- {nltk-3.2 → nltk-3.3}/nltk/parse/malt.py +356 -356
- {nltk-3.2 → nltk-3.3}/nltk/parse/nonprojectivedependencyparser.py +783 -783
- {nltk-3.2 → nltk-3.3}/nltk/parse/pchart.py +522 -522
- {nltk-3.2 → nltk-3.3}/nltk/parse/projectivedependencyparser.py +579 -578
- {nltk-3.2 → nltk-3.3}/nltk/parse/recursivedescent.py +655 -656
- {nltk-3.2 → nltk-3.3}/nltk/parse/shiftreduce.py +458 -459
- {nltk-3.2 → nltk-3.3}/nltk/parse/stanford.py +431 -406
- {nltk-3.2 → nltk-3.3}/nltk/parse/transitionparser.py +774 -772
- {nltk-3.2 → nltk-3.3}/nltk/parse/util.py +231 -231
- {nltk-3.2 → nltk-3.3}/nltk/parse/viterbi.py +401 -401
- {nltk-3.2 → nltk-3.3}/nltk/probability.py +2410 -2355
- {nltk-3.2 → nltk-3.3}/nltk/sem/__init__.py +61 -61
- {nltk-3.2 → nltk-3.3}/nltk/sem/boxer.py +1261 -1261
- {nltk-3.2 → nltk-3.3}/nltk/sem/chat80.py +782 -782
- {nltk-3.2 → nltk-3.3}/nltk/sem/cooper_storage.py +118 -118
- {nltk-3.2 → nltk-3.3}/nltk/sem/drt.py +1258 -1257
- {nltk-3.2 → nltk-3.3}/nltk/sem/drt_glue_demo.py +485 -489
- {nltk-3.2 → nltk-3.3}/nltk/sem/evaluate.py +790 -784
- {nltk-3.2 → nltk-3.3}/nltk/sem/glue.py +696 -694
- {nltk-3.2 → nltk-3.3}/nltk/sem/hole.py +386 -384
- {nltk-3.2 → nltk-3.3}/nltk/sem/lfg.py +210 -208
- {nltk-3.2 → nltk-3.3}/nltk/sem/linearlogic.py +451 -449
- {nltk-3.2 → nltk-3.3}/nltk/sem/logic.py +1910 -1910
- {nltk-3.2 → nltk-3.3}/nltk/sem/relextract.py +476 -483
- {nltk-3.2 → nltk-3.3}/nltk/sem/skolemize.py +101 -101
- {nltk-3.2 → nltk-3.3}/nltk/sem/util.py +249 -249
- {nltk-3.2 → nltk-3.3}/nltk/sentiment/__init__.py +14 -14
- {nltk-3.2 → nltk-3.3}/nltk/sentiment/sentiment_analyzer.py +229 -229
- {nltk-3.2 → nltk-3.3}/nltk/sentiment/util.py +762 -752
- {nltk-3.2 → nltk-3.3}/nltk/sentiment/vader.py +443 -445
- {nltk-3.2 → nltk-3.3}/nltk/stem/__init__.py +31 -33
- {nltk-3.2 → nltk-3.3}/nltk/stem/api.py +28 -25
- nltk-3.3/nltk/stem/arlstem.py +369 -0
- {nltk-3.2 → nltk-3.3}/nltk/stem/isri.py +345 -345
- {nltk-3.2 → nltk-3.3}/nltk/stem/lancaster.py +337 -310
- nltk-3.3/nltk/stem/porter.py +710 -0
- {nltk-3.2 → nltk-3.3}/nltk/stem/regexp.py +61 -61
- {nltk-3.2 → nltk-3.3}/nltk/stem/rslp.py +142 -142
- {nltk-3.2 → nltk-3.3}/nltk/stem/snowball.py +4236 -3712
- {nltk-3.2 → nltk-3.3}/nltk/stem/util.py +22 -12
- {nltk-3.2 → nltk-3.3}/nltk/stem/wordnet.py +51 -51
- {nltk-3.2 → nltk-3.3}/nltk/tag/__init__.py +152 -127
- {nltk-3.2 → nltk-3.3}/nltk/tag/api.py +86 -81
- {nltk-3.2 → nltk-3.3}/nltk/tag/brill.py +424 -426
- {nltk-3.2 → nltk-3.3}/nltk/tag/brill_trainer.py +608 -608
- {nltk-3.2 → nltk-3.3}/nltk/tag/crf.py +204 -200
- {nltk-3.2 → nltk-3.3}/nltk/tag/hmm.py +1277 -1277
- {nltk-3.2 → nltk-3.3}/nltk/tag/hunpos.py +132 -132
- {nltk-3.2 → nltk-3.3}/nltk/tag/mapping.py +101 -101
- {nltk-3.2 → nltk-3.3}/nltk/tag/perceptron.py +329 -314
- {nltk-3.2 → nltk-3.3}/nltk/tag/senna.py +147 -145
- {nltk-3.2 → nltk-3.3}/nltk/tag/sequential.py +740 -736
- {nltk-3.2 → nltk-3.3}/nltk/tag/stanford.py +219 -196
- {nltk-3.2 → nltk-3.3}/nltk/tag/tnt.py +595 -604
- {nltk-3.2 → nltk-3.3}/nltk/tag/util.py +72 -72
- {nltk-3.2 → nltk-3.3}/nltk/tbl/__init__.py +28 -28
- {nltk-3.2 → nltk-3.3}/nltk/tbl/api.py +1 -1
- {nltk-3.2 → nltk-3.3}/nltk/tbl/demo.py +366 -366
- {nltk-3.2 → nltk-3.3}/nltk/tbl/erroranalysis.py +39 -39
- {nltk-3.2 → nltk-3.3}/nltk/tbl/feature.py +259 -261
- {nltk-3.2 → nltk-3.3}/nltk/tbl/rule.py +321 -321
- {nltk-3.2 → nltk-3.3}/nltk/tbl/template.py +303 -308
- {nltk-3.2 → nltk-3.3}/nltk/test/__init__.py +18 -18
- {nltk-3.2 → nltk-3.3}/nltk/test/all.py +24 -23
- {nltk-3.2 → nltk-3.3}/nltk/test/bleu.doctest +14 -14
- {nltk-3.2 → nltk-3.3}/nltk/test/bnc.doctest +60 -60
- {nltk-3.2 → nltk-3.3}/nltk/test/ccg.doctest +376 -395
- nltk-3.3/nltk/test/ccg_semantics.doctest +553 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/chat80.doctest +234 -234
- {nltk-3.2 → nltk-3.3}/nltk/test/childes.doctest +184 -184
- {nltk-3.2 → nltk-3.3}/nltk/test/childes_fixt.py +14 -13
- {nltk-3.2 → nltk-3.3}/nltk/test/chunk.doctest +373 -373
- {nltk-3.2 → nltk-3.3}/nltk/test/classify.doctest +185 -185
- {nltk-3.2 → nltk-3.3}/nltk/test/classify_fixt.py +11 -10
- nltk-3.3/nltk/test/collections.doctest +20 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/collocations.doctest +276 -276
- {nltk-3.2 → nltk-3.3}/nltk/test/compat.doctest +134 -138
- {nltk-3.2 → nltk-3.3}/nltk/test/compat_fixt.py +9 -8
- nltk-3.3/nltk/test/concordance.doctest +55 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/corpus.doctest +2200 -2212
- {nltk-3.2 → nltk-3.3}/nltk/test/corpus_fixt.py +3 -3
- {nltk-3.2 → nltk-3.3}/nltk/test/crubadan.doctest +65 -65
- {nltk-3.2 → nltk-3.3}/nltk/test/data.doctest +379 -379
- {nltk-3.2 → nltk-3.3}/nltk/test/dependency.doctest +241 -241
- {nltk-3.2 → nltk-3.3}/nltk/test/discourse.doctest +546 -546
- {nltk-3.2 → nltk-3.3}/nltk/test/discourse_fixt.py +14 -13
- {nltk-3.2 → nltk-3.3}/nltk/test/doctest_nose_plugin.py +159 -156
- {nltk-3.2 → nltk-3.3}/nltk/test/drt.doctest +517 -517
- {nltk-3.2 → nltk-3.3}/nltk/test/featgram.doctest +607 -607
- {nltk-3.2 → nltk-3.3}/nltk/test/featstruct.doctest +1229 -1230
- {nltk-3.2 → nltk-3.3}/nltk/test/framenet.doctest +288 -239
- {nltk-3.2 → nltk-3.3}/nltk/test/generate.doctest +67 -67
- {nltk-3.2 → nltk-3.3}/nltk/test/gensim.doctest +140 -141
- {nltk-3.2 → nltk-3.3}/nltk/test/gensim_fixt.py +10 -9
- {nltk-3.2 → nltk-3.3}/nltk/test/gluesemantics.doctest +384 -386
- {nltk-3.2 → nltk-3.3}/nltk/test/gluesemantics_malt.doctest +68 -68
- {nltk-3.2 → nltk-3.3}/nltk/test/gluesemantics_malt_fixt.py +12 -11
- {nltk-3.2 → nltk-3.3}/nltk/test/grammar.doctest +48 -48
- {nltk-3.2 → nltk-3.3}/nltk/test/grammartestsuites.doctest +109 -109
- {nltk-3.2 → nltk-3.3}/nltk/test/index.doctest +100 -100
- {nltk-3.2 → nltk-3.3}/nltk/test/inference.doctest +534 -534
- {nltk-3.2 → nltk-3.3}/nltk/test/inference_fixt.py +12 -11
- {nltk-3.2 → nltk-3.3}/nltk/test/internals.doctest +140 -140
- {nltk-3.2 → nltk-3.3}/nltk/test/japanese.doctest +48 -48
- {nltk-3.2 → nltk-3.3}/nltk/test/logic.doctest +1098 -1098
- {nltk-3.2 → nltk-3.3}/nltk/test/metrics.doctest +270 -270
- {nltk-3.2 → nltk-3.3}/nltk/test/misc.doctest +118 -118
- {nltk-3.2 → nltk-3.3}/nltk/test/nonmonotonic.doctest +286 -286
- {nltk-3.2 → nltk-3.3}/nltk/test/nonmonotonic_fixt.py +12 -11
- {nltk-3.2 → nltk-3.3}/nltk/test/paice.doctest +35 -35
- {nltk-3.2 → nltk-3.3}/nltk/test/parse.doctest +884 -884
- {nltk-3.2 → nltk-3.3}/nltk/test/portuguese_en.doctest +565 -565
- {nltk-3.2 → nltk-3.3}/nltk/test/portuguese_en_fixt.py +16 -16
- {nltk-3.2 → nltk-3.3}/nltk/test/probability.doctest +304 -304
- {nltk-3.2 → nltk-3.3}/nltk/test/probability_fixt.py +13 -12
- {nltk-3.2 → nltk-3.3}/nltk/test/propbank.doctest +176 -176
- {nltk-3.2 → nltk-3.3}/nltk/test/relextract.doctest +263 -263
- {nltk-3.2 → nltk-3.3}/nltk/test/resolution.doctest +221 -221
- {nltk-3.2 → nltk-3.3}/nltk/test/runtests.py +86 -64
- {nltk-3.2 → nltk-3.3}/nltk/test/segmentation_fixt.py +10 -10
- {nltk-3.2 → nltk-3.3}/nltk/test/semantics.doctest +665 -665
- {nltk-3.2 → nltk-3.3}/nltk/test/semantics_fixt.py +7 -7
- {nltk-3.2 → nltk-3.3}/nltk/test/sentiment.doctest +233 -233
- {nltk-3.2 → nltk-3.3}/nltk/test/sentiwordnet.doctest +41 -41
- {nltk-3.2 → nltk-3.3}/nltk/test/simple.doctest +85 -85
- {nltk-3.2 → nltk-3.3}/nltk/test/stem.doctest +78 -78
- {nltk-3.2 → nltk-3.3}/nltk/test/tag.doctest +33 -33
- {nltk-3.2 → nltk-3.3}/nltk/test/tokenize.doctest +273 -166
- {nltk-3.2 → nltk-3.3}/nltk/test/toolbox.doctest +307 -307
- {nltk-3.2 → nltk-3.3}/nltk/test/translate.doctest +242 -242
- {nltk-3.2 → nltk-3.3}/nltk/test/translate_fixt.py +3 -3
- {nltk-3.2 → nltk-3.3}/nltk/test/tree.doctest +1101 -1101
- {nltk-3.2 → nltk-3.3}/nltk/test/treeprettyprinter.doctest +127 -127
- {nltk-3.2 → nltk-3.3}/nltk/test/treetransforms.doctest +156 -156
- nltk-3.3/nltk/test/unit/test_2x_compat.py +63 -0
- 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 → nltk-3.3}/nltk/test/unit/test_classify.py +55 -53
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_collocations.py +88 -79
- 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 → nltk-3.3}/nltk/test/unit/test_corpora.py +200 -183
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_corpus_views.py +45 -45
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_hmm.py +88 -88
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_json2csv_corpus.py +188 -187
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_naivebayes.py +26 -26
- nltk-3.3/nltk/test/unit/test_rte_classify.py +86 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_seekable_unicode_stream_reader.py +124 -124
- 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 → nltk-3.3}/nltk/test/unit/test_tag.py +20 -20
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_tgrep.py +628 -626
- nltk-3.3/nltk/test/unit/test_tokenize.py +168 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/test_twitter_auth.py +185 -185
- 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.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm1.py +75 -75
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm2.py +87 -87
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm3.py +105 -105
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm4.py +126 -126
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm5.py +166 -166
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_ibm_model.py +270 -270
- nltk-3.3/nltk/test/unit/translate/test_nist.py +37 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/test_stack_decoder.py +300 -300
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/utils.py +41 -41
- {nltk-3.2 → nltk-3.3}/nltk/test/util.doctest +48 -48
- {nltk-3.2 → nltk-3.3}/nltk/test/wordnet.doctest +595 -581
- {nltk-3.2 → nltk-3.3}/nltk/test/wordnet_fixt.py +7 -6
- {nltk-3.2 → nltk-3.3}/nltk/test/wordnet_lch.doctest +53 -53
- {nltk-3.2 → nltk-3.3}/nltk/test/wsd.doctest +68 -68
- {nltk-3.2 → nltk-3.3}/nltk/text.py +663 -610
- {nltk-3.2 → nltk-3.3}/nltk/tgrep.py +938 -937
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/__init__.py +130 -107
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/api.py +77 -78
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/casual.py +343 -342
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/mwe.py +120 -120
- nltk-3.3/nltk/tokenize/nist.py +173 -0
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/punkt.py +1620 -1601
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/regexp.py +208 -202
- nltk-3.3/nltk/tokenize/repp.py +151 -0
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/sexpr.py +140 -142
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/simple.py +138 -136
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/stanford.py +117 -113
- nltk-3.3/nltk/tokenize/stanford_segmenter.py +246 -0
- {nltk-3.2 → nltk-3.3}/nltk/tokenize/texttiling.py +458 -460
- 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 → nltk-3.3}/nltk/toolbox.py +499 -497
- {nltk-3.2 → nltk-3.3}/nltk/translate/__init__.py +24 -24
- {nltk-3.2 → nltk-3.3}/nltk/translate/api.py +331 -321
- {nltk-3.2 → nltk-3.3}/nltk/translate/bleu_score.py +615 -556
- nltk-3.3/nltk/translate/chrf_score.py +137 -0
- {nltk-3.2 → nltk-3.3}/nltk/translate/gale_church.py +248 -235
- {nltk-3.2 → nltk-3.3}/nltk/translate/gdfa.py +135 -131
- nltk-3.3/nltk/translate/gleu_score.py +193 -0
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm1.py +250 -241
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm2.py +308 -308
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm3.py +337 -337
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm4.py +467 -467
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm5.py +639 -639
- {nltk-3.2 → nltk-3.3}/nltk/translate/ibm_model.py +536 -533
- {nltk-3.2 → nltk-3.3}/nltk/translate/metrics.py +40 -40
- nltk-3.3/nltk/translate/nist_score.py +178 -0
- {nltk-3.2 → nltk-3.3}/nltk/translate/phrase_based.py +175 -175
- {nltk-3.2 → nltk-3.3}/nltk/translate/ribes_score.py +325 -325
- {nltk-3.2 → nltk-3.3}/nltk/translate/stack_decoder.py +499 -495
- {nltk-3.2 → nltk-3.3}/nltk/tree.py +1605 -1603
- {nltk-3.2 → nltk-3.3}/nltk/treeprettyprinter.py +564 -564
- {nltk-3.2 → nltk-3.3}/nltk/treetransforms.py +309 -309
- {nltk-3.2 → nltk-3.3}/nltk/twitter/__init__.py +28 -28
- {nltk-3.2 → nltk-3.3}/nltk/twitter/api.py +141 -136
- {nltk-3.2 → nltk-3.3}/nltk/twitter/common.py +264 -258
- {nltk-3.2 → nltk-3.3}/nltk/twitter/twitter_demo.py +288 -288
- {nltk-3.2 → nltk-3.3}/nltk/twitter/twitterclient.py +530 -530
- {nltk-3.2 → nltk-3.3}/nltk/twitter/util.py +147 -146
- nltk-3.3/nltk/util.py +751 -0
- {nltk-3.2 → nltk-3.3}/nltk/wsd.py +53 -53
- {nltk-3.2 → nltk-3.3/nltk.egg-info}/PKG-INFO +13 -5
- {nltk-3.2 → nltk-3.3}/nltk.egg-info/SOURCES.txt +26 -3
- nltk-3.3/nltk.egg-info/requires.txt +31 -0
- {nltk-3.2 → nltk-3.3}/setup.cfg +0 -1
- {nltk-3.2 → nltk-3.3}/setup.py +102 -75
- nltk-3.2/nltk/VERSION +0 -1
- nltk-3.2/nltk/compat.py +0 -680
- nltk-3.2/nltk/corpus/reader/pl196x.py +0 -278
- nltk-3.2/nltk/corpus/reader/verbnet.py +0 -408
- nltk-3.2/nltk/corpus/reader/wordlist.py +0 -37
- nltk-3.2/nltk/sentiment/vader_lexicon.txt +0 -7517
- nltk-3.2/nltk/six.py +0 -868
- nltk-3.2/nltk/stem/porter.py +0 -692
- nltk-3.2/nltk/test/unit/test_2x_compat.py +0 -26
- nltk-3.2/nltk/test/unit/test_stem.py +0 -36
- nltk-3.2/nltk/test/unit/test_tokenize.py +0 -23
- nltk-3.2/nltk/test/unit/translate/test_bleu.py +0 -84
- nltk-3.2/nltk/tokenize/treebank.py +0 -124
- nltk-3.2/nltk/tokenize/util.py +0 -90
- nltk-3.2/nltk/util.py +0 -1364
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/__init__.py +0 -0
- {nltk-3.2 → nltk-3.3}/nltk/test/unit/translate/__init__.py +0 -0
- {nltk-3.2 → nltk-3.3}/nltk.egg-info/dependency_links.txt +0 -0
- {nltk-3.2 → nltk-3.3}/nltk.egg-info/not-zip-safe +0 -0
- {nltk-3.2 → nltk-3.3}/nltk.egg-info/top_level.txt +0 -0
|
@@ -1,1264 +1,1262 @@
|
|
|
1
|
-
# Natural Language Toolkit: Regexp Chunk Parser Application
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2001-
|
|
4
|
-
# Author: Edward Loper <edloper@gmail.com>
|
|
5
|
-
# URL: <http://nltk.org/>
|
|
6
|
-
# For license information, see LICENSE.TXT
|
|
7
|
-
|
|
8
|
-
"""
|
|
9
|
-
A graphical tool for exploring the regular expression based chunk
|
|
10
|
-
parser ``nltk.chunk.RegexpChunkParser``.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
# Todo: Add a way to select the development set from the menubar. This
|
|
14
|
-
# might just need to be a selection box (conll vs treebank etc) plus
|
|
15
|
-
# configuration parameters to select what's being chunked (eg VP vs NP)
|
|
16
|
-
# and what part of the data is being used as the development set.
|
|
17
|
-
|
|
18
|
-
from __future__ import division
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
from
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
from nltk.
|
|
31
|
-
from nltk.util import
|
|
32
|
-
from nltk.
|
|
33
|
-
from nltk.
|
|
34
|
-
from nltk.chunk import
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#:
|
|
50
|
-
#:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
#:
|
|
82
|
-
#:
|
|
83
|
-
#: - A
|
|
84
|
-
#: -
|
|
85
|
-
#:
|
|
86
|
-
#:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"<
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
"your grammar
|
|
118
|
-
"indicates how many of
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"<
|
|
128
|
-
"
|
|
129
|
-
"regexp
|
|
130
|
-
"<
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"<
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"<
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"<
|
|
143
|
-
"<
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"\t<var>x</var
|
|
147
|
-
"\t<var>x</var
|
|
148
|
-
"\t<var>x</var
|
|
149
|
-
"\t
|
|
150
|
-
"\t
|
|
151
|
-
"\t
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
|
|
160
|
-
'\t<
|
|
161
|
-
'\t\tMatches <match>"
|
|
162
|
-
'\t
|
|
163
|
-
'\t<
|
|
164
|
-
'\t\tMatches <match>"
|
|
165
|
-
'\t
|
|
166
|
-
'\t<
|
|
167
|
-
'\t
|
|
168
|
-
'\t<
|
|
169
|
-
'\t\tMatches <match>"
|
|
170
|
-
'\t
|
|
171
|
-
'\t<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
'
|
|
178
|
-
'
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
('
|
|
184
|
-
('
|
|
185
|
-
('
|
|
186
|
-
('
|
|
187
|
-
('
|
|
188
|
-
('
|
|
189
|
-
('
|
|
190
|
-
('
|
|
191
|
-
('
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
grammar = re.sub('
|
|
254
|
-
grammar =
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
:param
|
|
268
|
-
:param
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
self.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
top
|
|
336
|
-
top.
|
|
337
|
-
top.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
self._devset_size
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
self.
|
|
346
|
-
self.
|
|
347
|
-
self.
|
|
348
|
-
self.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
self.grammarbox.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
self.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
top.bind('<Control-
|
|
363
|
-
top.bind('<Control-
|
|
364
|
-
top.bind('<
|
|
365
|
-
top.bind('<
|
|
366
|
-
top.bind('<Control-
|
|
367
|
-
|
|
368
|
-
self.grammarbox.bind('<Control-
|
|
369
|
-
self.grammarbox.bind('<Control-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
self._size
|
|
378
|
-
self.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
filemenu
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
viewmenu
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
devsetmenu
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
helpmenu
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
#
|
|
483
|
-
#
|
|
484
|
-
#
|
|
485
|
-
#
|
|
486
|
-
#
|
|
487
|
-
#
|
|
488
|
-
#
|
|
489
|
-
#
|
|
490
|
-
#
|
|
491
|
-
#
|
|
492
|
-
#
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
self.evalbox.create_line(left,
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
'
|
|
541
|
-
'
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if self.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
self.
|
|
566
|
-
self.
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
#
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
self.
|
|
576
|
-
self.
|
|
577
|
-
self.
|
|
578
|
-
self.
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
self.
|
|
582
|
-
self.
|
|
583
|
-
self.
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
#
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
self._eval_score.
|
|
607
|
-
self._eval_score.
|
|
608
|
-
|
|
609
|
-
self.
|
|
610
|
-
self.
|
|
611
|
-
self.
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
self.
|
|
618
|
-
self.
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
frame0
|
|
639
|
-
frame0.grid_columnconfigure(
|
|
640
|
-
frame0.
|
|
641
|
-
frame0.grid_rowconfigure(
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
self.
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
grammar_scrollbar =
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
frame3 =
|
|
661
|
-
frame3
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
self.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
helptab_frame =
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
label
|
|
677
|
-
|
|
678
|
-
#
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
self.
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
self.
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
self.devset_scroll =
|
|
708
|
-
self.
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
self.
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
frame1 =
|
|
717
|
-
frame1
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
self.
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
frame2 =
|
|
745
|
-
|
|
746
|
-
self._autoscale
|
|
747
|
-
self._autoscale.
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
self._eval_lines
|
|
751
|
-
self._eval_lines.
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
self.status =
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
self.
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
Frame(frame0, height=
|
|
769
|
-
Frame(frame0, height=
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
#
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
self.devsetbox.tag_config('
|
|
781
|
-
self.devsetbox.tag_config('
|
|
782
|
-
self.devsetbox.tag_config('
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
#
|
|
786
|
-
self.grammarbox.tag_config('
|
|
787
|
-
self.grammarbox.tag_config('
|
|
788
|
-
self.grammarbox.tag_config('
|
|
789
|
-
self.grammarbox.tag_config('
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
self.
|
|
795
|
-
self.
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
self.devsetbox['
|
|
799
|
-
|
|
800
|
-
self.
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
self.devsetbox.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
tagseq
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
for
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
self.devsetbox.
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
self.devsetbox.
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
self.devsetbox.
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
self.devsetbox.
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
#
|
|
849
|
-
#
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
self.helpbox
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
('\
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
self.
|
|
863
|
-
self.helpbox.
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
#
|
|
895
|
-
|
|
896
|
-
self.grammarbox
|
|
897
|
-
self.grammarbox.
|
|
898
|
-
self.grammarbox.
|
|
899
|
-
self.
|
|
900
|
-
self.
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
self.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
self.top
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
self.
|
|
960
|
-
self.
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
self.devsetbox['
|
|
965
|
-
self.devsetbox
|
|
966
|
-
self.
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
self.
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
self.grammarbox.tag_remove('
|
|
1007
|
-
self.grammarbox.tag_remove('
|
|
1008
|
-
self.grammarbox.
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
self.
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
line =
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
normalized_grammar
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
#
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
#
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
self.
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
self.
|
|
1083
|
-
self.
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
self.devsetbox.tag_remove('
|
|
1099
|
-
self.devsetbox.tag_remove('false-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
#
|
|
1122
|
-
#
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
'%s.%s' % (self.linenum[sentnum], self.charnum[sentnum,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
self.
|
|
1137
|
-
self.
|
|
1138
|
-
self.
|
|
1139
|
-
self.
|
|
1140
|
-
self.
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
self.
|
|
1144
|
-
self.
|
|
1145
|
-
self.
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
'#
|
|
1150
|
-
'
|
|
1151
|
-
'
|
|
1152
|
-
'#
|
|
1153
|
-
'#
|
|
1154
|
-
'#
|
|
1155
|
-
'
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
self.
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
self.
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
outfile.write('#
|
|
1206
|
-
outfile.write('#
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
outfile.write('
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
self.
|
|
1237
|
-
self.show_devset(
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
self.
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
__all__ = ['app']
|
|
1264
|
-
|
|
1
|
+
# Natural Language Toolkit: Regexp Chunk Parser Application
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
4
|
+
# Author: Edward Loper <edloper@gmail.com>
|
|
5
|
+
# URL: <http://nltk.org/>
|
|
6
|
+
# For license information, see LICENSE.TXT
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
A graphical tool for exploring the regular expression based chunk
|
|
10
|
+
parser ``nltk.chunk.RegexpChunkParser``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# Todo: Add a way to select the development set from the menubar. This
|
|
14
|
+
# might just need to be a selection box (conll vs treebank etc) plus
|
|
15
|
+
# configuration parameters to select what's being chunked (eg VP vs NP)
|
|
16
|
+
# and what part of the data is being used as the development set.
|
|
17
|
+
|
|
18
|
+
from __future__ import division
|
|
19
|
+
import time
|
|
20
|
+
import textwrap
|
|
21
|
+
import re
|
|
22
|
+
import random
|
|
23
|
+
|
|
24
|
+
from six.moves.tkinter import (Button, Canvas, Checkbutton, Frame, IntVar,
|
|
25
|
+
Label, Menu, Scrollbar, Text, Tk)
|
|
26
|
+
from six.moves.tkinter_tkfiledialog import askopenfilename, asksaveasfilename
|
|
27
|
+
from six.moves.tkinter_font import Font
|
|
28
|
+
|
|
29
|
+
from nltk.tree import Tree
|
|
30
|
+
from nltk.util import in_idle
|
|
31
|
+
from nltk.draw.util import ShowText
|
|
32
|
+
from nltk.corpus import conll2000, treebank_chunk
|
|
33
|
+
from nltk.chunk import ChunkScore, RegexpChunkParser
|
|
34
|
+
from nltk.chunk.regexp import RegexpChunkRule
|
|
35
|
+
|
|
36
|
+
class RegexpChunkApp(object):
|
|
37
|
+
"""
|
|
38
|
+
A graphical tool for exploring the regular expression based chunk
|
|
39
|
+
parser ``nltk.chunk.RegexpChunkParser``.
|
|
40
|
+
|
|
41
|
+
See ``HELP`` for instructional text.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
##/////////////////////////////////////////////////////////////////
|
|
45
|
+
## Help Text
|
|
46
|
+
##/////////////////////////////////////////////////////////////////
|
|
47
|
+
|
|
48
|
+
#: A dictionary mapping from part of speech tags to descriptions,
|
|
49
|
+
#: which is used in the help text. (This should probably live with
|
|
50
|
+
#: the conll and/or treebank corpus instead.)
|
|
51
|
+
TAGSET = {
|
|
52
|
+
'CC': 'Coordinating conjunction', 'PRP$': 'Possessive pronoun',
|
|
53
|
+
'CD': 'Cardinal number', 'RB': 'Adverb',
|
|
54
|
+
'DT': 'Determiner', 'RBR': 'Adverb, comparative',
|
|
55
|
+
'EX': 'Existential there', 'RBS': 'Adverb, superlative',
|
|
56
|
+
'FW': 'Foreign word', 'RP': 'Particle',
|
|
57
|
+
'JJ': 'Adjective', 'TO': 'to',
|
|
58
|
+
'JJR': 'Adjective, comparative', 'UH': 'Interjection',
|
|
59
|
+
'JJS': 'Adjective, superlative', 'VB': 'Verb, base form',
|
|
60
|
+
'LS': 'List item marker', 'VBD': 'Verb, past tense',
|
|
61
|
+
'MD': 'Modal', 'NNS': 'Noun, plural',
|
|
62
|
+
'NN': 'Noun, singular or masps', 'VBN': 'Verb, past participle',
|
|
63
|
+
'VBZ': 'Verb,3rd ps. sing. present', 'NNP': 'Proper noun, singular',
|
|
64
|
+
'NNPS': 'Proper noun plural', 'WDT': 'wh-determiner',
|
|
65
|
+
'PDT': 'Predeterminer', 'WP': 'wh-pronoun',
|
|
66
|
+
'POS': 'Possessive ending', 'WP$': 'Possessive wh-pronoun',
|
|
67
|
+
'PRP': 'Personal pronoun', 'WRB': 'wh-adverb',
|
|
68
|
+
'(': 'open parenthesis', ')': 'close parenthesis',
|
|
69
|
+
'``': 'open quote', ',': 'comma',
|
|
70
|
+
"''": 'close quote', '.': 'period',
|
|
71
|
+
'#': 'pound sign (currency marker)',
|
|
72
|
+
'$': 'dollar sign (currency marker)',
|
|
73
|
+
'IN': 'Preposition/subord. conjunction',
|
|
74
|
+
'SYM': 'Symbol (mathematical or scientific)',
|
|
75
|
+
'VBG': 'Verb, gerund/present participle',
|
|
76
|
+
'VBP': 'Verb, non-3rd ps. sing. present',
|
|
77
|
+
':': 'colon',
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#: Contents for the help box. This is a list of tuples, one for
|
|
81
|
+
#: each help page, where each tuple has four elements:
|
|
82
|
+
#: - A title (displayed as a tab)
|
|
83
|
+
#: - A string description of tabstops (see Tkinter.Text for details)
|
|
84
|
+
#: - The text contents for the help page. You can use expressions
|
|
85
|
+
#: like <red>...</red> to colorize the text; see ``HELP_AUTOTAG``
|
|
86
|
+
#: for a list of tags you can use for colorizing.
|
|
87
|
+
HELP = [
|
|
88
|
+
('Help', '20',
|
|
89
|
+
"Welcome to the regular expression chunk-parser grammar editor. "
|
|
90
|
+
"You can use this editor to develop and test chunk parser grammars "
|
|
91
|
+
"based on NLTK's RegexpChunkParser class.\n\n"
|
|
92
|
+
# Help box.
|
|
93
|
+
"Use this box ('Help') to learn more about the editor; click on the "
|
|
94
|
+
"tabs for help on specific topics:"
|
|
95
|
+
"<indent>\n"
|
|
96
|
+
"Rules: grammar rule types\n"
|
|
97
|
+
"Regexps: regular expression syntax\n"
|
|
98
|
+
"Tags: part of speech tags\n</indent>\n"
|
|
99
|
+
# Grammar.
|
|
100
|
+
"Use the upper-left box ('Grammar') to edit your grammar. "
|
|
101
|
+
"Each line of your grammar specifies a single 'rule', "
|
|
102
|
+
"which performs an action such as creating a chunk or merging "
|
|
103
|
+
"two chunks.\n\n"
|
|
104
|
+
# Dev set.
|
|
105
|
+
"The lower-left box ('Development Set') runs your grammar on the "
|
|
106
|
+
"development set, and displays the results. "
|
|
107
|
+
"Your grammar's chunks are <highlight>highlighted</highlight>, and "
|
|
108
|
+
"the correct (gold standard) chunks are "
|
|
109
|
+
"<underline>underlined</underline>. If they "
|
|
110
|
+
"match, they are displayed in <green>green</green>; otherwise, "
|
|
111
|
+
"they are displayed in <red>red</red>. The box displays a single "
|
|
112
|
+
"sentence from the development set at a time; use the scrollbar or "
|
|
113
|
+
"the next/previous buttons view additional sentences.\n\n"
|
|
114
|
+
# Performance
|
|
115
|
+
"The lower-right box ('Evaluation') tracks the performance of "
|
|
116
|
+
"your grammar on the development set. The 'precision' axis "
|
|
117
|
+
"indicates how many of your grammar's chunks are correct; and "
|
|
118
|
+
"the 'recall' axis indicates how many of the gold standard "
|
|
119
|
+
"chunks your system generated. Typically, you should try to "
|
|
120
|
+
"design a grammar that scores high on both metrics. The "
|
|
121
|
+
"exact precision and recall of the current grammar, as well "
|
|
122
|
+
"as their harmonic mean (the 'f-score'), are displayed in "
|
|
123
|
+
"the status bar at the bottom of the window."
|
|
124
|
+
),
|
|
125
|
+
('Rules', '10',
|
|
126
|
+
"<h1>{...regexp...}</h1>"
|
|
127
|
+
"<indent>\nChunk rule: creates new chunks from words matching "
|
|
128
|
+
"regexp.</indent>\n\n"
|
|
129
|
+
"<h1>}...regexp...{</h1>"
|
|
130
|
+
"<indent>\nChink rule: removes words matching regexp from existing "
|
|
131
|
+
"chunks.</indent>\n\n"
|
|
132
|
+
"<h1>...regexp1...}{...regexp2...</h1>"
|
|
133
|
+
"<indent>\nSplit rule: splits chunks that match regexp1 followed by "
|
|
134
|
+
"regexp2 in two.</indent>\n\n"
|
|
135
|
+
"<h1>...regexp...{}...regexp...</h1>"
|
|
136
|
+
"<indent>\nMerge rule: joins consecutive chunks that match regexp1 "
|
|
137
|
+
"and regexp2</indent>\n"
|
|
138
|
+
),
|
|
139
|
+
('Regexps', '10 60',
|
|
140
|
+
#"Regular Expression Syntax Summary:\n\n"
|
|
141
|
+
"<h1>Pattern\t\tMatches...</h1>\n"
|
|
142
|
+
"<hangindent>"
|
|
143
|
+
"\t<<var>T</var>>\ta word with tag <var>T</var> "
|
|
144
|
+
"(where <var>T</var> may be a regexp).\n"
|
|
145
|
+
"\t<var>x</var>?\tan optional <var>x</var>\n"
|
|
146
|
+
"\t<var>x</var>+\ta sequence of 1 or more <var>x</var>'s\n"
|
|
147
|
+
"\t<var>x</var>*\ta sequence of 0 or more <var>x</var>'s\n"
|
|
148
|
+
"\t<var>x</var>|<var>y</var>\t<var>x</var> or <var>y</var>\n"
|
|
149
|
+
"\t.\tmatches any character\n"
|
|
150
|
+
"\t(<var>x</var>)\tTreats <var>x</var> as a group\n"
|
|
151
|
+
"\t# <var>x...</var>\tTreats <var>x...</var> "
|
|
152
|
+
"(to the end of the line) as a comment\n"
|
|
153
|
+
"\t\\<var>C</var>\tmatches character <var>C</var> "
|
|
154
|
+
"(useful when <var>C</var> is a special character "
|
|
155
|
+
"like + or #)\n"
|
|
156
|
+
"</hangindent>"
|
|
157
|
+
"\n<h1>Examples:</h1>\n"
|
|
158
|
+
"<hangindent>"
|
|
159
|
+
'\t<regexp><NN></regexp>\n'
|
|
160
|
+
'\t\tMatches <match>"cow/NN"</match>\n'
|
|
161
|
+
'\t\tMatches <match>"green/NN"</match>\n'
|
|
162
|
+
'\t<regexp><VB.*></regexp>\n'
|
|
163
|
+
'\t\tMatches <match>"eating/VBG"</match>\n'
|
|
164
|
+
'\t\tMatches <match>"ate/VBD"</match>\n'
|
|
165
|
+
'\t<regexp><IN><DT><NN></regexp>\n'
|
|
166
|
+
'\t\tMatches <match>"on/IN the/DT car/NN"</match>\n'
|
|
167
|
+
'\t<regexp><RB>?<VBD></regexp>\n'
|
|
168
|
+
'\t\tMatches <match>"ran/VBD"</match>\n'
|
|
169
|
+
'\t\tMatches <match>"slowly/RB ate/VBD"</match>\n'
|
|
170
|
+
'\t<regexp><\#><CD> # This is a comment...</regexp>\n'
|
|
171
|
+
'\t\tMatches <match>"#/# 100/CD"</match>\n'
|
|
172
|
+
"</hangindent>"
|
|
173
|
+
),
|
|
174
|
+
('Tags', '10 60',
|
|
175
|
+
"<h1>Part of Speech Tags:</h1>\n" +
|
|
176
|
+
'<hangindent>' +
|
|
177
|
+
'<<TAGSET>>' + # this gets auto-substituted w/ self.TAGSET
|
|
178
|
+
'</hangindent>\n')
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
HELP_AUTOTAG = [
|
|
182
|
+
('red', dict(foreground='#a00')),
|
|
183
|
+
('green', dict(foreground='#080')),
|
|
184
|
+
('highlight', dict(background='#ddd')),
|
|
185
|
+
('underline', dict(underline=True)),
|
|
186
|
+
('h1', dict(underline=True)),
|
|
187
|
+
('indent', dict(lmargin1=20, lmargin2=20)),
|
|
188
|
+
('hangindent', dict(lmargin1=0, lmargin2=60)),
|
|
189
|
+
('var', dict(foreground='#88f')),
|
|
190
|
+
('regexp', dict(foreground='#ba7')),
|
|
191
|
+
('match', dict(foreground='#6a6')),
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
##/////////////////////////////////////////////////////////////////
|
|
195
|
+
## Config Parmeters
|
|
196
|
+
##/////////////////////////////////////////////////////////////////
|
|
197
|
+
|
|
198
|
+
_EVAL_DELAY = 1
|
|
199
|
+
"""If the user has not pressed any key for this amount of time (in
|
|
200
|
+
seconds), and the current grammar has not been evaluated, then
|
|
201
|
+
the eval demon will evaluate it."""
|
|
202
|
+
|
|
203
|
+
_EVAL_CHUNK = 15
|
|
204
|
+
"""The number of sentences that should be evaluated by the eval
|
|
205
|
+
demon each time it runs."""
|
|
206
|
+
_EVAL_FREQ = 0.2
|
|
207
|
+
"""The frequency (in seconds) at which the eval demon is run"""
|
|
208
|
+
_EVAL_DEMON_MIN = .02
|
|
209
|
+
"""The minimum amount of time that the eval demon should take each time
|
|
210
|
+
it runs -- if it takes less than this time, _EVAL_CHUNK will be
|
|
211
|
+
modified upwards."""
|
|
212
|
+
_EVAL_DEMON_MAX = .04
|
|
213
|
+
"""The maximum amount of time that the eval demon should take each time
|
|
214
|
+
it runs -- if it takes more than this time, _EVAL_CHUNK will be
|
|
215
|
+
modified downwards."""
|
|
216
|
+
|
|
217
|
+
_GRAMMARBOX_PARAMS = dict(
|
|
218
|
+
width=40, height=12, background='#efe', highlightbackground='#efe',
|
|
219
|
+
highlightthickness=1, relief='groove', border=2, wrap='word')
|
|
220
|
+
_HELPBOX_PARAMS = dict(
|
|
221
|
+
width=15, height=15, background='#efe', highlightbackground='#efe',
|
|
222
|
+
foreground='#555',
|
|
223
|
+
highlightthickness=1, relief='groove', border=2, wrap='word')
|
|
224
|
+
_DEVSETBOX_PARAMS = dict(
|
|
225
|
+
width=70, height=10, background='#eef', highlightbackground='#eef',
|
|
226
|
+
highlightthickness=1, relief='groove', border=2, wrap='word',
|
|
227
|
+
tabs=(30,))
|
|
228
|
+
_STATUS_PARAMS = dict(
|
|
229
|
+
background='#9bb', relief='groove', border=2)
|
|
230
|
+
_FONT_PARAMS = dict(
|
|
231
|
+
family='helvetica', size=-20)
|
|
232
|
+
_FRAME_PARAMS = dict(
|
|
233
|
+
background='#777', padx=2, pady=2, border=3)
|
|
234
|
+
_EVALBOX_PARAMS = dict(
|
|
235
|
+
background='#eef', highlightbackground='#eef',
|
|
236
|
+
highlightthickness=1, relief='groove', border=2,
|
|
237
|
+
width=300, height=280)
|
|
238
|
+
_BUTTON_PARAMS = dict(
|
|
239
|
+
background='#777', activebackground='#777',
|
|
240
|
+
highlightbackground='#777')
|
|
241
|
+
_HELPTAB_BG_COLOR = '#aba'
|
|
242
|
+
_HELPTAB_FG_COLOR = '#efe'
|
|
243
|
+
|
|
244
|
+
_HELPTAB_FG_PARAMS = dict(background='#efe')
|
|
245
|
+
_HELPTAB_BG_PARAMS = dict(background='#aba')
|
|
246
|
+
_HELPTAB_SPACER = 6
|
|
247
|
+
|
|
248
|
+
def normalize_grammar(self, grammar):
|
|
249
|
+
# Strip comments
|
|
250
|
+
grammar = re.sub(r'((\\.|[^#])*)(#.*)?', r'\1', grammar)
|
|
251
|
+
# Normalize whitespace
|
|
252
|
+
grammar = re.sub(' +', ' ', grammar)
|
|
253
|
+
grammar = re.sub('\n\s+', '\n', grammar)
|
|
254
|
+
grammar = grammar.strip()
|
|
255
|
+
# [xx] Hack: automatically backslash $!
|
|
256
|
+
grammar = re.sub(r'([^\\])\$', r'\1\\$', grammar)
|
|
257
|
+
return grammar
|
|
258
|
+
|
|
259
|
+
def __init__(self, devset_name='conll2000', devset=None,
|
|
260
|
+
grammar = '', chunk_label='NP', tagset=None):
|
|
261
|
+
"""
|
|
262
|
+
:param devset_name: The name of the development set; used for
|
|
263
|
+
display & for save files. If either the name 'treebank'
|
|
264
|
+
or the name 'conll2000' is used, and devset is None, then
|
|
265
|
+
devset will be set automatically.
|
|
266
|
+
:param devset: A list of chunked sentences
|
|
267
|
+
:param grammar: The initial grammar to display.
|
|
268
|
+
:param tagset: Dictionary from tags to string descriptions, used
|
|
269
|
+
for the help page. Defaults to ``self.TAGSET``.
|
|
270
|
+
"""
|
|
271
|
+
self._chunk_label = chunk_label
|
|
272
|
+
|
|
273
|
+
if tagset is None: tagset = self.TAGSET
|
|
274
|
+
self.tagset = tagset
|
|
275
|
+
|
|
276
|
+
# Named development sets:
|
|
277
|
+
if devset is None:
|
|
278
|
+
if devset_name == 'conll2000':
|
|
279
|
+
devset = conll2000.chunked_sents('train.txt')#[:100]
|
|
280
|
+
elif devset == 'treebank':
|
|
281
|
+
devset = treebank_chunk.chunked_sents()#[:100]
|
|
282
|
+
else:
|
|
283
|
+
raise ValueError('Unknown development set %s' % devset_name)
|
|
284
|
+
|
|
285
|
+
self.chunker = None
|
|
286
|
+
"""The chunker built from the grammar string"""
|
|
287
|
+
|
|
288
|
+
self.grammar = grammar
|
|
289
|
+
"""The unparsed grammar string"""
|
|
290
|
+
|
|
291
|
+
self.normalized_grammar = None
|
|
292
|
+
"""A normalized version of ``self.grammar``."""
|
|
293
|
+
|
|
294
|
+
self.grammar_changed = 0
|
|
295
|
+
"""The last time() that the grammar was changed."""
|
|
296
|
+
|
|
297
|
+
self.devset = devset
|
|
298
|
+
"""The development set -- a list of chunked sentences."""
|
|
299
|
+
|
|
300
|
+
self.devset_name = devset_name
|
|
301
|
+
"""The name of the development set (for save files)."""
|
|
302
|
+
|
|
303
|
+
self.devset_index = -1
|
|
304
|
+
"""The index into the development set of the first instance
|
|
305
|
+
that's currently being viewed."""
|
|
306
|
+
|
|
307
|
+
self._last_keypress = 0
|
|
308
|
+
"""The time() when a key was most recently pressed"""
|
|
309
|
+
|
|
310
|
+
self._history = []
|
|
311
|
+
"""A list of (grammar, precision, recall, fscore) tuples for
|
|
312
|
+
grammars that the user has already tried."""
|
|
313
|
+
|
|
314
|
+
self._history_index = 0
|
|
315
|
+
"""When the user is scrolling through previous grammars, this
|
|
316
|
+
is used to keep track of which grammar they're looking at."""
|
|
317
|
+
|
|
318
|
+
self._eval_grammar = None
|
|
319
|
+
"""The grammar that is being currently evaluated by the eval
|
|
320
|
+
demon."""
|
|
321
|
+
|
|
322
|
+
self._eval_normalized_grammar = None
|
|
323
|
+
"""A normalized copy of ``_eval_grammar``."""
|
|
324
|
+
|
|
325
|
+
self._eval_index = 0
|
|
326
|
+
"""The index of the next sentence in the development set that
|
|
327
|
+
should be looked at by the eval demon."""
|
|
328
|
+
|
|
329
|
+
self._eval_score = ChunkScore(chunk_label=chunk_label)
|
|
330
|
+
"""The ``ChunkScore`` object that's used to keep track of the score
|
|
331
|
+
of the current grammar on the development set."""
|
|
332
|
+
|
|
333
|
+
# Set up the main window.
|
|
334
|
+
top = self.top = Tk()
|
|
335
|
+
top.geometry('+50+50')
|
|
336
|
+
top.title('Regexp Chunk Parser App')
|
|
337
|
+
top.bind('<Control-q>', self.destroy)
|
|
338
|
+
|
|
339
|
+
# Varaible that restricts how much of the devset we look at.
|
|
340
|
+
self._devset_size = IntVar(top)
|
|
341
|
+
self._devset_size.set(100)
|
|
342
|
+
|
|
343
|
+
# Set up all the tkinter widgets
|
|
344
|
+
self._init_fonts(top)
|
|
345
|
+
self._init_widgets(top)
|
|
346
|
+
self._init_bindings(top)
|
|
347
|
+
self._init_menubar(top)
|
|
348
|
+
self.grammarbox.focus()
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
# If a grammar was given, then display it.
|
|
352
|
+
if grammar:
|
|
353
|
+
self.grammarbox.insert('end', grammar+'\n')
|
|
354
|
+
self.grammarbox.mark_set('insert', '1.0')
|
|
355
|
+
|
|
356
|
+
# Display the first item in the development set
|
|
357
|
+
self.show_devset(0)
|
|
358
|
+
self.update()
|
|
359
|
+
|
|
360
|
+
def _init_bindings(self, top):
|
|
361
|
+
top.bind('<Control-n>', self._devset_next)
|
|
362
|
+
top.bind('<Control-p>', self._devset_prev)
|
|
363
|
+
top.bind('<Control-t>', self.toggle_show_trace)
|
|
364
|
+
top.bind('<KeyPress>', self.update)
|
|
365
|
+
top.bind('<Control-s>', lambda e: self.save_grammar())
|
|
366
|
+
top.bind('<Control-o>', lambda e: self.load_grammar())
|
|
367
|
+
self.grammarbox.bind('<Control-t>', self.toggle_show_trace)
|
|
368
|
+
self.grammarbox.bind('<Control-n>', self._devset_next)
|
|
369
|
+
self.grammarbox.bind('<Control-p>', self._devset_prev)
|
|
370
|
+
|
|
371
|
+
# Redraw the eval graph when the window size changes
|
|
372
|
+
self.evalbox.bind('<Configure>', self._eval_plot)
|
|
373
|
+
|
|
374
|
+
def _init_fonts(self, top):
|
|
375
|
+
# TWhat's our font size (default=same as sysfont)
|
|
376
|
+
self._size = IntVar(top)
|
|
377
|
+
self._size.set(20)
|
|
378
|
+
self._font = Font(family='helvetica',
|
|
379
|
+
size=-self._size.get())
|
|
380
|
+
self._smallfont = Font(family='helvetica',
|
|
381
|
+
size=-(int(self._size.get()*14//20)))
|
|
382
|
+
|
|
383
|
+
def _init_menubar(self, parent):
|
|
384
|
+
menubar = Menu(parent)
|
|
385
|
+
|
|
386
|
+
filemenu = Menu(menubar, tearoff=0)
|
|
387
|
+
filemenu.add_command(label='Reset Application', underline=0,
|
|
388
|
+
command=self.reset)
|
|
389
|
+
filemenu.add_command(label='Save Current Grammar', underline=0,
|
|
390
|
+
accelerator='Ctrl-s',
|
|
391
|
+
command=self.save_grammar)
|
|
392
|
+
filemenu.add_command(label='Load Grammar', underline=0,
|
|
393
|
+
accelerator='Ctrl-o',
|
|
394
|
+
command=self.load_grammar)
|
|
395
|
+
|
|
396
|
+
filemenu.add_command(label='Save Grammar History', underline=13,
|
|
397
|
+
command=self.save_history)
|
|
398
|
+
|
|
399
|
+
filemenu.add_command(label='Exit', underline=1,
|
|
400
|
+
command=self.destroy, accelerator='Ctrl-q')
|
|
401
|
+
menubar.add_cascade(label='File', underline=0, menu=filemenu)
|
|
402
|
+
|
|
403
|
+
viewmenu = Menu(menubar, tearoff=0)
|
|
404
|
+
viewmenu.add_radiobutton(label='Tiny', variable=self._size,
|
|
405
|
+
underline=0, value=10, command=self.resize)
|
|
406
|
+
viewmenu.add_radiobutton(label='Small', variable=self._size,
|
|
407
|
+
underline=0, value=16, command=self.resize)
|
|
408
|
+
viewmenu.add_radiobutton(label='Medium', variable=self._size,
|
|
409
|
+
underline=0, value=20, command=self.resize)
|
|
410
|
+
viewmenu.add_radiobutton(label='Large', variable=self._size,
|
|
411
|
+
underline=0, value=24, command=self.resize)
|
|
412
|
+
viewmenu.add_radiobutton(label='Huge', variable=self._size,
|
|
413
|
+
underline=0, value=34, command=self.resize)
|
|
414
|
+
menubar.add_cascade(label='View', underline=0, menu=viewmenu)
|
|
415
|
+
|
|
416
|
+
devsetmenu = Menu(menubar, tearoff=0)
|
|
417
|
+
devsetmenu.add_radiobutton(label='50 sentences',
|
|
418
|
+
variable=self._devset_size,
|
|
419
|
+
value=50, command=self.set_devset_size)
|
|
420
|
+
devsetmenu.add_radiobutton(label='100 sentences',
|
|
421
|
+
variable=self._devset_size,
|
|
422
|
+
value=100, command=self.set_devset_size)
|
|
423
|
+
devsetmenu.add_radiobutton(label='200 sentences',
|
|
424
|
+
variable=self._devset_size,
|
|
425
|
+
value=200, command=self.set_devset_size)
|
|
426
|
+
devsetmenu.add_radiobutton(label='500 sentences',
|
|
427
|
+
variable=self._devset_size,
|
|
428
|
+
value=500, command=self.set_devset_size)
|
|
429
|
+
menubar.add_cascade(label='Development-Set', underline=0,
|
|
430
|
+
menu=devsetmenu)
|
|
431
|
+
|
|
432
|
+
helpmenu = Menu(menubar, tearoff=0)
|
|
433
|
+
helpmenu.add_command(label='About', underline=0,
|
|
434
|
+
command=self.about)
|
|
435
|
+
menubar.add_cascade(label='Help', underline=0, menu=helpmenu)
|
|
436
|
+
|
|
437
|
+
parent.config(menu=menubar)
|
|
438
|
+
|
|
439
|
+
def toggle_show_trace(self, *e):
|
|
440
|
+
if self._showing_trace:
|
|
441
|
+
self.show_devset()
|
|
442
|
+
else:
|
|
443
|
+
self.show_trace()
|
|
444
|
+
return 'break'
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
_SCALE_N = 5 # center on the last 5 examples.
|
|
448
|
+
_DRAW_LINES = False
|
|
449
|
+
def _eval_plot(self, *e, **config):
|
|
450
|
+
width = config.get('width', self.evalbox.winfo_width())
|
|
451
|
+
height = config.get('height', self.evalbox.winfo_height())
|
|
452
|
+
|
|
453
|
+
# Clear the canvas
|
|
454
|
+
self.evalbox.delete('all')
|
|
455
|
+
|
|
456
|
+
# Draw the precision & recall labels.
|
|
457
|
+
tag = self.evalbox.create_text(10, height//2-10, justify='left',
|
|
458
|
+
anchor='w', text='Precision')
|
|
459
|
+
left, right = self.evalbox.bbox(tag)[2] + 5, width-10
|
|
460
|
+
tag = self.evalbox.create_text(left + (width-left)//2, height-10,
|
|
461
|
+
anchor='s', text='Recall', justify='center')
|
|
462
|
+
top, bot = 10, self.evalbox.bbox(tag)[1]-10
|
|
463
|
+
|
|
464
|
+
# Draw masks for clipping the plot.
|
|
465
|
+
bg = self._EVALBOX_PARAMS['background']
|
|
466
|
+
self.evalbox.lower(self.evalbox.create_rectangle(0, 0, left-1, 5000,
|
|
467
|
+
fill=bg, outline=bg))
|
|
468
|
+
self.evalbox.lower(self.evalbox.create_rectangle(0, bot+1, 5000, 5000,
|
|
469
|
+
fill=bg, outline=bg))
|
|
470
|
+
|
|
471
|
+
# Calculate the plot's scale.
|
|
472
|
+
if self._autoscale.get() and len(self._history) > 1:
|
|
473
|
+
max_precision = max_recall = 0
|
|
474
|
+
min_precision = min_recall = 1
|
|
475
|
+
for i in range(1, min(len(self._history), self._SCALE_N+1)):
|
|
476
|
+
grammar, precision, recall, fmeasure = self._history[-i]
|
|
477
|
+
min_precision = min(precision, min_precision)
|
|
478
|
+
min_recall = min(recall, min_recall)
|
|
479
|
+
max_precision = max(precision, max_precision)
|
|
480
|
+
max_recall = max(recall, max_recall)
|
|
481
|
+
# if max_precision-min_precision > max_recall-min_recall:
|
|
482
|
+
# min_recall -= (max_precision-min_precision)/2
|
|
483
|
+
# max_recall += (max_precision-min_precision)/2
|
|
484
|
+
# else:
|
|
485
|
+
# min_precision -= (max_recall-min_recall)/2
|
|
486
|
+
# max_precision += (max_recall-min_recall)/2
|
|
487
|
+
# if min_recall < 0:
|
|
488
|
+
# max_recall -= min_recall
|
|
489
|
+
# min_recall = 0
|
|
490
|
+
# if min_precision < 0:
|
|
491
|
+
# max_precision -= min_precision
|
|
492
|
+
# min_precision = 0
|
|
493
|
+
min_precision = max(min_precision-.01, 0)
|
|
494
|
+
min_recall = max(min_recall-.01, 0)
|
|
495
|
+
max_precision = min(max_precision+.01, 1)
|
|
496
|
+
max_recall = min(max_recall+.01, 1)
|
|
497
|
+
else:
|
|
498
|
+
min_precision = min_recall = 0
|
|
499
|
+
max_precision = max_recall = 1
|
|
500
|
+
|
|
501
|
+
# Draw the axis lines & grid lines
|
|
502
|
+
for i in range(11):
|
|
503
|
+
x = left + (right-left)*((i/10.-min_recall)/
|
|
504
|
+
(max_recall-min_recall))
|
|
505
|
+
y = bot - (bot-top)*((i/10.-min_precision)/
|
|
506
|
+
(max_precision-min_precision))
|
|
507
|
+
if left < x < right:
|
|
508
|
+
self.evalbox.create_line(x, top, x, bot, fill='#888')
|
|
509
|
+
if top < y < bot:
|
|
510
|
+
self.evalbox.create_line(left, y, right, y, fill='#888')
|
|
511
|
+
self.evalbox.create_line(left, top, left, bot)
|
|
512
|
+
self.evalbox.create_line(left, bot, right, bot)
|
|
513
|
+
|
|
514
|
+
# Display the plot's scale
|
|
515
|
+
self.evalbox.create_text(
|
|
516
|
+
left-3, bot, justify='right', anchor='se',
|
|
517
|
+
text='%d%%' % (100*min_precision))
|
|
518
|
+
self.evalbox.create_text(
|
|
519
|
+
left-3, top, justify='right', anchor='ne',
|
|
520
|
+
text='%d%%' % (100*max_precision))
|
|
521
|
+
self.evalbox.create_text(
|
|
522
|
+
left, bot+3, justify='center', anchor='nw',
|
|
523
|
+
text='%d%%' % (100*min_recall))
|
|
524
|
+
self.evalbox.create_text(
|
|
525
|
+
right, bot+3, justify='center', anchor='ne',
|
|
526
|
+
text='%d%%' % (100*max_recall))
|
|
527
|
+
|
|
528
|
+
# Display the scores.
|
|
529
|
+
prev_x = prev_y = None
|
|
530
|
+
for i, (_, precision, recall, fscore) in enumerate(self._history):
|
|
531
|
+
x = left + (right-left) * ((recall-min_recall) /
|
|
532
|
+
(max_recall-min_recall))
|
|
533
|
+
y = bot - (bot-top) * ((precision-min_precision) /
|
|
534
|
+
(max_precision-min_precision))
|
|
535
|
+
if i == self._history_index:
|
|
536
|
+
self.evalbox.create_oval(x-2,y-2,x+2,y+2,
|
|
537
|
+
fill='#0f0', outline='#000')
|
|
538
|
+
self.status['text'] = (
|
|
539
|
+
'Precision: %.2f%%\t' % (precision*100)+
|
|
540
|
+
'Recall: %.2f%%\t' % (recall*100)+
|
|
541
|
+
'F-score: %.2f%%' % (fscore*100))
|
|
542
|
+
else:
|
|
543
|
+
self.evalbox.lower(
|
|
544
|
+
self.evalbox.create_oval(x-2,y-2,x+2,y+2,
|
|
545
|
+
fill='#afa', outline='#8c8'))
|
|
546
|
+
if prev_x is not None and self._eval_lines.get():
|
|
547
|
+
self.evalbox.lower(
|
|
548
|
+
self.evalbox.create_line(prev_x, prev_y, x, y,
|
|
549
|
+
fill='#8c8'))
|
|
550
|
+
prev_x, prev_y = x, y
|
|
551
|
+
|
|
552
|
+
_eval_demon_running = False
|
|
553
|
+
def _eval_demon(self):
|
|
554
|
+
if self.top is None: return
|
|
555
|
+
if self.chunker is None:
|
|
556
|
+
self._eval_demon_running = False
|
|
557
|
+
return
|
|
558
|
+
|
|
559
|
+
# Note our starting time.
|
|
560
|
+
t0 = time.time()
|
|
561
|
+
|
|
562
|
+
# If are still typing, then wait for them to finish.
|
|
563
|
+
if (time.time()-self._last_keypress < self._EVAL_DELAY and
|
|
564
|
+
self.normalized_grammar != self._eval_normalized_grammar):
|
|
565
|
+
self._eval_demon_running = True
|
|
566
|
+
return self.top.after(int(self._EVAL_FREQ*1000), self._eval_demon)
|
|
567
|
+
|
|
568
|
+
# If the grammar changed, restart the evaluation.
|
|
569
|
+
if self.normalized_grammar != self._eval_normalized_grammar:
|
|
570
|
+
# Check if we've seen this grammar already. If so, then
|
|
571
|
+
# just use the old evaluation values.
|
|
572
|
+
for (g, p, r, f) in self._history:
|
|
573
|
+
if self.normalized_grammar == self.normalize_grammar(g):
|
|
574
|
+
self._history.append( (g, p, r, f) )
|
|
575
|
+
self._history_index = len(self._history) - 1
|
|
576
|
+
self._eval_plot()
|
|
577
|
+
self._eval_demon_running = False
|
|
578
|
+
self._eval_normalized_grammar = None
|
|
579
|
+
return
|
|
580
|
+
self._eval_index = 0
|
|
581
|
+
self._eval_score = ChunkScore(chunk_label=self._chunk_label)
|
|
582
|
+
self._eval_grammar = self.grammar
|
|
583
|
+
self._eval_normalized_grammar = self.normalized_grammar
|
|
584
|
+
|
|
585
|
+
# If the grammar is empty, the don't bother evaluating it, or
|
|
586
|
+
# recording it in history -- the score will just be 0.
|
|
587
|
+
if self.normalized_grammar.strip() == '':
|
|
588
|
+
#self._eval_index = self._devset_size.get()
|
|
589
|
+
self._eval_demon_running = False
|
|
590
|
+
return
|
|
591
|
+
|
|
592
|
+
# Score the next set of examples
|
|
593
|
+
for gold in self.devset[self._eval_index:
|
|
594
|
+
min(self._eval_index+self._EVAL_CHUNK,
|
|
595
|
+
self._devset_size.get())]:
|
|
596
|
+
guess = self._chunkparse(gold.leaves())
|
|
597
|
+
self._eval_score.score(gold, guess)
|
|
598
|
+
|
|
599
|
+
# update our index in the devset.
|
|
600
|
+
self._eval_index += self._EVAL_CHUNK
|
|
601
|
+
|
|
602
|
+
# Check if we're done
|
|
603
|
+
if self._eval_index >= self._devset_size.get():
|
|
604
|
+
self._history.append( (self._eval_grammar,
|
|
605
|
+
self._eval_score.precision(),
|
|
606
|
+
self._eval_score.recall(),
|
|
607
|
+
self._eval_score.f_measure()) )
|
|
608
|
+
self._history_index = len(self._history)-1
|
|
609
|
+
self._eval_plot()
|
|
610
|
+
self._eval_demon_running = False
|
|
611
|
+
self._eval_normalized_grammar = None
|
|
612
|
+
else:
|
|
613
|
+
progress = 100*self._eval_index/self._devset_size.get()
|
|
614
|
+
self.status['text'] = ('Evaluating on Development Set (%d%%)' %
|
|
615
|
+
progress)
|
|
616
|
+
self._eval_demon_running = True
|
|
617
|
+
self._adaptively_modify_eval_chunk(time.time() - t0)
|
|
618
|
+
self.top.after(int(self._EVAL_FREQ*1000), self._eval_demon)
|
|
619
|
+
|
|
620
|
+
def _adaptively_modify_eval_chunk(self, t):
|
|
621
|
+
"""
|
|
622
|
+
Modify _EVAL_CHUNK to try to keep the amount of time that the
|
|
623
|
+
eval demon takes between _EVAL_DEMON_MIN and _EVAL_DEMON_MAX.
|
|
624
|
+
|
|
625
|
+
:param t: The amount of time that the eval demon took.
|
|
626
|
+
"""
|
|
627
|
+
if t > self._EVAL_DEMON_MAX and self._EVAL_CHUNK > 5:
|
|
628
|
+
self._EVAL_CHUNK = min(self._EVAL_CHUNK-1,
|
|
629
|
+
max(int(self._EVAL_CHUNK*(self._EVAL_DEMON_MAX/t)),
|
|
630
|
+
self._EVAL_CHUNK-10))
|
|
631
|
+
elif t < self._EVAL_DEMON_MIN:
|
|
632
|
+
self._EVAL_CHUNK = max(self._EVAL_CHUNK+1,
|
|
633
|
+
min(int(self._EVAL_CHUNK*(self._EVAL_DEMON_MIN/t)),
|
|
634
|
+
self._EVAL_CHUNK+10))
|
|
635
|
+
|
|
636
|
+
def _init_widgets(self, top):
|
|
637
|
+
frame0 = Frame(top, **self._FRAME_PARAMS)
|
|
638
|
+
frame0.grid_columnconfigure(0, weight=4)
|
|
639
|
+
frame0.grid_columnconfigure(3, weight=2)
|
|
640
|
+
frame0.grid_rowconfigure(1, weight=1)
|
|
641
|
+
frame0.grid_rowconfigure(5, weight=1)
|
|
642
|
+
|
|
643
|
+
# The grammar
|
|
644
|
+
self.grammarbox = Text(frame0, font=self._font,
|
|
645
|
+
**self._GRAMMARBOX_PARAMS)
|
|
646
|
+
self.grammarlabel = Label(frame0, font=self._font, text='Grammar:',
|
|
647
|
+
highlightcolor='black',
|
|
648
|
+
background=self._GRAMMARBOX_PARAMS['background'])
|
|
649
|
+
self.grammarlabel.grid(column=0, row=0, sticky='SW')
|
|
650
|
+
self.grammarbox.grid(column=0, row=1, sticky='NEWS')
|
|
651
|
+
|
|
652
|
+
# Scroll bar for grammar
|
|
653
|
+
grammar_scrollbar = Scrollbar(frame0, command=self.grammarbox.yview)
|
|
654
|
+
grammar_scrollbar.grid(column=1, row=1, sticky='NWS')
|
|
655
|
+
self.grammarbox.config(yscrollcommand=grammar_scrollbar.set)
|
|
656
|
+
|
|
657
|
+
# grammar buttons
|
|
658
|
+
bg = self._FRAME_PARAMS['background']
|
|
659
|
+
frame3 = Frame(frame0, background=bg)
|
|
660
|
+
frame3.grid(column=0, row=2, sticky='EW')
|
|
661
|
+
Button(frame3, text='Prev Grammar', command=self._history_prev,
|
|
662
|
+
**self._BUTTON_PARAMS).pack(side='left')
|
|
663
|
+
Button(frame3, text='Next Grammar', command=self._history_next,
|
|
664
|
+
**self._BUTTON_PARAMS).pack(side='left')
|
|
665
|
+
|
|
666
|
+
# Help box
|
|
667
|
+
self.helpbox = Text(frame0, font=self._smallfont,
|
|
668
|
+
**self._HELPBOX_PARAMS)
|
|
669
|
+
self.helpbox.grid(column=3, row=1, sticky='NEWS')
|
|
670
|
+
self.helptabs = {}
|
|
671
|
+
bg = self._FRAME_PARAMS['background']
|
|
672
|
+
helptab_frame = Frame(frame0, background=bg)
|
|
673
|
+
helptab_frame.grid(column=3, row=0, sticky='SW')
|
|
674
|
+
for i, (tab, tabstops, text) in enumerate(self.HELP):
|
|
675
|
+
label = Label(helptab_frame, text=tab, font=self._smallfont)
|
|
676
|
+
label.grid(column=i*2, row=0, sticky='S')
|
|
677
|
+
#help_frame.grid_columnconfigure(i, weight=1)
|
|
678
|
+
#label.pack(side='left')
|
|
679
|
+
label.bind('<ButtonPress>', lambda e, tab=tab: self.show_help(tab))
|
|
680
|
+
self.helptabs[tab] = label
|
|
681
|
+
Frame(helptab_frame, height=1, width=self._HELPTAB_SPACER,
|
|
682
|
+
background=bg).grid(column=i*2+1, row=0)
|
|
683
|
+
self.helptabs[self.HELP[0][0]].configure(font=self._font)
|
|
684
|
+
self.helpbox.tag_config('elide', elide=True)
|
|
685
|
+
for (tag, params) in self.HELP_AUTOTAG:
|
|
686
|
+
self.helpbox.tag_config('tag-%s' % tag, **params)
|
|
687
|
+
self.show_help(self.HELP[0][0])
|
|
688
|
+
|
|
689
|
+
# Scroll bar for helpbox
|
|
690
|
+
help_scrollbar = Scrollbar(frame0, command=self.helpbox.yview)
|
|
691
|
+
self.helpbox.config(yscrollcommand=help_scrollbar.set)
|
|
692
|
+
help_scrollbar.grid(column=4, row=1, sticky='NWS')
|
|
693
|
+
|
|
694
|
+
# The dev set
|
|
695
|
+
frame4 = Frame(frame0, background=self._FRAME_PARAMS['background'])
|
|
696
|
+
self.devsetbox = Text(frame4, font=self._font,
|
|
697
|
+
**self._DEVSETBOX_PARAMS)
|
|
698
|
+
self.devsetbox.pack(expand=True, fill='both')
|
|
699
|
+
self.devsetlabel = Label(frame0, font=self._font,
|
|
700
|
+
text='Development Set:', justify='right',
|
|
701
|
+
background=self._DEVSETBOX_PARAMS['background'])
|
|
702
|
+
self.devsetlabel.grid(column=0, row=4, sticky='SW')
|
|
703
|
+
frame4.grid(column=0, row=5, sticky='NEWS')
|
|
704
|
+
|
|
705
|
+
# dev set scrollbars
|
|
706
|
+
self.devset_scroll = Scrollbar(frame0, command=self._devset_scroll)
|
|
707
|
+
self.devset_scroll.grid(column=1, row=5, sticky='NWS')
|
|
708
|
+
self.devset_xscroll = Scrollbar(frame4, command=self.devsetbox.xview,
|
|
709
|
+
orient='horiz')
|
|
710
|
+
self.devsetbox['xscrollcommand'] = self.devset_xscroll.set
|
|
711
|
+
self.devset_xscroll.pack(side='bottom', fill='x')
|
|
712
|
+
|
|
713
|
+
# dev set buttons
|
|
714
|
+
bg = self._FRAME_PARAMS['background']
|
|
715
|
+
frame1 = Frame(frame0, background=bg)
|
|
716
|
+
frame1.grid(column=0, row=7, sticky='EW')
|
|
717
|
+
Button(frame1, text='Prev Example (Ctrl-p)',
|
|
718
|
+
command=self._devset_prev,
|
|
719
|
+
**self._BUTTON_PARAMS).pack(side='left')
|
|
720
|
+
Button(frame1, text='Next Example (Ctrl-n)',
|
|
721
|
+
command=self._devset_next,
|
|
722
|
+
**self._BUTTON_PARAMS).pack(side='left')
|
|
723
|
+
self.devset_button = Button(frame1, text='Show example',
|
|
724
|
+
command=self.show_devset,
|
|
725
|
+
state='disabled',
|
|
726
|
+
**self._BUTTON_PARAMS)
|
|
727
|
+
self.devset_button.pack(side='right')
|
|
728
|
+
self.trace_button = Button(frame1, text='Show trace',
|
|
729
|
+
command=self.show_trace,
|
|
730
|
+
**self._BUTTON_PARAMS)
|
|
731
|
+
self.trace_button.pack(side='right')
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
# evaluation box
|
|
735
|
+
self.evalbox = Canvas(frame0, **self._EVALBOX_PARAMS)
|
|
736
|
+
label = Label(frame0, font=self._font, text='Evaluation:',
|
|
737
|
+
justify='right', background=self._EVALBOX_PARAMS['background'])
|
|
738
|
+
label.grid(column=3, row=4, sticky='SW')
|
|
739
|
+
self.evalbox.grid(column=3, row=5, sticky='NEWS', columnspan=2)
|
|
740
|
+
|
|
741
|
+
# evaluation box buttons
|
|
742
|
+
bg = self._FRAME_PARAMS['background']
|
|
743
|
+
frame2 = Frame(frame0, background=bg)
|
|
744
|
+
frame2.grid(column=3, row=7, sticky='EW')
|
|
745
|
+
self._autoscale = IntVar(self.top)
|
|
746
|
+
self._autoscale.set(False)
|
|
747
|
+
Checkbutton(frame2, variable=self._autoscale, command=self._eval_plot,
|
|
748
|
+
text='Zoom', **self._BUTTON_PARAMS).pack(side='left')
|
|
749
|
+
self._eval_lines = IntVar(self.top)
|
|
750
|
+
self._eval_lines.set(False)
|
|
751
|
+
Checkbutton(frame2, variable=self._eval_lines, command=self._eval_plot,
|
|
752
|
+
text='Lines', **self._BUTTON_PARAMS).pack(side='left')
|
|
753
|
+
Button(frame2, text='History',
|
|
754
|
+
**self._BUTTON_PARAMS).pack(side='right')
|
|
755
|
+
|
|
756
|
+
# The status label
|
|
757
|
+
self.status = Label(frame0, font=self._font, **self._STATUS_PARAMS)
|
|
758
|
+
self.status.grid(column=0, row=9, sticky='NEW', padx=3, pady=2,
|
|
759
|
+
columnspan=5)
|
|
760
|
+
|
|
761
|
+
# Help box & devset box can't be edited.
|
|
762
|
+
self.helpbox['state'] = 'disabled'
|
|
763
|
+
self.devsetbox['state'] = 'disabled'
|
|
764
|
+
|
|
765
|
+
# Spacers
|
|
766
|
+
bg = self._FRAME_PARAMS['background']
|
|
767
|
+
Frame(frame0, height=10, width=0, background=bg).grid(column=0, row=3)
|
|
768
|
+
Frame(frame0, height=0, width=10, background=bg).grid(column=2, row=0)
|
|
769
|
+
Frame(frame0, height=6, width=0, background=bg).grid(column=0, row=8)
|
|
770
|
+
|
|
771
|
+
# pack the frame.
|
|
772
|
+
frame0.pack(fill='both', expand=True)
|
|
773
|
+
|
|
774
|
+
# Set up colors for the devset box
|
|
775
|
+
self.devsetbox.tag_config('true-pos', background='#afa',
|
|
776
|
+
underline='True')
|
|
777
|
+
self.devsetbox.tag_config('false-neg', underline='True',
|
|
778
|
+
foreground='#800')
|
|
779
|
+
self.devsetbox.tag_config('false-pos', background='#faa')
|
|
780
|
+
self.devsetbox.tag_config('trace', foreground='#666', wrap='none')
|
|
781
|
+
self.devsetbox.tag_config('wrapindent', lmargin2=30, wrap='none')
|
|
782
|
+
self.devsetbox.tag_config('error', foreground='#800')
|
|
783
|
+
|
|
784
|
+
# And for the grammarbox
|
|
785
|
+
self.grammarbox.tag_config('error', background='#fec')
|
|
786
|
+
self.grammarbox.tag_config('comment', foreground='#840')
|
|
787
|
+
self.grammarbox.tag_config('angle', foreground='#00f')
|
|
788
|
+
self.grammarbox.tag_config('brace', foreground='#0a0')
|
|
789
|
+
self.grammarbox.tag_config('hangindent', lmargin1=0, lmargin2=40)
|
|
790
|
+
|
|
791
|
+
_showing_trace = False
|
|
792
|
+
def show_trace(self, *e):
|
|
793
|
+
self._showing_trace = True
|
|
794
|
+
self.trace_button['state'] = 'disabled'
|
|
795
|
+
self.devset_button['state'] = 'normal'
|
|
796
|
+
|
|
797
|
+
self.devsetbox['state'] = 'normal'
|
|
798
|
+
#self.devsetbox['wrap'] = 'none'
|
|
799
|
+
self.devsetbox.delete('1.0', 'end')
|
|
800
|
+
self.devsetlabel['text']='Development Set (%d/%d)' % (
|
|
801
|
+
(self.devset_index+1, self._devset_size.get()))
|
|
802
|
+
|
|
803
|
+
if self.chunker is None:
|
|
804
|
+
self.devsetbox.insert('1.0', 'Trace: waiting for a valid grammar.')
|
|
805
|
+
self.devsetbox.tag_add('error', '1.0', 'end')
|
|
806
|
+
return # can't do anything more
|
|
807
|
+
|
|
808
|
+
gold_tree = self.devset[self.devset_index]
|
|
809
|
+
rules = self.chunker.rules()
|
|
810
|
+
|
|
811
|
+
# Calculate the tag sequence
|
|
812
|
+
tagseq = '\t'
|
|
813
|
+
charnum = [1]
|
|
814
|
+
for wordnum, (word, pos) in enumerate(gold_tree.leaves()):
|
|
815
|
+
tagseq += '%s ' % pos
|
|
816
|
+
charnum.append(len(tagseq))
|
|
817
|
+
self.charnum = dict(((i, j), charnum[j])
|
|
818
|
+
for i in range(len(rules)+1)
|
|
819
|
+
for j in range(len(charnum)))
|
|
820
|
+
self.linenum = dict((i,i*2+2) for i in range(len(rules)+1))
|
|
821
|
+
|
|
822
|
+
for i in range(len(rules)+1):
|
|
823
|
+
if i == 0:
|
|
824
|
+
self.devsetbox.insert('end', 'Start:\n')
|
|
825
|
+
self.devsetbox.tag_add('trace', 'end -2c linestart', 'end -2c')
|
|
826
|
+
else:
|
|
827
|
+
self.devsetbox.insert('end', 'Apply %s:\n' % rules[i-1])
|
|
828
|
+
self.devsetbox.tag_add('trace', 'end -2c linestart', 'end -2c')
|
|
829
|
+
# Display the tag sequence.
|
|
830
|
+
self.devsetbox.insert('end', tagseq+'\n')
|
|
831
|
+
self.devsetbox.tag_add('wrapindent','end -2c linestart','end -2c')
|
|
832
|
+
# Run a partial parser, and extract gold & test chunks
|
|
833
|
+
chunker = RegexpChunkParser(rules[:i])
|
|
834
|
+
test_tree = self._chunkparse(gold_tree.leaves())
|
|
835
|
+
gold_chunks = self._chunks(gold_tree)
|
|
836
|
+
test_chunks = self._chunks(test_tree)
|
|
837
|
+
# Compare them.
|
|
838
|
+
for chunk in gold_chunks.intersection(test_chunks):
|
|
839
|
+
self._color_chunk(i, chunk, 'true-pos')
|
|
840
|
+
for chunk in gold_chunks - test_chunks:
|
|
841
|
+
self._color_chunk(i, chunk, 'false-neg')
|
|
842
|
+
for chunk in test_chunks - gold_chunks:
|
|
843
|
+
self._color_chunk(i, chunk, 'false-pos')
|
|
844
|
+
self.devsetbox.insert('end', 'Finished.\n')
|
|
845
|
+
self.devsetbox.tag_add('trace', 'end -2c linestart', 'end -2c')
|
|
846
|
+
|
|
847
|
+
# This is a hack, because the x-scrollbar isn't updating its
|
|
848
|
+
# position right -- I'm not sure what the underlying cause is
|
|
849
|
+
# though. (This is on OS X w/ python 2.5)
|
|
850
|
+
self.top.after(100, self.devset_xscroll.set, 0, .3)
|
|
851
|
+
|
|
852
|
+
def show_help(self, tab):
|
|
853
|
+
self.helpbox['state'] = 'normal'
|
|
854
|
+
self.helpbox.delete('1.0', 'end')
|
|
855
|
+
for (name, tabstops, text) in self.HELP:
|
|
856
|
+
if name == tab:
|
|
857
|
+
text = text.replace('<<TAGSET>>', '\n'.join(
|
|
858
|
+
('\t%s\t%s' % item for item in sorted(list(self.tagset.items()),
|
|
859
|
+
key=lambda t_w:re.match('\w+',t_w[0]) and (0,t_w[0]) or (1,t_w[0])))))
|
|
860
|
+
|
|
861
|
+
self.helptabs[name].config(**self._HELPTAB_FG_PARAMS)
|
|
862
|
+
self.helpbox.config(tabs=tabstops)
|
|
863
|
+
self.helpbox.insert('1.0', text+'\n'*20)
|
|
864
|
+
C = '1.0 + %d chars'
|
|
865
|
+
for (tag, params) in self.HELP_AUTOTAG:
|
|
866
|
+
pattern = '(?s)(<%s>)(.*?)(</%s>)' % (tag, tag)
|
|
867
|
+
for m in re.finditer(pattern, text):
|
|
868
|
+
self.helpbox.tag_add('elide',
|
|
869
|
+
C % m.start(1), C % m.end(1))
|
|
870
|
+
self.helpbox.tag_add('tag-%s' % tag,
|
|
871
|
+
C % m.start(2), C % m.end(2))
|
|
872
|
+
self.helpbox.tag_add('elide',
|
|
873
|
+
C % m.start(3), C % m.end(3))
|
|
874
|
+
else:
|
|
875
|
+
self.helptabs[name].config(**self._HELPTAB_BG_PARAMS)
|
|
876
|
+
self.helpbox['state'] = 'disabled'
|
|
877
|
+
|
|
878
|
+
def _history_prev(self, *e):
|
|
879
|
+
self._view_history(self._history_index-1)
|
|
880
|
+
return 'break'
|
|
881
|
+
|
|
882
|
+
def _history_next(self, *e):
|
|
883
|
+
self._view_history(self._history_index+1)
|
|
884
|
+
return 'break'
|
|
885
|
+
|
|
886
|
+
def _view_history(self, index):
|
|
887
|
+
# Bounds & sanity checking:
|
|
888
|
+
index = max(0, min(len(self._history)-1, index))
|
|
889
|
+
if not self._history: return
|
|
890
|
+
# Already viewing the requested history item?
|
|
891
|
+
if index == self._history_index:
|
|
892
|
+
return
|
|
893
|
+
# Show the requested grammar. It will get added to _history
|
|
894
|
+
# only if they edit it (causing self.update() to get run.)
|
|
895
|
+
self.grammarbox['state'] = 'normal'
|
|
896
|
+
self.grammarbox.delete('1.0', 'end')
|
|
897
|
+
self.grammarbox.insert('end', self._history[index][0])
|
|
898
|
+
self.grammarbox.mark_set('insert', '1.0')
|
|
899
|
+
self._history_index = index
|
|
900
|
+
self._syntax_highlight_grammar(self._history[index][0])
|
|
901
|
+
# Record the normalized grammar & regenerate the chunker.
|
|
902
|
+
self.normalized_grammar = self.normalize_grammar(
|
|
903
|
+
self._history[index][0])
|
|
904
|
+
if self.normalized_grammar:
|
|
905
|
+
rules = [RegexpChunkRule.fromstring(line)
|
|
906
|
+
for line in self.normalized_grammar.split('\n')]
|
|
907
|
+
else:
|
|
908
|
+
rules = []
|
|
909
|
+
self.chunker = RegexpChunkParser(rules)
|
|
910
|
+
# Show the score.
|
|
911
|
+
self._eval_plot()
|
|
912
|
+
# Update the devset box
|
|
913
|
+
self._highlight_devset()
|
|
914
|
+
if self._showing_trace: self.show_trace()
|
|
915
|
+
# Update the grammar label
|
|
916
|
+
if self._history_index < len(self._history)-1:
|
|
917
|
+
self.grammarlabel['text'] = 'Grammar %s/%s:' % (
|
|
918
|
+
self._history_index+1, len(self._history))
|
|
919
|
+
else:
|
|
920
|
+
self.grammarlabel['text'] = 'Grammar:'
|
|
921
|
+
|
|
922
|
+
def _devset_next(self, *e):
|
|
923
|
+
self._devset_scroll('scroll', 1, 'page')
|
|
924
|
+
return 'break'
|
|
925
|
+
|
|
926
|
+
def _devset_prev(self, *e):
|
|
927
|
+
self._devset_scroll('scroll', -1, 'page')
|
|
928
|
+
return 'break'
|
|
929
|
+
|
|
930
|
+
def destroy(self, *e):
|
|
931
|
+
if self.top is None: return
|
|
932
|
+
self.top.destroy()
|
|
933
|
+
self.top = None
|
|
934
|
+
|
|
935
|
+
def _devset_scroll(self, command, *args):
|
|
936
|
+
N = 1 # size of a page -- one sentence.
|
|
937
|
+
showing_trace = self._showing_trace
|
|
938
|
+
if command == 'scroll' and args[1].startswith('unit'):
|
|
939
|
+
self.show_devset(self.devset_index+int(args[0]))
|
|
940
|
+
elif command == 'scroll' and args[1].startswith('page'):
|
|
941
|
+
self.show_devset(self.devset_index+N*int(args[0]))
|
|
942
|
+
elif command == 'moveto':
|
|
943
|
+
self.show_devset(int(float(args[0])*self._devset_size.get()))
|
|
944
|
+
else:
|
|
945
|
+
assert 0, 'bad scroll command %s %s' % (command, args)
|
|
946
|
+
if showing_trace:
|
|
947
|
+
self.show_trace()
|
|
948
|
+
|
|
949
|
+
def show_devset(self, index=None):
|
|
950
|
+
if index is None: index = self.devset_index
|
|
951
|
+
|
|
952
|
+
# Bounds checking
|
|
953
|
+
index = min(max(0, index), self._devset_size.get()-1)
|
|
954
|
+
|
|
955
|
+
if index == self.devset_index and not self._showing_trace: return
|
|
956
|
+
self.devset_index = index
|
|
957
|
+
|
|
958
|
+
self._showing_trace = False
|
|
959
|
+
self.trace_button['state'] = 'normal'
|
|
960
|
+
self.devset_button['state'] = 'disabled'
|
|
961
|
+
|
|
962
|
+
# Clear the text box.
|
|
963
|
+
self.devsetbox['state'] = 'normal'
|
|
964
|
+
self.devsetbox['wrap'] = 'word'
|
|
965
|
+
self.devsetbox.delete('1.0', 'end')
|
|
966
|
+
self.devsetlabel['text']='Development Set (%d/%d)' % (
|
|
967
|
+
(self.devset_index+1, self._devset_size.get()))
|
|
968
|
+
|
|
969
|
+
# Add the sentences
|
|
970
|
+
sample = self.devset[self.devset_index:self.devset_index+1]
|
|
971
|
+
self.charnum = {}
|
|
972
|
+
self.linenum = {0:1}
|
|
973
|
+
for sentnum, sent in enumerate(sample):
|
|
974
|
+
linestr = ''
|
|
975
|
+
for wordnum, (word, pos) in enumerate(sent.leaves()):
|
|
976
|
+
self.charnum[sentnum, wordnum] = len(linestr)
|
|
977
|
+
linestr += '%s/%s ' % (word, pos)
|
|
978
|
+
self.charnum[sentnum, wordnum+1] = len(linestr)
|
|
979
|
+
self.devsetbox.insert('end', linestr[:-1]+'\n\n')
|
|
980
|
+
|
|
981
|
+
# Highlight chunks in the dev set
|
|
982
|
+
if self.chunker is not None:
|
|
983
|
+
self._highlight_devset()
|
|
984
|
+
self.devsetbox['state'] = 'disabled'
|
|
985
|
+
|
|
986
|
+
# Update the scrollbar
|
|
987
|
+
first = self.devset_index/self._devset_size.get()
|
|
988
|
+
last = (self.devset_index + 2) / self._devset_size.get()
|
|
989
|
+
self.devset_scroll.set(first, last)
|
|
990
|
+
|
|
991
|
+
def _chunks(self, tree):
|
|
992
|
+
chunks = set()
|
|
993
|
+
wordnum = 0
|
|
994
|
+
for child in tree:
|
|
995
|
+
if isinstance(child, Tree):
|
|
996
|
+
if child.label() == self._chunk_label:
|
|
997
|
+
chunks.add( (wordnum, wordnum+len(child)) )
|
|
998
|
+
wordnum += len(child)
|
|
999
|
+
else:
|
|
1000
|
+
wordnum += 1
|
|
1001
|
+
return chunks
|
|
1002
|
+
|
|
1003
|
+
def _syntax_highlight_grammar(self, grammar):
|
|
1004
|
+
if self.top is None: return
|
|
1005
|
+
self.grammarbox.tag_remove('comment', '1.0', 'end')
|
|
1006
|
+
self.grammarbox.tag_remove('angle', '1.0', 'end')
|
|
1007
|
+
self.grammarbox.tag_remove('brace', '1.0', 'end')
|
|
1008
|
+
self.grammarbox.tag_add('hangindent', '1.0', 'end')
|
|
1009
|
+
for lineno, line in enumerate(grammar.split('\n')):
|
|
1010
|
+
if not line.strip(): continue
|
|
1011
|
+
m = re.match(r'(\\.|[^#])*(#.*)?', line)
|
|
1012
|
+
comment_start = None
|
|
1013
|
+
if m.group(2):
|
|
1014
|
+
comment_start = m.start(2)
|
|
1015
|
+
s = '%d.%d' % (lineno+1, m.start(2))
|
|
1016
|
+
e = '%d.%d' % (lineno+1, m.end(2))
|
|
1017
|
+
self.grammarbox.tag_add('comment', s, e)
|
|
1018
|
+
for m in re.finditer('[<>{}]', line):
|
|
1019
|
+
if comment_start is not None and m.start() >= comment_start:
|
|
1020
|
+
break
|
|
1021
|
+
s = '%d.%d' % (lineno+1, m.start())
|
|
1022
|
+
e = '%d.%d' % (lineno+1, m.end())
|
|
1023
|
+
if m.group() in '<>':
|
|
1024
|
+
self.grammarbox.tag_add('angle', s, e)
|
|
1025
|
+
else:
|
|
1026
|
+
self.grammarbox.tag_add('brace', s, e)
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
def _grammarcheck(self, grammar):
|
|
1030
|
+
if self.top is None: return
|
|
1031
|
+
self.grammarbox.tag_remove('error', '1.0', 'end')
|
|
1032
|
+
self._grammarcheck_errs = []
|
|
1033
|
+
for lineno, line in enumerate(grammar.split('\n')):
|
|
1034
|
+
line = re.sub(r'((\\.|[^#])*)(#.*)?', r'\1', line)
|
|
1035
|
+
line = line.strip()
|
|
1036
|
+
if line:
|
|
1037
|
+
try:
|
|
1038
|
+
RegexpChunkRule.fromstring(line)
|
|
1039
|
+
except ValueError as e:
|
|
1040
|
+
self.grammarbox.tag_add('error', '%s.0' % (lineno+1),
|
|
1041
|
+
'%s.0 lineend' % (lineno+1))
|
|
1042
|
+
self.status['text'] = ''
|
|
1043
|
+
|
|
1044
|
+
def update(self, *event):
|
|
1045
|
+
# Record when update was called (for grammarcheck)
|
|
1046
|
+
if event:
|
|
1047
|
+
self._last_keypress = time.time()
|
|
1048
|
+
|
|
1049
|
+
# Read the grammar from the Text box.
|
|
1050
|
+
self.grammar = grammar = self.grammarbox.get('1.0', 'end')
|
|
1051
|
+
|
|
1052
|
+
# If the grammar hasn't changed, do nothing:
|
|
1053
|
+
normalized_grammar = self.normalize_grammar(grammar)
|
|
1054
|
+
if normalized_grammar == self.normalized_grammar:
|
|
1055
|
+
return
|
|
1056
|
+
else:
|
|
1057
|
+
self.normalized_grammar = normalized_grammar
|
|
1058
|
+
|
|
1059
|
+
# If the grammar has changed, and we're looking at history,
|
|
1060
|
+
# then stop looking at history.
|
|
1061
|
+
if self._history_index < len(self._history)-1:
|
|
1062
|
+
self.grammarlabel['text'] = 'Grammar:'
|
|
1063
|
+
|
|
1064
|
+
self._syntax_highlight_grammar(grammar)
|
|
1065
|
+
|
|
1066
|
+
# The grammar has changed; try parsing it. If it doesn't
|
|
1067
|
+
# parse, do nothing. (flag error location?)
|
|
1068
|
+
try:
|
|
1069
|
+
# Note: the normalized grammar has no blank lines.
|
|
1070
|
+
if normalized_grammar:
|
|
1071
|
+
rules = [RegexpChunkRule.fromstring(line)
|
|
1072
|
+
for line in normalized_grammar.split('\n')]
|
|
1073
|
+
else:
|
|
1074
|
+
rules = []
|
|
1075
|
+
except ValueError as e:
|
|
1076
|
+
# Use the un-normalized grammar for error highlighting.
|
|
1077
|
+
self._grammarcheck(grammar)
|
|
1078
|
+
self.chunker = None
|
|
1079
|
+
return
|
|
1080
|
+
|
|
1081
|
+
self.chunker = RegexpChunkParser(rules)
|
|
1082
|
+
self.grammarbox.tag_remove('error', '1.0', 'end')
|
|
1083
|
+
self.grammar_changed = time.time()
|
|
1084
|
+
# Display the results
|
|
1085
|
+
if self._showing_trace:
|
|
1086
|
+
self.show_trace()
|
|
1087
|
+
else:
|
|
1088
|
+
self._highlight_devset()
|
|
1089
|
+
# Start the eval demon
|
|
1090
|
+
if not self._eval_demon_running:
|
|
1091
|
+
self._eval_demon()
|
|
1092
|
+
|
|
1093
|
+
def _highlight_devset(self, sample=None):
|
|
1094
|
+
if sample is None:
|
|
1095
|
+
sample = self.devset[self.devset_index:self.devset_index+1]
|
|
1096
|
+
|
|
1097
|
+
self.devsetbox.tag_remove('true-pos', '1.0', 'end')
|
|
1098
|
+
self.devsetbox.tag_remove('false-neg', '1.0', 'end')
|
|
1099
|
+
self.devsetbox.tag_remove('false-pos', '1.0', 'end')
|
|
1100
|
+
|
|
1101
|
+
# Run the grammar on the test cases.
|
|
1102
|
+
for sentnum, gold_tree in enumerate(sample):
|
|
1103
|
+
# Run the chunk parser
|
|
1104
|
+
test_tree = self._chunkparse(gold_tree.leaves())
|
|
1105
|
+
# Extract gold & test chunks
|
|
1106
|
+
gold_chunks = self._chunks(gold_tree)
|
|
1107
|
+
test_chunks = self._chunks(test_tree)
|
|
1108
|
+
# Compare them.
|
|
1109
|
+
for chunk in gold_chunks.intersection(test_chunks):
|
|
1110
|
+
self._color_chunk(sentnum, chunk, 'true-pos')
|
|
1111
|
+
for chunk in gold_chunks - test_chunks:
|
|
1112
|
+
self._color_chunk(sentnum, chunk, 'false-neg')
|
|
1113
|
+
for chunk in test_chunks - gold_chunks:
|
|
1114
|
+
self._color_chunk(sentnum, chunk, 'false-pos')
|
|
1115
|
+
|
|
1116
|
+
def _chunkparse(self, words):
|
|
1117
|
+
try:
|
|
1118
|
+
return self.chunker.parse(words)
|
|
1119
|
+
except (ValueError, IndexError) as e:
|
|
1120
|
+
# There's an error somewhere in the grammar, but we're not sure
|
|
1121
|
+
# exactly where, so just mark the whole grammar as bad.
|
|
1122
|
+
# E.g., this is caused by: "({<NN>})"
|
|
1123
|
+
self.grammarbox.tag_add('error', '1.0', 'end')
|
|
1124
|
+
# Treat it as tagging nothing:
|
|
1125
|
+
return words
|
|
1126
|
+
|
|
1127
|
+
def _color_chunk(self, sentnum, chunk, tag):
|
|
1128
|
+
start, end = chunk
|
|
1129
|
+
self.devsetbox.tag_add(tag,
|
|
1130
|
+
'%s.%s' % (self.linenum[sentnum], self.charnum[sentnum, start]),
|
|
1131
|
+
'%s.%s' % (self.linenum[sentnum], self.charnum[sentnum, end]-1))
|
|
1132
|
+
|
|
1133
|
+
def reset(self):
|
|
1134
|
+
# Clear various variables
|
|
1135
|
+
self.chunker = None
|
|
1136
|
+
self.grammar = None
|
|
1137
|
+
self.normalized_grammar = None
|
|
1138
|
+
self.grammar_changed = 0
|
|
1139
|
+
self._history = []
|
|
1140
|
+
self._history_index = 0
|
|
1141
|
+
# Update the on-screen display.
|
|
1142
|
+
self.grammarbox.delete('1.0', 'end')
|
|
1143
|
+
self.show_devset(0)
|
|
1144
|
+
self.update()
|
|
1145
|
+
#self._eval_plot()
|
|
1146
|
+
|
|
1147
|
+
SAVE_GRAMMAR_TEMPLATE = (
|
|
1148
|
+
'# Regexp Chunk Parsing Grammar\n'
|
|
1149
|
+
'# Saved %(date)s\n'
|
|
1150
|
+
'#\n'
|
|
1151
|
+
'# Development set: %(devset)s\n'
|
|
1152
|
+
'# Precision: %(precision)s\n'
|
|
1153
|
+
'# Recall: %(recall)s\n'
|
|
1154
|
+
'# F-score: %(fscore)s\n\n'
|
|
1155
|
+
'%(grammar)s\n')
|
|
1156
|
+
|
|
1157
|
+
def save_grammar(self, filename=None):
|
|
1158
|
+
if not filename:
|
|
1159
|
+
ftypes = [('Chunk Gramamr', '.chunk'),
|
|
1160
|
+
('All files', '*')]
|
|
1161
|
+
filename = asksaveasfilename(filetypes=ftypes,
|
|
1162
|
+
defaultextension='.chunk')
|
|
1163
|
+
if not filename: return
|
|
1164
|
+
if (self._history and self.normalized_grammar ==
|
|
1165
|
+
self.normalize_grammar(self._history[-1][0])):
|
|
1166
|
+
precision, recall, fscore = ['%.2f%%' % (100*v) for v in
|
|
1167
|
+
self._history[-1][1:]]
|
|
1168
|
+
elif self.chunker is None:
|
|
1169
|
+
precision = recall = fscore = 'Grammar not well formed'
|
|
1170
|
+
else:
|
|
1171
|
+
precision = recall = fscore = 'Not finished evaluation yet'
|
|
1172
|
+
|
|
1173
|
+
with open(filename, 'w') as outfile:
|
|
1174
|
+
outfile.write(self.SAVE_GRAMMAR_TEMPLATE % dict(
|
|
1175
|
+
date=time.ctime(), devset=self.devset_name,
|
|
1176
|
+
precision=precision, recall=recall, fscore=fscore,
|
|
1177
|
+
grammar=self.grammar.strip()))
|
|
1178
|
+
|
|
1179
|
+
def load_grammar(self, filename=None):
|
|
1180
|
+
if not filename:
|
|
1181
|
+
ftypes = [('Chunk Gramamr', '.chunk'),
|
|
1182
|
+
('All files', '*')]
|
|
1183
|
+
filename = askopenfilename(filetypes=ftypes,
|
|
1184
|
+
defaultextension='.chunk')
|
|
1185
|
+
if not filename: return
|
|
1186
|
+
self.grammarbox.delete('1.0', 'end')
|
|
1187
|
+
self.update()
|
|
1188
|
+
with open(filename, 'r') as infile:
|
|
1189
|
+
grammar = infile.read()
|
|
1190
|
+
grammar = re.sub('^\# Regexp Chunk Parsing Grammar[\s\S]*'
|
|
1191
|
+
'F-score:.*\n', '', grammar).lstrip()
|
|
1192
|
+
self.grammarbox.insert('1.0', grammar)
|
|
1193
|
+
self.update()
|
|
1194
|
+
|
|
1195
|
+
def save_history(self, filename=None):
|
|
1196
|
+
if not filename:
|
|
1197
|
+
ftypes = [('Chunk Gramamr History', '.txt'),
|
|
1198
|
+
('All files', '*')]
|
|
1199
|
+
filename = asksaveasfilename(filetypes=ftypes,
|
|
1200
|
+
defaultextension='.txt')
|
|
1201
|
+
if not filename: return
|
|
1202
|
+
|
|
1203
|
+
with open(filename, 'w') as outfile:
|
|
1204
|
+
outfile.write('# Regexp Chunk Parsing Grammar History\n')
|
|
1205
|
+
outfile.write('# Saved %s\n' % time.ctime())
|
|
1206
|
+
outfile.write('# Development set: %s\n' % self.devset_name)
|
|
1207
|
+
for i, (g, p, r, f) in enumerate(self._history):
|
|
1208
|
+
hdr = ('Grammar %d/%d (precision=%.2f%%, recall=%.2f%%, '
|
|
1209
|
+
'fscore=%.2f%%)' % (i+1, len(self._history),
|
|
1210
|
+
p*100, r*100, f*100))
|
|
1211
|
+
outfile.write('\n%s\n' % hdr)
|
|
1212
|
+
outfile.write(''.join(' %s\n' % line for line in g.strip().split()))
|
|
1213
|
+
|
|
1214
|
+
if not (self._history and self.normalized_grammar ==
|
|
1215
|
+
self.normalize_grammar(self._history[-1][0])):
|
|
1216
|
+
if self.chunker is None:
|
|
1217
|
+
outfile.write('\nCurrent Grammar (not well-formed)\n')
|
|
1218
|
+
else:
|
|
1219
|
+
outfile.write('\nCurrent Grammar (not evaluated)\n')
|
|
1220
|
+
outfile.write(''.join(' %s\n' % line for line
|
|
1221
|
+
in self.grammar.strip().split()))
|
|
1222
|
+
|
|
1223
|
+
def about(self, *e):
|
|
1224
|
+
ABOUT = ("NLTK RegExp Chunk Parser Application\n"+
|
|
1225
|
+
"Written by Edward Loper")
|
|
1226
|
+
TITLE = 'About: Regular Expression Chunk Parser Application'
|
|
1227
|
+
try:
|
|
1228
|
+
from six.moves.tkinter_messagebox import Message
|
|
1229
|
+
Message(message=ABOUT, title=TITLE).show()
|
|
1230
|
+
except:
|
|
1231
|
+
ShowText(self.top, TITLE, ABOUT)
|
|
1232
|
+
|
|
1233
|
+
def set_devset_size(self, size=None):
|
|
1234
|
+
if size is not None: self._devset_size.set(size)
|
|
1235
|
+
self._devset_size.set(min(len(self.devset), self._devset_size.get()))
|
|
1236
|
+
self.show_devset(1)
|
|
1237
|
+
self.show_devset(0)
|
|
1238
|
+
# what about history? Evaluated at diff dev set sizes!
|
|
1239
|
+
|
|
1240
|
+
def resize(self, size=None):
|
|
1241
|
+
if size is not None: self._size.set(size)
|
|
1242
|
+
size = self._size.get()
|
|
1243
|
+
self._font.configure(size=-(abs(size)))
|
|
1244
|
+
self._smallfont.configure(size=min(-10, -(abs(size))*14//20))
|
|
1245
|
+
|
|
1246
|
+
def mainloop(self, *args, **kwargs):
|
|
1247
|
+
"""
|
|
1248
|
+
Enter the Tkinter mainloop. This function must be called if
|
|
1249
|
+
this demo is created from a non-interactive program (e.g.
|
|
1250
|
+
from a secript); otherwise, the demo will close as soon as
|
|
1251
|
+
the script completes.
|
|
1252
|
+
"""
|
|
1253
|
+
if in_idle(): return
|
|
1254
|
+
self.top.mainloop(*args, **kwargs)
|
|
1255
|
+
|
|
1256
|
+
def app():
|
|
1257
|
+
RegexpChunkApp().mainloop()
|
|
1258
|
+
|
|
1259
|
+
if __name__ == '__main__':
|
|
1260
|
+
app()
|
|
1261
|
+
|
|
1262
|
+
__all__ = ['app']
|