Skip to content

Commit b688d6c

Browse files
committed
update
1 parent 58b51bb commit b688d6c

File tree

5 files changed

+176
-38
lines changed

5 files changed

+176
-38
lines changed

nb/nb15.jl

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,46 @@ crps_tbl = table(crps)
77
tnzl_tbl = table(tnzl)
88
bw_texts = Buckwalter.(verses(crps_tbl[1]))
99

10-
rvis = RhythmicVis(last_recited, LastRecitedVisArgs(three))
11-
f, d = rvis(bw_texts)
12-
f
13-
14-
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")
21+
]
1522

16-
d
17-
f
1823
y1_chars = Array{LastRecitedSyllable,1}()
1924
y2_chars = Array{LastRecitedSyllable,1}()
2025
y3_chars = Array{LastRecitedSyllable,1}()
21-
for text in bw_texts
26+
for text in alfatihah_bw
2227
chars_tuple = last_syllable(text)
2328
push!(y1_chars, chars_tuple[1])
2429
push!(y2_chars, chars_tuple[2])
2530
push!(y3_chars, chars_tuple[3])
2631
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)
32+
y1, y1_dict = to_number(y1_chars)
33+
y2, y2_dict = to_number(y2_chars)
34+
y3, y3_dict = to_number(y3_chars)
35+
36+
y1 == [1, 1, 1, 1, 1, 1, 1]
37+
y2 == [1, 2, 1, 2, 2, 1, 2]
38+
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)
41+
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
47+
)
48+
49+
50+
rvis = RhythmicVis(last_recited::VisType, LastRecitedVisArgs(three))
51+
f, d = rvis(bw_texts)
52+
f

src/Yunir.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export Alignment, AbstractCAMeLDB, AbstractEncoder, SimpleEncoding
3232
export @transliterator, genproperties
3333

3434
# text wrapper
35-
export Arabic, Buckwalter
35+
export Ar, Bw
3636

3737
# Orthography
3838
export AbstractCharacter, AbstractCharacter, AbstractConsonant, AbstractSolar, AbstractLunar,
@@ -50,6 +50,7 @@ export Alif, AlifMaksurah, Ba, Ta, TaMarbuta, Tha, Jeem, HHa, Kha, Dal, Thal, Ra
5050

5151
# Rhyme
5252
export Harakaat, Syllabification, Syllable, Segment, Sequence, sequence, vowel_indices, syllabic_consistency
53+
export VisType, LastRecitedVariants, LastRecitedVisArgs, RhythmicVis, LastRecitedSyllable, last_syllable, to_number
5354

5455
# Symmetric Analysis
5556
export Slicer, AyahEmbeddings, AyahMidpoints, gen_midpoints, gen_slices, fitness, selection, slicer, five_summary, refine!, mutate!, crossover!

src/analysis/rhythmic/vis.jl

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,109 @@
1+
"""
2+
VisType
3+
4+
Enum specifying the type of plot.
5+
6+
# Variants
7+
- `last_recited`: plots the last recited syllable
8+
- `schimiller`: generates the Joseph Schimiller rhythmic graph
9+
"""
110
@enum VisType last_recited schimiller
11+
12+
"""
13+
LastRecitedVariants
14+
15+
Enum specifying the variant of last-recited visualization.
16+
17+
# Variants
18+
- `one`: only shows the syllable in the y-axis of the graph
19+
- `two`: includes additional subplot now accounting the consonant after the syllable
20+
- `three`: is `two` variant but with another suplot now accounting consonants before and after the syllable
21+
"""
222
@enum LastRecitedVariants one two three
323

424
abstract type AbstractRhythmicVisArgs end;
525
abstract type AbstractSyllable end;
26+
27+
"""
28+
RhythmicVis(type::VisType, args::T) where T <: AbstractRhythmicVisArgs
29+
30+
Create a `RhythmicVis` object with the specified visualization type and arguments.
31+
32+
# Arguments
33+
- `type::VisType`: The type of rhythmic visualization (from the `VisType` enum)
34+
- `args::T`: Visualization arguments, must be a subtype of `AbstractRhythmicVisArgs`
35+
36+
# Examples
37+
```julia
38+
args = LastRecitedVisArgs(fig, "My Title")
39+
vis = RhythmicVis(last_recited::VisType, args)
40+
```
41+
"""
642
struct RhythmicVis{T <: AbstractRhythmicVisArgs}
743
type::VisType
844
args::T
945
end
1046

