-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRakefile
37 lines (32 loc) · 926 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require "bundler/gem_tasks"
$LOAD_PATH << "lib"
require "cantonese/syllables/scraper"
require 'json'
require 'set'
desc "scrape data file"
task :scrape do
include Cantonese::Syllables
all_characters = {}
all_sounds = {}
Scraper.list.each do |syllable|
puts "Fetch #{syllable[:text]} ..."
sounds = Scraper.syllable(syllable[:url])
sounds.each do |sound|
sound[:characters].each do |character|
sounds = Scraper.word(character)
all_characters[character] = sounds
sounds.each do |sound|
all_sounds[sound] ||= []
all_sounds[sound] << character unless all_sounds[sound].include?(character)
end
end
end
end
# save output files
File.open("data/characters.json","w") do |f|
f.write(JSON.pretty_generate(all_characters))
end
File.open("data/sounds.json","w") do |f|
f.write(JSON.pretty_generate(all_sounds))
end
end