Skip to content

Commit

Permalink
Added 5-second timeout to WordNet alternatives on creating reserved-w…
Browse files Browse the repository at this point in the history
…ord models #501 [Marcel Molina]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@455 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 18, 2005
1 parent 53088c4 commit 652f1ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Added 5-second timeout to WordNet alternatives on creating reserved-word models #501 [Marcel Molina]

* Fixed binding of caller #496 [Alexey]


Expand Down
14 changes: 9 additions & 5 deletions railties/bin/generate
Expand Up @@ -6,14 +6,18 @@ ARGV.shift unless ARGV.empty? or not ['--help', '-h'].include?(ARGV[0])

def find_synonyms(word)
require 'open-uri'
require 'timeout'

uri = "http://wordnet.princeton.edu/cgi-bin/webwn2.0?stage=2" +
"&word=%s&posnumber=1&searchtypenumber=2&senses=&showglosses=1"

open(uri % word) do |stream|
data = stream.read.gsub("&nbsp;", " ").gsub("<BR>", "")
data.scan(/^Sense \d+\n.+?\n\n/m)
timeout(5) do
open(uri % word) do |stream|
data = stream.read.gsub("&nbsp;", " ").gsub("<BR>", "")
data.scan(/^Sense \d+\n.+?\n\n/m)
end
end
rescue Exception
rescue Timeout::Error, Exception
return nil
end

Expand Down Expand Up @@ -66,4 +70,4 @@ end_usage
#{$0} login
end_usage
exit 0
end
end

0 comments on commit 652f1ef

Please sign in to comment.