wordnet 0.0.5 → 1.0.0.pre.126

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gemtest +0 -0
  2. data/History.rdoc +5 -0
  3. data/LICENSE +9 -9
  4. data/Manifest.txt +39 -0
  5. data/README.rdoc +60 -0
  6. data/Rakefile +47 -267
  7. data/TODO +9 -0
  8. data/WordNet30-license.txt +31 -0
  9. data/examples/add-laced-boots.rb +35 -0
  10. data/examples/clothes-with-collars.rb +42 -0
  11. data/examples/clothesWithTongues.rb +0 -0
  12. data/examples/domainTree.rb +0 -0
  13. data/examples/memberTree.rb +0 -0
  14. data/lib/wordnet/constants.rb +259 -296
  15. data/lib/wordnet/lexicallink.rb +34 -0
  16. data/lib/wordnet/lexicon.rb +158 -386
  17. data/lib/wordnet/mixins.rb +62 -0
  18. data/lib/wordnet/model.rb +78 -0
  19. data/lib/wordnet/morph.rb +25 -0
  20. data/lib/wordnet/semanticlink.rb +52 -0
  21. data/lib/wordnet/sense.rb +55 -0
  22. data/lib/wordnet/sumoterm.rb +21 -0
  23. data/lib/wordnet/synset.rb +404 -859
  24. data/lib/wordnet/utils.rb +126 -0
  25. data/lib/wordnet/word.rb +119 -0
  26. data/lib/wordnet.rb +113 -76
  27. data/spec/lib/helpers.rb +102 -133
  28. data/spec/linguawordnet.tests.rb +38 -0
  29. data/spec/wordnet/lexicon_spec.rb +96 -186
  30. data/spec/wordnet/model_spec.rb +59 -0
  31. data/spec/wordnet/semanticlink_spec.rb +42 -0
  32. data/spec/wordnet/synset_spec.rb +27 -256
  33. data/spec/wordnet/word_spec.rb +58 -0
  34. data/spec/wordnet_spec.rb +52 -0
  35. data.tar.gz.sig +0 -0
  36. metadata +227 -188
  37. metadata.gz.sig +0 -0
  38. data/ChangeLog +0 -720
  39. data/README +0 -93
  40. data/Rakefile.local +0 -46
  41. data/convertdb.rb +0 -417
  42. data/examples/addLacedBoots.rb +0 -27
  43. data/examples/clothesWithCollars.rb +0 -36
  44. data/rake/dependencies.rb +0 -76
  45. data/rake/helpers.rb +0 -384
  46. data/rake/manual.rb +0 -755
  47. data/rake/packaging.rb +0 -112
  48. data/rake/publishing.rb +0 -303
  49. data/rake/rdoc.rb +0 -35
  50. data/rake/style.rb +0 -62
  51. data/rake/svn.rb +0 -469
  52. data/rake/testing.rb +0 -192
  53. data/rake/verifytask.rb +0 -64
  54. data/utils.rb +0 -838
