|
| 1 | +using DataFrames |
| 2 | +using QuranTree |
| 3 | +using Makie |
| 4 | +using Colors |
| 5 | +using CairoMakie |
| 6 | +using MakieThemes |
| 7 | +using Yunir |
| 8 | + |
| 9 | +CairoMakie.activate!(type = "svg") |
| 10 | +active_theme = :dust |
| 11 | + |
| 12 | +if active_theme == :earth |
| 13 | + Makie.set_theme!(ggthemr(:earth)) |
| 14 | + current_theme = Dict( |
| 15 | + :background => "#36312C", |
| 16 | + :text => ["#555555", "#F8F8F0"], |
| 17 | + :line => ["#ffffff", "#827D77"], |
| 18 | + :gridline => "#504940", |
| 19 | + :swatch => ["#F8F8F0", "#DB784D", "#95CC5E", "#E84646", "#F8BB39", "#7A7267", "#E1AA93", "#168E7F", "#2B338E"], |
| 20 | + :gradient => ["#7A7267", "#DB784D"] |
| 21 | + ) |
| 22 | +elseif active_theme == :dust |
| 23 | + Makie.set_theme!(ggthemr(:dust)) |
| 24 | + current_theme = Dict( |
| 25 | + :background => "#FAF7F2", |
| 26 | + :text => ["#5b4f41", "#5b4f41"], |
| 27 | + :line => ["#8d7a64", "#8d7a64"], |
| 28 | + :gridline => "#E3DDCC", |
| 29 | + :swatch => ["#555555", "#db735c", "#EFA86E", "#9A8A76", "#F3C57B", "#7A6752", "#2A91A2", "#87F28A", "#6EDCEF"], |
| 30 | + :gradient => ["#F3C57B", "#7A6752"] |
| 31 | + ) |
| 32 | +else |
| 33 | + error("No active_theme=" * string(active_theme)) |
| 34 | +end; |
| 35 | +colors = [parse(Color, i) for i in current_theme[:swatch]] |
| 36 | +crps, tnzl = load(QuranData()); |
| 37 | +crps_tbl = table(crps) |
| 38 | +tnzl_tbl = table(tnzl) |
| 39 | + |
| 40 | +function last_syllable(bw_texts) |
| 41 | + bw1_texts = Array{String,1}() |
| 42 | + bw2_texts = Array{String,1}() |
| 43 | + bw3_texts = Array{String,1}() |
| 44 | + for bw_text in bw_texts |
| 45 | + @info bw_text |
| 46 | + push!(bw1_texts, replace(bw_text[end-3:end-2], "o" => "")) |
| 47 | + push!(bw2_texts, replace(bw_text[end-3:end-1], "o" => "")) |
| 48 | + push!(bw3_texts, replace(bw_text[end-4:end-1], "o" => "")) |
| 49 | + end |
| 50 | + return bw1_texts, bw2_texts, bw3_texts |
| 51 | +end |
| 52 | + |
| 53 | +function encode_to_number(ychars::Array{String}) |
| 54 | + y = unique(ychars) |
| 55 | + y_dict = Dict() |
| 56 | + for i in eachindex(y) |
| 57 | + if i == 1 |
| 58 | + y_dict[y[i]] = i |
| 59 | + end |
| 60 | + |
| 61 | + if y[i] .∈ Ref(Set(keys(y_dict))) |
| 62 | + continue |
| 63 | + else |
| 64 | + y_dict[y[i]] = i |
| 65 | + end |
| 66 | + end |
| 67 | + y_vec = Array{Int64,1}() |
| 68 | + for i in ychars |
| 69 | + push!(y_vec, y_dict[i]) |
| 70 | + end |
| 71 | + return y_vec, y_dict # scaling to 100 since algo will fail saying range step cannot 0 |
| 72 | +end |
| 73 | + |
| 74 | +bw_texts = verses(crps_tbl[1]) |
| 75 | +y1_chars, y2_chars, y3_chars = last_syllable(bw_texts) |
| 76 | +y1, y1_dict = encode_to_number(y1_chars) |
| 77 | +y2, y2_dict = encode_to_number(y2_chars) |
| 78 | +y3, y3_dict = encode_to_number(y3_chars) |
| 79 | + |
| 80 | +f = Figure(resolution=(800, 800)); |
| 81 | +a1 = Axis(f[1, 1], |
| 82 | + ylabel="Last Pronounced Syllable\n\n\n", |
| 83 | + title="Surah Al-Fatihah\n\n", |
| 84 | + yticks=(unique(y1), unique(string.(y1_chars))), |
| 85 | + xticks = collect(eachindex(y1_chars)) |
| 86 | +) |
| 87 | +# ylims!(a1, 100, maximum(y1) .+1) |
| 88 | + |
| 89 | +a2 = Axis(f[2, 1], |
| 90 | + ylabel="3 Characters\n\n\n", |
| 91 | + yticks=(unique(y2), unique(string.(y2_chars))), |
| 92 | + xticks = collect(eachindex(y2_chars)) |
| 93 | +) |
| 94 | + |
| 95 | +a3 = Axis(f[3, 1], |
| 96 | + ylabel="3-4 Characters\n\n", |
| 97 | + yticks=(unique(y3), unique(string.(y3_chars))), |
| 98 | + xticks = collect(eachindex(y3_chars)) |
| 99 | +) |
| 100 | + |
| 101 | +lines!(a1, collect(eachindex(y1_chars)), y1) |
| 102 | +hidexdecorations!(a1) |
| 103 | +lines!(a2, collect(eachindex(y2_chars)), y2) |
| 104 | +hidexdecorations!(a2) |
| 105 | +lines!(a3, collect(eachindex(y3_chars)), y3) |
| 106 | + |
| 107 | +f |
| 108 | + |
| 109 | +bw_texts = verses(crps_tbl[55]) |
| 110 | +y1_chars, y2_chars, y3_chars = last_syllable(bw_texts) |
| 111 | +y1, y1_dict = encode_to_number(y1_chars) |
| 112 | +y2, y2_dict = encode_to_number(y2_chars) |
| 113 | +y3, y3_dict = encode_to_number(y3_chars) |
| 114 | + |
| 115 | +# f = Figure(resolution=(500, 500)); |
| 116 | +a1 = Axis(f[1, 2], |
| 117 | + # ylabel="Last Syllable", |
| 118 | + title="Surah Ar-Rahman\n\n", |
| 119 | + yticks=(unique(y1), unique(string.(y1_chars))), |
| 120 | + # xticks = collect(eachindex(y1_chars)) |
| 121 | +) |
| 122 | + |
| 123 | +a2 = Axis(f[2, 2], |
| 124 | + # ylabel="2-3 Characters", |
| 125 | + yticks=(unique(y2), unique(string.(y2_chars))), |
| 126 | + # xticks = collect(eachindex(y2_chars)) |
| 127 | +) |
| 128 | + |
| 129 | +a3 = Axis(f[3, 2], |
| 130 | + # ylabel="3-4 Characters", |
| 131 | + # yticks=(collect(eachindex(y3_chars)), string.(y3_chars)), |
| 132 | + # xticks = collect(eachindex(y3_chars)) |
| 133 | +) |
| 134 | + |
| 135 | +lines!(a1, collect(eachindex(y1_chars)), y1) |
| 136 | +hidexdecorations!(a1) |
| 137 | +lines!(a2, collect(eachindex(y2_chars)), y2) |
| 138 | +hidexdecorations!(a2) |
| 139 | +lines!(a3, collect(eachindex(y3_chars)), y3) |
| 140 | +f |
| 141 | + |
| 142 | +# save("plots/plot_rhythmic1.svg", f) |
0 commit comments