47+
"""
48+
LastRecitedVisArgs <: AbstractRhythmicVisArgs
49+
50+
Create a `LastRecitedVisArgs` with `variant` argument specifying the number of characters before and after the last recited syllable, this variant is
51+
specified by the `LastRecitedVariants` which takes `one`, `two`, or `three` variant. It also takes `fig_args` argument to specify the details of the `Makie.Figure`.
52+
The third argument `title` specifies the title of the graph.
53+
"""
1154
struct LastRecitedVisArgs <: AbstractRhythmicVisArgs
1255
variant::LastRecitedVariants
1356
fig_args::Makie.Figure
1457
title::String
1558
end
16-
LastRecitedVisArgs() = LastRecitedVisArgs(one, Figure(resolution=(800, 800)), "")
59+
60+
"""
61+
LastRecitedVisArgs
62+
63+
Create a LastRecitedVisArgs object with the following default arguments: `one::LastRecitedVariants`, `Figure(resolution=(800, 800))`, and title="".
64+
"""
65+
LastRecitedVisArgs() = LastRecitedVisArgs(one::LastRecitedVariants, Figure(resolution=(800, 800)), "")
66+
67+
"""
68+
LastRecitedVisArgs(variant::LastRecitedVariants)
69+
70+
Create a LastRecitedVisArgs object with custom `variant` specification and default values for the remaining arguments set to: `Figure(resolution=(800, 800))`, and title="".
71+
"""
1772
LastRecitedVisArgs(variant::LastRecitedVariants) = LastRecitedVisArgs(variant, Figure(resolution=(800, 800)), "")
1873

74+
"""
75+
LastRecitedSyllable <: AbstractSyllable
76+
77+
Create a LastRecitedSyllable object with `syllable` field.
78+
"""
1979
struct LastRecitedSyllable <: AbstractSyllable
20-
syllable::Buckwalter
80+
syllable::Bw
2181
end
2282

