grammar_cop 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +8 -0
- data/data/.DS_Store +0 -0
- data/data/Makefile +511 -0
- data/data/Makefile.am +4 -0
- data/data/Makefile.in +511 -0
- data/data/de/.DS_Store +0 -0
- data/data/de/4.0.affix +7 -0
- data/data/de/4.0.dict +474 -0
- data/data/de/Makefile +387 -0
- data/data/de/Makefile.am +9 -0
- data/data/de/Makefile.in +387 -0
- data/data/en/.DS_Store +0 -0
- data/data/en/4.0.affix +26 -0
- data/data/en/4.0.batch +1002 -0
- data/data/en/4.0.biolg.batch +411 -0
- data/data/en/4.0.constituent-knowledge +127 -0
- data/data/en/4.0.dict +8759 -0
- data/data/en/4.0.dict.m4 +6928 -0
- data/data/en/4.0.enwiki.batch +14 -0
- data/data/en/4.0.fixes.batch +2776 -0
- data/data/en/4.0.knowledge +306 -0
- data/data/en/4.0.regex +225 -0
- data/data/en/4.0.voa.batch +114 -0
- data/data/en/Makefile +554 -0
- data/data/en/Makefile.am +19 -0
- data/data/en/Makefile.in +554 -0
- data/data/en/README +173 -0
- data/data/en/tiny.dict +157 -0
- data/data/en/words/.DS_Store +0 -0
- data/data/en/words/Makefile +456 -0
- data/data/en/words/Makefile.am +78 -0
- data/data/en/words/Makefile.in +456 -0
- data/data/en/words/currency +205 -0
- data/data/en/words/currency.p +28 -0
- data/data/en/words/entities.given-bisex.sing +39 -0
- data/data/en/words/entities.given-female.sing +4141 -0
- data/data/en/words/entities.given-male.sing +1633 -0
- data/data/en/words/entities.locations.sing +68 -0
- data/data/en/words/entities.national.sing +253 -0
- data/data/en/words/entities.organizations.sing +7 -0
- data/data/en/words/entities.us-states.sing +11 -0
- data/data/en/words/units.1 +45 -0
- data/data/en/words/units.1.dot +4 -0
- data/data/en/words/units.3 +2 -0
- data/data/en/words/units.4 +5 -0
- data/data/en/words/units.4.dot +1 -0
- data/data/en/words/words-medical.adv.1 +1191 -0
- data/data/en/words/words-medical.prep.1 +67 -0
- data/data/en/words/words-medical.v.4.1 +2835 -0
- data/data/en/words/words-medical.v.4.2 +2848 -0
- data/data/en/words/words-medical.v.4.3 +3011 -0
- data/data/en/words/words-medical.v.4.4 +3036 -0
- data/data/en/words/words-medical.v.4.5 +3050 -0
- data/data/en/words/words.adj.1 +6794 -0
- data/data/en/words/words.adj.2 +638 -0
- data/data/en/words/words.adj.3 +667 -0
- data/data/en/words/words.adv.1 +1573 -0
- data/data/en/words/words.adv.2 +67 -0
- data/data/en/words/words.adv.3 +157 -0
- data/data/en/words/words.adv.4 +80 -0
- data/data/en/words/words.n.1 +11464 -0
- data/data/en/words/words.n.1.wiki +264 -0
- data/data/en/words/words.n.2.s +2017 -0
- data/data/en/words/words.n.2.s.biolg +1 -0
- data/data/en/words/words.n.2.s.wiki +298 -0
- data/data/en/words/words.n.2.x +65 -0
- data/data/en/words/words.n.2.x.wiki +10 -0
- data/data/en/words/words.n.3 +5717 -0
- data/data/en/words/words.n.t +23 -0
- data/data/en/words/words.v.1.1 +1038 -0
- data/data/en/words/words.v.1.2 +1043 -0
- data/data/en/words/words.v.1.3 +1052 -0
- data/data/en/words/words.v.1.4 +1023 -0
- data/data/en/words/words.v.1.p +17 -0
- data/data/en/words/words.v.10.1 +14 -0
- data/data/en/words/words.v.10.2 +15 -0
- data/data/en/words/words.v.10.3 +88 -0
- data/data/en/words/words.v.10.4 +17 -0
- data/data/en/words/words.v.2.1 +1253 -0
- data/data/en/words/words.v.2.2 +1304 -0
- data/data/en/words/words.v.2.3 +1280 -0
- data/data/en/words/words.v.2.4 +1285 -0
- data/data/en/words/words.v.2.5 +1287 -0
- data/data/en/words/words.v.4.1 +2472 -0
- data/data/en/words/words.v.4.2 +2487 -0
- data/data/en/words/words.v.4.3 +2441 -0
- data/data/en/words/words.v.4.4 +2478 -0
- data/data/en/words/words.v.4.5 +2483 -0
- data/data/en/words/words.v.5.1 +98 -0
- data/data/en/words/words.v.5.2 +98 -0
- data/data/en/words/words.v.5.3 +103 -0
- data/data/en/words/words.v.5.4 +102 -0
- data/data/en/words/words.v.6.1 +388 -0
- data/data/en/words/words.v.6.2 +401 -0
- data/data/en/words/words.v.6.3 +397 -0
- data/data/en/words/words.v.6.4 +405 -0
- data/data/en/words/words.v.6.5 +401 -0
- data/data/en/words/words.v.8.1 +117 -0
- data/data/en/words/words.v.8.2 +118 -0
- data/data/en/words/words.v.8.3 +118 -0
- data/data/en/words/words.v.8.4 +119 -0
- data/data/en/words/words.v.8.5 +119 -0
- data/data/en/words/words.y +104 -0
- data/data/lt/.DS_Store +0 -0
- data/data/lt/4.0.affix +6 -0
- data/data/lt/4.0.constituent-knowledge +24 -0
- data/data/lt/4.0.dict +135 -0
- data/data/lt/4.0.knowledge +38 -0
- data/data/lt/Makefile +389 -0
- data/data/lt/Makefile.am +11 -0
- data/data/lt/Makefile.in +389 -0
- data/ext/.DS_Store +0 -0
- data/ext/link_grammar/.DS_Store +0 -0
- data/ext/link_grammar/extconf.rb +2 -0
- data/ext/link_grammar/link-grammar/.DS_Store +0 -0
- data/ext/link_grammar/link-grammar/.deps/analyze-linkage.Plo +198 -0
- data/ext/link_grammar/link-grammar/.deps/and.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/api.Plo +244 -0
- data/ext/link_grammar/link-grammar/.deps/build-disjuncts.Plo +212 -0
- data/ext/link_grammar/link-grammar/.deps/command-line.Plo +201 -0
- data/ext/link_grammar/link-grammar/.deps/constituents.Plo +201 -0
- data/ext/link_grammar/link-grammar/.deps/count.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/disjunct-utils.Plo +126 -0
- data/ext/link_grammar/link-grammar/.deps/disjuncts.Plo +123 -0
- data/ext/link_grammar/link-grammar/.deps/error.Plo +121 -0
- data/ext/link_grammar/link-grammar/.deps/expand.Plo +133 -0
- data/ext/link_grammar/link-grammar/.deps/extract-links.Plo +198 -0
- data/ext/link_grammar/link-grammar/.deps/fast-match.Plo +200 -0
- data/ext/link_grammar/link-grammar/.deps/idiom.Plo +200 -0
- data/ext/link_grammar/link-grammar/.deps/jni-client.Plo +217 -0
- data/ext/link_grammar/link-grammar/.deps/link-parser.Po +1 -0
- data/ext/link_grammar/link-grammar/.deps/massage.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/post-process.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/pp_knowledge.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/pp_lexer.Plo +201 -0
- data/ext/link_grammar/link-grammar/.deps/pp_linkset.Plo +200 -0
- data/ext/link_grammar/link-grammar/.deps/prefix.Plo +102 -0
- data/ext/link_grammar/link-grammar/.deps/preparation.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/print-util.Plo +200 -0
- data/ext/link_grammar/link-grammar/.deps/print.Plo +201 -0
- data/ext/link_grammar/link-grammar/.deps/prune.Plo +202 -0
- data/ext/link_grammar/link-grammar/.deps/read-dict.Plo +223 -0
- data/ext/link_grammar/link-grammar/.deps/read-regex.Plo +123 -0
- data/ext/link_grammar/link-grammar/.deps/regex-morph.Plo +131 -0
- data/ext/link_grammar/link-grammar/.deps/resources.Plo +203 -0
- data/ext/link_grammar/link-grammar/.deps/spellcheck-aspell.Plo +1 -0
- data/ext/link_grammar/link-grammar/.deps/spellcheck-hun.Plo +115 -0
- data/ext/link_grammar/link-grammar/.deps/string-set.Plo +198 -0
- data/ext/link_grammar/link-grammar/.deps/tokenize.Plo +160 -0
- data/ext/link_grammar/link-grammar/.deps/utilities.Plo +222 -0
- data/ext/link_grammar/link-grammar/.deps/word-file.Plo +201 -0
- data/ext/link_grammar/link-grammar/.deps/word-utils.Plo +212 -0
- data/ext/link_grammar/link-grammar/.libs/analyze-linkage.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/and.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/api.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/build-disjuncts.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/command-line.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/constituents.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/count.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/disjunct-utils.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/disjuncts.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/error.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/expand.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/extract-links.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/fast-match.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/idiom.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/jni-client.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java-symbols.expsym +31 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java.4.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java.4.dylib.dSYM/Contents/Info.plist +20 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java.4.dylib.dSYM/Contents/Resources/DWARF/liblink-grammar-java.4.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java.a +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-java.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar-symbols.expsym +194 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.4.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.4.dylib.dSYM/Contents/Info.plist +20 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.4.dylib.dSYM/Contents/Resources/DWARF/liblink-grammar.4.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.a +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.dylib +0 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.la +41 -0
- data/ext/link_grammar/link-grammar/.libs/liblink-grammar.lai +41 -0
- data/ext/link_grammar/link-grammar/.libs/massage.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/post-process.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/pp_knowledge.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/pp_lexer.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/pp_linkset.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/prefix.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/preparation.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/print-util.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/print.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/prune.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/read-dict.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/read-regex.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/regex-morph.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/resources.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/spellcheck-aspell.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/spellcheck-hun.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/string-set.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/tokenize.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/utilities.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/word-file.o +0 -0
- data/ext/link_grammar/link-grammar/.libs/word-utils.o +0 -0
- data/ext/link_grammar/link-grammar/Makefile +900 -0
- data/ext/link_grammar/link-grammar/Makefile.am +202 -0
- data/ext/link_grammar/link-grammar/Makefile.in +900 -0
- data/ext/link_grammar/link-grammar/analyze-linkage.c +1317 -0
- data/ext/link_grammar/link-grammar/analyze-linkage.h +24 -0
- data/ext/link_grammar/link-grammar/and.c +1603 -0
- data/ext/link_grammar/link-grammar/and.h +27 -0
- data/ext/link_grammar/link-grammar/api-structures.h +362 -0
- data/ext/link_grammar/link-grammar/api-types.h +72 -0
- data/ext/link_grammar/link-grammar/api.c +1887 -0
- data/ext/link_grammar/link-grammar/api.h +96 -0
- data/ext/link_grammar/link-grammar/autoit/.DS_Store +0 -0
- data/ext/link_grammar/link-grammar/autoit/README +10 -0
- data/ext/link_grammar/link-grammar/autoit/_LGTest.au3 +22 -0
- data/ext/link_grammar/link-grammar/autoit/_LinkGrammar.au3 +545 -0
- data/ext/link_grammar/link-grammar/build-disjuncts.c +487 -0
- data/ext/link_grammar/link-grammar/build-disjuncts.h +21 -0
- data/ext/link_grammar/link-grammar/command-line.c +458 -0
- data/ext/link_grammar/link-grammar/command-line.h +15 -0
- data/ext/link_grammar/link-grammar/constituents.c +1836 -0
- data/ext/link_grammar/link-grammar/constituents.h +26 -0
- data/ext/link_grammar/link-grammar/corpus/.DS_Store +0 -0
- data/ext/link_grammar/link-grammar/corpus/.deps/cluster.Plo +1 -0
- data/ext/link_grammar/link-grammar/corpus/.deps/corpus.Plo +1 -0
- data/ext/link_grammar/link-grammar/corpus/Makefile +527 -0
- data/ext/link_grammar/link-grammar/corpus/Makefile.am +46 -0
- data/ext/link_grammar/link-grammar/corpus/Makefile.in +527 -0
- data/ext/link_grammar/link-grammar/corpus/README +17 -0
- data/ext/link_grammar/link-grammar/corpus/cluster.c +286 -0
- data/ext/link_grammar/link-grammar/corpus/cluster.h +32 -0
- data/ext/link_grammar/link-grammar/corpus/corpus.c +483 -0
- data/ext/link_grammar/link-grammar/corpus/corpus.h +46 -0
- data/ext/link_grammar/link-grammar/count.c +828 -0
- data/ext/link_grammar/link-grammar/count.h +25 -0
- data/ext/link_grammar/link-grammar/disjunct-utils.c +261 -0
- data/ext/link_grammar/link-grammar/disjunct-utils.h +27 -0
- data/ext/link_grammar/link-grammar/disjuncts.c +138 -0
- data/ext/link_grammar/link-grammar/disjuncts.h +13 -0
- data/ext/link_grammar/link-grammar/error.c +92 -0
- data/ext/link_grammar/link-grammar/error.h +35 -0
- data/ext/link_grammar/link-grammar/expand.c +67 -0
- data/ext/link_grammar/link-grammar/expand.h +13 -0
- data/ext/link_grammar/link-grammar/externs.h +22 -0
- data/ext/link_grammar/link-grammar/extract-links.c +625 -0
- data/ext/link_grammar/link-grammar/extract-links.h +16 -0
- data/ext/link_grammar/link-grammar/fast-match.c +309 -0
- data/ext/link_grammar/link-grammar/fast-match.h +17 -0
- data/ext/link_grammar/link-grammar/idiom.c +373 -0
- data/ext/link_grammar/link-grammar/idiom.h +15 -0
- data/ext/link_grammar/link-grammar/jni-client.c +779 -0
- data/ext/link_grammar/link-grammar/jni-client.h +236 -0
- data/ext/link_grammar/link-grammar/liblink-grammar-java.la +42 -0
- data/ext/link_grammar/link-grammar/liblink-grammar.la +41 -0
- data/ext/link_grammar/link-grammar/link-features.h +37 -0
- data/ext/link_grammar/link-grammar/link-features.h.in +37 -0
- data/ext/link_grammar/link-grammar/link-grammar-java.def +31 -0
- data/ext/link_grammar/link-grammar/link-grammar.def +194 -0
- data/ext/link_grammar/link-grammar/link-includes.h +465 -0
- data/ext/link_grammar/link-grammar/link-parser.c +849 -0
- data/ext/link_grammar/link-grammar/massage.c +329 -0
- data/ext/link_grammar/link-grammar/massage.h +13 -0
- data/ext/link_grammar/link-grammar/post-process.c +1113 -0
- data/ext/link_grammar/link-grammar/post-process.h +45 -0
- data/ext/link_grammar/link-grammar/pp_knowledge.c +376 -0
- data/ext/link_grammar/link-grammar/pp_knowledge.h +14 -0
- data/ext/link_grammar/link-grammar/pp_lexer.c +1920 -0
- data/ext/link_grammar/link-grammar/pp_lexer.h +19 -0
- data/ext/link_grammar/link-grammar/pp_linkset.c +158 -0
- data/ext/link_grammar/link-grammar/pp_linkset.h +20 -0
- data/ext/link_grammar/link-grammar/prefix.c +482 -0
- data/ext/link_grammar/link-grammar/prefix.h +139 -0
- data/ext/link_grammar/link-grammar/preparation.c +412 -0
- data/ext/link_grammar/link-grammar/preparation.h +20 -0
- data/ext/link_grammar/link-grammar/print-util.c +87 -0
- data/ext/link_grammar/link-grammar/print-util.h +32 -0
- data/ext/link_grammar/link-grammar/print.c +1085 -0
- data/ext/link_grammar/link-grammar/print.h +16 -0
- data/ext/link_grammar/link-grammar/prune.c +1864 -0
- data/ext/link_grammar/link-grammar/prune.h +17 -0
- data/ext/link_grammar/link-grammar/read-dict.c +1785 -0
- data/ext/link_grammar/link-grammar/read-dict.h +29 -0
- data/ext/link_grammar/link-grammar/read-regex.c +161 -0
- data/ext/link_grammar/link-grammar/read-regex.h +12 -0
- data/ext/link_grammar/link-grammar/regex-morph.c +126 -0
- data/ext/link_grammar/link-grammar/regex-morph.h +17 -0
- data/ext/link_grammar/link-grammar/resources.c +180 -0
- data/ext/link_grammar/link-grammar/resources.h +23 -0
- data/ext/link_grammar/link-grammar/sat-solver/.DS_Store +0 -0
- data/ext/link_grammar/link-grammar/sat-solver/.deps/fast-sprintf.Plo +1 -0
- data/ext/link_grammar/link-grammar/sat-solver/.deps/sat-encoder.Plo +1 -0
- data/ext/link_grammar/link-grammar/sat-solver/.deps/util.Plo +1 -0
- data/ext/link_grammar/link-grammar/sat-solver/.deps/variables.Plo +1 -0
- data/ext/link_grammar/link-grammar/sat-solver/.deps/word-tag.Plo +1 -0
- data/ext/link_grammar/link-grammar/sat-solver/Makefile +527 -0
- data/ext/link_grammar/link-grammar/sat-solver/Makefile.am +29 -0
- data/ext/link_grammar/link-grammar/sat-solver/Makefile.in +527 -0
- data/ext/link_grammar/link-grammar/sat-solver/clock.hpp +33 -0
- data/ext/link_grammar/link-grammar/sat-solver/fast-sprintf.cpp +26 -0
- data/ext/link_grammar/link-grammar/sat-solver/fast-sprintf.hpp +7 -0
- data/ext/link_grammar/link-grammar/sat-solver/guiding.hpp +244 -0
- data/ext/link_grammar/link-grammar/sat-solver/matrix-ut.hpp +79 -0
- data/ext/link_grammar/link-grammar/sat-solver/sat-encoder.cpp +2811 -0
- data/ext/link_grammar/link-grammar/sat-solver/sat-encoder.h +11 -0
- data/ext/link_grammar/link-grammar/sat-solver/sat-encoder.hpp +381 -0
- data/ext/link_grammar/link-grammar/sat-solver/trie.hpp +118 -0
- data/ext/link_grammar/link-grammar/sat-solver/util.cpp +23 -0
- data/ext/link_grammar/link-grammar/sat-solver/util.hpp +14 -0
- data/ext/link_grammar/link-grammar/sat-solver/variables.cpp +5 -0
- data/ext/link_grammar/link-grammar/sat-solver/variables.hpp +829 -0
- data/ext/link_grammar/link-grammar/sat-solver/word-tag.cpp +159 -0
- data/ext/link_grammar/link-grammar/sat-solver/word-tag.hpp +162 -0
- data/ext/link_grammar/link-grammar/spellcheck-aspell.c +148 -0
- data/ext/link_grammar/link-grammar/spellcheck-hun.c +136 -0
- data/ext/link_grammar/link-grammar/spellcheck.h +34 -0
- data/ext/link_grammar/link-grammar/string-set.c +169 -0
- data/ext/link_grammar/link-grammar/string-set.h +16 -0
- data/ext/link_grammar/link-grammar/structures.h +498 -0
- data/ext/link_grammar/link-grammar/tokenize.c +1049 -0
- data/ext/link_grammar/link-grammar/tokenize.h +15 -0
- data/ext/link_grammar/link-grammar/utilities.c +847 -0
- data/ext/link_grammar/link-grammar/utilities.h +281 -0
- data/ext/link_grammar/link-grammar/word-file.c +124 -0
- data/ext/link_grammar/link-grammar/word-file.h +15 -0
- data/ext/link_grammar/link-grammar/word-utils.c +526 -0
- data/ext/link_grammar/link-grammar/word-utils.h +152 -0
- data/ext/link_grammar/link_grammar.c +202 -0
- data/ext/link_grammar/link_grammar.h +99 -0
- data/grammar_cop.gemspec +24 -0
- data/lib/.DS_Store +0 -0
- data/lib/grammar_cop.rb +9 -0
- data/lib/grammar_cop/.DS_Store +0 -0
- data/lib/grammar_cop/dictionary.rb +19 -0
- data/lib/grammar_cop/linkage.rb +30 -0
- data/lib/grammar_cop/parse_options.rb +32 -0
- data/lib/grammar_cop/sentence.rb +36 -0
- data/lib/grammar_cop/version.rb +3 -0
- data/test/.DS_Store +0 -0
- data/test/grammar_cop_test.rb +27 -0
- metadata +407 -0
@@ -0,0 +1,487 @@
|
|
1
|
+
/*************************************************************************/
|
2
|
+
/* Copyright (c) 2004 */
|
3
|
+
/* Daniel Sleator, David Temperley, and John Lafferty */
|
4
|
+
/* All rights reserved */
|
5
|
+
/* */
|
6
|
+
/* Use of the link grammar parsing system is subject to the terms of the */
|
7
|
+
/* license set forth in the LICENSE file included with this software, */
|
8
|
+
/* and also available at http://www.link.cs.cmu.edu/link/license.html */
|
9
|
+
/* This license allows free redistribution and use in source and binary */
|
10
|
+
/* forms, with or without modification, subject to certain conditions. */
|
11
|
+
/* */
|
12
|
+
/*************************************************************************/
|
13
|
+
|
14
|
+
/* stuff for transforming a dictionary entry into a disjunct list */
|
15
|
+
|
16
|
+
#include <math.h>
|
17
|
+
#include "api.h"
|
18
|
+
#include "disjunct-utils.h"
|
19
|
+
#include "utilities.h" /* For Win32 compatibility features */
|
20
|
+
|
21
|
+
/* Temporary connectors used while converting expressions into disjunct lists */
|
22
|
+
typedef struct Tconnector_struct Tconnector;
|
23
|
+
struct Tconnector_struct
|
24
|
+
{
|
25
|
+
char multi; /* TRUE if this is a multi-connector */
|
26
|
+
char dir; /* '-' for left and '+' for right */
|
27
|
+
Tconnector * next;
|
28
|
+
const char * string;
|
29
|
+
};
|
30
|
+
|
31
|
+
typedef struct clause_struct Clause;
|
32
|
+
struct clause_struct
|
33
|
+
{
|
34
|
+
Clause * next;
|
35
|
+
float cost;
|
36
|
+
float maxcost;
|
37
|
+
Tconnector * c;
|
38
|
+
};
|
39
|
+
|
40
|
+
static void free_Tconnectors(Tconnector *e)
|
41
|
+
{
|
42
|
+
Tconnector * n;
|
43
|
+
for(;e != NULL; e=n)
|
44
|
+
{
|
45
|
+
n = e->next;
|
46
|
+
xfree((char *)e, sizeof(Tconnector));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
static void free_clause_list(Clause *c)
|
51
|
+
{
|
52
|
+
Clause *c1;
|
53
|
+
while (c != NULL)
|
54
|
+
{
|
55
|
+
c1 = c->next;
|
56
|
+
free_Tconnectors(c->c);
|
57
|
+
xfree((char *)c, sizeof(Clause));
|
58
|
+
c = c1;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
#ifdef UNUSED_FUNCTION
|
63
|
+
/**
|
64
|
+
* This builds a new copy of the connector list pointed to by c.
|
65
|
+
* Strings, as usual, are not copied.
|
66
|
+
*/
|
67
|
+
static Tconnector * copy_Tconnectors(Tconnector * c)
|
68
|
+
{
|
69
|
+
Tconnector *c1;
|
70
|
+
if (c == NULL) return NULL;
|
71
|
+
c1 = (Tconnector *) xalloc(sizeof(Tconnector));
|
72
|
+
*c1 = *c;
|
73
|
+
c1->next = copy_Tconnectors(c->next);
|
74
|
+
return c1;
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* This builds a new copy of the clause pointed to by d (except for the
|
79
|
+
* next field which is set to NULL). Strings, as usual, are not copied.
|
80
|
+
*/
|
81
|
+
static Clause * copy_clause(Clause * d)
|
82
|
+
{
|
83
|
+
Clause * d1;
|
84
|
+
if (d == NULL) return NULL;
|
85
|
+
d1 = (Clause *) xalloc(sizeof(Clause));
|
86
|
+
*d1 = *d;
|
87
|
+
d1->next = NULL;
|
88
|
+
d1->c = copy_Tconnectors(d->c);
|
89
|
+
return d1;
|
90
|
+
}
|
91
|
+
#endif /* UNUSED_FUNCTION */
|
92
|
+
|
93
|
+
/**
|
94
|
+
* reverse the order of the list e. destructive
|
95
|
+
*/
|
96
|
+
static Tconnector * Treverse(Tconnector *e)
|
97
|
+
{
|
98
|
+
Tconnector * head, *x;
|
99
|
+
head = NULL;
|
100
|
+
while (e != NULL) {
|
101
|
+
x = e->next;
|
102
|
+
e->next = head;
|
103
|
+
head = e;
|
104
|
+
e = x;
|
105
|
+
}
|
106
|
+
return head;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* reverse the order of the list e. destructive
|
111
|
+
*/
|
112
|
+
static Connector * reverse(Connector *e)
|
113
|
+
{
|
114
|
+
Connector * head, *x;
|
115
|
+
head = NULL;
|
116
|
+
while (e != NULL) {
|
117
|
+
x = e->next;
|
118
|
+
e->next = head;
|
119
|
+
head = e;
|
120
|
+
e = x;
|
121
|
+
}
|
122
|
+
return head;
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Builds a new list of connectors that is the catenation of e1 with e2.
|
127
|
+
* does not effect lists e1 or e2. Order is maintained.
|
128
|
+
*/
|
129
|
+
static Tconnector * catenate(Tconnector * e1, Tconnector * e2)
|
130
|
+
{
|
131
|
+
Tconnector * e, * head;
|
132
|
+
head = NULL;
|
133
|
+
for (;e1 != NULL; e1 = e1->next) {
|
134
|
+
e = (Tconnector *) xalloc(sizeof(Tconnector));
|
135
|
+
*e = *e1;
|
136
|
+
e->next = head;
|
137
|
+
head = e;
|
138
|
+
}
|
139
|
+
for (;e2 != NULL; e2 = e2->next) {
|
140
|
+
e = (Tconnector *) xalloc(sizeof(Tconnector));
|
141
|
+
*e = *e2;
|
142
|
+
e->next = head;
|
143
|
+
head = e;
|
144
|
+
}
|
145
|
+
return Treverse(head);
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* build the connector for the terminal node n
|
150
|
+
*/
|
151
|
+
static Tconnector * build_terminal(Exp * e)
|
152
|
+
{
|
153
|
+
Tconnector * c;
|
154
|
+
c = (Tconnector *) xalloc(sizeof(Tconnector));
|
155
|
+
c->string = e->u.string;
|
156
|
+
c->multi = e->multi;
|
157
|
+
c->dir = e->dir;
|
158
|
+
c->next = NULL;
|
159
|
+
return c;
|
160
|
+
}
|
161
|
+
|
162
|
+
#ifdef UNUSED_FUNCTION
|
163
|
+
static xxxfloat-int maxcost_of_expression(Exp *e)
|
164
|
+
{
|
165
|
+
E_list * e_list;
|
166
|
+
int m, m1;
|
167
|
+
|
168
|
+
m = 0;
|
169
|
+
|
170
|
+
if ((e->type == AND_type) || (e->type == OR_type)) {
|
171
|
+
for (e_list = e->u.l; e_list != NULL; e_list = e_list->next) {
|
172
|
+
m1 = maxcost_of_expression(e_list->e);
|
173
|
+
m = MAX(m, m1);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
return (m + e->cost);
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* This returns the maximum maxcost of any disjunct in the sentence
|
181
|
+
* Assumes the sentence expressions have been constructed
|
182
|
+
*/
|
183
|
+
static xxx-float-int maxcost_of_sentence(Sentence sent)
|
184
|
+
{
|
185
|
+
X_node * x;
|
186
|
+
int w, m, m1;
|
187
|
+
m = 0;
|
188
|
+
|
189
|
+
for (w = 0; w < sent->length; w++)
|
190
|
+
{
|
191
|
+
for (x = sent->word[w].x; x != NULL; x = x->next)
|
192
|
+
{
|
193
|
+
m1 = maxcost_of_expression(x->exp),
|
194
|
+
m = MAX(m, m1);
|
195
|
+
}
|
196
|
+
}
|
197
|
+
return m;
|
198
|
+
}
|
199
|
+
#endif /* UNUSED_FUNCTION */
|
200
|
+
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Build the clause for the expression e. Does not change e
|
204
|
+
*/
|
205
|
+
static Clause * build_clause(Exp *e)
|
206
|
+
{
|
207
|
+
Clause *c = NULL, *c1, *c2, *c3, *c4, *c_head;
|
208
|
+
E_list * e_list;
|
209
|
+
|
210
|
+
assert(e != NULL, "build_clause called with null parameter");
|
211
|
+
if (e->type == AND_type)
|
212
|
+
{
|
213
|
+
c1 = (Clause *) xalloc(sizeof (Clause));
|
214
|
+
c1->c = NULL;
|
215
|
+
c1->next = NULL;
|
216
|
+
c1->cost = 0.0f;
|
217
|
+
c1->maxcost = 0.0f ;
|
218
|
+
for (e_list = e->u.l; e_list != NULL; e_list = e_list->next)
|
219
|
+
{
|
220
|
+
c2 = build_clause(e_list->e);
|
221
|
+
c_head = NULL;
|
222
|
+
for (c3 = c1; c3 != NULL; c3 = c3->next)
|
223
|
+
{
|
224
|
+
for (c4 = c2; c4 != NULL; c4 = c4->next)
|
225
|
+
{
|
226
|
+
c = (Clause *) xalloc(sizeof (Clause));
|
227
|
+
c->cost = c3->cost + c4->cost;
|
228
|
+
c->maxcost = fmaxf(c3->maxcost,c4->maxcost);
|
229
|
+
c->c = catenate(c3->c, c4->c);
|
230
|
+
c->next = c_head;
|
231
|
+
c_head = c;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
free_clause_list(c1);
|
235
|
+
free_clause_list(c2);
|
236
|
+
c1 = c_head;
|
237
|
+
}
|
238
|
+
c = c1;
|
239
|
+
}
|
240
|
+
else if (e->type == OR_type)
|
241
|
+
{
|
242
|
+
/* we'll catenate the lists of clauses */
|
243
|
+
c = NULL;
|
244
|
+
for (e_list = e->u.l; e_list != NULL; e_list = e_list->next)
|
245
|
+
{
|
246
|
+
c1 = build_clause(e_list->e);
|
247
|
+
while(c1 != NULL) {
|
248
|
+
c3 = c1->next;
|
249
|
+
c1->next = c;
|
250
|
+
c = c1;
|
251
|
+
c1 = c3;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
else if (e->type == CONNECTOR_type)
|
256
|
+
{
|
257
|
+
c = (Clause *) xalloc(sizeof(Clause));
|
258
|
+
c->c = build_terminal(e);
|
259
|
+
c->cost = 0.0f;
|
260
|
+
c->maxcost = 0.0f;
|
261
|
+
c->next = NULL;
|
262
|
+
}
|
263
|
+
else
|
264
|
+
{
|
265
|
+
assert(FALSE, "an expression node with no type");
|
266
|
+
}
|
267
|
+
|
268
|
+
/* c now points to the list of clauses */
|
269
|
+
for (c1 = c; c1 != NULL; c1 = c1->next)
|
270
|
+
{
|
271
|
+
c1->cost += e->cost;
|
272
|
+
/* c1->maxcost = MAX(c1->maxcost,e->cost); */
|
273
|
+
/* Above is how Dennis had it. Someone changed it to below.
|
274
|
+
* However, this can sometimes lead to a maxcost that is less
|
275
|
+
* than the cost ! -- which seems wrong to me ... seems Dennis
|
276
|
+
* had it right!?
|
277
|
+
*/
|
278
|
+
c1->maxcost += e->cost;
|
279
|
+
}
|
280
|
+
return c;
|
281
|
+
}
|
282
|
+
|
283
|
+
/* #define DEBUG */
|
284
|
+
#ifdef DEBUG
|
285
|
+
/* Misc printing functions, useful for debugging */
|
286
|
+
|
287
|
+
static void print_Tconnector_list(Tconnector * e)
|
288
|
+
{
|
289
|
+
for (;e != NULL; e=e->next) {
|
290
|
+
if (e->multi) printf("@");
|
291
|
+
printf("%s",e->string);
|
292
|
+
printf("%c", e->dir);
|
293
|
+
if (e->next != NULL) printf(" ");
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
static void print_clause_list(Clause * c)
|
298
|
+
{
|
299
|
+
for (;c != NULL; c=c->next) {
|
300
|
+
printf(" Clause: ");
|
301
|
+
printf("(%4.2f, %4.2f) ", c->cost, c->maxcost);
|
302
|
+
print_Tconnector_list(c->c);
|
303
|
+
printf("\n");
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
static void print_connector_list(Connector * e)
|
308
|
+
{
|
309
|
+
for (;e != NULL; e=e->next)
|
310
|
+
{
|
311
|
+
printf("%s",e->string);
|
312
|
+
if (e->label != NORMAL_LABEL) {
|
313
|
+
printf("%3d", e->label);
|
314
|
+
} else {
|
315
|
+
printf(" ");
|
316
|
+
}
|
317
|
+
if (e->next != NULL) printf(" ");
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
static void print_disjunct_list(Disjunct * c)
|
322
|
+
{
|
323
|
+
for (;c != NULL; c=c->next) {
|
324
|
+
printf("%10s: ", c->string);
|
325
|
+
printf("(%f) ", c->cost);
|
326
|
+
print_connector_list(c->left);
|
327
|
+
printf(" <--> ");
|
328
|
+
print_connector_list(c->right);
|
329
|
+
printf("\n");
|
330
|
+
}
|
331
|
+
}
|
332
|
+
#endif /* DEBUG */
|
333
|
+
|
334
|
+
/**
|
335
|
+
* Build a new list of connectors starting from the Tconnectors
|
336
|
+
* in the list pointed to by e. Keep only those whose strings whose
|
337
|
+
* direction has the value c.
|
338
|
+
*/
|
339
|
+
static Connector * extract_connectors(Tconnector *e, int c)
|
340
|
+
{
|
341
|
+
Connector *e1;
|
342
|
+
if (e == NULL) return NULL;
|
343
|
+
if (e->dir == c)
|
344
|
+
{
|
345
|
+
e1 = connector_new();
|
346
|
+
e1->next = extract_connectors(e->next,c);
|
347
|
+
e1->multi = e->multi;
|
348
|
+
e1->string = e->string;
|
349
|
+
e1->word = 0;
|
350
|
+
return e1;
|
351
|
+
}
|
352
|
+
else
|
353
|
+
{
|
354
|
+
return extract_connectors(e->next,c);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
/**
|
359
|
+
* Build a disjunct list out of the clause list c.
|
360
|
+
* string is the print name of word that generated this disjunct.
|
361
|
+
*/
|
362
|
+
static Disjunct *
|
363
|
+
build_disjunct(Clause * cl, const char * string, float cost_cutoff)
|
364
|
+
{
|
365
|
+
Disjunct *dis, *ndis;
|
366
|
+
dis = NULL;
|
367
|
+
for (; cl != NULL; cl = cl->next)
|
368
|
+
{
|
369
|
+
if (cl->maxcost <= cost_cutoff)
|
370
|
+
{
|
371
|
+
ndis = (Disjunct *) xalloc(sizeof(Disjunct));
|
372
|
+
ndis->left = reverse(extract_connectors(cl->c, '-'));
|
373
|
+
ndis->right = reverse(extract_connectors(cl->c, '+'));
|
374
|
+
ndis->string = string;
|
375
|
+
ndis->cost = cl->cost;
|
376
|
+
ndis->next = dis;
|
377
|
+
dis = ndis;
|
378
|
+
}
|
379
|
+
}
|
380
|
+
return dis;
|
381
|
+
}
|
382
|
+
|
383
|
+
Disjunct * build_disjuncts_for_X_node(X_node * x, float cost_cutoff)
|
384
|
+
{
|
385
|
+
Clause *c ;
|
386
|
+
Disjunct * dis;
|
387
|
+
/* print_expression(x->exp); printf("\n"); */
|
388
|
+
c = build_clause(x->exp);
|
389
|
+
/* print_clause_list(c); */
|
390
|
+
dis = build_disjunct(c, x->string, cost_cutoff);
|
391
|
+
/* print_disjunct_list(dis); */
|
392
|
+
free_clause_list(c);
|
393
|
+
return dis;
|
394
|
+
}
|
395
|
+
|
396
|
+
#if DEBUG
|
397
|
+
/* There is a much better print_expression elsewhere
|
398
|
+
* This one is for low-level debug. */
|
399
|
+
void prt_exp(Exp *e, int i)
|
400
|
+
{
|
401
|
+
if (e == NULL) return;
|
402
|
+
|
403
|
+
for(int j =0; j<i; j++) printf(" ");
|
404
|
+
printf ("type=%d dir=%c multi=%d cost=%f\n", e->type, e->dir, e->multi, e->cost);
|
405
|
+
if (e->type != CONNECTOR_type)
|
406
|
+
{
|
407
|
+
E_list *l = e->u.l;
|
408
|
+
while(l)
|
409
|
+
{
|
410
|
+
prt_exp(l->e, i+2);
|
411
|
+
l = l->next;
|
412
|
+
}
|
413
|
+
}
|
414
|
+
else
|
415
|
+
{
|
416
|
+
for(int j =0; j<i; j++) printf(" ");
|
417
|
+
printf("con=%s\n", e->u.string);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
#endif
|
421
|
+
|
422
|
+
/**
|
423
|
+
* Build a list of disjuncts.
|
424
|
+
*
|
425
|
+
* This is mostly used only for counting the number of disjuncts
|
426
|
+
* (but is otherwise "almost" obsolete ??)
|
427
|
+
*/
|
428
|
+
Disjunct * build_disjuncts_for_dict_node(Dict_node *dn)
|
429
|
+
{
|
430
|
+
Disjunct *dj;
|
431
|
+
X_node x;
|
432
|
+
x.exp = dn->exp;
|
433
|
+
x.string = dn->string;
|
434
|
+
dj = build_disjuncts_for_X_node(&x, MAX_CONNECTOR_COST);
|
435
|
+
/* print_disjunct_list(dj); */
|
436
|
+
return dj;
|
437
|
+
}
|
438
|
+
|
439
|
+
/**
|
440
|
+
* build_word_expressions() -- build list of expressions for a word
|
441
|
+
*
|
442
|
+
* Looks up the word s in the dictionary. Returns NULL if it's not there.
|
443
|
+
* If there, it builds the list of expressions for the word, and returns
|
444
|
+
* a pointer to it.
|
445
|
+
*/
|
446
|
+
X_node * build_word_expressions(Dictionary dict, const char * s)
|
447
|
+
{
|
448
|
+
Dict_node * dn, *dn_head;
|
449
|
+
X_node * x, * y;
|
450
|
+
|
451
|
+
dn_head = dictionary_lookup_list(dict, s);
|
452
|
+
dn = dn_head;
|
453
|
+
|
454
|
+
x = NULL;
|
455
|
+
while (dn != NULL)
|
456
|
+
{
|
457
|
+
y = (X_node *) xalloc(sizeof(X_node));
|
458
|
+
y->next = x;
|
459
|
+
x = y;
|
460
|
+
x->exp = copy_Exp(dn->exp);
|
461
|
+
x->string = dn->string;
|
462
|
+
dn = dn->right;
|
463
|
+
}
|
464
|
+
free_lookup_list (dn_head);
|
465
|
+
return x;
|
466
|
+
}
|
467
|
+
|
468
|
+
/**
|
469
|
+
* Turn sentence expressions into disjuncts.
|
470
|
+
* Sentence expressions must have been built, before calling this routine.
|
471
|
+
*/
|
472
|
+
void build_sentence_disjuncts(Sentence sent, float cost_cutoff)
|
473
|
+
{
|
474
|
+
Disjunct * d;
|
475
|
+
X_node * x;
|
476
|
+
int w;
|
477
|
+
for (w = 0; w < sent->length; w++)
|
478
|
+
{
|
479
|
+
d = NULL;
|
480
|
+
for (x = sent->word[w].x; x != NULL; x = x->next)
|
481
|
+
{
|
482
|
+
Disjunct *dx = build_disjuncts_for_X_node(x, cost_cutoff);
|
483
|
+
d = catenate_disjuncts(dx, d);
|
484
|
+
}
|
485
|
+
sent->word[w].d = d;
|
486
|
+
}
|
487
|
+
}
|