data/rake/helpers.rb DELETED
@@ -1,384 +0,0 @@
1
- #####################################################################
2
- ### G L O B A L H E L P E R F U N C T I O N S
3
- #####################################################################
4
-
5
- require 'pathname'
6
- require 'readline'
7
-
8
- # Set some ANSI escape code constants (Shamelessly stolen from Perl's
9
- # Term::ANSIColor by Russ Allbery <rra@stanford.edu> and Zenin <zenin@best.com>
10
- ANSI_ATTRIBUTES = {
11
- 'clear' => 0,
12
- 'reset' => 0,
13
- 'bold' => 1,
14
- 'dark' => 2,
15
- 'underline' => 4,
16
- 'underscore' => 4,
17
- 'blink' => 5,
18
- 'reverse' => 7,
19
- 'concealed' => 8,
20
-
21
- 'black' => 30, 'on_black' => 40,
22
- 'red' => 31, 'on_red' => 41,
23
- 'green' => 32, 'on_green' => 42,
24
- 'yellow' => 33, 'on_yellow' => 43,
25
- 'blue' => 34, 'on_blue' => 44,
26
- 'magenta' => 35, 'on_magenta' => 45,
27
- 'cyan' => 36, 'on_cyan' => 46,
28
- 'white' => 37, 'on_white' => 47
29
- }
30
-
31
-
32
- MULTILINE_PROMPT = <<-'EOF'
33
- Enter one or more values for '%s'.
34
- A blank line finishes input.
35
- EOF
36
-
37
-
38
- CLEAR_TO_EOL = "\e[K"
39
- CLEAR_CURRENT_LINE = "\e[2K"
40
-
41
-
42
- ### Output a logging message
43
- def log( *msg )
44
- output = colorize( msg.flatten.join(' '), 'cyan' )
45
- $deferr.puts( output )
46
- end
47
-
48
-
49
- ### Output a logging message if tracing is on
50
- def trace( *msg )
51
- return unless $trace
52
- output = colorize( msg.flatten.join(' '), 'yellow' )
53
- $deferr.puts( output )
54
- end
55
-
56
-
57
- ### Run the specified command +cmd+ with system(), failing if the execution
58
- ### fails.
59
- def run( *cmd )
60
- cmd.flatten!
61
-
62
- log( cmd.collect {|part| part =~ /\s/ ? part.inspect : part} )
63
- if $dryrun
64
- $deferr.puts "(dry run mode)"
65
- else
66
- system( *cmd )
67
- unless $?.success?
68
- fail "Command failed: [%s]" % [cmd.join(' ')]
69
- end
70
- end
71
- end
72
-
73
-
74
- ### Open a pipe to a process running the given +cmd+ and call the given block with it.
75
- def pipeto( *cmd )
76
- $DEBUG = true
77
-
78
- cmd.flatten!
79
- log( "Opening a pipe to: ", cmd.collect {|part| part =~ /\s/ ? part.inspect : part} )
80
- if $dryrun
81
- $deferr.puts "(dry run mode)"
82
- else
83
- open( '|-', 'w+' ) do |io|
84
-
85
- # Parent
86
- if io
87
- yield( io )
88
-
89
- # Child
90
- else
91
- exec( *cmd )
92
- fail "Command failed: [%s]" % [cmd.join(' ')]
93
- end
94
- end
95
- end
96
- end
97
-
98
-
99
- ### Download the file at +sourceuri+ via HTTP and write it to +targetfile+.
100
- def download( sourceuri, targetfile=nil )
101
- oldsync = $defout.sync
102
- $defout.sync = true
103
- require 'net/http'
104
- require 'uri'
105
-
106
- targetpath = Pathname.new( targetfile )
107
-
108
- log "Downloading %s to %s" % [sourceuri, targetfile]
109
- targetpath.open( File::WRONLY|File::TRUNC|File::CREAT, 0644 ) do |ofh|
110
-
111
- url = sourceuri.is_a?( URI ) ? sourceuri : URI.parse( sourceuri )
112
- downloaded = false
113
- limit = 5
114
-
115
- until downloaded or limit.zero?
116
- Net::HTTP.start( url.host, url.port ) do |http|
117
- req = Net::HTTP::Get.new( url.path )
118
-
119
- http.request( req ) do |res|
120
- if res.is_a?( Net::HTTPSuccess )
121
- log "Downloading..."
122
- res.read_body do |buf|
123
- ofh.print( buf )
124
- end
125
- downloaded = true
126
- puts "done."
127
-
128
- elsif res.is_a?( Net::HTTPRedirection )
129
- url = URI.parse( res['location'] )
130
- log "...following redirection to: %s" % [ url ]
131
- limit -= 1
132
- sleep 0.2
133
- next
134
-
135
- else
136
- res.error!
137
- end
138
- end
139
- end
140
- end
141
-
142
- end
143
-
144
- return targetpath
145
- ensure
146
- $defout.sync = oldsync
147
- end
148
-
149
-
150
- ### Return the fully-qualified path to the specified +program+ in the PATH.
151
- def which( program )
152
- ENV['PATH'].split(/:/).
153
- collect {|dir| Pathname.new(dir) + program }.
154
- find {|path| path.exist? && path.executable? }
155
- end
156
-
157
-
158
- ### Create a string that contains the ANSI codes specified and return it
159
- def ansi_code( *attributes )
160
- attributes.flatten!
161
- attributes.collect! {|at| at.to_s }
162
- # $deferr.puts "Returning ansicode for TERM = %p: %p" %
163
- # [ ENV['TERM'], attributes ]
164
- return '' unless /(?:vt10[03]|xterm(?:-color)?|linux|screen)/i =~ ENV['TERM']
165
- attributes = ANSI_ATTRIBUTES.values_at( *attributes ).compact.join(';')
166
-
167
- # $deferr.puts " attr is: %p" % [attributes]
168
- if attributes.empty?
169
- return ''
170
- else
171
- return "\e[%sm" % attributes
172
- end
173
- end
174
-
175
-
176
- ### Colorize the given +string+ with the specified +attributes+ and return it, handling
177
- ### line-endings, color reset, etc.
178
- def colorize( *args )
179
- string = ''
180
-
181
- if block_given?
182
- string = yield
183
- else
184
- string = args.shift
185
- end
186
-
187
- ending = string[/(\s)$/] || ''
188
- string = string.rstrip
189
-
190
- return ansi_code( args.flatten ) + string + ansi_code( 'reset' ) + ending
191
- end
192
-
193
-
194
- ### Output the specified <tt>msg</tt> as an ANSI-colored error message
195
- ### (white on red).
196
- def error_message( msg, details='' )
197
- $deferr.puts colorize( 'bold', 'white', 'on_red' ) { msg } + details
198
- end
199
- alias :error :error_message
200
-
201
-
202
- ### Highlight and embed a prompt control character in the given +string+ and return it.
203
- def make_prompt_string( string )
204
- return CLEAR_CURRENT_LINE + colorize( 'bold', 'green' ) { string + ' ' }
205
- end
206
-
207
-
208
- ### Output the specified <tt>prompt_string</tt> as a prompt (in green) and
209
- ### return the user's input with leading and trailing spaces removed. If a
210
- ### test is provided, the prompt will repeat until the test returns true.
211
- ### An optional failure message can also be passed in.
212
- def prompt( prompt_string, failure_msg="Try again." ) # :yields: response
213
- prompt_string.chomp!
214
- prompt_string << ":" unless /\W$/.match( prompt_string )
215
- response = nil
216
-
217
- begin
218
- prompt = make_prompt_string( prompt_string )
219
- response = Readline.readline( prompt ) || ''
220
- response.strip!
221
- if block_given? && ! yield( response )
222
- error_message( failure_msg + "\n\n" )
223
- response = nil
224
- end
225
- end while response.nil?
226
-
227
- return response
228
- end
229
-
230
-
231
- ### Prompt the user with the given <tt>prompt_string</tt> via #prompt,
232
- ### substituting the given <tt>default</tt> if the user doesn't input
233
- ### anything. If a test is provided, the prompt will repeat until the test
234
- ### returns true. An optional failure message can also be passed in.
235
- def prompt_with_default( prompt_string, default, failure_msg="Try again." )
236
- response = nil
237
-
238
- begin
239
- default ||= '~'
240
- response = prompt( "%s [%s]" % [ prompt_string, default ] )
241
- response = default.to_s if !response.nil? && response.empty?
242
-
243
- trace "Validating reponse %p" % [ response ]
244
-
245
- # the block is a validator. We need to make sure that the user didn't
246
- # enter '~', because if they did, it's nil and we should move on. If
247
- # they didn't, then call the block.
248
- if block_given? && response != '~' && ! yield( response )
249
- error_message( failure_msg + "\n\n" )
250
- response = nil
251
- end
252
- end while response.nil?
253
-
254
- return nil if response == '~'
255
- return response
256
- end
257
-
258
-
259
- ### Prompt for an array of values
260
- def prompt_for_multiple_values( label, default=nil )
261
- $stderr.puts( MULTILINE_PROMPT % [label] )
262
- if default
263
- $stderr.puts "Enter a single blank line to keep the default:\n %p" % [ default ]
264
- end
265
-
266
- results = []
267
- result = nil
268
-
269
- begin
270
- result = Readline.readline( make_prompt_string("> ") )
271
- if result.nil? || result.empty?
272
- results << default if default && results.empty?
273
- else
274
- results << result
275
- end
276
- end until result.nil? || result.empty?
277
-
278
- return results.flatten
279
- end
280
-
281
-
282
- ### Turn echo and masking of input on/off.
283
- def noecho( masked=false )
284
- require 'termios'
285
-
286
- rval = nil
287
- term = Termios.getattr( $stdin )
288
-
289
- begin
290
- newt = term.dup
291
- newt.c_lflag &= ~Termios::ECHO
292
- newt.c_lflag &= ~Termios::ICANON if masked
293
-
294
- Termios.tcsetattr( $stdin, Termios::TCSANOW, newt )
295
-
296
- rval = yield
297
- ensure
298
- Termios.tcsetattr( $stdin, Termios::TCSANOW, term )
299
- end
300
-
301
- return rval
302
- end
303
-
304
-
305
- ### Prompt the user for her password, turning off echo if the 'termios' module is
306
- ### available.
307
- def prompt_for_password( prompt="Password: " )
308
- return noecho( true ) do
309
- $stderr.print( prompt )
310
- ($stdin.gets || '').chomp
311
- end
312
- end
313
-
314
-
315
- ### Display a description of a potentially-dangerous task, and prompt
316
- ### for confirmation. If the user answers with anything that begins
317
- ### with 'y', yield to the block, else raise with an error.
318
- def ask_for_confirmation( description )
319
- puts description
320
-
321
- answer = prompt_with_default( "Continue?", 'n' ) do |input|
322
- input =~ /^[yn]/i
323
- end
324
-
325
- case answer
326
- when /^y/i
327
- yield
328
- else
329
- error "Aborted."
330
- fail
331
- end
332
- end
333
- alias :prompt_for_confirmation :ask_for_confirmation
334
-
335
-
336
- ### Search line-by-line in the specified +file+ for the given +regexp+, returning the
337
- ### first match, or nil if no match was found. If the +regexp+ has any capture groups,
338
- ### those will be returned in an Array, else the whole matching line is returned.
339
- def find_pattern_in_file( regexp, file )
340
- rval = nil
341
-
342
- File.open( file, 'r' ).each do |line|
343
- if (( match = regexp.match(line) ))
344
- rval = match.captures.empty? ? match[0] : match.captures
345
- break
346
- end
347
- end
348
-
349
- return rval
350
- end
351
-
352
-
353
- ### Get a list of the file or files to run rspec on.
354
- def rspec_files
355
- if ENV['class']
356
- classname = ENV['class']
357
- spec_file = SPECSDIR + "#{classname}_spec.rb"
358
- raise "Can't find the spec file for the class '#{classname}'" unless spec_file.exist?
359
- return [ spec_file ]
360
- else
361
- return SPEC_FILES
362
- end
363
- end
364
-
365
-
366
- ### Invoke the user's editor on the given +filename+ and return the exit code
367
- ### from doing so.
368
- def edit( filename )
369
- editor = ENV['EDITOR'] || ENV['VISUAL'] || DEFAULT_EDITOR
370
- system editor, filename
371
- unless $?.success?
372
- fail "Editor exited uncleanly."
373
- end
374
- end
375
-
376
-
377
- ### Extract all the non Rake-target arguments from ARGV and return them.
378
- def get_target_args
379
- args = ARGV.reject {|arg| Rake::Task.task_defined?(arg) }
380
- return args
381
- end
382
-
383
-
384
-