Skip to content

Commit 58b51bb

Browse files
committed
update rhythmic vis
1 parent 849779f commit 58b51bb

File tree

2 files changed

+84
-31
lines changed

2 files changed

+84
-31
lines changed

nb/nb15.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# test
2+
using QuranTree
3+
using CairoMakie
4+
5+
crps, tnzl = load(QuranData());
6+
crps_tbl = table(crps)
7+
tnzl_tbl = table(tnzl)
8+
bw_texts = Buckwalter.(verses(crps_tbl[1]))
9+
10+
rvis = RhythmicVis(last_recited, LastRecitedVisArgs(three))
11+
f, d = rvis(bw_texts)
12+
f
13+
14+
15+
16+
d
17+
f
18+
y1_chars = Array{LastRecitedSyllable,1}()
19+
y2_chars = Array{LastRecitedSyllable,1}()
20+
y3_chars = Array{LastRecitedSyllable,1}()
21+
for text in bw_texts
22+
chars_tuple = last_syllable(text)
23+
push!(y1_chars, chars_tuple[1])
24+
push!(y2_chars, chars_tuple[2])
25+
push!(y3_chars, chars_tuple[3])
26+
end
27+
28+
29+
30+
31+
y_dict = Dict{LastRecitedSyllable,Int64}()
32+
y_dict[y3_chars[1]] = 1
33+
34+
35+
y3_chars[1] Ref(Set(keys(y_dict)))
36+
y1_chars
37+
38+
y1_chars, y2_chars, y3_chars = last_syllable.(bw_texts)
39+
y1, y1_dict = encode_to_number(y1_chars)
40+
y2, y2_dict = encode_to_number(y2_chars)
41+
y3, y3_dict = encode_to_number(y3_chars)

src/analysis/rhythmic/vis.jl

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
@enum VisType last_recited schimiller
2+
@enum LastRecitedVariants one two three
23

34
abstract type AbstractRhythmicVisArgs end;
45
abstract type AbstractSyllable end;
5-
struct RhythmicVis{T} where T <: AbstractRhythmicVisArgs
6+
struct RhythmicVis{T <: AbstractRhythmicVisArgs}
67
type::VisType
78
args::T
89
end
910

1011
struct LastRecitedVisArgs <: AbstractRhythmicVisArgs
11-
fig_args::Figure
12+
variant::LastRecitedVariants
13+
fig_args::Makie.Figure
1214
title::String
1315
end
14-
LastRecitedVisArgs() = LastRecitedVisArgs(Figure(resolution=(800, 800)), "")
16+
LastRecitedVisArgs() = LastRecitedVisArgs(one, Figure(resolution=(800, 800)), "")
17+
LastRecitedVisArgs(variant::LastRecitedVariants) = LastRecitedVisArgs(variant, Figure(resolution=(800, 800)), "")
1518

1619
struct LastRecitedSyllable <: AbstractSyllable
1720
syllable::Buckwalter
1821
end
1922

20-
function (r::RhythmicVis)(texts::Array{Buckwalter})
23+
function (r::RhythmicVis)(texts::Array{Buckwalter})::Tuple{Makie.Figure,NTuple{3,Tuple{Array{Int64,1},Dict{LastRecitedSyllable,Int64}}}}
2124
if r.type == last_recited
22-
y1_chars, y2_chars, y3_chars = last_syllable.(texts)
23-
y1, y1_dict = encode_to_number(y1_chars)
24-
y2, y2_dict = encode_to_number(y2_chars)
25-
y3, y3_dict = encode_to_number(y3_chars)
25+
y1_chars = Array{LastRecitedSyllable,1}()
26+
y2_chars = Array{LastRecitedSyllable,1}()
27+
y3_chars = Array{LastRecitedSyllable,1}()
28+
for text in texts
29+
chars_tuple = last_syllable(text)
30+
push!(y1_chars, chars_tuple[1])
31+
push!(y2_chars, chars_tuple[2])
32+
push!(y3_chars, chars_tuple[3])
33+
end
34+
y1, y1_dict = to_number(y1_chars)
35+
y2, y2_dict = to_number(y2_chars)
36+
y3, y3_dict = to_number(y3_chars)
37+
fig = if r.args.variant === one
38+
vis(y1_chars, y1, vis_args=r.args)
39+
elseif r.args.variant === two
40+
vis(y1_chars, y1, x2=y2_chars, y2=y2, vis_args=r.args)
41+
else
42+
vis(y1_chars, y1, x2=y2_chars, y2=y2, x3=y3_chars, y3=y3, vis_args=r.args)
43+
end
44+
return fig, ((y1, y1_dict), (y2, y2_dict), (y3, y3_dict))
2645
end
2746
end
2847

