|
1 | 1 | @enum VisType last_recited schimiller |
| 2 | +@enum LastRecitedVariants one two three |
2 | 3 |
|
3 | 4 | abstract type AbstractRhythmicVisArgs end; |
4 | 5 | abstract type AbstractSyllable end; |
5 | | -struct RhythmicVis{T} where T <: AbstractRhythmicVisArgs |
| 6 | +struct RhythmicVis{T <: AbstractRhythmicVisArgs} |
6 | 7 | type::VisType |
7 | 8 | args::T |
8 | 9 | end |
9 | 10 |
|
10 | 11 | struct LastRecitedVisArgs <: AbstractRhythmicVisArgs |
11 | | - fig_args::Figure |
| 12 | + variant::LastRecitedVariants |
| 13 | + fig_args::Makie.Figure |
12 | 14 | title::String |
13 | 15 | 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)), "") |
15 | 18 |
|
16 | 19 | struct LastRecitedSyllable <: AbstractSyllable |
17 | 20 | syllable::Buckwalter |
18 | 21 | end |
19 | 22 |
|
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}}}} |
21 | 24 | 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)) |
26 | 45 | end |
27 | 46 | end |
28 | 47 |
|
|
31 | 50 |
|
32 | 51 | Extracts the last recited syllable from one to two characters prior and after the said vowel. |
33 | 52 | """ |
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" => "")) |
38 | 57 | return LastRecitedSyllable(out1), LastRecitedSyllable(out2), LastRecitedSyllable(out3) |
39 | 58 | end |
40 | 59 |
|
|
43 | 62 |
|
44 | 63 | Converts |
45 | 64 | """ |
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}() |
49 | 68 | for i in eachindex(y) |
50 | 69 | if i == 1 |
51 | 70 | y_dict[y[i]] = i |
52 | 71 | end |
53 | 72 |
|
54 | | - if y[i] .∈ Ref(Set(keys(y_dict))) |
| 73 | + if y[i] ∈ keys(y_dict) |
55 | 74 | continue |
56 | | - else |
| 75 | + else |
57 | 76 | y_dict[y[i]] = i |
58 | 77 | end |
59 | 78 | end |
60 | 79 | 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]) |
63 | 82 | 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 |
65 | 84 | end |
66 | 85 |
|
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, |
76 | 88 | y2::Union{Nothing,Array{Int64,1}}=nothing, |
| 89 | + x3::Union{Nothing,Array{LastRecitedSyllable,1}}=nothing, |
77 | 90 | y3::Union{Nothing,Array{Int64,1}}=nothing, |
78 | | - vis_args::LastRecitedVisArgs) |
| 91 | + vis_args::LastRecitedVisArgs=LastRecitedVisArgs())::Makie.Figure |
79 | 92 | f = vis_args.fig_args; |
80 | 93 | a1 = Axis(f[1, 1], |
81 | 94 | ylabel="Last Pronounced Syllable\n\n\n", |
@@ -118,6 +131,5 @@ function vis(x1::Array{String,1}, y1::Array{Int64,1}; |
118 | 131 | lines!(a3, collect(eachindex(x3)), y3) |
119 | 132 | else |
120 | 133 | end |
121 | | - |
122 | 134 | f |
123 | 135 | end |
0 commit comments