-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
141 lines (114 loc) · 3.31 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
DATA_DIR = File.join(File.dirname(__FILE__), 'data') + '/'
task :default => ['data:all']
namespace :git do
desc "Git pull"
task :pull do
sh "git pull"
end
desc "Git push"
task :push do
sh "git push"
end
desc "Git add ."
task :add, :path do |t, args|
sh "git add #{args[:path]}"
end
desc "Git commit"
task :commit, :message do |t, args|
status = %x{git status}
unless status =~ /nothing to commit|no changes added to commit/
sh "git commit -m '#{args[:message]}'"
end
end
end
namespace :data do
task :ensure_data_directory do
Dir.mkdir(DATA_DIR) unless File.exists?(DATA_DIR)
end
desc "Download and update all data"
task :all do
Rake::Task['git:pull'].invoke
Rake::Task['data:update:jmdict'].invoke
Rake::Task['git:push'].invoke
Rake::Task['git:add'].reenable
Rake::Task['git:commit'].reenable
Rake::Task['git:push'].reenable
Rake::Task['data:update:kanjidic2'].invoke
Rake::Task['git:push'].invoke
Rake::Task['git:add'].reenable
Rake::Task['git:commit'].reenable
Rake::Task['git:push'].reenable
Rake::Task['data:update:radk'].invoke
Rake::Task['git:push'].invoke
Rake::Task['git:add'].reenable
Rake::Task['git:commit'].reenable
Rake::Task['git:push'].reenable
Rake::Task['data:update:tanaka'].invoke
Rake::Task['git:push'].invoke
end
namespace :update do
desc "Update JMdict"
task :jmdict do
Rake::Task['data:dl:jmdict'].invoke
Rake::Task['git:add'].invoke(DATA_DIR)
Rake::Task['git:commit'].invoke("JMdict #{Time.now}")
end
desc "Update Kanjidic2"
task :kanjidic2 do
Rake::Task['data:dl:kanjidic2'].invoke
Rake::Task['git:add'].invoke(DATA_DIR)
Rake::Task['git:commit'].invoke("Kanjidic2 #{Time.now}")
end
desc "Update Radkfile"
task :radk do
Rake::Task['data:dl:radk'].invoke
Rake::Task['git:add'].invoke(DATA_DIR)
Rake::Task['git:commit'].invoke("Radk #{Time.now}")
end
desc "Update Tanaka corpus"
task :tanaka do
Rake::Task['data:dl:tanaka'].invoke
Rake::Task['git:add'].invoke(DATA_DIR)
Rake::Task['git:commit'].invoke("Tanaka #{Time.now}")
end
end
namespace :dl do
desc "Download JMdict"
task :jmdict => [:ensure_data_directory] do
dl_and_gunzip('http://ftp.monash.edu.au/pub/nihongo/JMdict.gz')
end
desc "Download Kanjidic2"
task :kanjidic2 => [:ensure_data_directory] do
dl_and_gunzip('http://www.csse.monash.edu.au/~jwb/kanjidic2/kanjidic2.xml.gz')
end
desc "Download Radk"
task :radk => [:ensure_data_directory] do
dl_and_gunzip('ftp://ftp.monash.edu.au/pub/nihongo/radkfile.gz')
end
desc "Download Tanaka Corpus"
task :tanaka => [:ensure_data_directory] do
dl('http://tatoeba.org/files/downloads/wwwjdic.csv')
end
def dl(url)
filename = url.split('/')[-1]
target_path = DATA_DIR + filename
sh "rm #{target_path}" if File.exists?(target_path)
sh "wget -O #{target_path} #{url}"
target_path
end
def gunzip(path)
sh "gunzip -f #{path}"
end
def bunzip2(path)
sh "bunzip2 -f #{path}"
end
def dl_and_gunzip(url)
path = dl(url)
gunzip(path)
end
def dl_and_bunzip2(url)
path = dl(url)
bunzip2(path)
end
end
end