Skip to content

Commit a4d6361

Browse files
committed
update
1 parent 2995ea4 commit a4d6361

File tree

6 files changed

+189
-131
lines changed

6 files changed

+189
-131
lines changed

nb/nb15.jl

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
# test
2-
using QuranTree
2+
using Yunir
33
using CairoMakie
44

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-
last_syllable(bw_texts[1])
11-
last_syllable(Buckwalter("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi")) === (LastRecitedSyllable(Buckwalter("iy")), LastRecitedSyllable(Buckwalter("iym")), LastRecitedSyllable(Buckwalter("Hiym")))
12-
13-
alfatihah_bw = [
14-
Buckwalter("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi"),
15-
Buckwalter("{loHamodu lil~ahi rab~i {loEa`lamiyna"),
16-
Buckwalter("{lr~aHoma`ni {lr~aHiymi"),
17-
Buckwalter("ma`liki yawomi {ld~iyni"),
18-
Buckwalter("<iy~aAka naEobudu wa<iy~aAka nasotaEiynu"),
19-
Buckwalter("{hodinaA {lS~ira`Ta {lomusotaqiyma"),
20-
Buckwalter("Sira`Ta {l~a*iyna >anoEamota Ealayohimo gayori {lomagoDuwbi Ealayohimo walaA {lD~aA^l~iyna")
5+
bw_texts = [
6+
Bw("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi"),
7+
Bw("{loHamodu lil~ahi rab~i {loEa`lamiyna"),
8+
Bw("{lr~aHoma`ni {lr~aHiymi"),
9+
Bw("ma`liki yawomi {ld~iyni"),
10+
Bw("<iy~aAka naEobudu wa<iy~aAka nasotaEiynu"),
11+
Bw("{hodinaA {lS~ira`Ta {lomusotaqiyma"),
12+
Bw("Sira`Ta {l~a*iyna >anoEamota Ealayohimo gayori {lomagoDuwbi Ealayohimo walaA {lD~aA^l~iyna")
2113
]
2214

15+
last_syllable(LastRecited(A), bw_texts[1])
16+
last_syllable(LastRecited(B), Bw("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi")) === (LastRecitedSyllable(Bw("iy")), LastRecitedSyllable(Bw("iym")))
17+
last_syllable(LastRecited(C), Bw("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi")) === (LastRecitedSyllable(Bw("iy")), LastRecitedSyllable(Bw("iym")), LastRecitedSyllable(Bw("Hiym")))
18+
19+
20+
21+
22+
23+
24+
LastRecited(A)
25+
2326
y1_chars = Vector{LastRecitedSyllable}()
2427
y2_chars = Vector{LastRecitedSyllable}()
2528
y3_chars = Vector{LastRecitedSyllable}()
26-
for text in alfatihah_bw
29+
for text in bw_texts
2730
chars_tuple = last_syllable(text)
2831
push!(y1_chars, chars_tuple[1])
2932
push!(y2_chars, chars_tuple[2])
@@ -36,17 +39,21 @@ y3, y3_dict = to_number(y3_chars)
3639
y1 == [1, 1, 1, 1, 1, 1, 1]
3740
y2 == [1, 2, 1, 2, 2, 1, 2]
3841
y3 == [1, 2, 1, 3, 4, 5, 3]
39-
y1_dict == Dict(LastRecitedSyllable(Buckwalter("iy")) => 1)
40-
y2_dict == Dict(LastRecitedSyllable(Buckwalter("iym")) => 1, LastRecitedSyllable(Buckwalter("iyn")) => 2)
42+
y1_dict == Dict(LastRecitedSyllable(Bw("iy")) => 1)
43+
y2_dict == Dict(LastRecitedSyllable(Bw("iym")) => 1, LastRecitedSyllable(Bw("iyn")) => 2)
4144
y3_dict == Dict(
42-
LastRecitedSyllable(Buckwalter("Eiyn")) => 4,
43-
LastRecitedSyllable(Buckwalter("~iyn")) => 3,
44-
LastRecitedSyllable(Buckwalter("qiym")) => 5,
45-
LastRecitedSyllable(Buckwalter("Hiym")) => 1,
46-
LastRecitedSyllable(Buckwalter("miyn")) => 2
45+
LastRecitedSyllable(Bw("Eiyn")) => 4,
46+
LastRecitedSyllable(Bw("~iyn")) => 3,
47+
LastRecitedSyllable(Bw("qiym")) => 5,
48+
LastRecitedSyllable(Bw("Hiym")) => 1,
49+
LastRecitedSyllable(Bw("miyn")) => 2
4750
)
4851

49-
50-
rvis = RhythmicVis(last_recited::VisType, LastRecitedVisArgs(three))
52+
rvis = RhythmicVis(LastRecited(A))
5153
f, d = rvis(bw_texts)
5254
f
55+
56+
57+
58+
###
59+
LastRecited(LastRecitedVariants.one)

nb/nb16.jl

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Yunir
33
using CairoMakie
44

5-
function rhythmic_states(texts::Vector{Bw}, state_timings::Dict{Bw,Int64})::Vector{Vector{Int64}}
5+
function rhythmic_states(data::Schillinger, texts::Vector{Bw})::Vector{Vector{RState}}
66
texts = map(x -> string.(split(x.text)), texts)
77
r = Syllabification(true, Syllable(1, 0, 10))
88

@@ -25,21 +25,21 @@ function rhythmic_states(texts::Vector{Bw}, state_timings::Dict{Bw,Int64})::Vect
2525
k += 1
2626
push!(all_segments, segments)
2727
end
28-
return map(segments -> syllabic_consistency(segments, state_timings), all_segments)
28+
return map(segments -> syllabic_consistency(segments, data.state_timings), all_segments)
2929
end
3030

31-
tajweed_timings = Dict{Bw,Int64}(
32-
Bw("i") => 1, # kasra
33-
Bw("a") => 1, # fatha
34-
Bw("u") => 1, # damma
35-
Bw("F") => 1, # fatha tanween
36-
Bw("N") => 1, # damma tanween
37-
Bw("K") => 1, # kasra tanween
38-
Bw("iy") => 2, # kasra + yaa
39-
Bw("aA") => 2, # fatha + alif
40-
Bw("uw") => 2, # damma + waw
41-
Bw("a`") => 2,
42-
Bw("^") => 4 # maddah
31+
tajweed_timings = Dict{Bw,RState}(
32+
Bw("i") => RState(1, "short"), # kasra
33+
Bw("a") => RState(1, "short"), # fatha
34+
Bw("u") => RState(1, "short"), # damma
35+
Bw("F") => RState(1, "short"), # fatha tanween
36+
Bw("N") => RState(1, "short"), # damma tanween
37+
Bw("K") => RState(1, "short"), # kasra tanween
38+
Bw("iy") => RState(2, "long"), # kasra + yaa
39+
Bw("aA") => RState(2, "long"), # fatha + alif
40+
Bw("uw") => RState(2, "long"), # damma + waw
41+
Bw("a`") => RState(2, "long"),
42+
Bw("^") => RState(4, "maddah") # maddah
4343
)
4444

4545
bw_texts = [
@@ -51,10 +51,60 @@ bw_texts = [
5151
Bw("{hodinaA {lS~ira`Ta {lomusotaqiyma"),
5252
Bw("Sira`Ta {l~a*iyna >anoEamota Ealayohimo gayori {lomagoDuwbi Ealayohimo walaA {lD~aA^l~iyna")
5353
]
54-
rhythms = rhythmic_states(bw_texts, tajweed_timings)
55-
fig = Figure(size=(900,900))
56-
mgrd = fig[1, 1] = GridLayout()
57-
grd1 = mgrd[1, 1] = GridLayout()
58-
grd2 = mgrd[1, 2] = GridLayout()
59-
grd3 = mgrd[2, 1] = GridLayout()
60-
grd4 = mgrd[2, 2] = GridLayout()
54+
55+
struct Schillinger <: AbstractRhythmicVisArgs
56+
state_timings::Dict{Bw,RState}
57+
end
58+
59+
function vis(rhythms::Vector{Vector{RState}}, fig::Makie.Figure=Figure(size=(900,900)), title::String="Title", xlabel::String="Time in Seconds", ylabel::String="Line")
60+
mgrd = fig[1, 1] = GridLayout()
61+
grd = mgrd[1, 1] = GridLayout()
62+
63+
k = 1
64+
axs = Axis[]
65+
phases = rhythms[1]
66+
for phases in rhythms
67+
push!(axs, Axis(grd[k, 1],
68+
title= k == 1 ? title : "",
69+
xlabel=k < length(rhythms) ? "" : xlabel,
70+
ylabel="$(k)",
71+
ygridvisible=true,
72+
xgridvisible=false,
73+
yticks=(1:length(phases), repeat([""], length(phases)))))
74+
75+
steps = Int64[]; j = 2
76+
for phase in phases
77+
steps = vcat(steps, repeat([(j-1) % 2], phase.state))
78+
j += 1
79+
end
80+
stairs!(axs[k], steps, step=:center)
81+
82+
if k != length(rhythms)
83+
hidexdecorations!(axs[k])
84+
hidespines!(axs[k])
85+
else
86+
hidespines!(axs[k])
87+
end
88+
k += 1
89+
end
90+
linkxaxes!(axs..., )
91+
ax = Axis(mgrd[1,1], ylabel=ylabel * "\n\n\n",
92+
ygridvisible=false,
93+
xgridvisible=false,
94+
xticklabelsvisible=false,
95+
yticklabelsvisible=false,
96+
xticksize=0,
97+
yticksize=0,
98+
spinewidth=0,
99+
100+
)
101+
fig
102+
end
103+
104+
rhythms = rhythmic_states(Schillinger(tajweed_timings), bw_texts)
105+
vis(rhythms)
106+
107+
108+
args = Schillinger(tajweed_timings)
109+
110+
typeof(args) === Schillinger

src/Yunir.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export Alif, AlifMaksurah, Ba, Ta, TaMarbuta, Tha, Jeem, HHa, Kha, Dal, Thal, Ra
4949
AlifMaddah, AlifHamzaAbove, AlifHamzaBelow, AlifHamzatWasl, WawHamzaAbove, YaHamzaAbove
5050

5151
# Rhyme
52-
export Harakaat, Syllabification, Syllable, Segment, Sequence, sequence, vowel_indices, syllabic_consistency
53-
export VisType, LastRecitedVariants, LastRecited, RhythmicVis, LastRecitedSyllable, last_syllable, to_number
54-
52+
export AbstractRhythmicVisArgs, Harakaat, Syllabification, Syllable, Segment, Sequence, RState, sequence, vowel_indices, syllabic_consistency
53+
export LastRecited, RhythmicVis, LastRecitedSyllable, last_syllable, to_number
54+
export LastRecitedVariants, A, B, C
5555
# Symmetric Analysis
5656
export Slicer, AyahEmbeddings, AyahMidpoints, gen_midpoints, gen_slices, fitness, selection, slicer, five_summary, refine!, mutate!, crossover!
5757

src/analysis/rhythmic/utils.jl

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,19 @@ function (r::Syllabification)(text::String; isarabic::Bool=false, first_word::Bo
311311
end
312312
end
313313

314+
315+
"""
316+
Rhythmic State
317+
"""
318+
struct RState
319+
state::Int64
320+
label::String
321+
end
322+
323+
RState(state) = RState(state, "")
324+
314325
"""
315-
syllabic_consistency(segments::Vector{Segment}, syllable_timings::Dict{String,Int64})
326+
syllabic_consistency(segments::Vector{Segment}, syllable_timings::Dict{Bw,RState})
316327
317328
Compute syllabic_consistency from a given `segments` and `syllable_timings`. THIS WILL ONLY WORK IF THE VOWEL HAS ONLY 1 TRAIL
318329
```julia-repl
@@ -336,26 +347,28 @@ julia> for i in texts
336347
end
337348
j += 1
338349
end
339-
julia> tajweed_timings = Dict{String,Int64}(
340-
"i" => 1,
341-
"a" => 1,
342-
"u" => 1,
343-
"F" => 1,
344-
"N" => 1,
345-
"K" => 1,
346-
"iy" => 2,
347-
"aA" => 2,
348-
"uw" => 2,
349-
"^" => 4
350-
)
350+
julia> tajweed_timings = Dict{Bw,RState}(
351+
Bw("i") => RState(1, "short"), # kasra
352+
Bw("a") => RState(1, "short"), # fatha
353+
Bw("u") => RState(1, "short"), # damma
354+
Bw("F") => RState(1, "short"), # fatha tanween
355+
Bw("N") => RState(1, "short"), # damma tanween
356+
Bw("K") => RState(1, "short"), # kasra tanween
357+
Bw("iy") => RState(2, "long"), # kasra + yaa
358+
Bw("aA") => RState(2, "long"), # fatha + alif
359+
Bw("uw") => RState(2, "long"), # damma + waw
360+
Bw("a`") => RState(2, "long"),
361+
Bw("^") => RState(4, "maddah") # maddah
362+
)
363+
351364
julia> syllabic_consistency(segments, tajweed_timings)
352365
```
353366
"""
354-
function syllabic_consistency(segments::Vector{Segment}, syllable_timings::Dict{Bw,Int64})::Vector{Int64}
355-
segment_scores = Int64[]
367+
function syllabic_consistency(segments::Vector{Segment}, syllable_timings::Dict{Bw,RState})::Vector{RState}
368+
segment_scores = RState[]
356369
for segment in segments
357370
syllables = split(segment.segment, "?")
358-
syllable_scores = Int64[]
371+
syllable_scores = RState[]
359372
for syllable in syllables
360373
if occursin('{', syllable)
361374
push!(syllable_scores, syllable_timings[Bw("a")])
@@ -394,6 +407,5 @@ function syllabic_consistency(segments::Vector{Segment}, syllable_timings::Dict{
394407
end
395408
push!(segment_scores, syllable_scores...)
396409
end
397-
println("Here is the segment_scores ", segment_scores)
398410
return segment_scores
399-
end
411+
end

0 commit comments

Comments
 (0)