rwdeliza 0.03

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.
Files changed (222) hide show
  1. data/ElizaData/database/db.1 +7015 -0
  2. data/ElizaData/database/db.10 +7001 -0
  3. data/ElizaData/database/db.11 +7001 -0
  4. data/ElizaData/database/db.12 +7003 -0
  5. data/ElizaData/database/db.13 +7003 -0
  6. data/ElizaData/database/db.14 +7008 -0
  7. data/ElizaData/database/db.15 +7001 -0
  8. data/ElizaData/database/db.16 +7001 -0
  9. data/ElizaData/database/db.17 +7001 -0
  10. data/ElizaData/database/db.18 +7001 -0
  11. data/ElizaData/database/db.19 +7001 -0
  12. data/ElizaData/database/db.2 +7001 -0
  13. data/ElizaData/database/db.20 +5467 -0
  14. data/ElizaData/database/db.3 +7001 -0
  15. data/ElizaData/database/db.4 +7001 -0
  16. data/ElizaData/database/db.5 +7001 -0
  17. data/ElizaData/database/db.6 +7001 -0
  18. data/ElizaData/database/db.7 +7001 -0
  19. data/ElizaData/database/db.8 +7001 -0
  20. data/ElizaData/database/db.9 +7001 -0
  21. data/ElizaData/responses/hello.res +1 -0
  22. data/ElizaData/responses/i_agree.res +1 -0
  23. data/ElizaData/responses/i_am_listening_to_you.res +1 -0
  24. data/ElizaData/responses/please_explain.res +1 -0
  25. data/ElizaData/responses/thank_you.res +1 -0
  26. data/ElizaData/tiny.dict +211 -0
  27. data/ElizaData/words/adjectives1.words +906 -0
  28. data/ElizaData/words/adjectives2w.words +1 -0
  29. data/ElizaData/words/noun0.words +15 -0
  30. data/ElizaData/words/noun1.words +1391 -0
  31. data/ElizaData/words/noun2.words +1924 -0
  32. data/ElizaData/words/noun4.words +330 -0
  33. data/ElizaData/words/pronoun1.words +6 -0
  34. data/ElizaData/words/verb4.words +350 -0
  35. data/ElizaData/words/verb42.words +391 -0
  36. data/ElizaData/words/verb42w.words +1 -0
  37. data/ElizaData/words/verb43.words +402 -0
  38. data/ElizaData/words/verb43w.words +1 -0
  39. data/ElizaData/words/verb45.words +452 -0
  40. data/ElizaData/words/verb4w.words +1 -0
  41. data/ElizaData/words/verb5.words +13 -0
  42. data/ElizaData/words/verb61.words +35 -0
  43. data/ElizaData/words/verb62.words +41 -0
  44. data/ElizaData/words/verb83.words +17 -0
  45. data/Readme.txt +462 -0
  46. data/bin/rwdeliza +19 -0
  47. data/code/01rwdcore/01rwdcore.rb +29 -0
  48. data/code/01rwdcore/02helptexthashbegin.rb +4 -0
  49. data/code/01rwdcore/03helptexthash.rb +23 -0
  50. data/code/01rwdcore/04helptextend.rb +6 -0
  51. data/code/01rwdcore/jumplinkcommand.rb +26 -0
  52. data/code/01rwdcore/openhelpwindow.rb +31 -0
  53. data/code/01rwdcore/returntomain.rb +10 -0
  54. data/code/01rwdcore/rundocuments.rb +10 -0
  55. data/code/01rwdcore/runeditconfiguration.rb +10 -0
  56. data/code/01rwdcore/runhelpabout.rb +10 -0
  57. data/code/01rwdcore/runopentinkerdocument.rb +7 -0
  58. data/code/01rwdcore/rwdtinkerversion.rb +22 -0
  59. data/code/01rwdcore/rwdwindowreturn.rb +9 -0
  60. data/code/01rwdcore/selectiontab.rb +9 -0
  61. data/code/01rwdcore/setuphelpaboutoptions.rb +13 -0
  62. data/code/01rwdcore/setuptinkerdocuments.rb +6 -0
  63. data/code/01rwdcore/test_cases.rb +109 -0
  64. data/code/01rwdcore/test_harness.rb +13 -0
  65. data/code/01rwdcore/uploadreturns.rb +62 -0
  66. data/code/dd0viewphoto/dd0viewphoto.rb +3 -0
  67. data/code/superant.com.rwdeliza/0uninstallapplet.rb +10 -0
  68. data/code/superant.com.rwdeliza/eliza01.rb +45 -0
  69. data/code/superant.com.rwdeliza/helptexthashrwdeliza.rb +39 -0
  70. data/code/superant.com.rwdeliza/openhelpwindowrwdeliza.rb +23 -0
  71. data/code/superant.com.rwdeliza/runrwdshellwindow.rb +12 -0
  72. data/code/superant.com.rwdeliza/rwdtinkerversion.rb +10 -0
  73. data/code/superant.com.rwdeliza/tagsentence.rb +39 -0
  74. data/code/superant.com.rwdtinkerbackwindow/diagnostictab.rb +19 -0
  75. data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +61 -0
  76. data/code/superant.com.rwdtinkerbackwindow/initiateapplets.rb +240 -0
  77. data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +34 -0
  78. data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +20 -0
  79. data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
  80. data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +53 -0
  81. data/code/superant.com.rwdtinkerbackwindow/listinstalledfiles.rb +12 -0
  82. data/code/superant.com.rwdtinkerbackwindow/listzips.rb +27 -0
  83. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationrecord.rb +22 -0
  84. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationvariables.rb +14 -0
  85. data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
  86. data/code/superant.com.rwdtinkerbackwindow/openappletname.rb +19 -0
  87. data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +38 -0
  88. data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
  89. data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +46 -0
  90. data/code/superant.com.rwdtinkerbackwindow/removeappletvariables.rb +52 -0
  91. data/code/superant.com.rwdtinkerbackwindow/runremoteinstall.rb +11 -0
  92. data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +15 -0
  93. data/code/superant.com.rwdtinkerbackwindow/rwdtinkerwin2version.rb +13 -0
  94. data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +19 -0
  95. data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +22 -0
  96. data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +24 -0
  97. data/code/superant.com.words/dictlookup.rb +20 -0
  98. data/code/superant.com.words/runfortunewindow.rb +14 -0
  99. data/code/superant.com.words/runrwdwordsbackwindow.rb +10 -0
  100. data/code/superant.com.words/runrwdwordsversion.rb +14 -0
  101. data/code/superant.com.words/rwdtinkerversion.rb +10 -0
  102. data/code/zz0applicationend/zz0end.rb +4 -0
  103. data/configuration/language.dist +8 -0
  104. data/configuration/rwdapplicationidentity.dist +3 -0
  105. data/configuration/rwdtinker.dist +18 -0
  106. data/configuration/rwdweliza-0.03.dist +31 -0
  107. data/configuration/tinkerwin2variables.dist +17 -0
  108. data/gui/00coreguibegin/applicationguitop.rwd +4 -0
  109. data/gui/frontwindow0/cc0openphoto.rwd +22 -0
  110. data/gui/frontwindowselections/00selectiontabbegin.rwd +11 -0
  111. data/gui/frontwindowselections/jumplinkcommands.rwd +15 -0
  112. data/gui/frontwindowselections/wwselectionend.rwd +3 -0
  113. data/gui/frontwindowtdocuments/00documentbegin.rwd +6 -0
  114. data/gui/frontwindowtdocuments/tinkerdocuments.rwd +14 -0
  115. data/gui/frontwindowtdocuments/zzdocumentend.rwd +8 -0
  116. data/gui/helpaboutbegin/zzzrwdlasttab.rwd +6 -0
  117. data/gui/helpaboutbegin/zzzzhelpscreenstart.rwd +3 -0
  118. data/gui/helpaboutbegin/zzzzzzhelpabouttab.rwd +15 -0
  119. data/gui/helpaboutzend/helpscreenend.rwd +3 -0
  120. data/gui/helpaboutzend/zhelpscreenstart2.rwd +3 -0
  121. data/gui/helpaboutzend/zzzzhelpabout2.rwd +15 -0
  122. data/gui/helpaboutzend/zzzzhelpscreen2end.rwd +3 -0
  123. data/gui/tinkerbackwindows/superant.com.refreshwindow/fortunerefreshwindowtwo.rwd +9 -0
  124. data/gui/tinkerbackwindows/superant.com.rwdeliza/1appname.rwd +5 -0
  125. data/gui/tinkerbackwindows/superant.com.rwdeliza/1eliza.rwd +21 -0
  126. data/gui/tinkerbackwindows/superant.com.rwdeliza/4sentance.rwd +21 -0
  127. data/gui/tinkerbackwindows/superant.com.rwdeliza/98jumplinkcommands.rwd +17 -0
  128. data/gui/tinkerbackwindows/superant.com.rwdeliza/zbackend.rwd +6 -0
  129. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/1appname.rwd +5 -0
  130. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/20downloadftp.rwd +45 -0
  131. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/67viewconfiguration.rwd +29 -0
  132. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/70rwddiagnostics.rwd +16 -0
  133. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/m01menubegin.rwd +18 -0
  134. data/gui/tinkerbackwindows/superant.com.rwdschedulebackwindow/zvbackend.rwd +6 -0
  135. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/1appname.rwd +5 -0
  136. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +41 -0
  137. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
  138. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +44 -0
  139. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +30 -0
  140. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/70rwddiagnostics.rwd +29 -0
  141. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/81jumplinkcommands.rwd +17 -0
  142. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/9backend.rwd +6 -0
  143. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +31 -0
  144. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/9end.rwd +4 -0
  145. data/gui/tinkerbackwindows/superant.com.versionwindow/1appname.rwd +19 -0
  146. data/gui/tinkerbackwindows/superant.com.versionwindow/helpaboutwindow.rwd +17 -0
  147. data/gui/tinkerbackwindows/superant.com.words/1appname.rwd +4 -0
  148. data/gui/tinkerbackwindows/superant.com.words/1dictionary.rwd +19 -0
  149. data/gui/tinkerbackwindows/superant.com.words/3rwdfortune.rwd +14 -0
  150. data/gui/tinkerbackwindows/superant.com.words/77jumplinkcommands.rwd +17 -0
  151. data/gui/tinkerbackwindows/superant.com.words/z9end.rwd +6 -0
  152. data/gui/zzcoreguiend/yy9rwdend.rwd +4 -0
  153. data/init.rb +277 -0
  154. data/installed/rwdweliza-0.03.inf +24 -0
  155. data/installed/temp.rb +1 -0
  156. data/lang/en/rwdcore/languagefile.rb +58 -0
  157. data/lang/es/rwdcore/languagefile-es.rb +62 -0
  158. data/lang/fr/rwdcore/languagefile.rb +64 -0
  159. data/lang/jp/rwdcore/languagefile.rb +72 -0
  160. data/lang/nl/rwdcore/languagefile.rb +75 -0
  161. data/lib/dict.rb +438 -0
  162. data/lib/druida.rb +499 -0
  163. data/lib/hashslice.rb +71 -0
  164. data/lib/linguistics.rb +360 -0
  165. data/lib/linguistics/en.rb +1601 -0
  166. data/lib/linguistics/en/infinitive.rb +1148 -0
  167. data/lib/linguistics/en/linkparser.rb +142 -0
  168. data/lib/linguistics/en/wordnet.rb +253 -0
  169. data/lib/linguistics/iso639.rb +456 -0
  170. data/lib/linkparser.rb +461 -0
  171. data/lib/linkparser/connection.rb +81 -0
  172. data/lib/linkparser/connector.rb +201 -0
  173. data/lib/linkparser/definition.rb +225 -0
  174. data/lib/linkparser/dictionary.rb +208 -0
  175. data/lib/linkparser/linkage.rb +185 -0
  176. data/lib/linkparser/log.rb +39 -0
  177. data/lib/linkparser/sentence.rb +79 -0
  178. data/lib/linkparser/utils.rb +540 -0
  179. data/lib/linkparser/word.rb +92 -0
  180. data/lib/rconftool.rb +380 -0
  181. data/lib/rwd/browser.rb +123 -0
  182. data/lib/rwd/ftools.rb +174 -0
  183. data/lib/rwd/mime.rb +328 -0
  184. data/lib/rwd/net.rb +866 -0
  185. data/lib/rwd/ruby.rb +889 -0
  186. data/lib/rwd/rwd.rb +1942 -0
  187. data/lib/rwd/sgml.rb +236 -0
  188. data/lib/rwd/thread.rb +63 -0
  189. data/lib/rwd/tree.rb +371 -0
  190. data/lib/rwd/xml.rb +101 -0
  191. data/lib/zip/ioextras.rb +114 -0
  192. data/lib/zip/stdrubyext.rb +111 -0
  193. data/lib/zip/tempfile_bugfixed.rb +195 -0
  194. data/lib/zip/zip.rb +1378 -0
  195. data/lib/zip/zipfilesystem.rb +558 -0
  196. data/lib/zip/ziprequire.rb +61 -0
  197. data/rwd_files/HowTo_Eliza.txt +195 -0
  198. data/rwd_files/HowTo_Tinker.txt +471 -0
  199. data/rwd_files/HowTo_TinkerWin2.txt +202 -0
  200. data/rwd_files/Readme.txt +57 -0
  201. data/rwd_files/RubyWebDialogs.html +6 -0
  202. data/rwd_files/favicon.ico +0 -0
  203. data/rwd_files/rdoc-style.css +175 -0
  204. data/rwd_files/rwdapplications.html +54 -0
  205. data/rwd_files/tinker.png +0 -0
  206. data/rwdconfig.dist +21 -0
  207. data/rwdeliza.rb +1 -0
  208. data/tests/RubyGauge.rb +179 -0
  209. data/tests/checkdepends.sh +4 -0
  210. data/tests/cleancnf.sh +6 -0
  211. data/tests/makedist-rwdweliza.rb +56 -0
  212. data/tests/makedist.rb +66 -0
  213. data/tests/rdep.rb +354 -0
  214. data/tests/totranslate.lang +93 -0
  215. data/zips/rwdwaddresses-1.05.zip +0 -0
  216. data/zips/rwdwcalc-0.61.zip +0 -0
  217. data/zips/rwdwgutenberg-0.09.zip +0 -0
  218. data/zips/rwdwschedule-1.04.zip +0 -0
  219. data/zips/rwdwshell-1.04.zip +0 -0
  220. data/zips/temp.rb +1 -0
  221. data/zips/wrubyslippers-1.06.zip +0 -0
  222. metadata +282 -0
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # dictionary.rb - this file contains the Dictionary class of the
4
+ # Ruby-LinkParser system. This governs the parsing of the dictionary files
5
+ # into their respective data structures.
6
+ #
7
+ # == Synopsis
8
+ #
9
+ # require "linkparser/dictionary"
10
+ #
11
+ # dict_opts = Hash::new('')
12
+ # dict_opts[dict] = "tiny.dict"
13
+ # dict_opts[affix] = "4.0.affix"
14
+ # dict_opts[datadir] = "/usr/local/share/linkparser"
15
+ # dict = LinkParser::Dictionary::new(dict_opts)
16
+ # puts dict['word'].to_connectors
17
+ #
18
+ # == Rcsid
19
+ #
20
+ # $Id: dictionary.rb,v 1.16 2003/08/28 04:49:34 stillflame Exp $
21
+ #
22
+ # == Authors
23
+ #
24
+ # Martin Chase <stillflame@FaerieMUD.org>
25
+ #
26
+ #:include: COPYRIGHT
27
+ #
28
+ #---
29
+ #
30
+ # Please see the file COPYRIGHT for licensing details.
31
+ #
32
+
33
+ require "forwardable"
34
+ require "rbconfig"
35
+ #require "linkparser/log"
36
+ require "linkparser/utils"
37
+ require "linkparser/definition"
38
+
39
+ class LinkParser
40
+
41
+ class Dictionary
42
+
43
+ DefaultDataDir = Config::CONFIG['datadir']
44
+
45
+ # Lots of constants for the handling of the different dictionary files.
46
+ Dict = 1
47
+ Affix = 2
48
+ Post = 3
49
+ Constituent = 4
50
+ DefaultDict = "4.0.dict"
51
+ DefaultAffix = "4.0.affix"
52
+ DefaultPost = "4.0.knowledge"
53
+ DefaultConstituent = "4.0.constituent-knowledge"
54
+
55
+ class << self
56
+
57
+ # This parses a dictionary string/file for its words and their
58
+ # definitions, returning a hash keyed by word with values being
59
+ # LinkParser::Definition objects.
60
+ def read_dict( dict, datadir = DefaultDataDir )
61
+ wordHash = {} # Hash#[] is faster than BinarySearchTree#[]
62
+ macros = [] # Array#each is faster than Hash#each
63
+
64
+ # read the dictionary file into an array of words:definition
65
+ # "statements", excluding comments.
66
+ statements = dict.gsub(/\n+|\s*%(?!\").*?\n/, " ").split(/\s*;(?!\")\s*/).compact
67
+ return nil if statements.empty?
68
+ statements.each {|statement|
69
+ words, definition = statement.split(/\s*:(?!\")\s*/)
70
+ macros.each {|macro|
71
+ definition.gsub!(macro[0], macro[1])
72
+ }
73
+ if(words =~ /<.*>/)
74
+ words.strip!
75
+ macros << [Regexp::new(words), definition]
76
+ elsif(!words or !definition)
77
+ $stderr.print "dict error #{statement}"
78
+
79
+ # raise ParseError, "Dictionary outta whack: '#{statement}'"
80
+ else
81
+ if words =~ /^\// #/
82
+ # then it's a filename, not a word, and the file will
83
+ # contain a list of words.
84
+ # Log.info("Reading in words from %s." % datadir + words)
85
+ $stderr.print "Reading in words \n"
86
+ words = File.open(datadir + words) {|f| f.read(f.stat.size)}
87
+ end
88
+ # so now we have a bunch of words and their shared
89
+ # definition. put each word into the hash with a value of
90
+ # the definition data structure.
91
+ words.gsub!(/"([^ ]+?)"/, '\1') # punctuation marks are in double-quotes
92
+ words = words.split(/\s+/)
93
+ definition = Definition::new(definition)
94
+ words.each {|word|
95
+ wordHash[word] = definition unless word.empty?
96
+ }
97
+ end
98
+ }
99
+ return wordHash
100
+ end
101
+
102
+ # This takes a filename of a dictionary, and reads it into the
103
+ # word-keyed hash.
104
+ def open_read_dict( dicttype, dictname, datadir = DefaultDataDir )
105
+ if dictname and dictname.empty?
106
+ # do nothing
107
+ return nil
108
+ else
109
+ if dictname
110
+ f = File.open( File.join(datadir, dictname) )
111
+ else
112
+ default = case dicttype
113
+ when Dict
114
+ DefaultDict
115
+ when Affix
116
+ DefaultAffix
117
+ when Post
118
+ DefaultPost
119
+ when Constituent
120
+ DefaultConstituent
121
+ end
122
+ f = File.open( File.join(datadir, default) )
123
+ end
124
+ return read_dict(f.read(f.stat.size), datadir)
125
+ end
126
+ end
127
+
128
+ end # class << self
129
+
130
+ extend Forwardable
131
+
132
+ # Initializes a new Dictionary object. takes a hash as its argument.
133
+ # entries:
134
+ # datadir - the directory where the dictionary files are located
135
+ # dict - the main dictionary file
136
+ # affix - the affix dictionary file
137
+ # knowledge - the post-processing dictionary file
138
+ # constituent-knowledge - the constituent knowledge dictionary file
139
+ #
140
+ # setting a value to an empty string prevents it from being used, which
141
+ # will work out fine for all but the datadir and the main dict. a value
142
+ # set to nil will mean to use the default setting.
143
+ def initialize( dict_opts )
144
+ @datadir = dict_opts['datadir'] || DefaultDataDir
145
+
146
+ @dict = Dictionary::open_read_dict( Dict,
147
+ dict_opts['dict'], @datadir )
148
+ @affix = Dictionary::open_read_dict( Affix,
149
+ dict_opts['affix'], @datadir )
150
+ @post = Dictionary::open_read_dict( Post,
151
+ dict_opts['knowledge'], @datadir )
152
+ @constituent = Dictionary::open_read_dict( Constituent,
153
+ dict_opts['constituent-knowledge'], @datadir )
154
+ end
155
+
156
+ # the directory that the dictionary files are located
157
+ attr_reader :datadir
158
+
159
+ # the main dictionary hash
160
+ attr_reader :dict
161
+
162
+ def_delegators :@dict, *(Hash.instance_methods(false))
163
+
164
+ # does affix processing on the words, which is just separating
165
+ # conjunctions and punctuation from the words they are next to.
166
+ def affix( words )
167
+ return words unless @affix
168
+ @affix.each {|punct,move|
169
+ words = words.inject([]) {|arr,ele|
170
+ if /RPUNC/.match(move.inspect) && /(.*)(#{Regexp.escape(punct)}.*)$/.match(ele)
171
+ arr << $1 << $2
172
+ elsif /LPUNC/.match(move.inspect) && /^(#{Regexp.escape(punct)})(.*)/.match(ele)
173
+ arr << $1 << $2
174
+ else
175
+ arr << ele
176
+ end
177
+ }
178
+ }
179
+ words
180
+ end
181
+
182
+ # the post-processing dictionary hash
183
+ attr_reader :post
184
+
185
+ # the constituent-knowledge dictionary hash
186
+ attr_reader :constituent
187
+
188
+ end # class Dictionary
189
+ end # module LinkParser
190
+
191
+ if $0 == __FILE__
192
+ # require 'profile'
193
+
194
+ # p LinkParser::Dictionary::read_dict("/home/stillflame/src/system-4.1/link-4.1/data/tiny.dict")["dog"]
195
+
196
+ s = <<-DICT
197
+ <macro>:(A- and {Bb+ or @C+});
198
+ <meow>:(Aa- & E+);
199
+ bar:(A- or A-) and A-;
200
+ foo:( ((A- and E-) and {Bb+ or (@C+ and De-)});% and (E+) );
201
+ word: %comment - miaow
202
+ (<meow>) | (<macro> & [@Dd- or De-]);
203
+ meow:(A+ and {B- or C-});
204
+ boo:[[[()]]];
205
+ am:((Sp- or (RS- & Bp-) or ({Q-} & SIp+)) & (((O+ or B-) & {@MV+}) or P+ or AF-));
206
+ DICT
207
+ LinkParser::Dictionary::read_dict(s).each {|k,v| puts "#{k} = #{(v).to_connectors}"}
208
+ end
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # linkage.rb - this file contains the class declarations for the
4
+ # LinkParser::Linkage class.
5
+ #
6
+ # == Synopsis
7
+ #
8
+ #
9
+ # == Rcsid
10
+ #
11
+ # $Id: linkage.rb,v 1.12 2003/08/10 21:56:40 stillflame Exp $
12
+ #
13
+ # == Authors
14
+ #
15
+ # Martin Chase <stillflame@FaerieMUD.org>
16
+ #
17
+ #:include: COPYRIGHT
18
+ #
19
+ #---
20
+ #
21
+ # Please see the file COPYRIGHT for licensing details.
22
+ #
23
+
24
+ require "linkparser/word"
25
+ require "linkparser/connection"
26
+ #require "linkparser/log"
27
+
28
+ class LinkParser
29
+
30
+ class Linkage
31
+
32
+ def initialize( words=[], connections=[] )
33
+ @connections = connections
34
+ @words = words
35
+ end
36
+
37
+ # the connections of this linkage
38
+ attr_reader :connections
39
+
40
+ # the words in this linkage
41
+ attr_reader :words
42
+
43
+ # Combine two linkages together.
44
+ def combine(other)
45
+ Linkage::new( @words.superimpose(other.words),
46
+ @connections + other.connections )
47
+ end
48
+ alias :+ :combine
49
+
50
+ # add new connections to the list of connections
51
+ def add_connections(*connections)
52
+ @connections += connections
53
+ self
54
+ end
55
+ alias :addConnections :add_connections
56
+
57
+ ### Inserts into this linkage the connection and words found in the
58
+ ### supplied arguments.
59
+ def insert(connection, left, right, left_word, right_word)
60
+ @connections << connection
61
+ if @words[left]
62
+ @words[left].combine!(left_word)
63
+ else
64
+ @words[left] = left_word
65
+ end
66
+ if @words[right]
67
+ @words[right].combine!(right_word)
68
+ else
69
+ @words[right] = right_word
70
+ end
71
+ self
72
+ end
73
+
74
+ # returns whether or not the linkage is valid
75
+ def valid?
76
+ (@connections.length + 1) >= @words.length
77
+ end
78
+
79
+ # returns whether the linkage is connected
80
+ def connected?
81
+ @words.length == @words.compact.length
82
+ end
83
+
84
+ # Hash on the only important part - the connections.
85
+ def hash
86
+ @connections.sort.hash
87
+ end
88
+
89
+ # Equality based only on the "important" parts.
90
+ def eql?(o)
91
+ @connections.sort.eql?(o.connections.sort)
92
+ end
93
+
94
+ # string display
95
+ def inspect
96
+ result = @words.collect {|word| word.to_s}.join(" ") +
97
+ " --- " + @connections.join(" ")
98
+ #:TODO: ?
99
+ end
100
+
101
+ # pretty string display
102
+ def to_s
103
+ rows = [] # the diagram
104
+ rows.unshift(@words.join(' ').split('')) # insert the words
105
+ pos = 0
106
+ starts = @words.map {|word| # the starting position of each word
107
+ start = pos
108
+ pos += word.to_s.length + 1
109
+ start
110
+ }
111
+ offsets = @words.map {|word| word.to_s.length / 2}
112
+ centers = (starts.zip(offsets)).map {|c| c[0]+c[1]} # where to attach connections to each word
113
+ pos = 0
114
+ spaces = [] # where there are spaces between words
115
+ @words.each {|word|
116
+ spaces << ((pos - 1)..(pos - 1)) if pos.nonzero?
117
+ pos += word.to_s.length + 1
118
+ }
119
+ rows.unshift(Array.new(rows[0].length, " "))
120
+ centers.each {|i| rows[0][i] = "|"}
121
+ conns = @connections.dup
122
+ until conns.empty?
123
+ row = Array.new(rows[0].length, " ")
124
+ these = []
125
+ conns.delete_if {|conn| conn.length == (rows.length - 1) and these << conn}
126
+ #:TODO: loops infinitely - need to use counter instead of rows.length
127
+ #next if these.empty?
128
+ these.each {|conn|
129
+ first = centers[conn.lword.position]
130
+ last = centers[conn.rword.position]
131
+ span = (first..last)
132
+ dist = span.to_a.length
133
+ disp = "+" + conn.to_s + "+" # minimum display string
134
+ if disp.length > dist
135
+ #:TODO: *ack*
136
+ # i will need to expand the spaces inbetween the words,
137
+ # as well as between the connection arcs, and then
138
+ # update the centers and spaces array. this could be
139
+ # done one space at a time, cycling through the possible
140
+ # word gaps.
141
+ space_affect = (spaces.index(spaces.find {|r| first <= r.first}))..(spaces.length - 1)
142
+ cent_affect = (centers.index(centers.find {|i| first <= i}))..(centers.length - 1)
143
+ until dist >= disp.length
144
+ #:?:
145
+ dist += 1
146
+ # centers.map! {|i|
147
+ # cent_affect.member?(centers.index(i)) ? i + 1 : i
148
+ # }
149
+ # first = centers[conn.lword.position]
150
+ # last = centers[conn.rword.position]
151
+ # span = (first..last)
152
+ # dist = span.to_a.length
153
+ end
154
+ elsif disp.length < dist
155
+ side = true
156
+ until disp.length >= dist
157
+ if side
158
+ disp[0] = "+-"
159
+ else
160
+ disp[-1] = "-+"
161
+ end
162
+ side = ! side
163
+ end
164
+ end
165
+ first.upto(last) do |i|
166
+ row[i] = disp.slice!(0).chr
167
+ end
168
+ }
169
+ centers.each_with_index {|i,w|
170
+ row[i] = "|" if row[i] == " " and
171
+ conns.find {|conn| [conn.rword, conn.lword].include?(@words[w])}
172
+ }
173
+ rows.unshift(row)
174
+ end
175
+ return (rows.map {|row| row.join('')}).join("\n")
176
+ end
177
+
178
+ # string conversion
179
+ def to_str
180
+ @words.join(' ')
181
+ end
182
+
183
+ end # class Linkage
184
+
185
+ end # class LinkParser
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # log - Sets up the logger by which the linkparser system can log itself.
4
+ #
5
+ # == Synopsis
6
+ #
7
+ #
8
+ #
9
+ # == Description
10
+ #
11
+ #
12
+ # == Author
13
+ #
14
+ # Martin Chase <stillflame@FaerieMUD.org>
15
+ #
16
+ # == Copyright
17
+ #
18
+ # Copyright (c) 2002, 2003 The FaerieMUD Consortium. All rights reserved.
19
+ #
20
+ # This module is free software. You may use, modify, and/or redistribute this
21
+ # software under the terms of the Perl Artistic License. (See
22
+ # http://language.perl.com/misc/Artistic.html)
23
+
24
+ require "log4r"
25
+
26
+ class LinkParser
27
+
28
+ include Log4r
29
+
30
+ Log = Logger::new( "LinkParser" )
31
+ Outputter.stderr.formatter =
32
+ PatternFormatter::new( :pattern => '\e[1;32m[%l] %C:\e[0m %.1024m' )
33
+ Log.outputters = Outputter.stderr
34
+ if $DEBUG
35
+ Log.level = Log4r::ALL
36
+ else
37
+ Log.level = Log4r::INFO
38
+ end
39
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # sentence.rb - this file contains the class definition for the
4
+ # LinkParser::Sentence class.
5
+ #
6
+
7
+ require "forwardable"
8
+
9
+ class LinkParser
10
+
11
+ class Sentence
12
+
13
+ extend Forwardable
14
+
15
+ # initializes a new Sentence object
16
+ def initialize
17
+ @definitions = []
18
+ @linkages = []
19
+ @names = []
20
+ end
21
+
22
+ # the definitions in this sentence
23
+ attr_accessor :definitions
24
+
25
+ # the linkages of this sentence
26
+ attr_accessor :linkages
27
+
28
+ # the words in this sentence
29
+ attr_accessor :names
30
+
31
+ def_delegators :@definitions, *(Array.instance_methods(false))
32
+
33
+ def to_str
34
+ @names.join(" ")
35
+ end
36
+
37
+ def sentence?
38
+ ! @linkages.empty?
39
+ end
40
+
41
+ def verb
42
+ return nil if @linkages.empty?
43
+ @linkages.find {|linkage|
44
+ vrb = linkage.connections.find {|conn|
45
+ conn.name.match(/^S/)
46
+ }
47
+ return vrb.rword if vrb
48
+ vrb = linkage.connections.find {|conn|
49
+ conn.name.match(/^O/)
50
+ }
51
+ return vrb.lword if vrb
52
+ }
53
+ return nil
54
+ end
55
+
56
+ def subject
57
+ return nil if @linkages.empty?
58
+ @linkages.find {|linkage|
59
+ subj = linkage.connections.find {|conn|
60
+ conn.name.match(/^S/)
61
+ }
62
+ return subj.lword if subj
63
+ }
64
+ return nil
65
+ end
66
+
67
+ def object
68
+ return nil if @linkages.empty?
69
+ @linkages.find {|linkage|
70
+ obj = linkage.connections.find {|conn|
71
+ conn.name.match(/^O/)
72
+ }
73
+ return obj.rword if obj
74
+ }
75
+ return nil
76
+ end
77
+
78
+ end # class Sentence
79
+ end # class LinkParser