@@ -31,10 +50,10 @@ end
3150
3251
Extracts the last recited syllable from one to two characters prior and after the said vowel.
3352
"""
34-
function last_syllable(text::Buckwalter)::Tuple{Buckwalter,Buckwalter,Buckwalter}
35-
out1 = Buckwalter(replace(text[end-3:end-2], "o" => ""))
36-
out2 = Buckwalter(replace(text[end-3:end-1], "o" => ""))
37-
out3 = Buckwalter(replace(text[end-4:end-1], "o" => ""))
53+
function last_syllable(text::Buckwalter)::NTuple{3,LastRecitedSyllable}
54+
out1 = Buckwalter(replace(text.text[end-3:end-2], "o" => ""))
55+
out2 = Buckwalter(replace(text.text[end-3:end-1], "o" => ""))
56+
out3 = Buckwalter(replace(text.text[end-4:end-1], "o" => ""))
3857
return LastRecitedSyllable(out1), LastRecitedSyllable(out2), LastRecitedSyllable(out3)
3958
end
4059

@@ -43,39 +62,33 @@ end
4362
4463
Converts
4564
"""
46-
function to_number(texts::Array{LastRecitedSyllable})
47-
y = unique(map(x -> x.syllable.text, texts))
48-
y_dict = Dict()
65+
function to_number(texts::Array{LastRecitedSyllable})::Tuple{Array{Int64,1},Dict{LastRecitedSyllable,Int64}}
66+
y = unique(texts)
67+
y_dict = Dict{LastRecitedSyllable,Int64}()
4968
for i in eachindex(y)
5069
if i == 1
5170
y_dict[y[i]] = i
5271
end
5372

54-
if y[i] .∈ Ref(Set(keys(y_dict)))
73+
if y[i] keys(y_dict)
5574
continue
56-
else
75+
else
5776
y_dict[y[i]] = i
5877
end
5978
end
6079
y_vec = Array{Int64,1}()
61-
for i in ychars
62-
push!(y_vec, y_dict[i])
80+
for text in texts
81+
push!(y_vec, y_dict[text])
6382
end
64-
return y_vec, y_dict # scaling to 100 since algo will fail saying range step cannot 0
83+
return y_vec, y_dict
6584
end
6685

67-
bw_texts = verses(crps_tbl[1])
68-
y1_chars, y2_chars, y3_chars = last_syllable(bw_texts)
69-
y1, y1_dict = encode_to_number(y1_chars)
70-
y2, y2_dict = encode_to_number(y2_chars)
71-
y3, y3_dict = encode_to_number(y3_chars)
72-
73-
function vis(x1::Array{String,1}, y1::Array{Int64,1};
74-
x2::Union{Nothing,Array{String,1}}=nothing,
75-
x3::Union{Nothing,Array{String,1}}=nothing,
86+
function vis(x1::Array{LastRecitedSyllable,1}, y1::Array{Int64,1};
87+
x2::Union{Nothing,Array{LastRecitedSyllable,1}}=nothing,
7688
y2::Union{Nothing,Array{Int64,1}}=nothing,
89+
x3::Union{Nothing,Array{LastRecitedSyllable,1}}=nothing,
7790
y3::Union{Nothing,Array{Int64,1}}=nothing,
78-
vis_args::LastRecitedVisArgs)
91+
vis_args::LastRecitedVisArgs=LastRecitedVisArgs())::Makie.Figure
7992
f = vis_args.fig_args;
8093
a1 = Axis(f[1, 1],
8194
ylabel="Last Pronounced Syllable\n\n\n",
@@ -118,6 +131,5 @@ function vis(x1::Array{String,1}, y1::Array{Int64,1};
118131
lines!(a3, collect(eachindex(x3)), y3)
119132
else
120133
end
121-
122134
f
123135
end

0 commit comments

Comments
 (0)