23-
function (r::RhythmicVis)(texts::Array{Buckwalter})::Tuple{Makie.Figure,NTuple{3,Tuple{Array{Int64,1},Dict{LastRecitedSyllable,Int64}}}}
83+
"""
84+
(r::RhythmicVis)(texts::Array{Bw})
85+
86+
Generate a rhythmic visualization from an array of Bw-encoded texts.
87+
88+
This is a functor/callable method for `RhythmicVis` objects.
89+
90+
# Arguments
91+
- `texts::Array{Bw}`: Array of texts in Bw transliteration
92+
93+
# Returns
94+
A tuple containing:
95+
- `Makie.Figure`: The generated visualization figure
96+
- `NTuple{3,...}`: A 3-tuple where each element is a tuple of:
97+
- `Array{Int64,1}`: Array of integer values
98+
- `Dict{LastRecitedSyllable,Int64}`: Dictionary mapping syllables to counts
99+
100+
# Examples
101+
```julia
102+
vis = RhythmicVis(last_recited, LastRecitedVisArgs())
103+
fig, data = vis(buckwalter_texts)
104+
```
105+
"""
106+
function (r::RhythmicVis)(texts::Array{Bw})::Tuple{Makie.Figure,NTuple{3,Tuple{Array{Int64,1},Dict{LastRecitedSyllable,Int64}}}}
24107
if r.type == last_recited
25108
y1_chars = Array{LastRecitedSyllable,1}()
26109
y2_chars = Array{LastRecitedSyllable,1}()
@@ -46,21 +129,23 @@ function (r::RhythmicVis)(texts::Array{Buckwalter})::Tuple{Makie.Figure,NTuple{3
46129
end
47130

48131
"""
49-
last_syllable(text::Buckwalter)
132+
last_syllable(text::Bw)
50133
51-
Extracts the last recited syllable from one to two characters prior and after the said vowel.
134+
Extract the last syllables from Bw-encoded text.
135+
136+
Returns a 3-tuple of `LastRecitedSyllable` values which are described as the description of the three variants of `LastRecitedVariants`, respectively.
52137
"""
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" => ""))
138+
function last_syllable(text::Bw)::NTuple{3,LastRecitedSyllable}
139+
out1 = Bw(replace(text.text[end-3:end-2], "o" => ""))
140+
out2 = Bw(replace(text.text[end-3:end-1], "o" => ""))
141+
out3 = Bw(replace(text.text[end-4:end-1], "o" => ""))
57142
return LastRecitedSyllable(out1), LastRecitedSyllable(out2), LastRecitedSyllable(out3)
58143
end
59144

60145
"""
61146
to_number(texts::Array{LastRecitedSyllable})
62147
63-
Converts
148+
Assign a unique sequence (sorted based on first appearance in the array) of number to the unique values of `LastRecitedSyllable` texts to be used as y-axis location for plotting Rhythmic last recited syllable.
64149
"""
65150
function to_number(texts::Array{LastRecitedSyllable})::Tuple{Array{Int64,1},Dict{LastRecitedSyllable,Int64}}
66151
y = unique(texts)
@@ -89,6 +174,7 @@ function vis(x1::Array{LastRecitedSyllable,1}, y1::Array{Int64,1};
89174
x3::Union{Nothing,Array{LastRecitedSyllable,1}}=nothing,
90175
y3::Union{Nothing,Array{Int64,1}}=nothing,
91176
vis_args::LastRecitedVisArgs=LastRecitedVisArgs())::Makie.Figure
177+
x1 = map(x -> x.syllable.text, x1)
92178
f = vis_args.fig_args;
93179
a1 = Axis(f[1, 1],
94180
ylabel="Last Pronounced Syllable\n\n\n",
@@ -99,6 +185,8 @@ function vis(x1::Array{LastRecitedSyllable,1}, y1::Array{Int64,1};
99185
lines!(a1, collect(eachindex(x1)), y1)
100186

101187
if x2 !== nothing && x3 !== nothing
188+
x2 = map(x -> x.syllable.text, x2)
189+
x3 = map(x -> x.syllable.text, x3)
102190
a2 = Axis(f[2, 1],
103191
ylabel="3 Characters\n\n\n",
104192
yticks=(unique(y2), unique(string.(x2))),
@@ -109,11 +197,10 @@ function vis(x1::Array{LastRecitedSyllable,1}, y1::Array{Int64,1};
109197
yticks=(unique(y3), unique(string.(x3))),
110198
xticks = collect(eachindex(x3))
111199
)
112-
hidexdecorations!(a1)
113200
lines!(a2, collect(eachindex(x2)), y2)
114-
hidexdecorations!(a2)
115201
lines!(a3, collect(eachindex(x3)), y3)
116202
elseif x2 !== nothing && x3 === nothing
203+
x2 = map(x -> x.syllable.text, x2)
117204
a2 = Axis(f[2, 1],
118205
ylabel="3 Characters\n\n\n",
119206
yticks=(unique(y2), unique(string.(x2))),
@@ -122,6 +209,7 @@ function vis(x1::Array{LastRecitedSyllable,1}, y1::Array{Int64,1};
122209
hidexdecorations!(a1)
123210
lines!(a2, collect(eachindex(x2)), y2)
124211
elseif x2 === nothing && x3 !== nothing
212+
x3 = map(x -> x.syllable.text, x3)
125213
a3 = Axis(f[3, 1],
126214
ylabel="3-4 Characters\n\n",
127215
yticks=(unique(y3), unique(string.(x3))),

src/utils/texts_wrapper.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
struct Arabic
1+
struct Ar
22
text::String
33
end
44

5-
struct Buckwalter
5+
struct Bw
66
text::String
77
end

test/runtests.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,42 @@ using Yunir
525525
# In this case, it should identify the explicit vowel 'a'
526526
@test any(x -> x.char == "a", result.harakaat)
527527
end
528+
529+
@testset "Rhythmic Vis" begin
530+
@test last_syllable(Bw("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi")) === (LastRecitedSyllable(Bw("iy")), LastRecitedSyllable(Bw("iym")), LastRecitedSyllable(Bw("Hiym")))
531+
alfatihah_bw = [
532+
Bw("bisomi {ll~ahi {lr~aHoma`ni {lr~aHiymi"),
533+
Bw("{loHamodu lil~ahi rab~i {loEa`lamiyna"),
534+
Bw("{lr~aHoma`ni {lr~aHiymi"),
535+
Bw("ma`liki yawomi {ld~iyni"),
536+
Bw("<iy~aAka naEobudu wa<iy~aAka nasotaEiynu"),
537+
Bw("{hodinaA {lS~ira`Ta {lomusotaqiyma"),
538+
Bw("Sira`Ta {l~a*iyna >anoEamota Ealayohimo gayori {lomagoDuwbi Ealayohimo walaA {lD~aA^l~iyna")
539+
]
540+
y1_chars = Array{LastRecitedSyllable,1}()
541+
y2_chars = Array{LastRecitedSyllable,1}()
542+
y3_chars = Array{LastRecitedSyllable,1}()
543+
for text in alfatihah_bw
544+
chars_tuple = last_syllable(text)
545+
push!(y1_chars, chars_tuple[1])
546+
push!(y2_chars, chars_tuple[2])
547+
push!(y3_chars, chars_tuple[3])
548+
end
549+
y1, y1_dict = to_number(y1_chars)
550+
y2, y2_dict = to_number(y2_chars)
551+
y3, y3_dict = to_number(y3_chars)
552+
553+
@test y1 == [1, 1, 1, 1, 1, 1, 1]
554+
@test y2 == [1, 2, 1, 2, 2, 1, 2]
555+
@test y3 == [1, 2, 1, 3, 4, 5, 3]
556+
@test y1_dict == Dict(LastRecitedSyllable(Bw("iy")) => 1)
557+
@test y2_dict == Dict(LastRecitedSyllable(Bw("iym")) => 1, LastRecitedSyllable(Bw("iyn")) => 2)
558+
@test y3_dict == Dict(
559+
LastRecitedSyllable(Bw("Eiyn")) => 4,
560+
LastRecitedSyllable(Bw("~iyn")) => 3,
561+
LastRecitedSyllable(Bw("qiym")) => 5,
562+
LastRecitedSyllable(Bw("Hiym")) => 1,
563+
LastRecitedSyllable(Bw("miyn")) => 2
564+
)
565+
end
528566
end

0 commit comments

Comments
 (0)