-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScript_freqs_Dictionaries.jl
38 lines (34 loc) · 1.02 KB
/
Script_freqs_Dictionaries.jl
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
using Dictionaries, BenchmarkTools
function get_freqs_dict(in_wds)
"""Base Julia dictionary"""
freqs = Dict{String, Int64}()
for wd in in_wds
cur_wd = wd.match
freqs[cur_wd] = get(freqs, cur_wd, 0) + 1
end # next word
return freqs
end # function
function get_freqs_dictionary(in_wds)
"""Dictinaries.jl dictionary"""
freqs = Dictionaries.Dictionary{String, Int64}()
for wd in in_wds
cur_wd = wd.match
iskey, t = gettoken(freqs, cur_wd)
if iskey
set!(freqs, cur_wd, gettokenvalue(freqs, t) + 1)
else
insert!(freqs, cur_wd, 1)
end
end # next word
return freqs
end # function
### main ###
txt = open("/Users/ekb5/Downloads/big_badboy_alphanum.txt") do infile
# txt = open("/path/to/filename.txt") do infile
read(infile, String)
end
wds = eachmatch(r"[-'A-Z]+", uppercase(txt))
println("Dictionaries.jl Dictionary()")
@btime get_freqs_dictionary(wds)
println("Base Dict():")
@btime get_freqs_dict(wds)