Ticket #10710: update_synonym_lookup_for_wordnet_3.diff
| File update_synonym_lookup_for_wordnet_3.diff, 1.4 kB (added by tom./, 11 months ago) |
|---|
-
railties/lib/rails_generator/commands.rb
old new 386 386 end_message 387 387 if suggest = find_synonyms(class_name) 388 388 message << "\n Suggestions: \n\n" 389 message << suggest.join("\n") 389 message << suggest.join("\n") 390 390 end 391 391 raise UsageError, message 392 392 end 393 393 394 SYNONYM_LOOKUP_URI = "http://wordnet.princeton.edu/ cgi-bin/webwn2.0?stage=2&word=%s&posnumber=1&searchtypenumber=2&senses=&showglosses=1"394 SYNONYM_LOOKUP_URI = "http://wordnet.princeton.edu/perl/webwn?s=%s" 395 395 396 396 # Look up synonyms on WordNet. Thanks to Florian Gross (flgr). 397 397 def find_synonyms(word) … … 399 399 require 'timeout' 400 400 timeout(5) do 401 401 open(SYNONYM_LOOKUP_URI % word) do |stream| 402 data = stream.read.gsub(" ", " ").gsub("<BR>", "")403 data .scan(/^Sense \d+\n.+?\n\n/m)402 # Grab words linked to dictionary entries as possible synonyms 403 data = stream.read.gsub(" ", " ").scan(/<a href="webwn.*?">([\w ]*?)<\/a>/s).uniq 404 404 end 405 405 end 406 406 rescue Exception