Sha256: ba0525cf64bffa8837a641ab7b249700527fa3a88baa4b40903f708fe0649292

Contents?: true

Size: 811 Bytes

Versions: 6

Compression:

Stored size: 811 Bytes

Contents

require 'open-uri'
require 'cgi'
require 'json'

per_page = 500
base_url = "https://simple.wiktionary.org/w/api.php?action=query&aplimit=#{per_page}&list=allpages&format=json"
filename = "evaluation/dictionary.yml"
count    = nil
apfrom   = ""
num      = 0
titles   = []

begin
  url = base_url + "&apfrom=#{apfrom}"

  puts "downloading page %2d: #{url}" % num

  body   = open(url).read
  json   = JSON.load(body)
  count  = json["query"]["allpages"].size
  apfrom = CGI.escape(json["query"]["allpages"].last['title']) if count > 0

  titles += json["query"]["allpages"].map {|hash| hash["title"] }
  num    += 1
end while count == per_page

require 'yaml'

File.open(filename, 'w') do |file|
  file.write(titles.uniq.to_yaml)
end

puts "
Number of titles: #{titles.uniq.size}
Dictionary saved: #{filename}
"

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
did_you_mean-1.0.0 evaluation/dictionary_generator.rb
did_you_mean-1.0.0.rc1 evaluation/dictionary_generator.rb
did_you_mean-1.0.0.beta3 evaluation/dictionary_generator.rb
did_you_mean-1.0.0.beta2 evaluation/dictionary_generator.rb
did_you_mean-0.10.0-java evaluation/dictionary_generator.rb
did_you_mean-0.10.0 evaluation/dictionary_generator.rb