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,1257 +1,1258 @@
|
|
|
1
|
-
# Natural Language Toolkit: Discourse Representation Theory (DRT)
|
|
2
|
-
#
|
|
3
|
-
# Author: Dan Garrette <dhgarrette@gmail.com>
|
|
4
|
-
#
|
|
5
|
-
# Copyright (C) 2001-
|
|
6
|
-
# URL: <http://nltk.org/>
|
|
7
|
-
# For license information, see LICENSE.TXT
|
|
8
|
-
from __future__ import print_function, unicode_literals
|
|
9
|
-
|
|
10
|
-
import operator
|
|
11
|
-
from functools import reduce
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
from tkinter
|
|
29
|
-
from
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[(x,
|
|
58
|
-
[(
|
|
59
|
-
[(
|
|
60
|
-
[(DrtTokens.
|
|
61
|
-
[(DrtTokens.
|
|
62
|
-
[(
|
|
63
|
-
[(x,
|
|
64
|
-
[(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
self.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
self.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
Expression
|
|
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
|
-
:param
|
|
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
|
-
self.function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
self.
|
|
286
|
-
self.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
isinstance(cond.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
drs.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
new_cond_simp.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
'
|
|
424
|
-
|
|
425
|
-
['|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
sorted(
|
|
449
|
-
sorted(
|
|
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
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
self.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
self.
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
[
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
['
|
|
590
|
-
['
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
term
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
['
|
|
616
|
-
['
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
['
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
self
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
self.
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
self.
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
[func_line + '
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
if
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
r_cond.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
:param
|
|
930
|
-
:param
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
master
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
canvas
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
canvas.
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
self.
|
|
956
|
-
self.
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
:param
|
|
977
|
-
:param
|
|
978
|
-
:
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
:param
|
|
988
|
-
:param
|
|
989
|
-
:
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
self.
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
:param
|
|
1008
|
-
:param
|
|
1009
|
-
:
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
:param
|
|
1020
|
-
:param
|
|
1021
|
-
:param
|
|
1022
|
-
:
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
expression.
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
bottom
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
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
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
print(dexpr(r'([x],[
|
|
1197
|
-
print(dexpr(r'
|
|
1198
|
-
print(dexpr(r'\x.([],[
|
|
1199
|
-
print(dexpr(r'(
|
|
1200
|
-
print(dexpr(r'(([],[walks(x)])
|
|
1201
|
-
print(dexpr(r'([
|
|
1202
|
-
print(dexpr(r'([x],[
|
|
1203
|
-
print(dexpr(r'([
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
print(
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
print(
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
print(
|
|
1217
|
-
print(resolve_anaphora(dexpr(r'([
|
|
1218
|
-
print(resolve_anaphora(dexpr(r'(([x
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
dexpr(r"([],[
|
|
1223
|
-
dexpr(r"([x
|
|
1224
|
-
dexpr(r"([
|
|
1225
|
-
dexpr(r"
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
r'
|
|
1238
|
-
r'([
|
|
1239
|
-
r'([x],[
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
r'([x],[
|
|
1243
|
-
r'
|
|
1244
|
-
r'\x
|
|
1245
|
-
r'
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
r'([
|
|
1249
|
-
]
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
d.
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1
|
+
# Natural Language Toolkit: Discourse Representation Theory (DRT)
|
|
2
|
+
#
|
|
3
|
+
# Author: Dan Garrette <dhgarrette@gmail.com>
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2001-2018 NLTK Project
|
|
6
|
+
# URL: <http://nltk.org/>
|
|
7
|
+
# For license information, see LICENSE.TXT
|
|
8
|
+
from __future__ import print_function, unicode_literals
|
|
9
|
+
|
|
10
|
+
import operator
|
|
11
|
+
from functools import reduce
|
|
12
|
+
from itertools import chain
|
|
13
|
+
|
|
14
|
+
from six import string_types
|
|
15
|
+
|
|
16
|
+
from nltk.compat import python_2_unicode_compatible
|
|
17
|
+
from nltk.sem.logic import (APP, AbstractVariableExpression, AllExpression,
|
|
18
|
+
AndExpression, ApplicationExpression, BinaryExpression,
|
|
19
|
+
BooleanExpression, ConstantExpression, EqualityExpression,
|
|
20
|
+
EventVariableExpression, ExistsExpression, Expression,
|
|
21
|
+
FunctionVariableExpression, ImpExpression,
|
|
22
|
+
IndividualVariableExpression, LambdaExpression, Tokens,
|
|
23
|
+
LogicParser, NegatedExpression, OrExpression, Variable,
|
|
24
|
+
is_eventvar, is_funcvar, is_indvar, unique_variable)
|
|
25
|
+
|
|
26
|
+
# Import Tkinter-based modules if they are available
|
|
27
|
+
try:
|
|
28
|
+
from six.moves.tkinter import Canvas, Tk
|
|
29
|
+
from six.moves.tkinter_font import Font
|
|
30
|
+
from nltk.util import in_idle
|
|
31
|
+
|
|
32
|
+
except ImportError:
|
|
33
|
+
# No need to print a warning here, nltk.draw has already printed one.
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
class DrtTokens(Tokens):
|
|
37
|
+
DRS = 'DRS'
|
|
38
|
+
DRS_CONC = '+'
|
|
39
|
+
PRONOUN = 'PRO'
|
|
40
|
+
OPEN_BRACKET = '['
|
|
41
|
+
CLOSE_BRACKET = ']'
|
|
42
|
+
COLON = ':'
|
|
43
|
+
|
|
44
|
+
PUNCT = [DRS_CONC, OPEN_BRACKET, CLOSE_BRACKET, COLON]
|
|
45
|
+
|
|
46
|
+
SYMBOLS = Tokens.SYMBOLS + PUNCT
|
|
47
|
+
|
|
48
|
+
TOKENS = Tokens.TOKENS + [DRS] + PUNCT
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class DrtParser(LogicParser):
|
|
52
|
+
"""A lambda calculus expression parser."""
|
|
53
|
+
def __init__(self):
|
|
54
|
+
LogicParser.__init__(self)
|
|
55
|
+
|
|
56
|
+
self.operator_precedence = dict(
|
|
57
|
+
[(x,1) for x in DrtTokens.LAMBDA_LIST] + \
|
|
58
|
+
[(x,2) for x in DrtTokens.NOT_LIST] + \
|
|
59
|
+
[(APP,3)] + \
|
|
60
|
+
[(x,4) for x in DrtTokens.EQ_LIST+Tokens.NEQ_LIST] + \
|
|
61
|
+
[(DrtTokens.COLON,5)] + \
|
|
62
|
+
[(DrtTokens.DRS_CONC,6)] + \
|
|
63
|
+
[(x,7) for x in DrtTokens.OR_LIST] + \
|
|
64
|
+
[(x,8) for x in DrtTokens.IMP_LIST] + \
|
|
65
|
+
[(None,9)])
|
|
66
|
+
|
|
67
|
+
def get_all_symbols(self):
|
|
68
|
+
"""This method exists to be overridden"""
|
|
69
|
+
return DrtTokens.SYMBOLS
|
|
70
|
+
|
|
71
|
+
def isvariable(self, tok):
|
|
72
|
+
return tok not in DrtTokens.TOKENS
|
|
73
|
+
|
|
74
|
+
def handle(self, tok, context):
|
|
75
|
+
"""This method is intended to be overridden for logics that
|
|
76
|
+
use different operators or expressions"""
|
|
77
|
+
if tok in DrtTokens.NOT_LIST:
|
|
78
|
+
return self.handle_negation(tok, context)
|
|
79
|
+
|
|
80
|
+
elif tok in DrtTokens.LAMBDA_LIST:
|
|
81
|
+
return self.handle_lambda(tok, context)
|
|
82
|
+
|
|
83
|
+
elif tok == DrtTokens.OPEN:
|
|
84
|
+
if self.inRange(0) and self.token(0) == DrtTokens.OPEN_BRACKET:
|
|
85
|
+
return self.handle_DRS(tok, context)
|
|
86
|
+
else:
|
|
87
|
+
return self.handle_open(tok, context)
|
|
88
|
+
|
|
89
|
+
elif tok.upper() == DrtTokens.DRS:
|
|
90
|
+
self.assertNextToken(DrtTokens.OPEN)
|
|
91
|
+
return self.handle_DRS(tok, context)
|
|
92
|
+
|
|
93
|
+
elif self.isvariable(tok):
|
|
94
|
+
if self.inRange(0) and self.token(0) == DrtTokens.COLON:
|
|
95
|
+
return self.handle_prop(tok, context)
|
|
96
|
+
else:
|
|
97
|
+
return self.handle_variable(tok, context)
|
|
98
|
+
|
|
99
|
+
def make_NegatedExpression(self, expression):
|
|
100
|
+
return DrtNegatedExpression(expression)
|
|
101
|
+
|
|
102
|
+
def handle_DRS(self, tok, context):
|
|
103
|
+
# a DRS
|
|
104
|
+
refs = self.handle_refs()
|
|
105
|
+
if self.inRange(0) and self.token(0) == DrtTokens.COMMA: #if there is a comma (it's optional)
|
|
106
|
+
self.token() # swallow the comma
|
|
107
|
+
conds = self.handle_conds(context)
|
|
108
|
+
self.assertNextToken(DrtTokens.CLOSE)
|
|
109
|
+
return DRS(refs, conds, None)
|
|
110
|
+
|
|
111
|
+
def handle_refs(self):
|
|
112
|
+
self.assertNextToken(DrtTokens.OPEN_BRACKET)
|
|
113
|
+
refs = []
|
|
114
|
+
while self.inRange(0) and self.token(0) != DrtTokens.CLOSE_BRACKET:
|
|
115
|
+
# Support expressions like: DRS([x y],C) == DRS([x,y],C)
|
|
116
|
+
if refs and self.token(0) == DrtTokens.COMMA:
|
|
117
|
+
self.token() # swallow the comma
|
|
118
|
+
refs.append(self.get_next_token_variable('quantified'))
|
|
119
|
+
self.assertNextToken(DrtTokens.CLOSE_BRACKET)
|
|
120
|
+
return refs
|
|
121
|
+
|
|
122
|
+
def handle_conds(self, context):
|
|
123
|
+
self.assertNextToken(DrtTokens.OPEN_BRACKET)
|
|
124
|
+
conds = []
|
|
125
|
+
while self.inRange(0) and self.token(0) != DrtTokens.CLOSE_BRACKET:
|
|
126
|
+
# Support expressions like: DRS([x y],C) == DRS([x, y],C)
|
|
127
|
+
if conds and self.token(0) == DrtTokens.COMMA:
|
|
128
|
+
self.token() # swallow the comma
|
|
129
|
+
conds.append(self.process_next_expression(context))
|
|
130
|
+
self.assertNextToken(DrtTokens.CLOSE_BRACKET)
|
|
131
|
+
return conds
|
|
132
|
+
|
|
133
|
+
def handle_prop(self, tok, context):
|
|
134
|
+
variable = self.make_VariableExpression(tok)
|
|
135
|
+
self.assertNextToken(':')
|
|
136
|
+
drs = self.process_next_expression(DrtTokens.COLON)
|
|
137
|
+
return DrtProposition(variable, drs)
|
|
138
|
+
|
|
139
|
+
def make_EqualityExpression(self, first, second):
|
|
140
|
+
"""This method serves as a hook for other logic parsers that
|
|
141
|
+
have different equality expression classes"""
|
|
142
|
+
return DrtEqualityExpression(first, second)
|
|
143
|
+
|
|
144
|
+
def get_BooleanExpression_factory(self, tok):
|
|
145
|
+
"""This method serves as a hook for other logic parsers that
|
|
146
|
+
have different boolean operators"""
|
|
147
|
+
if tok == DrtTokens.DRS_CONC:
|
|
148
|
+
return lambda first, second: DrtConcatenation(first, second, None)
|
|
149
|
+
elif tok in DrtTokens.OR_LIST:
|
|
150
|
+
return DrtOrExpression
|
|
151
|
+
elif tok in DrtTokens.IMP_LIST:
|
|
152
|
+
def make_imp_expression(first, second):
|
|
153
|
+
if isinstance(first, DRS):
|
|
154
|
+
return DRS(first.refs, first.conds, second)
|
|
155
|
+
if isinstance(first, DrtConcatenation):
|
|
156
|
+
return DrtConcatenation(first.first, first.second, second)
|
|
157
|
+
raise Exception('Antecedent of implication must be a DRS')
|
|
158
|
+
return make_imp_expression
|
|
159
|
+
else:
|
|
160
|
+
return None
|
|
161
|
+
|
|
162
|
+
def make_BooleanExpression(self, factory, first, second):
|
|
163
|
+
return factory(first, second)
|
|
164
|
+
|
|
165
|
+
def make_ApplicationExpression(self, function, argument):
|
|
166
|
+
return DrtApplicationExpression(function, argument)
|
|
167
|
+
|
|
168
|
+
def make_VariableExpression(self, name):
|
|
169
|
+
return DrtVariableExpression(Variable(name))
|
|
170
|
+
|
|
171
|
+
def make_LambdaExpression(self, variables, term):
|
|
172
|
+
return DrtLambdaExpression(variables, term)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class DrtExpression(object):
|
|
176
|
+
"""
|
|
177
|
+
This is the base abstract DRT Expression from which every DRT
|
|
178
|
+
Expression extends.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
_drt_parser = DrtParser()
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
def fromstring(cls, s):
|
|
185
|
+
return cls._drt_parser.parse(s)
|
|
186
|
+
|
|
187
|
+
def applyto(self, other):
|
|
188
|
+
return DrtApplicationExpression(self, other)
|
|
189
|
+
|
|
190
|
+
def __neg__(self):
|
|
191
|
+
return DrtNegatedExpression(self)
|
|
192
|
+
|
|
193
|
+
def __and__(self, other):
|
|
194
|
+
raise NotImplementedError()
|
|
195
|
+
|
|
196
|
+
def __or__(self, other):
|
|
197
|
+
assert isinstance(other, DrtExpression)
|
|
198
|
+
return DrtOrExpression(self, other)
|
|
199
|
+
|
|
200
|
+
def __gt__(self, other):
|
|
201
|
+
assert isinstance(other, DrtExpression)
|
|
202
|
+
if isinstance(self, DRS):
|
|
203
|
+
return DRS(self.refs, self.conds, other)
|
|
204
|
+
if isinstance(self, DrtConcatenation):
|
|
205
|
+
return DrtConcatenation(self.first, self.second, other)
|
|
206
|
+
raise Exception('Antecedent of implication must be a DRS')
|
|
207
|
+
|
|
208
|
+
def equiv(self, other, prover=None):
|
|
209
|
+
"""
|
|
210
|
+
Check for logical equivalence.
|
|
211
|
+
Pass the expression (self <-> other) to the theorem prover.
|
|
212
|
+
If the prover says it is valid, then the self and other are equal.
|
|
213
|
+
|
|
214
|
+
:param other: an ``DrtExpression`` to check equality against
|
|
215
|
+
:param prover: a ``nltk.inference.api.Prover``
|
|
216
|
+
"""
|
|
217
|
+
assert isinstance(other, DrtExpression)
|
|
218
|
+
|
|
219
|
+
f1 = self.simplify().fol();
|
|
220
|
+
f2 = other.simplify().fol();
|
|
221
|
+
return f1.equiv(f2, prover)
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def type(self):
|
|
225
|
+
raise AttributeError("'%s' object has no attribute 'type'" %
|
|
226
|
+
self.__class__.__name__)
|
|
227
|
+
|
|
228
|
+
def typecheck(self, signature=None):
|
|
229
|
+
raise NotImplementedError()
|
|
230
|
+
|
|
231
|
+
def __add__(self, other):
|
|
232
|
+
return DrtConcatenation(self, other, None)
|
|
233
|
+
|
|
234
|
+
def get_refs(self, recursive=False):
|
|
235
|
+
"""
|
|
236
|
+
Return the set of discourse referents in this DRS.
|
|
237
|
+
:param recursive: bool Also find discourse referents in subterms?
|
|
238
|
+
:return: list of ``Variable`` objects
|
|
239
|
+
"""
|
|
240
|
+
raise NotImplementedError()
|
|
241
|
+
|
|
242
|
+
def is_pronoun_function(self):
|
|
243
|
+
""" Is self of the form "PRO(x)"? """
|
|
244
|
+
return isinstance(self, DrtApplicationExpression) and \
|
|
245
|
+
isinstance(self.function, DrtAbstractVariableExpression) and \
|
|
246
|
+
self.function.variable.name == DrtTokens.PRONOUN and \
|
|
247
|
+
isinstance(self.argument, DrtIndividualVariableExpression)
|
|
248
|
+
|
|
249
|
+
def make_EqualityExpression(self, first, second):
|
|
250
|
+
return DrtEqualityExpression(first, second)
|
|
251
|
+
|
|
252
|
+
def make_VariableExpression(self, variable):
|
|
253
|
+
return DrtVariableExpression(variable)
|
|
254
|
+
|
|
255
|
+
def resolve_anaphora(self):
|
|
256
|
+
return resolve_anaphora(self)
|
|
257
|
+
|
|
258
|
+
def eliminate_equality(self):
|
|
259
|
+
return self.visit_structured(lambda e: e.eliminate_equality(),
|
|
260
|
+
self.__class__)
|
|
261
|
+
|
|
262
|
+
def pretty_format(self):
|
|
263
|
+
"""
|
|
264
|
+
Draw the DRS
|
|
265
|
+
:return: the pretty print string
|
|
266
|
+
"""
|
|
267
|
+
return '\n'.join(self._pretty())
|
|
268
|
+
|
|
269
|
+
def pretty_print(self):
|
|
270
|
+
print(self.pretty_format())
|
|
271
|
+
|
|
272
|
+
def draw(self):
|
|
273
|
+
DrsDrawer(self).draw()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
@python_2_unicode_compatible
|
|
277
|
+
class DRS(DrtExpression, Expression):
|
|
278
|
+
"""A Discourse Representation Structure."""
|
|
279
|
+
def __init__(self, refs, conds, consequent=None):
|
|
280
|
+
"""
|
|
281
|
+
:param refs: list of ``DrtIndividualVariableExpression`` for the
|
|
282
|
+
discourse referents
|
|
283
|
+
:param conds: list of ``Expression`` for the conditions
|
|
284
|
+
"""
|
|
285
|
+
self.refs = refs
|
|
286
|
+
self.conds = conds
|
|
287
|
+
self.consequent = consequent
|
|
288
|
+
|
|
289
|
+
def replace(self, variable, expression, replace_bound=False, alpha_convert=True):
|
|
290
|
+
"""Replace all instances of variable v with expression E in self,
|
|
291
|
+
where v is free in self."""
|
|
292
|
+
if variable in self.refs:
|
|
293
|
+
#if a bound variable is the thing being replaced
|
|
294
|
+
if not replace_bound:
|
|
295
|
+
return self
|
|
296
|
+
else:
|
|
297
|
+
i = self.refs.index(variable)
|
|
298
|
+
if self.consequent:
|
|
299
|
+
consequent = self.consequent.replace(variable, expression, True, alpha_convert)
|
|
300
|
+
else:
|
|
301
|
+
consequent = None
|
|
302
|
+
return DRS(self.refs[:i]+[expression.variable]+self.refs[i+1:],
|
|
303
|
+
[cond.replace(variable, expression, True, alpha_convert)
|
|
304
|
+
for cond in self.conds],
|
|
305
|
+
consequent)
|
|
306
|
+
else:
|
|
307
|
+
if alpha_convert:
|
|
308
|
+
# any bound variable that appears in the expression must
|
|
309
|
+
# be alpha converted to avoid a conflict
|
|
310
|
+
for ref in (set(self.refs) & expression.free()):
|
|
311
|
+
newvar = unique_variable(ref)
|
|
312
|
+
newvarex = DrtVariableExpression(newvar)
|
|
313
|
+
i = self.refs.index(ref)
|
|
314
|
+
if self.consequent:
|
|
315
|
+
consequent = self.consequent.replace(ref, newvarex, True, alpha_convert)
|
|
316
|
+
else:
|
|
317
|
+
consequent = None
|
|
318
|
+
self = DRS(self.refs[:i]+[newvar]+self.refs[i+1:],
|
|
319
|
+
[cond.replace(ref, newvarex, True, alpha_convert)
|
|
320
|
+
for cond in self.conds],
|
|
321
|
+
consequent)
|
|
322
|
+
|
|
323
|
+
#replace in the conditions
|
|
324
|
+
if self.consequent:
|
|
325
|
+
consequent = self.consequent.replace(variable, expression, replace_bound, alpha_convert)
|
|
326
|
+
else:
|
|
327
|
+
consequent = None
|
|
328
|
+
return DRS(self.refs,
|
|
329
|
+
[cond.replace(variable, expression, replace_bound, alpha_convert)
|
|
330
|
+
for cond in self.conds],
|
|
331
|
+
consequent)
|
|
332
|
+
|
|
333
|
+
def free(self):
|
|
334
|
+
""":see: Expression.free()"""
|
|
335
|
+
conds_free = reduce(operator.or_, [c.free() for c in self.conds], set())
|
|
336
|
+
if self.consequent:
|
|
337
|
+
conds_free.update(self.consequent.free())
|
|
338
|
+
return conds_free - set(self.refs)
|
|
339
|
+
|
|
340
|
+
def get_refs(self, recursive=False):
|
|
341
|
+
""":see: AbstractExpression.get_refs()"""
|
|
342
|
+
if recursive:
|
|
343
|
+
conds_refs = self.refs + list(chain(*(c.get_refs(True) for c in self.conds)))
|
|
344
|
+
if self.consequent:
|
|
345
|
+
conds_refs.extend(self.consequent.get_refs(True))
|
|
346
|
+
return conds_refs
|
|
347
|
+
else:
|
|
348
|
+
return self.refs
|
|
349
|
+
|
|
350
|
+
def visit(self, function, combinator):
|
|
351
|
+
""":see: Expression.visit()"""
|
|
352
|
+
parts = list(map(function, self.conds))
|
|
353
|
+
if self.consequent:
|
|
354
|
+
parts.append(function(self.consequent))
|
|
355
|
+
return combinator(parts)
|
|
356
|
+
|
|
357
|
+
def visit_structured(self, function, combinator):
|
|
358
|
+
""":see: Expression.visit_structured()"""
|
|
359
|
+
consequent = (function(self.consequent) if self.consequent else None)
|
|
360
|
+
return combinator(self.refs, list(map(function, self.conds)), consequent)
|
|
361
|
+
|
|
362
|
+
def eliminate_equality(self):
|
|
363
|
+
drs = self
|
|
364
|
+
i = 0
|
|
365
|
+
while i < len(drs.conds):
|
|
366
|
+
cond = drs.conds[i]
|
|
367
|
+
if isinstance(cond, EqualityExpression) and \
|
|
368
|
+
isinstance(cond.first, AbstractVariableExpression) and \
|
|
369
|
+
isinstance(cond.second, AbstractVariableExpression):
|
|
370
|
+
drs = DRS(list(set(drs.refs)-set([cond.second.variable])),
|
|
371
|
+
drs.conds[:i]+drs.conds[i+1:],
|
|
372
|
+
drs.consequent)
|
|
373
|
+
if cond.second.variable != cond.first.variable:
|
|
374
|
+
drs = drs.replace(cond.second.variable, cond.first, False, False)
|
|
375
|
+
i = 0
|
|
376
|
+
i -= 1
|
|
377
|
+
i += 1
|
|
378
|
+
|
|
379
|
+
conds = []
|
|
380
|
+
for cond in drs.conds:
|
|
381
|
+
new_cond = cond.eliminate_equality()
|
|
382
|
+
new_cond_simp = new_cond.simplify()
|
|
383
|
+
if not isinstance(new_cond_simp, DRS) or \
|
|
384
|
+
new_cond_simp.refs or new_cond_simp.conds or \
|
|
385
|
+
new_cond_simp.consequent:
|
|
386
|
+
conds.append(new_cond)
|
|
387
|
+
|
|
388
|
+
consequent = (drs.consequent.eliminate_equality() if drs.consequent else None)
|
|
389
|
+
return DRS(drs.refs, conds, consequent)
|
|
390
|
+
|
|
391
|
+
def fol(self):
|
|
392
|
+
if self.consequent:
|
|
393
|
+
accum = None
|
|
394
|
+
if self.conds:
|
|
395
|
+
accum = reduce(AndExpression, [c.fol() for c in self.conds])
|
|
396
|
+
|
|
397
|
+
if accum:
|
|
398
|
+
accum = ImpExpression(accum, self.consequent.fol())
|
|
399
|
+
else:
|
|
400
|
+
accum = self.consequent.fol()
|
|
401
|
+
|
|
402
|
+
for ref in self.refs[::-1]:
|
|
403
|
+
accum = AllExpression(ref, accum)
|
|
404
|
+
|
|
405
|
+
return accum
|
|
406
|
+
|
|
407
|
+
else:
|
|
408
|
+
if not self.conds:
|
|
409
|
+
raise Exception("Cannot convert DRS with no conditions to FOL.")
|
|
410
|
+
accum = reduce(AndExpression, [c.fol() for c in self.conds])
|
|
411
|
+
for ref in map(Variable, self._order_ref_strings(self.refs)[::-1]):
|
|
412
|
+
accum = ExistsExpression(ref, accum)
|
|
413
|
+
return accum
|
|
414
|
+
|
|
415
|
+
def _pretty(self):
|
|
416
|
+
refs_line = ' '.join(self._order_ref_strings(self.refs))
|
|
417
|
+
|
|
418
|
+
cond_lines = [cond for cond_line in [filter(lambda s: s.strip(), cond._pretty())
|
|
419
|
+
for cond in self.conds]
|
|
420
|
+
for cond in cond_line]
|
|
421
|
+
length = max([len(refs_line)] + list(map(len, cond_lines)))
|
|
422
|
+
drs = ([' _' + '_' * length + '_ ',
|
|
423
|
+
'| ' + refs_line.ljust(length) + ' |',
|
|
424
|
+
'|-' + '-' * length + '-|'] +
|
|
425
|
+
['| ' + line.ljust(length) + ' |' for line in cond_lines] +
|
|
426
|
+
['|_' + '_' * length + '_|'])
|
|
427
|
+
if self.consequent:
|
|
428
|
+
return DrtBinaryExpression._assemble_pretty(drs, DrtTokens.IMP,
|
|
429
|
+
self.consequent._pretty())
|
|
430
|
+
return drs
|
|
431
|
+
|
|
432
|
+
def _order_ref_strings(self, refs):
|
|
433
|
+
strings = ["%s" % ref for ref in refs]
|
|
434
|
+
ind_vars = []
|
|
435
|
+
func_vars = []
|
|
436
|
+
event_vars = []
|
|
437
|
+
other_vars = []
|
|
438
|
+
for s in strings:
|
|
439
|
+
if is_indvar(s):
|
|
440
|
+
ind_vars.append(s)
|
|
441
|
+
elif is_funcvar(s):
|
|
442
|
+
func_vars.append(s)
|
|
443
|
+
elif is_eventvar(s):
|
|
444
|
+
event_vars.append(s)
|
|
445
|
+
else:
|
|
446
|
+
other_vars.append(s)
|
|
447
|
+
return sorted(other_vars) + \
|
|
448
|
+
sorted(event_vars, key=lambda v: int([v[2:],-1][len(v[2:]) == 0])) + \
|
|
449
|
+
sorted(func_vars, key=lambda v: (v[0], int([v[1:],-1][len(v[1:])==0]))) + \
|
|
450
|
+
sorted(ind_vars, key=lambda v: (v[0], int([v[1:],-1][len(v[1:])==0])))
|
|
451
|
+
|
|
452
|
+
def __eq__(self, other):
|
|
453
|
+
r"""Defines equality modulo alphabetic variance.
|
|
454
|
+
If we are comparing \x.M and \y.N, then check equality of M and N[x/y]."""
|
|
455
|
+
if isinstance(other, DRS):
|
|
456
|
+
if len(self.refs) == len(other.refs):
|
|
457
|
+
converted_other = other
|
|
458
|
+
for (r1, r2) in zip(self.refs, converted_other.refs):
|
|
459
|
+
varex = self.make_VariableExpression(r1)
|
|
460
|
+
converted_other = converted_other.replace(r2, varex, True)
|
|
461
|
+
if self.consequent == converted_other.consequent and \
|
|
462
|
+
len(self.conds) == len(converted_other.conds):
|
|
463
|
+
for c1, c2 in zip(self.conds, converted_other.conds):
|
|
464
|
+
if not (c1 == c2):
|
|
465
|
+
return False
|
|
466
|
+
return True
|
|
467
|
+
return False
|
|
468
|
+
|
|
469
|
+
def __ne__(self, other):
|
|
470
|
+
return not self == other
|
|
471
|
+
|
|
472
|
+
__hash__ = Expression.__hash__
|
|
473
|
+
|
|
474
|
+
def __str__(self):
|
|
475
|
+
drs = '([%s],[%s])' % (','.join(self._order_ref_strings(self.refs)),
|
|
476
|
+
', '.join("%s" % cond for cond in self.conds)) # map(str, self.conds)))
|
|
477
|
+
if self.consequent:
|
|
478
|
+
return DrtTokens.OPEN + drs + ' ' + DrtTokens.IMP + ' ' + \
|
|
479
|
+
"%s" % self.consequent + DrtTokens.CLOSE
|
|
480
|
+
return drs
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def DrtVariableExpression(variable):
|
|
484
|
+
"""
|
|
485
|
+
This is a factory method that instantiates and returns a subtype of
|
|
486
|
+
``DrtAbstractVariableExpression`` appropriate for the given variable.
|
|
487
|
+
"""
|
|
488
|
+
if is_indvar(variable.name):
|
|
489
|
+
return DrtIndividualVariableExpression(variable)
|
|
490
|
+
elif is_funcvar(variable.name):
|
|
491
|
+
return DrtFunctionVariableExpression(variable)
|
|
492
|
+
elif is_eventvar(variable.name):
|
|
493
|
+
return DrtEventVariableExpression(variable)
|
|
494
|
+
else:
|
|
495
|
+
return DrtConstantExpression(variable)
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
class DrtAbstractVariableExpression(DrtExpression, AbstractVariableExpression):
|
|
499
|
+
def fol(self):
|
|
500
|
+
return self
|
|
501
|
+
|
|
502
|
+
def get_refs(self, recursive=False):
|
|
503
|
+
""":see: AbstractExpression.get_refs()"""
|
|
504
|
+
return []
|
|
505
|
+
|
|
506
|
+
def _pretty(self):
|
|
507
|
+
s = "%s" % self
|
|
508
|
+
blank = ' '*len(s)
|
|
509
|
+
return [blank, blank, s, blank]
|
|
510
|
+
|
|
511
|
+
def eliminate_equality(self):
|
|
512
|
+
return self
|
|
513
|
+
|
|
514
|
+
class DrtIndividualVariableExpression(DrtAbstractVariableExpression, IndividualVariableExpression):
|
|
515
|
+
pass
|
|
516
|
+
|
|
517
|
+
class DrtFunctionVariableExpression(DrtAbstractVariableExpression, FunctionVariableExpression):
|
|
518
|
+
pass
|
|
519
|
+
|
|
520
|
+
class DrtEventVariableExpression(DrtIndividualVariableExpression, EventVariableExpression):
|
|
521
|
+
pass
|
|
522
|
+
|
|
523
|
+
class DrtConstantExpression(DrtAbstractVariableExpression, ConstantExpression):
|
|
524
|
+
pass
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
@python_2_unicode_compatible
|
|
528
|
+
class DrtProposition(DrtExpression, Expression):
|
|
529
|
+
def __init__(self, variable, drs):
|
|
530
|
+
self.variable = variable
|
|
531
|
+
self.drs = drs
|
|
532
|
+
|
|
533
|
+
def replace(self, variable, expression, replace_bound=False, alpha_convert=True):
|
|
534
|
+
if self.variable == variable:
|
|
535
|
+
assert isinstance(expression, DrtAbstractVariableExpression), "Can only replace a proposition label with a variable"
|
|
536
|
+
return DrtProposition(expression.variable, self.drs.replace(variable, expression, replace_bound, alpha_convert))
|
|
537
|
+
else:
|
|
538
|
+
return DrtProposition(self.variable, self.drs.replace(variable, expression, replace_bound, alpha_convert))
|
|
539
|
+
|
|
540
|
+
def eliminate_equality(self):
|
|
541
|
+
return DrtProposition(self.variable, self.drs.eliminate_equality())
|
|
542
|
+
|
|
543
|
+
def get_refs(self, recursive=False):
|
|
544
|
+
return (self.drs.get_refs(True) if recursive else [])
|
|
545
|
+
|
|
546
|
+
def __eq__(self, other):
|
|
547
|
+
return self.__class__ == other.__class__ and \
|
|
548
|
+
self.variable == other.variable and \
|
|
549
|
+
self.drs == other.drs
|
|
550
|
+
|
|
551
|
+
def __ne__(self, other):
|
|
552
|
+
return not self == other
|
|
553
|
+
|
|
554
|
+
__hash__ = Expression.__hash__
|
|
555
|
+
|
|
556
|
+
def fol(self):
|
|
557
|
+
return self.drs.fol()
|
|
558
|
+
|
|
559
|
+
def _pretty(self):
|
|
560
|
+
drs_s = self.drs._pretty()
|
|
561
|
+
blank = ' ' * len("%s" % self.variable)
|
|
562
|
+
return ([blank + ' ' + line for line in drs_s[:1]] +
|
|
563
|
+
["%s" % self.variable + ':' + line for line in drs_s[1:2]] +
|
|
564
|
+
[blank + ' ' + line for line in drs_s[2:]])
|
|
565
|
+
|
|
566
|
+
def visit(self, function, combinator):
|
|
567
|
+
""":see: Expression.visit()"""
|
|
568
|
+
return combinator([function(self.drs)])
|
|
569
|
+
|
|
570
|
+
def visit_structured(self, function, combinator):
|
|
571
|
+
""":see: Expression.visit_structured()"""
|
|
572
|
+
return combinator(self.variable, function(self.drs))
|
|
573
|
+
|
|
574
|
+
def __str__(self):
|
|
575
|
+
return 'prop(%s, %s)' % (self.variable, self.drs)
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
class DrtNegatedExpression(DrtExpression, NegatedExpression):
|
|
579
|
+
def fol(self):
|
|
580
|
+
return NegatedExpression(self.term.fol())
|
|
581
|
+
|
|
582
|
+
def get_refs(self, recursive=False):
|
|
583
|
+
""":see: AbstractExpression.get_refs()"""
|
|
584
|
+
return self.term.get_refs(recursive)
|
|
585
|
+
|
|
586
|
+
def _pretty(self):
|
|
587
|
+
term_lines = self.term._pretty()
|
|
588
|
+
return ([' ' + line for line in term_lines[:2]] +
|
|
589
|
+
['__ ' + line for line in term_lines[2:3]] +
|
|
590
|
+
[' | ' + line for line in term_lines[3:4]] +
|
|
591
|
+
[' ' + line for line in term_lines[4:]])
|
|
592
|
+
|
|
593
|
+
class DrtLambdaExpression(DrtExpression, LambdaExpression):
|
|
594
|
+
def alpha_convert(self, newvar):
|
|
595
|
+
"""Rename all occurrences of the variable introduced by this variable
|
|
596
|
+
binder in the expression to ``newvar``.
|
|
597
|
+
:param newvar: ``Variable``, for the new variable
|
|
598
|
+
"""
|
|
599
|
+
return self.__class__(newvar, self.term.replace(self.variable,
|
|
600
|
+
DrtVariableExpression(newvar), True))
|
|
601
|
+
|
|
602
|
+
def fol(self):
|
|
603
|
+
return LambdaExpression(self.variable, self.term.fol())
|
|
604
|
+
|
|
605
|
+
def _pretty(self):
|
|
606
|
+
variables = [self.variable]
|
|
607
|
+
term = self.term
|
|
608
|
+
while term.__class__ == self.__class__:
|
|
609
|
+
variables.append(term.variable)
|
|
610
|
+
term = term.term
|
|
611
|
+
var_string = ' '.join("%s" % v for v in variables) + DrtTokens.DOT
|
|
612
|
+
term_lines = term._pretty()
|
|
613
|
+
blank = ' ' * len(var_string)
|
|
614
|
+
return ([' ' + blank + line for line in term_lines[:1]] +
|
|
615
|
+
[' \ ' + blank + line for line in term_lines[1:2]] +
|
|
616
|
+
[' /\ ' + var_string + line for line in term_lines[2:3]] +
|
|
617
|
+
[' ' + blank + line for line in term_lines[3:]])
|
|
618
|
+
|
|
619
|
+
class DrtBinaryExpression(DrtExpression, BinaryExpression):
|
|
620
|
+
def get_refs(self, recursive=False):
|
|
621
|
+
""":see: AbstractExpression.get_refs()"""
|
|
622
|
+
return self.first.get_refs(True) + self.second.get_refs(True) if recursive else []
|
|
623
|
+
|
|
624
|
+
def _pretty(self):
|
|
625
|
+
return DrtBinaryExpression._assemble_pretty(self._pretty_subex(self.first), self.getOp(), self._pretty_subex(self.second))
|
|
626
|
+
|
|
627
|
+
@staticmethod
|
|
628
|
+
def _assemble_pretty(first_lines, op, second_lines):
|
|
629
|
+
max_lines = max(len(first_lines), len(second_lines))
|
|
630
|
+
first_lines = _pad_vertically(first_lines, max_lines)
|
|
631
|
+
second_lines = _pad_vertically(second_lines, max_lines)
|
|
632
|
+
blank = ' ' * len(op)
|
|
633
|
+
first_second_lines = list(zip(first_lines, second_lines))
|
|
634
|
+
return ([' ' + first_line + ' ' + blank + ' ' + second_line + ' ' for first_line, second_line in first_second_lines[:2]] +
|
|
635
|
+
['(' + first_line + ' ' + op + ' ' + second_line + ')' for first_line, second_line in first_second_lines[2:3]] +
|
|
636
|
+
[' ' + first_line + ' ' + blank + ' ' + second_line + ' ' for first_line, second_line in first_second_lines[3:]])
|
|
637
|
+
|
|
638
|
+
def _pretty_subex(self, subex):
|
|
639
|
+
return subex._pretty()
|
|
640
|
+
|
|
641
|
+
class DrtBooleanExpression(DrtBinaryExpression, BooleanExpression):
|
|
642
|
+
pass
|
|
643
|
+
|
|
644
|
+
class DrtOrExpression(DrtBooleanExpression, OrExpression):
|
|
645
|
+
def fol(self):
|
|
646
|
+
return OrExpression(self.first.fol(), self.second.fol())
|
|
647
|
+
|
|
648
|
+
def _pretty_subex(self, subex):
|
|
649
|
+
if isinstance(subex, DrtOrExpression):
|
|
650
|
+
return [line[1:-1] for line in subex._pretty()]
|
|
651
|
+
return DrtBooleanExpression._pretty_subex(self, subex)
|
|
652
|
+
|
|
653
|
+
class DrtEqualityExpression(DrtBinaryExpression, EqualityExpression):
|
|
654
|
+
def fol(self):
|
|
655
|
+
return EqualityExpression(self.first.fol(), self.second.fol())
|
|
656
|
+
|
|
657
|
+
@python_2_unicode_compatible
|
|
658
|
+
class DrtConcatenation(DrtBooleanExpression):
|
|
659
|
+
"""DRS of the form '(DRS + DRS)'"""
|
|
660
|
+
def __init__(self, first, second, consequent=None):
|
|
661
|
+
DrtBooleanExpression.__init__(self, first, second)
|
|
662
|
+
self.consequent = consequent
|
|
663
|
+
|
|
664
|
+
def replace(self, variable, expression, replace_bound=False, alpha_convert=True):
|
|
665
|
+
"""Replace all instances of variable v with expression E in self,
|
|
666
|
+
where v is free in self."""
|
|
667
|
+
first = self.first
|
|
668
|
+
second = self.second
|
|
669
|
+
consequent = self.consequent
|
|
670
|
+
|
|
671
|
+
# If variable is bound
|
|
672
|
+
if variable in self.get_refs():
|
|
673
|
+
if replace_bound:
|
|
674
|
+
first = first.replace(variable, expression, replace_bound, alpha_convert)
|
|
675
|
+
second = second.replace(variable, expression, replace_bound, alpha_convert)
|
|
676
|
+
if consequent:
|
|
677
|
+
consequent = consequent.replace(variable, expression, replace_bound, alpha_convert)
|
|
678
|
+
else:
|
|
679
|
+
if alpha_convert:
|
|
680
|
+
# alpha convert every ref that is free in 'expression'
|
|
681
|
+
for ref in (set(self.get_refs(True)) & expression.free()):
|
|
682
|
+
v = DrtVariableExpression(unique_variable(ref))
|
|
683
|
+
first = first.replace(ref, v, True, alpha_convert)
|
|
684
|
+
second = second.replace(ref, v, True, alpha_convert)
|
|
685
|
+
if consequent:
|
|
686
|
+
consequent = consequent.replace(ref, v, True, alpha_convert)
|
|
687
|
+
|
|
688
|
+
first = first.replace(variable, expression, replace_bound, alpha_convert)
|
|
689
|
+
second = second.replace(variable, expression, replace_bound, alpha_convert)
|
|
690
|
+
if consequent:
|
|
691
|
+
consequent = consequent.replace(variable, expression, replace_bound, alpha_convert)
|
|
692
|
+
|
|
693
|
+
return self.__class__(first, second, consequent)
|
|
694
|
+
|
|
695
|
+
def eliminate_equality(self):
|
|
696
|
+
#TODO: at some point. for now, simplify.
|
|
697
|
+
drs = self.simplify()
|
|
698
|
+
assert not isinstance(drs, DrtConcatenation)
|
|
699
|
+
return drs.eliminate_equality()
|
|
700
|
+
|
|
701
|
+
def simplify(self):
|
|
702
|
+
first = self.first.simplify()
|
|
703
|
+
second = self.second.simplify()
|
|
704
|
+
consequent = (self.consequent.simplify() if self.consequent else None)
|
|
705
|
+
|
|
706
|
+
if isinstance(first, DRS) and isinstance(second, DRS):
|
|
707
|
+
# For any ref that is in both 'first' and 'second'
|
|
708
|
+
for ref in (set(first.get_refs(True)) & set(second.get_refs(True))):
|
|
709
|
+
# alpha convert the ref in 'second' to prevent collision
|
|
710
|
+
newvar = DrtVariableExpression(unique_variable(ref))
|
|
711
|
+
second = second.replace(ref, newvar, True)
|
|
712
|
+
|
|
713
|
+
return DRS(first.refs + second.refs, first.conds + second.conds, consequent)
|
|
714
|
+
else:
|
|
715
|
+
return self.__class__(first, second, consequent)
|
|
716
|
+
|
|
717
|
+
def get_refs(self, recursive=False):
|
|
718
|
+
""":see: AbstractExpression.get_refs()"""
|
|
719
|
+
refs = self.first.get_refs(recursive) + self.second.get_refs(recursive)
|
|
720
|
+
if self.consequent and recursive:
|
|
721
|
+
refs.extend(self.consequent.get_refs(True))
|
|
722
|
+
return refs
|
|
723
|
+
|
|
724
|
+
def getOp(self):
|
|
725
|
+
return DrtTokens.DRS_CONC
|
|
726
|
+
|
|
727
|
+
def __eq__(self, other):
|
|
728
|
+
r"""Defines equality modulo alphabetic variance.
|
|
729
|
+
If we are comparing \x.M and \y.N, then check equality of M and N[x/y]."""
|
|
730
|
+
if isinstance(other, DrtConcatenation):
|
|
731
|
+
self_refs = self.get_refs()
|
|
732
|
+
other_refs = other.get_refs()
|
|
733
|
+
if len(self_refs) == len(other_refs):
|
|
734
|
+
converted_other = other
|
|
735
|
+
for (r1,r2) in zip(self_refs, other_refs):
|
|
736
|
+
varex = self.make_VariableExpression(r1)
|
|
737
|
+
converted_other = converted_other.replace(r2, varex, True)
|
|
738
|
+
return self.first == converted_other.first and \
|
|
739
|
+
self.second == converted_other.second and \
|
|
740
|
+
self.consequent == converted_other.consequent
|
|
741
|
+
return False
|
|
742
|
+
|
|
743
|
+
def __ne__(self, other):
|
|
744
|
+
return not self == other
|
|
745
|
+
|
|
746
|
+
__hash__ = DrtBooleanExpression.__hash__
|
|
747
|
+
|
|
748
|
+
def fol(self):
|
|
749
|
+
e = AndExpression(self.first.fol(), self.second.fol())
|
|
750
|
+
if self.consequent:
|
|
751
|
+
e = ImpExpression(e, self.consequent.fol())
|
|
752
|
+
return e
|
|
753
|
+
|
|
754
|
+
def _pretty(self):
|
|
755
|
+
drs = DrtBinaryExpression._assemble_pretty(self._pretty_subex(self.first),
|
|
756
|
+
self.getOp(),
|
|
757
|
+
self._pretty_subex(self.second))
|
|
758
|
+
if self.consequent:
|
|
759
|
+
drs = DrtBinaryExpression._assemble_pretty(drs, DrtTokens.IMP,
|
|
760
|
+
self._pretty(self.consequent))
|
|
761
|
+
return drs
|
|
762
|
+
|
|
763
|
+
def _pretty_subex(self, subex):
|
|
764
|
+
if isinstance(subex, DrtConcatenation):
|
|
765
|
+
return [line[1:-1] for line in subex._pretty()]
|
|
766
|
+
return DrtBooleanExpression._pretty_subex(self, subex)
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
def visit(self, function, combinator):
|
|
770
|
+
""":see: Expression.visit()"""
|
|
771
|
+
if self.consequent:
|
|
772
|
+
return combinator([function(self.first), function(self.second), function(self.consequent)])
|
|
773
|
+
else:
|
|
774
|
+
return combinator([function(self.first), function(self.second)])
|
|
775
|
+
|
|
776
|
+
def __str__(self):
|
|
777
|
+
first = self._str_subex(self.first)
|
|
778
|
+
second = self._str_subex(self.second)
|
|
779
|
+
drs = Tokens.OPEN + first + ' ' + self.getOp() \
|
|
780
|
+
+ ' ' + second + Tokens.CLOSE
|
|
781
|
+
if self.consequent:
|
|
782
|
+
return DrtTokens.OPEN + drs + ' ' + DrtTokens.IMP + ' ' + \
|
|
783
|
+
"%s" % self.consequent + DrtTokens.CLOSE
|
|
784
|
+
return drs
|
|
785
|
+
|
|
786
|
+
def _str_subex(self, subex):
|
|
787
|
+
s = "%s" % subex
|
|
788
|
+
if isinstance(subex, DrtConcatenation) and subex.consequent is None:
|
|
789
|
+
return s[1:-1]
|
|
790
|
+
return s
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
class DrtApplicationExpression(DrtExpression, ApplicationExpression):
|
|
794
|
+
def fol(self):
|
|
795
|
+
return ApplicationExpression(self.function.fol(), self.argument.fol())
|
|
796
|
+
|
|
797
|
+
def get_refs(self, recursive=False):
|
|
798
|
+
""":see: AbstractExpression.get_refs()"""
|
|
799
|
+
return (self.function.get_refs(True) + self.argument.get_refs(True)
|
|
800
|
+
if recursive else [])
|
|
801
|
+
|
|
802
|
+
def _pretty(self):
|
|
803
|
+
function, args = self.uncurry()
|
|
804
|
+
function_lines = function._pretty()
|
|
805
|
+
args_lines = [arg._pretty() for arg in args]
|
|
806
|
+
max_lines = max(map(len, [function_lines] + args_lines))
|
|
807
|
+
function_lines = _pad_vertically(function_lines, max_lines)
|
|
808
|
+
args_lines = [_pad_vertically(arg_lines, max_lines) for arg_lines in args_lines]
|
|
809
|
+
func_args_lines = list(zip(function_lines, list(zip(*args_lines))))
|
|
810
|
+
return ([func_line + ' ' + ' '.join(args_line) + ' ' for func_line, args_line in func_args_lines[:2]] +
|
|
811
|
+
[func_line + '(' + ','.join(args_line) + ')' for func_line, args_line in func_args_lines[2:3]] +
|
|
812
|
+
[func_line + ' ' + ' '.join(args_line) + ' ' for func_line, args_line in func_args_lines[3:]])
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
def _pad_vertically(lines, max_lines):
|
|
816
|
+
pad_line = [' ' * len(lines[0])]
|
|
817
|
+
return lines + pad_line * (max_lines - len(lines))
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
@python_2_unicode_compatible
|
|
821
|
+
class PossibleAntecedents(list, DrtExpression, Expression):
|
|
822
|
+
def free(self):
|
|
823
|
+
"""Set of free variables."""
|
|
824
|
+
return set(self)
|
|
825
|
+
|
|
826
|
+
def replace(self, variable, expression, replace_bound=False, alpha_convert=True):
|
|
827
|
+
"""Replace all instances of variable v with expression E in self,
|
|
828
|
+
where v is free in self."""
|
|
829
|
+
result = PossibleAntecedents()
|
|
830
|
+
for item in self:
|
|
831
|
+
if item == variable:
|
|
832
|
+
self.append(expression)
|
|
833
|
+
else:
|
|
834
|
+
self.append(item)
|
|
835
|
+
return result
|
|
836
|
+
|
|
837
|
+
def _pretty(self):
|
|
838
|
+
s = "%s" % self
|
|
839
|
+
blank = ' ' * len(s)
|
|
840
|
+
return [blank, blank, s]
|
|
841
|
+
|
|
842
|
+
def __str__(self):
|
|
843
|
+
return '[' + ','.join("%s" % it for it in self) + ']'
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
class AnaphoraResolutionException(Exception):
|
|
847
|
+
pass
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
def resolve_anaphora(expression, trail=[]):
|
|
851
|
+
if isinstance(expression, ApplicationExpression):
|
|
852
|
+
if expression.is_pronoun_function():
|
|
853
|
+
possible_antecedents = PossibleAntecedents()
|
|
854
|
+
for ancestor in trail:
|
|
855
|
+
for ref in ancestor.get_refs():
|
|
856
|
+
refex = expression.make_VariableExpression(ref)
|
|
857
|
+
|
|
858
|
+
#==========================================================
|
|
859
|
+
# Don't allow resolution to itself or other types
|
|
860
|
+
#==========================================================
|
|
861
|
+
if refex.__class__ == expression.argument.__class__ and \
|
|
862
|
+
not (refex == expression.argument):
|
|
863
|
+
possible_antecedents.append(refex)
|
|
864
|
+
|
|
865
|
+
if len(possible_antecedents) == 1:
|
|
866
|
+
resolution = possible_antecedents[0]
|
|
867
|
+
else:
|
|
868
|
+
resolution = possible_antecedents
|
|
869
|
+
return expression.make_EqualityExpression(expression.argument, resolution)
|
|
870
|
+
else:
|
|
871
|
+
r_function = resolve_anaphora(expression.function, trail + [expression])
|
|
872
|
+
r_argument = resolve_anaphora(expression.argument, trail + [expression])
|
|
873
|
+
return expression.__class__(r_function, r_argument)
|
|
874
|
+
|
|
875
|
+
elif isinstance(expression, DRS):
|
|
876
|
+
r_conds = []
|
|
877
|
+
for cond in expression.conds:
|
|
878
|
+
r_cond = resolve_anaphora(cond, trail + [expression])
|
|
879
|
+
|
|
880
|
+
# if the condition is of the form '(x = [])' then raise exception
|
|
881
|
+
if isinstance(r_cond, EqualityExpression):
|
|
882
|
+
if isinstance(r_cond.first, PossibleAntecedents):
|
|
883
|
+
#Reverse the order so that the variable is on the left
|
|
884
|
+
temp = r_cond.first
|
|
885
|
+
r_cond.first = r_cond.second
|
|
886
|
+
r_cond.second = temp
|
|
887
|
+
if isinstance(r_cond.second, PossibleAntecedents):
|
|
888
|
+
if not r_cond.second:
|
|
889
|
+
raise AnaphoraResolutionException("Variable '%s' does not "
|
|
890
|
+
"resolve to anything." % r_cond.first)
|
|
891
|
+
|
|
892
|
+
r_conds.append(r_cond)
|
|
893
|
+
if expression.consequent:
|
|
894
|
+
consequent = resolve_anaphora(expression.consequent, trail + [expression])
|
|
895
|
+
else:
|
|
896
|
+
consequent = None
|
|
897
|
+
return expression.__class__(expression.refs, r_conds, consequent)
|
|
898
|
+
|
|
899
|
+
elif isinstance(expression, AbstractVariableExpression):
|
|
900
|
+
return expression
|
|
901
|
+
|
|
902
|
+
elif isinstance(expression, NegatedExpression):
|
|
903
|
+
return expression.__class__(resolve_anaphora(expression.term, trail + [expression]))
|
|
904
|
+
|
|
905
|
+
elif isinstance(expression, DrtConcatenation):
|
|
906
|
+
if expression.consequent:
|
|
907
|
+
consequent = resolve_anaphora(expression.consequent, trail + [expression])
|
|
908
|
+
else:
|
|
909
|
+
consequent = None
|
|
910
|
+
return expression.__class__(resolve_anaphora(expression.first, trail + [expression]),
|
|
911
|
+
resolve_anaphora(expression.second, trail + [expression]),
|
|
912
|
+
consequent)
|
|
913
|
+
|
|
914
|
+
elif isinstance(expression, BinaryExpression):
|
|
915
|
+
return expression.__class__(resolve_anaphora(expression.first, trail + [expression]),
|
|
916
|
+
resolve_anaphora(expression.second, trail + [expression]))
|
|
917
|
+
|
|
918
|
+
elif isinstance(expression, LambdaExpression):
|
|
919
|
+
return expression.__class__(expression.variable, resolve_anaphora(expression.term, trail + [expression]))
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
class DrsDrawer(object):
|
|
923
|
+
BUFFER = 3 #Space between elements
|
|
924
|
+
TOPSPACE = 10 #Space above whole DRS
|
|
925
|
+
OUTERSPACE = 6 #Space to the left, right, and bottom of the whle DRS
|
|
926
|
+
|
|
927
|
+
def __init__(self, drs, size_canvas=True, canvas=None):
|
|
928
|
+
"""
|
|
929
|
+
:param drs: ``DrtExpression``, The DRS to be drawn
|
|
930
|
+
:param size_canvas: bool, True if the canvas size should be the exact size of the DRS
|
|
931
|
+
:param canvas: ``Canvas`` The canvas on which to draw the DRS. If none is given, create a new canvas.
|
|
932
|
+
"""
|
|
933
|
+
master = None
|
|
934
|
+
if not canvas:
|
|
935
|
+
master = Tk()
|
|
936
|
+
master.title("DRT")
|
|
937
|
+
|
|
938
|
+
font = Font(family='helvetica', size=12)
|
|
939
|
+
|
|
940
|
+
if size_canvas:
|
|
941
|
+
canvas = Canvas(master, width=0, height=0)
|
|
942
|
+
canvas.font = font
|
|
943
|
+
self.canvas = canvas
|
|
944
|
+
(right, bottom) = self._visit(drs, self.OUTERSPACE, self.TOPSPACE)
|
|
945
|
+
|
|
946
|
+
width = max(right+self.OUTERSPACE, 100)
|
|
947
|
+
height = bottom+self.OUTERSPACE
|
|
948
|
+
canvas = Canvas(master, width=width, height=height)#, bg='white')
|
|
949
|
+
else:
|
|
950
|
+
canvas = Canvas(master, width=300, height=300)
|
|
951
|
+
|
|
952
|
+
canvas.pack()
|
|
953
|
+
canvas.font = font
|
|
954
|
+
|
|
955
|
+
self.canvas = canvas
|
|
956
|
+
self.drs = drs
|
|
957
|
+
self.master = master
|
|
958
|
+
|
|
959
|
+
def _get_text_height(self):
|
|
960
|
+
"""Get the height of a line of text"""
|
|
961
|
+
return self.canvas.font.metrics("linespace")
|
|
962
|
+
|
|
963
|
+
def draw(self, x=OUTERSPACE, y=TOPSPACE):
|
|
964
|
+
"""Draw the DRS"""
|
|
965
|
+
self._handle(self.drs, self._draw_command, x, y)
|
|
966
|
+
|
|
967
|
+
if self.master and not in_idle():
|
|
968
|
+
self.master.mainloop()
|
|
969
|
+
else:
|
|
970
|
+
return self._visit(self.drs, x, y)
|
|
971
|
+
|
|
972
|
+
def _visit(self, expression, x, y):
|
|
973
|
+
"""
|
|
974
|
+
Return the bottom-rightmost point without actually drawing the item
|
|
975
|
+
|
|
976
|
+
:param expression: the item to visit
|
|
977
|
+
:param x: the top of the current drawing area
|
|
978
|
+
:param y: the left side of the current drawing area
|
|
979
|
+
:return: the bottom-rightmost point
|
|
980
|
+
"""
|
|
981
|
+
return self._handle(expression, self._visit_command, x, y)
|
|
982
|
+
|
|
983
|
+
def _draw_command(self, item, x, y):
|
|
984
|
+
"""
|
|
985
|
+
Draw the given item at the given location
|
|
986
|
+
|
|
987
|
+
:param item: the item to draw
|
|
988
|
+
:param x: the top of the current drawing area
|
|
989
|
+
:param y: the left side of the current drawing area
|
|
990
|
+
:return: the bottom-rightmost point
|
|
991
|
+
"""
|
|
992
|
+
if isinstance(item, string_types):
|
|
993
|
+
self.canvas.create_text(x, y, anchor='nw', font=self.canvas.font, text=item)
|
|
994
|
+
elif isinstance(item, tuple):
|
|
995
|
+
# item is the lower-right of a box
|
|
996
|
+
(right, bottom) = item
|
|
997
|
+
self.canvas.create_rectangle(x, y, right, bottom)
|
|
998
|
+
horiz_line_y = y + self._get_text_height() + (self.BUFFER * 2) #the line separating refs from conds
|
|
999
|
+
self.canvas.create_line(x, horiz_line_y, right, horiz_line_y)
|
|
1000
|
+
|
|
1001
|
+
return self._visit_command(item, x, y)
|
|
1002
|
+
|
|
1003
|
+
def _visit_command(self, item, x, y):
|
|
1004
|
+
"""
|
|
1005
|
+
Return the bottom-rightmost point without actually drawing the item
|
|
1006
|
+
|
|
1007
|
+
:param item: the item to visit
|
|
1008
|
+
:param x: the top of the current drawing area
|
|
1009
|
+
:param y: the left side of the current drawing area
|
|
1010
|
+
:return: the bottom-rightmost point
|
|
1011
|
+
"""
|
|
1012
|
+
if isinstance(item, string_types):
|
|
1013
|
+
return (x + self.canvas.font.measure(item), y + self._get_text_height())
|
|
1014
|
+
elif isinstance(item, tuple):
|
|
1015
|
+
return item
|
|
1016
|
+
|
|
1017
|
+
def _handle(self, expression, command, x=0, y=0):
|
|
1018
|
+
"""
|
|
1019
|
+
:param expression: the expression to handle
|
|
1020
|
+
:param command: the function to apply, either _draw_command or _visit_command
|
|
1021
|
+
:param x: the top of the current drawing area
|
|
1022
|
+
:param y: the left side of the current drawing area
|
|
1023
|
+
:return: the bottom-rightmost point
|
|
1024
|
+
"""
|
|
1025
|
+
if command == self._visit_command:
|
|
1026
|
+
#if we don't need to draw the item, then we can use the cached values
|
|
1027
|
+
try:
|
|
1028
|
+
#attempt to retrieve cached values
|
|
1029
|
+
right = expression._drawing_width + x
|
|
1030
|
+
bottom = expression._drawing_height + y
|
|
1031
|
+
return (right, bottom)
|
|
1032
|
+
except AttributeError:
|
|
1033
|
+
#the values have not been cached yet, so compute them
|
|
1034
|
+
pass
|
|
1035
|
+
|
|
1036
|
+
if isinstance(expression, DrtAbstractVariableExpression):
|
|
1037
|
+
factory = self._handle_VariableExpression
|
|
1038
|
+
elif isinstance(expression, DRS):
|
|
1039
|
+
factory = self._handle_DRS
|
|
1040
|
+
elif isinstance(expression, DrtNegatedExpression):
|
|
1041
|
+
factory = self._handle_NegatedExpression
|
|
1042
|
+
elif isinstance(expression, DrtLambdaExpression):
|
|
1043
|
+
factory = self._handle_LambdaExpression
|
|
1044
|
+
elif isinstance(expression, BinaryExpression):
|
|
1045
|
+
factory = self._handle_BinaryExpression
|
|
1046
|
+
elif isinstance(expression, DrtApplicationExpression):
|
|
1047
|
+
factory = self._handle_ApplicationExpression
|
|
1048
|
+
elif isinstance(expression, PossibleAntecedents):
|
|
1049
|
+
factory = self._handle_VariableExpression
|
|
1050
|
+
elif isinstance(expression, DrtProposition):
|
|
1051
|
+
factory = self._handle_DrtProposition
|
|
1052
|
+
else:
|
|
1053
|
+
raise Exception(expression.__class__.__name__)
|
|
1054
|
+
|
|
1055
|
+
(right, bottom) = factory(expression, command, x, y)
|
|
1056
|
+
|
|
1057
|
+
#cache the values
|
|
1058
|
+
expression._drawing_width = right - x
|
|
1059
|
+
expression._drawing_height = bottom - y
|
|
1060
|
+
|
|
1061
|
+
return (right, bottom)
|
|
1062
|
+
|
|
1063
|
+
def _handle_VariableExpression(self, expression, command, x, y):
|
|
1064
|
+
return command("%s" % expression, x, y)
|
|
1065
|
+
|
|
1066
|
+
def _handle_NegatedExpression(self, expression, command, x, y):
|
|
1067
|
+
# Find the width of the negation symbol
|
|
1068
|
+
right = self._visit_command(DrtTokens.NOT, x, y)[0]
|
|
1069
|
+
|
|
1070
|
+
# Handle term
|
|
1071
|
+
(right, bottom) = self._handle(expression.term, command, right, y)
|
|
1072
|
+
|
|
1073
|
+
# Handle variables now that we know the y-coordinate
|
|
1074
|
+
command(DrtTokens.NOT, x, self._get_centered_top(y, bottom - y, self._get_text_height()))
|
|
1075
|
+
|
|
1076
|
+
return (right, bottom)
|
|
1077
|
+
|
|
1078
|
+
def _handle_DRS(self, expression, command, x, y):
|
|
1079
|
+
left = x + self.BUFFER #indent the left side
|
|
1080
|
+
bottom = y + self.BUFFER #indent the top
|
|
1081
|
+
|
|
1082
|
+
# Handle Discourse Referents
|
|
1083
|
+
if expression.refs:
|
|
1084
|
+
refs = ' '.join("%s"%r for r in expression.refs)
|
|
1085
|
+
else:
|
|
1086
|
+
refs = ' '
|
|
1087
|
+
(max_right, bottom) = command(refs, left, bottom)
|
|
1088
|
+
bottom += (self.BUFFER * 2)
|
|
1089
|
+
|
|
1090
|
+
# Handle Conditions
|
|
1091
|
+
if expression.conds:
|
|
1092
|
+
for cond in expression.conds:
|
|
1093
|
+
(right, bottom) = self._handle(cond, command, left, bottom)
|
|
1094
|
+
max_right = max(max_right, right)
|
|
1095
|
+
bottom += self.BUFFER
|
|
1096
|
+
else:
|
|
1097
|
+
bottom += self._get_text_height() + self.BUFFER
|
|
1098
|
+
|
|
1099
|
+
# Handle Box
|
|
1100
|
+
max_right += self.BUFFER
|
|
1101
|
+
return command((max_right, bottom), x, y)
|
|
1102
|
+
|
|
1103
|
+
def _handle_ApplicationExpression(self, expression, command, x, y):
|
|
1104
|
+
function, args = expression.uncurry()
|
|
1105
|
+
if not isinstance(function, DrtAbstractVariableExpression):
|
|
1106
|
+
#It's not a predicate expression ("P(x,y)"), so leave arguments curried
|
|
1107
|
+
function = expression.function
|
|
1108
|
+
args = [expression.argument]
|
|
1109
|
+
|
|
1110
|
+
# Get the max bottom of any element on the line
|
|
1111
|
+
function_bottom = self._visit(function, x, y)[1]
|
|
1112
|
+
max_bottom = max([function_bottom] + [self._visit(arg, x, y)[1] for arg in args])
|
|
1113
|
+
|
|
1114
|
+
line_height = max_bottom - y
|
|
1115
|
+
|
|
1116
|
+
# Handle 'function'
|
|
1117
|
+
function_drawing_top = self._get_centered_top(y, line_height, function._drawing_height)
|
|
1118
|
+
right = self._handle(function, command, x, function_drawing_top)[0]
|
|
1119
|
+
|
|
1120
|
+
# Handle open paren
|
|
1121
|
+
centred_string_top = self._get_centered_top(y, line_height, self._get_text_height())
|
|
1122
|
+
right = command(DrtTokens.OPEN, right, centred_string_top)[0]
|
|
1123
|
+
|
|
1124
|
+
# Handle each arg
|
|
1125
|
+
for (i,arg) in enumerate(args):
|
|
1126
|
+
arg_drawing_top = self._get_centered_top(y, line_height, arg._drawing_height)
|
|
1127
|
+
right = self._handle(arg, command, right, arg_drawing_top)[0]
|
|
1128
|
+
|
|
1129
|
+
if i+1 < len(args):
|
|
1130
|
+
#since it's not the last arg, add a comma
|
|
1131
|
+
right = command(DrtTokens.COMMA + ' ', right, centred_string_top)[0]
|
|
1132
|
+
|
|
1133
|
+
# Handle close paren
|
|
1134
|
+
right = command(DrtTokens.CLOSE, right, centred_string_top)[0]
|
|
1135
|
+
|
|
1136
|
+
return (right, max_bottom)
|
|
1137
|
+
|
|
1138
|
+
def _handle_LambdaExpression(self, expression, command, x, y):
|
|
1139
|
+
# Find the width of the lambda symbol and abstracted variables
|
|
1140
|
+
variables = DrtTokens.LAMBDA + "%s" % expression.variable + DrtTokens.DOT
|
|
1141
|
+
right = self._visit_command(variables, x, y)[0]
|
|
1142
|
+
|
|
1143
|
+
# Handle term
|
|
1144
|
+
(right, bottom) = self._handle(expression.term, command, right, y)
|
|
1145
|
+
|
|
1146
|
+
# Handle variables now that we know the y-coordinate
|
|
1147
|
+
command(variables, x, self._get_centered_top(y, bottom - y, self._get_text_height()))
|
|
1148
|
+
|
|
1149
|
+
return (right, bottom)
|
|
1150
|
+
|
|
1151
|
+
def _handle_BinaryExpression(self, expression, command, x, y):
|
|
1152
|
+
# Get the full height of the line, based on the operands
|
|
1153
|
+
first_height = self._visit(expression.first, 0, 0)[1]
|
|
1154
|
+
second_height = self._visit(expression.second, 0, 0)[1]
|
|
1155
|
+
line_height = max(first_height, second_height)
|
|
1156
|
+
|
|
1157
|
+
# Handle open paren
|
|
1158
|
+
centred_string_top = self._get_centered_top(y, line_height, self._get_text_height())
|
|
1159
|
+
right = command(DrtTokens.OPEN, x, centred_string_top)[0]
|
|
1160
|
+
|
|
1161
|
+
# Handle the first operand
|
|
1162
|
+
first_height = expression.first._drawing_height
|
|
1163
|
+
(right, first_bottom) = self._handle(expression.first, command, right, self._get_centered_top(y, line_height, first_height))
|
|
1164
|
+
|
|
1165
|
+
# Handle the operator
|
|
1166
|
+
right = command(' %s ' % expression.getOp(), right, centred_string_top)[0]
|
|
1167
|
+
|
|
1168
|
+
# Handle the second operand
|
|
1169
|
+
second_height = expression.second._drawing_height
|
|
1170
|
+
(right, second_bottom) = self._handle(expression.second, command, right, self._get_centered_top(y, line_height, second_height))
|
|
1171
|
+
|
|
1172
|
+
# Handle close paren
|
|
1173
|
+
right = command(DrtTokens.CLOSE, right, centred_string_top)[0]
|
|
1174
|
+
|
|
1175
|
+
return (right, max(first_bottom, second_bottom))
|
|
1176
|
+
|
|
1177
|
+
def _handle_DrtProposition(self, expression, command, x, y):
|
|
1178
|
+
# Find the width of the negation symbol
|
|
1179
|
+
right = command(expression.variable, x, y)[0]
|
|
1180
|
+
|
|
1181
|
+
# Handle term
|
|
1182
|
+
(right, bottom) = self._handle(expression.term, command, right, y)
|
|
1183
|
+
|
|
1184
|
+
return (right, bottom)
|
|
1185
|
+
|
|
1186
|
+
def _get_centered_top(self, top, full_height, item_height):
|
|
1187
|
+
"""Get the y-coordinate of the point that a figure should start at if
|
|
1188
|
+
its height is 'item_height' and it needs to be centered in an area that
|
|
1189
|
+
starts at 'top' and is 'full_height' tall."""
|
|
1190
|
+
return top + (full_height - item_height) / 2
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
def demo():
|
|
1194
|
+
print('='*20 + 'TEST PARSE' + '='*20)
|
|
1195
|
+
dexpr = DrtExpression.fromstring
|
|
1196
|
+
print(dexpr(r'([x,y],[sees(x,y)])'))
|
|
1197
|
+
print(dexpr(r'([x],[man(x), walks(x)])'))
|
|
1198
|
+
print(dexpr(r'\x.\y.([],[sees(x,y)])'))
|
|
1199
|
+
print(dexpr(r'\x.([],[walks(x)])(john)'))
|
|
1200
|
+
print(dexpr(r'(([x],[walks(x)]) + ([y],[runs(y)]))'))
|
|
1201
|
+
print(dexpr(r'(([],[walks(x)]) -> ([],[runs(x)]))'))
|
|
1202
|
+
print(dexpr(r'([x],[PRO(x), sees(John,x)])'))
|
|
1203
|
+
print(dexpr(r'([x],[man(x), -([],[walks(x)])])'))
|
|
1204
|
+
print(dexpr(r'([],[(([x],[man(x)]) -> ([],[walks(x)]))])'))
|
|
1205
|
+
|
|
1206
|
+
print('='*20 + 'Test fol()' + '='*20)
|
|
1207
|
+
print(dexpr(r'([x,y],[sees(x,y)])').fol())
|
|
1208
|
+
|
|
1209
|
+
print('='*20 + 'Test alpha conversion and lambda expression equality' + '='*20)
|
|
1210
|
+
e1 = dexpr(r'\x.([],[P(x)])')
|
|
1211
|
+
print(e1)
|
|
1212
|
+
e2 = e1.alpha_convert(Variable('z'))
|
|
1213
|
+
print(e2)
|
|
1214
|
+
print(e1 == e2)
|
|
1215
|
+
|
|
1216
|
+
print('='*20 + 'Test resolve_anaphora()' + '='*20)
|
|
1217
|
+
print(resolve_anaphora(dexpr(r'([x,y,z],[dog(x), cat(y), walks(z), PRO(z)])')))
|
|
1218
|
+
print(resolve_anaphora(dexpr(r'([],[(([x],[dog(x)]) -> ([y],[walks(y), PRO(y)]))])')))
|
|
1219
|
+
print(resolve_anaphora(dexpr(r'(([x,y],[]) + ([],[PRO(x)]))')))
|
|
1220
|
+
|
|
1221
|
+
print('='*20 + 'Test pretty_print()' + '='*20)
|
|
1222
|
+
dexpr(r"([],[])").pretty_print()
|
|
1223
|
+
dexpr(r"([],[([x],[big(x), dog(x)]) -> ([],[bark(x)]) -([x],[walk(x)])])").pretty_print()
|
|
1224
|
+
dexpr(r"([x,y],[x=y]) + ([z],[dog(z), walk(z)])").pretty_print()
|
|
1225
|
+
dexpr(r"([],[([x],[]) | ([y],[]) | ([z],[dog(z), walk(z)])])").pretty_print()
|
|
1226
|
+
dexpr(r"\P.\Q.(([x],[]) + P(x) + Q(x))(\x.([],[dog(x)]))").pretty_print()
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
def test_draw():
|
|
1230
|
+
try:
|
|
1231
|
+
from six.moves.tkinter import Tk
|
|
1232
|
+
except ImportError:
|
|
1233
|
+
from nose import SkipTest
|
|
1234
|
+
raise SkipTest("tkinter is required, but it's not available.")
|
|
1235
|
+
|
|
1236
|
+
expressions = [
|
|
1237
|
+
r'x',
|
|
1238
|
+
r'([],[])',
|
|
1239
|
+
r'([x],[])',
|
|
1240
|
+
r'([x],[man(x)])',
|
|
1241
|
+
|
|
1242
|
+
r'([x,y],[sees(x,y)])',
|
|
1243
|
+
r'([x],[man(x), walks(x)])',
|
|
1244
|
+
r'\x.([],[man(x), walks(x)])',
|
|
1245
|
+
r'\x y.([],[sees(x,y)])',
|
|
1246
|
+
r'([],[(([],[walks(x)]) + ([],[runs(x)]))])',
|
|
1247
|
+
|
|
1248
|
+
r'([x],[man(x), -([],[walks(x)])])',
|
|
1249
|
+
r'([],[(([x],[man(x)]) -> ([],[walks(x)]))])'
|
|
1250
|
+
]
|
|
1251
|
+
|
|
1252
|
+
for e in expressions:
|
|
1253
|
+
d = DrtExpression.fromstring(e)
|
|
1254
|
+
d.draw()
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
if __name__ == '__main__':
|
|
1258
|
+
demo()
|