rwdeliza 0.03

Sign up to get free protection for your applications and to get access to all the features.
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,81 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # connection.rb - this file contains the class declarations for the
4
+ # LinkParser::Connection class.
5
+ #
6
+ # == Synopsis
7
+ #
8
+ #
9
+ # == Rcsid
10
+ #
11
+ # $Id: connection.rb,v 1.3 2003/06/08 03:53:27 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
+ class LinkParser
25
+ class Connection
26
+ include Comparable
27
+
28
+ def initialize( conn1, conn2, lword, rword )
29
+ raise( ParseError::new( "A connection cannot be formed between two words that do not match: %s and %s" %
30
+ [ conn1, conn2 ]) ) unless
31
+ conn1.match(conn2)
32
+ @name, @subName = conn1.generalize(conn2)
33
+ @lword = lword
34
+ @rword = rword
35
+ @length = rword.position - lword.position
36
+ end
37
+
38
+ # the major name of the link
39
+ attr_reader :name
40
+
41
+ # the minor name of the link
42
+ attr_reader :subName
43
+
44
+ # the index of the word connected to this link on the left
45
+ attr_reader :lword
46
+
47
+ # the index of the word connected to this link on the right
48
+ attr_reader :rword
49
+
50
+ # the number of words spanned by this connection
51
+ attr_reader :length
52
+
53
+ # Hash on the important part - the name and subname.
54
+ def hash
55
+ [@name, @subName].hash
56
+ end
57
+
58
+ # Provide a consistent basis for sorting connections within a linkage to
59
+ # allow two linkages to be compared.
60
+ def <=>(other)
61
+ pos = self.lword.position <=> other.lword.position
62
+ return pos if pos.nonzero?
63
+ len = self.length <=> other.length
64
+ return len if len.nonzero?
65
+ return self.to_s <=> other.to_s
66
+ end
67
+
68
+ # Equality based only on the name and subname.
69
+ def eql?(o)
70
+ @name == o.name &&
71
+ @subName == o.subName &&
72
+ @length == o.length
73
+ end
74
+
75
+ # Stringification delegated to the @general connector.
76
+ def to_s
77
+ @name + @subName
78
+ end
79
+
80
+ end # class Connection
81
+ end # class LinkParser
@@ -0,0 +1,201 @@
1
+ #~/usr/bin/ruby
2
+ #
3
+ # connector.rb - this file contains the Connector class. This describes the
4
+ # behavior of an un-linked link, as they exist in the Definition of a word.
5
+ #
6
+ # == Synopsis
7
+ #
8
+ #
9
+ # == Rcsid
10
+ #
11
+ # $Id: connector.rb,v 1.5 2003/05/18 19:26:06 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
+ class LinkParser
25
+ class Connector
26
+
27
+ LEFT = 'l' # left side
28
+ RIGHT = 'r' # right side
29
+ BOTH = '*' # both sides
30
+ n = 1.0/0.0
31
+ ONCE = 1..1 # matches once
32
+ OPTIONAL = 0..1 # matches zero or one times
33
+ PLUS = 1..n # matches one or more times
34
+ STAR = 0..n # matches zero or more times
35
+ # The names 'star' and 'plus' are taken from regexen.
36
+ @@connectors = []
37
+
38
+ # Creates and returns a connector. Creation only happens once for each
39
+ # unique set of arguments.
40
+ # name - major name of the connector ('A','AA','P*',&c.)
41
+ # subName - minor name of the connector ('s' or 'p*x' from 'MVs' or
42
+ # 'MVp*x', respectively)
43
+ # side - which side the connector accepts from
44
+ # multiplicity - the number of connections required to satisfy this
45
+ # connector.
46
+ def Connector.new( name, subName='', side=BOTH, multiplicity=ONCE, cost=0 )
47
+ subName = '' unless subName
48
+ connector = super(name,subName,side,multiplicity,cost)
49
+ if(already = (@@connectors.find {|c| c.eql? connector}))
50
+ return already
51
+ else
52
+ @@connectors << connector
53
+ return connector
54
+ end
55
+ end
56
+
57
+ # Initializes a new Connector object.
58
+ def initialize( name, subName, side, multiplicity, cost )
59
+ @name = name
60
+ @subName = subName
61
+ @side = side
62
+ @multiplicity = multiplicity
63
+ @cost = cost
64
+ end
65
+
66
+ # The name of the connector.
67
+ attr_reader :name
68
+
69
+ # The sub name of the connector, if any.
70
+ attr_reader :subName
71
+
72
+ # The linking cost of the connector.
73
+ attr_reader :cost
74
+
75
+ # How many connections it takes to satisfy this connector.
76
+ attr_reader :multiplicity
77
+
78
+ # Whether or not the connector is optional.
79
+ def optional?
80
+ @multiplicity === 0
81
+ end
82
+ alias :optional :optional?
83
+
84
+ # Whether or not the connector accepts multiple connections.
85
+ def multiple?
86
+ @multiplicity === 2
87
+ end
88
+
89
+ # Which side the connector links to (LEFT, RIGHT or BOTH).
90
+ attr_reader :side
91
+
92
+ # Whether or not the connector links to the LEFT.
93
+ def left?
94
+ @side == LEFT or @side == BOTH
95
+ end
96
+
97
+ # Whether or not the connector links to the RIGHT.
98
+ def right?
99
+ @side == RIGHT or @side == BOTH
100
+ end
101
+
102
+ # Whether or not the connector links to both sides
103
+ def both?
104
+ @side == BOTH
105
+ end
106
+
107
+ # Returns self
108
+ def dup
109
+ self
110
+ end
111
+ alias :clone :dup
112
+
113
+ # Returns a simple stringy representation
114
+ def to_s
115
+ result = @name + @subName
116
+ result = "@" + result if self.multiple?
117
+ result += (@side == LEFT ? "-" : "+") unless @side == BOTH
118
+ result += "(#{@cost})" if self.cost.nonzero?
119
+ result = "{" + result + "}" if self.optional?
120
+ return result
121
+ end
122
+ alias :inspect :to_s
123
+
124
+ # Checks to see if the two connectors can match. rules for matching:
125
+ # 1: a '*' matches any character
126
+ # 2: a '^' matches only the '*' character
127
+ # 3: a 'a' matches either a 'a' or a '*' (for any character 'a-Z')
128
+ # 4: a Connector is considered to be followed by an infinite number of
129
+ # '*'s
130
+ def match(other)
131
+ return false unless (@side != other.side ||
132
+ @side == BOTH)
133
+ i = 0
134
+ while( i <= @name.length && i <= other.name.length )
135
+ return( false ) unless ( @name[i] == '*'[0] ||
136
+ other.name[i] == '*'[0] ||
137
+ ( (@name[i] == other.name[i]) &&
138
+ (@name[i] != '^'[0]) ) ||
139
+ (@name[i].nil? || other.name[i].nil?) )
140
+ i += 1
141
+ end
142
+
143
+ i = 0
144
+ while( i <= @subName.length && i <= other.subName.length )
145
+ return( false ) unless ( @subName[i] == '*'[0] ||
146
+ other.subName[i] == '*'[0] ||
147
+ ( (@subName[i] == other.subName[i]) &&
148
+ (@subName[i] != '^'[0]) ) ||
149
+ (@subName[i].nil? || other.subName[i].nil? ) )
150
+ i += 1
151
+ end
152
+
153
+ return true
154
+ end
155
+
156
+ # Generalizes this connector with the given other connector in a
157
+ # position-based comparison according to the following rules:
158
+ # Names are compared separately from subNames.
159
+ # Matching characters: left the same.
160
+ # '*' and any character: becomes a '*'.
161
+ # '^' matches only the '*' character
162
+ # Non-matching characters: turned into a '*'.
163
+ def generalize(other)
164
+ name = @name
165
+ subName = @subName
166
+
167
+ i = 0
168
+ while( i < name.length && i < other.name.length )
169
+ name[i] = '*' if name[i] != other.name[i] or
170
+ name[i,1] == '*' or other.name[i,1] == '*'
171
+ i += 1
172
+ end
173
+
174
+ if other.subName.empty?
175
+ subName = '*' * subName.length
176
+ elsif subName.empty?
177
+ subName = '*' * other.subName.length
178
+ else
179
+ i = 0
180
+ while( i < subName.length && i < other.subName.length )
181
+ subName[i] = '*' unless subName[i] == other.subName[i]
182
+ i += 1
183
+ end
184
+ end
185
+
186
+ return [name,subName]
187
+ end
188
+
189
+ # Tests for equality by value.
190
+ def eql?(other)
191
+ @name == other.name and
192
+ @subName == other.subName and
193
+ @cost == other.cost and
194
+ @multiplicity == other.multiplicity and
195
+ @side == other.side
196
+ end
197
+ alias :equal? :eql?;
198
+ alias :== :eql?;
199
+
200
+ end # class Connector
201
+ end # module LinkParser
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # definition.rb - contains the Definition class, a class the encompasses the
4
+ # way a word is defined in link grammar: a set of sets of connectors with
5
+ # sidedness.
6
+ #
7
+ # == Synopsis
8
+ #
9
+ #
10
+ # == Rcsid
11
+ #
12
+ # $Id: definition.rb,v 1.5 2003/05/15 01:51:32 stillflame Exp $
13
+ #
14
+ # == Authors
15
+ #
16
+ # Martin Chase <stillflame@FaerieMUD.org>
17
+ #
18
+ #:include: COPYRIGHT
19
+ #
20
+ #---
21
+ #
22
+ # Please see the file COPYRIGHT for licensing details.
23
+ #
24
+
25
+ #require "linkparser/log"
26
+ require "linkparser/utils"
27
+ require "linkparser/connector"
28
+
29
+ require "strscan"
30
+ require "forwardable"
31
+
32
+ class LinkParser
33
+
34
+ class Definition
35
+
36
+ # Constants for definition parsing.
37
+ Token = /\s+|@?[A-Z*^]+[a-z^*]*[+-]|\(|\[|\{|\)|\]|\}|[Aa][Nn][Dd]|&|[Oo][Rr]|\|/
38
+ Connect = /(@)?([A-Z*^]+[a-z^*]*)([+-])/
39
+ Conjunction = /(and)|(&)|(or)|(\|)/i
40
+ Open = /\(|\[|\{/
41
+ Close = /\)|\]|\}/
42
+ Space = /\s+/
43
+
44
+ # Takes a definition string and returns a Definition object populated
45
+ # with the set of sets of connectors that will satisfy that the provided
46
+ # string.
47
+ # args:
48
+ # definition - the string to be parsed for meaning, or a
49
+ # StringScanner on that string, possibly in mid-parse
50
+ def Definition.satisfy( definition )
51
+ Definition::new(Definition::re_satisfy(definition))
52
+ end
53
+
54
+ # The main body of satisfy,
55
+ def Definition.re_satisfy(definition)
56
+ definition = StringScanner.new( definition, false ) unless
57
+ definition.kind_of?(StringScanner)
58
+ results = []
59
+ side = nil
60
+ current = nil
61
+ multi = false
62
+
63
+ while definition.rest?
64
+ case current = definition.scan(Token)
65
+ when Connect
66
+ # Connectors - puts the connector alone in a set, and
67
+ # puts that into the results.
68
+ connector_m = Connect.match( current )
69
+ side = connector_m[3] =~ /-/ ? Connector::LEFT : Connector::RIGHT
70
+ multi = connector_m[1] ? Connector::PLUS : Connector::ONCE
71
+ name_scan = StringScanner::new(connector_m[2])
72
+ # Slurp in all the characters up to the last capitol
73
+ # letter and up to one star or caret.
74
+ name = name_scan.scan(/.*[A-Z][*^]?/)
75
+ sub_name = name_scan.rest or ''
76
+ # Log.debug( "Found connector '%s'" % current )
77
+ results << [ Connector::new(name, sub_name, side, multi) ]
78
+ when Conjunction
79
+ # Conjunctions (and, or) - combine the results so far with the
80
+ # results of what would be the rest of the parse, as per the
81
+ # rules of the conjunction used.
82
+ conj_m = Conjunction.match( current )
83
+ raise ParseError, "conjunction with nothing preceeding it: '#{definition.string}'" if
84
+ results.empty?
85
+ if conj_m[1] or conj_m[2]
86
+ # and, & - the new results will be every combination of the
87
+ # previous results and the results of the rest of the parse.
88
+ rest = re_satisfy(definition)
89
+ raise ParseError, "conjunction with nothing following: '#{definition.string}'" if
90
+ rest.empty?
91
+ results.combine!(rest)
92
+ else
93
+ # or, | - the new results will be the union of the previous
94
+ # results and the results of the rest of the parse.
95
+ rest = re_satisfy(definition)
96
+ raise ParseError, "conjunction with nothing following: '#{definition.string}'" if
97
+ rest.empty?
98
+ results.add!(rest)
99
+ end
100
+ return results
101
+ when Open
102
+ # Open parens - treated the same as a single connector, but
103
+ # concerning the entire contents of the parens.
104
+ if current =~ /\[/
105
+ re_satisfy( definition ).each {|set|
106
+ set.map! {|conn|
107
+ Connector.new(conn.name,conn.subName,conn.side,conn.multiplicity,conn.cost+1)
108
+ }
109
+ results << set
110
+ }
111
+ elsif current =~ /\{/
112
+ re_satisfy( definition ).each {|set|
113
+ set.map! {|conn|
114
+ if conn.multiplicity == Connector::ONCE
115
+ Connector.new(conn.name,conn.subName,conn.side,Connector::OPTIONAL,conn.cost)
116
+ elsif conn.multiplicity == Connector::PLUS
117
+ Connector.new(conn.name,conn.subName,conn.side,Connector::STAR,conn.cost)
118
+ else
119
+ conn
120
+ end
121
+ }
122
+ results << set
123
+ }
124
+ else
125
+ results.add!(re_satisfy( definition ))
126
+ end
127
+ raise ParseError, "improper parentheses usage: '#{definition.string}'" if
128
+ results.empty?
129
+ when Close
130
+ # Close parens - if this is found, the method returns, checking
131
+ # for the null-connector condition first.
132
+ return results.empty? ? [ [Connector::new("*")] ] : results
133
+ when Space
134
+ # Spaces - are ignored
135
+ when nil
136
+ # Nil - means the parse has encountered something not matching
137
+ # the Token regex.
138
+ raise ParseError, "Definition unparsable before end of definition: '#{definition.rest}'"
139
+ end
140
+ end
141
+
142
+ return results
143
+ end
144
+
145
+ extend Forwardable
146
+
147
+ # The single argument may be either a String or an Array. If the
148
+ # argument is a string, it is treated as a definition string, and won't
149
+ # be parsed until needed. If it is an array, no reverse engineering
150
+ # will be done to create the corresponding definition string.
151
+ def initialize( an_arg )
152
+ if an_arg.kind_of? String
153
+ @raw = an_arg
154
+ @connector_sets = []
155
+ else
156
+ @raw = nil
157
+ @connector_sets = an_arg
158
+ end
159
+ end
160
+
161
+ # The raw string from which this definition is derived.
162
+ attr_reader :raw
163
+
164
+ # The sets of sets of connectors that is the algorithmicly useful version
165
+ # of this object.
166
+ def connector_sets
167
+ if @connector_sets and @connector_sets.empty?
168
+ @connector_sets = Definition::re_satisfy(@raw)
169
+ else
170
+ @connector_sets
171
+ end
172
+ end
173
+ alias :connectorSets :connector_sets
174
+
175
+ # Delegate all calls of array-like methods to the connector sets.
176
+ def_delegators :connector_sets, *(Array.instance_methods(false) - %w{to_s inspect ==})
177
+
178
+ # The most sensible stringification of this definition.
179
+ def to_s
180
+ @raw ? @raw : self.to_connectors
181
+ end
182
+
183
+ # Stringification of the connector sets.
184
+ def to_connectors
185
+ self.connector_sets.inspect
186
+ end
187
+ alias :two_s :to_connectors
188
+
189
+ # Stringification with a 'sensible' opposite of the one for to_s.
190
+ def inspect
191
+ (@connector_sets && @connector_sets.empty?) ? @raw : @connector_sets.inspect
192
+ end
193
+
194
+ # tests for equality
195
+ def ==(other)
196
+ return(false) unless
197
+ other.kind_of?(self.class)
198
+ return(@raw == other.raw) if
199
+ (@raw && other.raw) and (@raw == other.raw)
200
+ return self.connector_sets.set_of_sets_equal?(other.connector_sets)
201
+ end
202
+ alias :=== :==;
203
+ alias :eql? :==;
204
+
205
+ # Returns those connector_sets which include a connector which matches the
206
+ # provided connector.
207
+ def sets_matching(connector)
208
+ self.find_all {|set|
209
+ set.find {|c|
210
+ c.match(connector)
211
+ }
212
+ }
213
+ end
214
+
215
+ # Returns whether or not there exists a matching connector to a given connector.
216
+ def includes_match?(connector)
217
+ self.find {|set|
218
+ set.find {|c|
219
+ c.match(connector)
220
+ }
221
+ }
222
+ end
223
+
224
+ end # class Definition
225
+ end # module LinkParser