-
Notifications
You must be signed in to change notification settings - Fork 1
/
parsedict.rb
46 lines (43 loc) · 1.02 KB
/
parsedict.rb
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
require 'json'
text = File.readlines('cleancmu.txt')
text2 = File.read('dict-old.json')
text3 = File.readlines('fakecmudict.txt')
sylhash = JSON.parse(text2)
#print sylhash
text.each do |thisline|
if thisline =~ /^\w/
thisarray = thisline.split(/\s+/)
thisword = thisarray[0]
sylcount = 0
thisarray.each do |thisdatum|
if thisdatum =~ /(\d)$/
sylcount += 1
end
end
if not sylhash[thisword.downcase]
#print("hi #{thisword}\n")
sylhash[thisword.downcase] = sylcount
else
#print("innit #{thisword.downcase}\n")
end
end
end
text3.each do |thisline|
if thisline =~ /^\w/
thisarray = thisline.split(/\s+/)
thisword = thisarray[0]
sylcount = 0
thisarray.each do |thisdatum|
if thisdatum =~ /(\d)$/
sylcount += 1
end
end
if not sylhash[thisword.downcase]
#print("hi #{thisword}\n")
sylhash[thisword.downcase] = sylcount
else
#print("innit #{thisword.downcase}\n")
end
end
end
print sylhash.to_json