Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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)

Update for WordNet 3.0, returns synonyms

  • railties/lib/rails_generator/commands.rb

    old new  
    386386end_message 
    387387            if suggest = find_synonyms(class_name) 
    388388              message << "\n  Suggestions:  \n\n" 
    389               message << suggest.join("\n") 
     389              message << suggest.join("\n") 
    390390            end 
    391391            raise UsageError, message 
    392392          end 
    393393 
    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
    395395 
    396396          # Look up synonyms on WordNet.  Thanks to Florian Gross (flgr). 
    397397          def find_synonyms(word) 
     
    399399            require 'timeout' 
    400400            timeout(5) do 
    401401              open(SYNONYM_LOOKUP_URI % word) do |stream| 
    402                 data = stream.read.gsub("&nbsp;", " ").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("&nbsp;", " ").scan(/<a href="webwn.*?">([\w ]*?)<\/a>/s).uniq 
    404404              end 
    405405            end 
    406406          rescue Exception