linkparser 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/linkparser.rb ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'linkparser_ext'
4
+
5
+
6
+ # The LinkParser top-level namespace.
7
+ #
8
+ # == Authors
9
+ #
10
+ # * Michael Granger <ged@FaerieMUD.org>
11
+ # * Martin Chase <stillflame@FaerieMUD.org>
12
+ #
13
+ # == Version
14
+ #
15
+ # $Id: linkparser.rb 48 2008-12-19 18:30:33Z deveiant $
16
+ #
17
+ # == License
18
+ #
19
+ # :include: LICENSE
20
+ #--
21
+ #
22
+ # See the LICENSE file for copyright/licensing information.
23
+ module LinkParser
24
+
25
+ require 'linkparser/sentence'
26
+ require 'linkparser/linkage'
27
+
28
+ # Release version
29
+ VERSION = '1.0.3'
30
+
31
+ # SVN Revision
32
+ SVNRev = %q$Rev: 48 $
33
+
34
+ # SVN Id
35
+ SVNId = %q$Id: linkparser.rb 48 2008-12-19 18:30:33Z deveiant $
36
+
37
+ end # class LinkParser
38
+
@@ -0,0 +1,248 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Additional high-level functionality for LinkParser::Sentence objects.
4
+ #
5
+ # == Synopsis
6
+ #
7
+ #
8
+ #
9
+ # == Authors
10
+ #
11
+ # * Michael Granger <ged@FaerieMUD.org>
12
+ #
13
+ # == License
14
+ #
15
+ # Copyright (c) 2007, 2008 The FaerieMUD Consortium
16
+ #
17
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ # of this software and associated documentation files (the "Software"), to deal
19
+ # in the Software without restriction, including without limitation the rights
20
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ # copies of the Software, and to permit persons to whom the Software is
22
+ # furnished to do so, subject to the following conditions:
23
+ #
24
+ # The above copyright notice and this permission notice shall be included in
25
+ # all copies or substantial portions of the Software.
26
+ #
27
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
+ # THE SOFTWARE.
34
+ #
35
+ # == Version
36
+ #
37
+ # $Id: linkage.rb 48 2008-12-19 18:30:33Z deveiant $
38
+ #
39
+
40
+ require 'linkparser'
41
+
42
+
43
+ ### Additional high-level functionality for LinkParser::Sentence objects.
44
+ class LinkParser::Linkage
45
+
46
+ # SVN Revision
47
+ SVNRev = %q$Rev: 48 $
48
+
49
+ # SVN Id
50
+ SVNId = %q$Id: linkage.rb 48 2008-12-19 18:30:33Z deveiant $
51
+
52
+ # Descriptions of the linkage types, keyed by linkage symbol
53
+ LINK_TYPES = {
54
+ :A => %{connects pre-noun ("attributive") adjectives to following nouns: "The BIG DOG chased me", "The BIG BLACK UGLY DOG chased me".},
55
+ :AA => %{is used in the construction "How [adj] a [noun] was it?". It connects the adjective to the following "a".},
56
+ :AF => %{connects adjectives to verbs in cases where the adjective is fronted, such as questions and indirect questions: "How BIG IS it?"},
57
+ :AL => %{connects a few determiners like "all" or "both" to following determiners: "ALL THE people are here".},
58
+ :AM => %{connects "as" to "much" or "many": "I don't go out AS MUCH now".},
59
+ :AN => %{connects noun-modifiers to following nouns: "The TAX PROPOSAL was rejected".},
60
+ :AZ => %{connects the word "as" back to certain verbs that can take "[obj] as [adj]" as a complement: "He VIEWED him AS stupid".},
61
+ :B => %{serves various functions involving relative clauses and questions. It connects transitive verbs back to their objects in relative clauses, questions, and indirect questions ("The DOG we CHASED", "WHO did you SEE?"); it also connects the main noun to the finite verb in subject-type relative clauses ("The DOG who CHASED me was black").},
62
+ :BI => %{connects forms of the verb "be" to certain idiomatic expressions: for example, cases like "He IS PRESIDENT of the company".},
63
+ :BT => %{is used with time expressions acting as fronted objects: "How many YEARS did it LAST?".},
64
+ :BW => %{connects "what" to various verbs like "think", which are not really transitive but can connect back to "what" in questions: "WHAT do you THINK?"},
65
+ :C => %{links conjunctions to subjects of subordinate clauses ("He left WHEN HE saw me"). it also links certain verbs to subjects of embedded clauses ("He SAID HE was sorry").},
66
+ :CC => %{connects clauses to following coordinating conjunctions ("SHE left BUT we stayed").},
67
+ :CO => %{connects "openers" to subjects of clauses: "APPARENTLY / ON Tuesday , THEY went to a movie".},
68
+ :CP => %{connects paraphrasing or quoting verbs to the wall (and, indirectly, to the paraphrased expression): "///// That is untrue, the spokesman SAID."},
69
+ :CQ => %{connects to auxiliaries in comparative constructions involving s-v inversion: "SHE has more money THAN DOES Joe".},
70
+ :CX => %{is used in comparative constructions where the right half of the comparative contains only an auxiliary: "She has more money THAN he DOES".},
71
+ :D => %{connects determiners to nouns: "THE DOG chased A CAT and SOME BIRDS".},
72
+ :DD => %{connects definite determiners ("the", "his") to certain things like number expressions and adjectives acting as nouns: "THE POOR", "THE TWO he mentioned".},
73
+ :DG => %{connects the word "The" with proper nouns: "the Riviera", "the Mississippi".},
74
+ :DP => %{connects possessive determiners to gerunds: "YOUR TELLING John to leave was stupid".},
75
+ :DT => %{connects determiners to nouns in idiomatic time expressions: "NEXT WEEK", "NEXT THURSDAY".},
76
+ :E => %{is used for verb-modifying adverbs which precede the verb: "He is APPARENTLY LEAVING".},
77
+ :EA => %{connects adverbs to adjectives: "She is a VERY GOOD player".},
78
+ :EB => %{connects adverbs to forms of "be" before an object or prepositional phrase: "He IS APPARENTLY a good programmer".},
79
+ :EC => %{connects adverbs to comparative adjectives: "It is MUCH BIGGER"},
80
+ :EE => %{connects adverbs to other adverbs: "He ran VERY QUICKLY".},
81
+ :EF => %{connects the word "enough" to preceding adjectives and adverbs: "He didn't run QUICKLY ENOUGH".},
82
+ :EI => %{connects a few adverbs to "after" and "before": "I left SOON AFTER I saw you".},
83
+ :EL => %{connects certain words to the word "else": something / everything / anything / nothing , somewhere (etc.), and someone (etc.).},
84
+ :EN => %{connects certain adverbs to expressions of quantity: "The class has NEARLY FIFTY students".},
85
+ :ER => %{is used the expression "The x-er..., the y-er...". it connects the two halfs of the expression together, via the comparative words (e.g. "The FASTER it is, the MORE they will like it").},
86
+ :EZ => %{connects certain adverbs to the word "as", like "just" and "almost": "You're JUST AS good as he is."},
87
+ :FL => %{connects "for" to "long": "I didn't wait FOR LONG".},
88
+ :FM => %{connects the preposition "from" to various other prepositions: "We heard a scream FROM INSIDE the house".},
89
+ :G => %{connects proper noun words together in series: "GEORGE HERBERT WALKER BUSH is here."},
90
+ :GN => %{(stage 2 only) connects a proper noun to a preceding common noun which introduces it: "The ACTOR Eddie MURPHY attended the event".},
91
+ :H => %{connects "how" to "much" or "many": "HOW MUCH money do you have".},
92
+ :I => %{connects infinitive verb forms to certain words such as modal verbs and "to": "You MUST DO it", "I want TO DO it".},
93
+ :ID => %{is a special class of link-types generated by the parser, with arbitrary four-letter names (such as "IDBT"), to connect together words of idiomatic expressions such as "at_hand" and "head_of_state".},
94
+ :IN => %{connects the preposition "in" to certain time expressions: "We did it IN DECEMBER".},
95
+ :J => %{connects prepositions to their objects: "The man WITH the HAT is here".},
96
+ :JG => %{connects certain prepositions to proper-noun objects: "The Emir OF KUWAIT is here".},
97
+ :JQ => %{connects prepositions to question-word determiners in "prepositional questions": "IN WHICH room were you sleeping?"},
98
+ :JT => %{connects certain conjunctions to time-expressions like "last week": "UNTIL last WEEK, I thought she liked me".},
99
+ :K => %{connects certain verbs with particles like "in", "out", "up" and the like: "He STOOD UP and WALKED OUT".},
100
+ :L => %{connects certain determiners to superlative adjectives: "He has THE BIGGEST room".},
101
+ :LE => %{is used in comparative constructions to connect an adjective to the second half of the comparative expression beyond a complement phrase: "It is more LIKELY that Joe will go THAN that Fred will go".},
102
+ :LI => %{connects certain verbs to the preposition "like": "I FEEL LIKE a fool."},
103
+ :M => %{connects nouns to various kinds of post-noun modifiers: prepositional phrases ("The MAN WITH the hat"), participle modifiers ("The WOMAN CARRYING the box"), prepositional relatives ("The MAN TO whom I was speaking"), and other kinds.},
104
+ :MF => %{is used in the expression "Many people were injured, SOME OF THEM children".},
105
+ :MG => %{allows certain prepositions to modify proper nouns: "The EMIR OF Kuwait is here".},
106
+ :MV => %{connects verbs and adjectives to modifying phrases that follow, like adverbs ("The dog RAN QUICKLY"), prepositional phrases ("The dog RAN IN the yard"), subordinating conjunctions ("He LEFT WHEN he saw me"), comparatives, participle phrases with commas, and other things.},
107
+ :MX => %{connects modifying phrases with commas to preceding nouns: "The DOG, a POODLE, was black". "JOHN, IN a black suit, looked great".},
108
+ :N => %{connects the word "not" to preceding auxiliaries: "He DID NOT go".},
109
+ :ND => %{connects numbers with expressions that require numerical determiners: "I saw him THREE WEEKS ago".},
110
+ :NF => %{is used with NJ in idiomatic number expressions involving "of": "He lives two THIRDS OF a mile from here".},
111
+ :NI => %{is used in a few special idiomatic number phrases: "I have BETWEEN 5 AND 20 dogs".},
112
+ :NJ => %{is used with NF in idiomatic number expressions involving "of": "He lives two thirds OF a MILE from here".},
113
+ :NN => %{connects number words together in series: "FOUR HUNDRED THOUSAND people live here".},
114
+ :NO => %{is used on words which have no normal linkage requirement, but need to be included in the dictionary, such as "um" and "ah".},
115
+ :NR => %{connects fraction words with superlatives: "It is the THIRD BIGGEST city in China".},
116
+ :NS => %{connects singular numbers (one, 1, a) to idiomatic expressions requiring number determiners: "I saw him ONE WEEK ago".},
117
+ :NT => %{connects "not" to "to": "I told you NOT TO come".},
118
+ :NW => %{is used in idiomatic fraction expressions: "TWO THIRDS of the students were women".},
119
+ :O => %{connects transitive verbs to their objects, direct or indirect: "She SAW ME", "I GAVE HIM the BOOK".},
120
+ :OD => %{is used for verbs like "rise" and "fall" which can take expressions of distance as complements: "It FELL five FEET".},
121
+ :OF => %{connects certain verbs and adjectives to the word "of": "She ACCUSED him OF the crime", "I'm PROUD OF you".},
122
+ :ON => %{connectors the word "on" to dates or days of the week in time expressions: "We saw her again ON TUESDAY".},
123
+ :OT => %{is used for verbs like "last" which can take time expressions as objects: "It LASTED five HOURS".},
124
+ :OX => %{is an object connector, analogous to SF, used for special "filler" words like "it" and "there" when used as objects: "That MAKES IT unlikely that she will come".},
125
+ :P => %{connects forms of the verb "be" to various words that can be its complements: prepositions, adjectives, and passive and progressive participles: "He WAS [ ANGRY / IN the yard / CHOSEN / RUNNING ]".},
126
+ :PF => %{is used in certain questions with "be", when the complement need of "be" is satisfied by a preceding question word: "WHERE are you?", "WHEN will it BE?"},
127
+ :PP => %{connects forms of "have" with past participles: "He HAS GONE".},
128
+ :Q => %{is used in questions. It connects the wall to the auxiliary in simple yes-no questions ("///// DID you go?"); it connects the question word to the auxiliary in where-when-how questions ("WHERE DID you go").},
129
+ :QI => %{connects certain verbs and adjectives to question-words, forming indirect questions: "He WONDERED WHAT she would say".},
130
+ :R => %{connects nouns to relative clauses. In subject-type relatives, it connects to the relative pronoun ("The DOG WHO chased me was black"); in object-type relatives, it connects either to the relative pronoun or to the subject of the relative clause ("The DOG THAT we chased was black", "The DOG WE chased was black").},
131
+ :RS => %{is used in subject-type relative clauses to connect the relative pronoun to the verb: "The dog WHO CHASED me was black".},
132
+ :RW => %{connects the right-wall to the left-wall in cases where the right-wall is not needed for punctuation purposes.},
133
+ :S => %{connects subject nouns to finite verbs: "The DOG CHASED the cat": "The DOG [ IS chasing / HAS chased / WILL chase ] the cat".},
134
+ :SF => %{is a special connector used to connect "filler" subjects like "it" and "there" to finite verbs: "THERE IS a problem", "IT IS likely that he will go".},
135
+ :SFI => %{connects "filler" subjects like "it" and "there" to verbs in cases with subject-verb inversion: "IS THERE a problem?", "IS IT likely that he will go?"},
136
+ :SI => %{connects subject nouns to finite verbs in cases of subject-verb inversion: "IS JOHN coming?", "Who DID HE see?"},
137
+ :SX => %{connects "I" to special first-person verbs lke "was" and "am".},
138
+ :SXI => %{connects "I" to first-person verbs in cases of s-v inversion.},
139
+ :TA => %{is used to connect adjectives like "late" to month names: "We did it in LATE DECEMBER".},
140
+ :TD => %{connects day-of-the-week words to time expressions like "morning": "We'll do it MONDAY MORNING".},
141
+ :TH => %{connects words that take "that [clause]" complements with the word "that". These include verbs ("She TOLD him THAT..."), nouns ("The IDEA THAT..."), and adjectives ("We are CERTAIN THAT").},
142
+ :TI => %{is used for titles like "president", which can be used in certain cirumstances without a determiner: "AS PRESIDENT of the company, it is my decision".},
143
+ :TM => %{is used to connect month names to day numbers: "It happened on JANUARY 21".},
144
+ :TO => %{connects verbs and adjectives which take infinitival complements to the word "to": "We TRIED TO start the car", "We are EAGER TO do it".},
145
+ :TQ => %{is the determiner connector for time expressions acting as fronted objects: "How MANY YEARS did it last".},
146
+ :TS => %{connects certain verbs that can take subjunctive clauses as complements - "suggest", "require" - to the word that: "We SUGGESTED THAT he go".},
147
+ :TW => %{connects days of the week to dates in time expressions: "The meeting will be on MONDAY, JANUARY 21".},
148
+ :TY => %{is used for certain idiomatic usages of year numbers: "I saw him on January 21 , 1990 ". (In this case it connects the day number to the year number.)},
149
+ :U => %{is a special connector on nouns, which is disjoined with both the determiner and subject-object connectors. It is used in idiomatic expressions like "What KIND_OF DOG did you buy?"},
150
+ :UN => %{connects the words "until" and "since" to certain time phrases like "after [clause]": "You should wait UNTIL AFTER you talk to me".},
151
+ :V => %{connects various verbs to idiomatic expressions that may be non-adjacent: "We TOOK him FOR_GRANTED", "We HELD her RESPONSIBLE".},
152
+ :W => %{connects the subjects of main clauses to the wall, in ordinary declaratives, imperatives, and most questions (except yes-no questions). It also connects coordinating conjunctions to following clauses: "We left BUT SHE stayed".},
153
+ :WN => %{connects the word "when" to time nouns like "year": "The YEAR WHEN we lived in England was wonderful".},
154
+ :WR => %{connects the word "where" to a few verbs like "put" in questions like "WHERE did you PUT it?".},
155
+ :X => %{is used with punctuation, to connect punctuation symbols either to words or to each other. For example, in this case, POODLE connects to commas on either side: "The dog , a POODLE , was black."},
156
+ :Y => %{is used in certain idiomatic time and place expressions, to connect quantity expressions to the head word of the expression: "He left three HOURS AGO", "She lives three MILES FROM the station".},
157
+ :YP => %{connects plural noun forms ending in s to "'" in possessive constructions: "The STUDENTS ' rooms are large".},
158
+ :YS => %{connects nouns to the possessive suffix "'s": "JOHN 'S dog is black".},
159
+ :Z => %{connects the preposition "as" to certain verbs: "AS we EXPECTED, he was late".},
160
+ }
161
+
162
+ # Link struct (:lword, :rword, :length, :label, :llabel, :rlabel, :desc)
163
+ Link = Struct.new( "LinkParserLink", :lword, :rword, :length, :label, :llabel, :rlabel, :desc )
164
+
165
+
166
+ ######
167
+ public
168
+ ######
169
+
170
+ ### Return a human-readable representation of the Sentence object.
171
+ def inspect
172
+ return %{#<%s:0x%x: sublinkage %d: [%d links]>} % [
173
+ self.class.name,
174
+ self.object_id / 2,
175
+ self.current_sublinkage,
176
+ self.num_links
177
+ ]
178
+ end
179
+
180
+
181
+ ### Return the +index+th link.
182
+ def link( index )
183
+ Link.new(
184
+ self.words[ self.link_lword(index) ],
185
+ self.words[ self.link_rword(index) ],
186
+ self.link_length(index),
187
+ self.link_label(index),
188
+ self.link_llabel(index),
189
+ self.link_rlabel(index),
190
+ LINK_TYPES[ self.link_label(index).gsub(/[^A-Z]+/, '').to_sym ]
191
+ )
192
+ end
193
+
194
+
195
+ ### Return the Array of words in the sentence as tokenized by the
196
+ ### parser.
197
+ def links
198
+ ( 0...self.link_count ).collect do |i|
199
+ self.link( i )
200
+ end
201
+ end
202
+
203
+
204
+ ### Return the verb word from the linkage.
205
+ def verb
206
+ if link = self.links.find {|link| link.llabel =~ /^(O([DFNTX]?)|P|BI|K|LI|MV|Q)[a-z\*]*/ }
207
+ # $deferr.puts "Picking %s: LL of %p is %s" % [ link.lword, link, link.llabel ]
208
+ return link.lword.sub( /\.v$/, '' )
209
+ elsif link = self.links.find {|link| link.rlabel =~ /^(SI|S|AF)[a-z\*]*/ }
210
+ # $deferr.puts "Picking %s: RL of %p is %s" % [ link.rword, link, link.rlabel ]
211
+ return link.rword.sub( /\.v$/, '' )
212
+ else
213
+ return nil
214
+ end
215
+ end
216
+
217
+
218
+ ### Return the subject from the linkage.
219
+ def subject
220
+ link = self.links.find {|link| link.llabel[0] == ?S } or return nil
221
+ return link.lword.sub( /\.[np]$/, '' )
222
+ end
223
+
224
+
225
+ ### Return the object from the linkage.
226
+ def object
227
+ link = self.links.find {|link| link.rlabel[0] == ?O } or return nil
228
+ return link.rword.sub( /\.[np]$/, '' )
229
+ end
230
+
231
+
232
+ ### Returns +true+ if the linkage indicates the sentence is phrased in the
233
+ ### imperative voice.
234
+ def imperative?
235
+ return self.links.find {|link| link.label == 'Wi' && link.rword =~ /\.v$/ } ?
236
+ true : false
237
+ end
238
+
239
+
240
+ ### Returns +true+ if the linkage has more than one sublinkage (i.e., the
241
+ ### sentence has a conjunction).
242
+ def has_conjunction?
243
+ return self.num_sublinkages > 1
244
+ end
245
+
246
+
247
+ end # class Sentence
248
+
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # A Sentence is the API's representation of an input string, tokenized
4
+ # and interpreted according to a specific Dictionary. After a Sentence
5
+ # is created and parsed, various attributes of the resulting set of
6
+ # linkages can be obtained.
7
+ #
8
+ # == Authors
9
+ #
10
+ # * Michael Granger <ged@FaerieMUD.org>
11
+ #
12
+ # == License
13
+ #
14
+ # Copyright (c) 2007, 2008 The FaerieMUD Consortium
15
+ #
16
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ # of this software and associated documentation files (the "Software"), to deal
18
+ # in the Software without restriction, including without limitation the rights
19
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ # copies of the Software, and to permit persons to whom the Software is
21
+ # furnished to do so, subject to the following conditions:
22
+ #
23
+ # The above copyright notice and this permission notice shall be included in
24
+ # all copies or substantial portions of the Software.
25
+ #
26
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
+ # THE SOFTWARE.
33
+ #
34
+ # == Version
35
+ #
36
+ # $Id: sentence.rb 21 2008-05-26 21:49:02Z deveiant $
37
+ #
38
+
39
+ require 'linkparser'
40
+
41
+
42
+ class LinkParser::Sentence
43
+
44
+ # SVN Revision
45
+ SVNRev = %q$Rev: 21 $
46
+
47
+ # SVN Id
48
+ SVNId = %q$Id: sentence.rb 21 2008-05-26 21:49:02Z deveiant $
49
+
50
+
51
+ ######
52
+ public
53
+ ######
54
+
55
+ ### Return a human-readable representation of the Sentence object.
56
+ def inspect
57
+ %{#<%s:0x%x "%s"/%d linkages/%d nulls>} % [
58
+ self.class.name,
59
+ self.object_id / 2,
60
+ self.words.join(" "),
61
+ self.num_linkages_found,
62
+ self.null_count,
63
+ ]
64
+ end
65
+
66
+
67
+ ### Return the Array of words in the sentence as tokenized by the
68
+ ### parser.
69
+ def words
70
+ (0...self.length).to_a.collect do |i|
71
+ self.word( i )
72
+ end
73
+ end
74
+
75
+
76
+ ### Print out the sentence
77
+ def to_s
78
+ return self.words.join(" ")
79
+ end
80
+
81
+
82
+ #########
83
+ protected
84
+ #########
85
+
86
+ ### Return the singleton class for this object
87
+ def singleton_class
88
+ class << self; self; end
89
+ end
90
+
91
+
92
+ ### Proxy method -- auto-delegate calls to the first linkage.
93
+ def method_missing( sym, *args )
94
+ linkage = self.linkages.first
95
+ return super unless !linkage.nil? && linkage.respond_to?( sym )
96
+
97
+ meth = linkage.method( sym )
98
+ self.singleton_class.send( :define_method, sym, &meth )
99
+
100
+ meth.call( *args )
101
+ rescue => err
102
+ raise err, err.message, err.backtrace[ 0..-2 ]
103
+ end
104
+
105
+ end # class Sentence
106
+
@@ -0,0 +1,76 @@
1
+ #
2
+ # Dependency-checking and Installation Rake Tasks
3
+ # $Id: dependencies.rb 43 2008-09-05 18:19:16Z deveiant $
4
+ #
5
+
6
+ require 'rubygems/dependency_installer'
7
+ require 'rubygems/source_index'
8
+ require 'rubygems/requirement'
9
+ require 'rubygems/doc_manager'
10
+
11
+ ### Install the specified +gems+ if they aren't already installed.
12
+ def install_gems( gems )
13
+
14
+ defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
15
+ :generate_rdoc => true,
16
+ :generate_ri => true,
17
+ :install_dir => Gem.dir,
18
+ :format_executable => false,
19
+ :test => false,
20
+ :version => Gem::Requirement.default,
21
+ })
22
+
23
+ # Check for root
24
+ if Process.euid != 0
25
+ $stderr.puts "This probably won't work, as you aren't root, but I'll try anyway"
26
+ end
27
+
28
+ gemindex = Gem::SourceIndex.from_installed_gems
29
+
30
+ gems.each do |gemname, reqstring|
31
+ requirement = Gem::Requirement.new( reqstring )
32
+ trace "requirement is: %p" % [ requirement ]
33
+
34
+ trace "Searching for an installed #{gemname}..."
35
+ specs = gemindex.find_name( gemname )
36
+ trace "...found %d specs: %s" %
37
+ [ specs.length, specs.collect {|s| "%s %s" % [s.name, s.version] }.join(', ') ]
38
+
39
+ if spec = specs.find {|spec| requirement.satisfied_by?(spec.version) }
40
+ log "Version %s of %s is already installed (needs %s); skipping..." %
41
+ [ spec.version, spec.name, requirement ]
42
+ next
43
+ end
44
+
45
+ rgv = Gem::Version.new( Gem::RubyGemsVersion )
46
+ installer = nil
47
+
48
+ log "Trying to install #{gemname.inspect} #{requirement}..."
49
+ if rgv >= Gem::Version.new( '1.1.1' )
50
+ installer = Gem::DependencyInstaller.new
51
+ installer.install( gemname, requirement )
52
+ else
53
+ installer = Gem::DependencyInstaller.new( gemname )
54
+ installer.install
55
+ end
56
+
57
+ installer.installed_gems.each do |spec|
58
+ log "Installed: %s" % [ spec.full_name ]
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+
65
+ ### Task: install runtime dependencies
66
+ desc "Install runtime dependencies as gems"
67
+ task :install_dependencies do
68
+ install_gems( DEPENDENCIES )
69
+ end
70
+
71
+ ### Task: install gems for development tasks
72
+ desc "Install development dependencies as gems"
73
+ task :install_dev_dependencies do
74
+ install_gems( DEVELOPMENT_DEPENDENCIES )
75
+ end
76
+