-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sort.dyalog
94 lines (75 loc) · 2.85 KB
/
Sort.dyalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
:Namespace Sort
⎕ML←1
Classic←{
⎕AV ⍺⍺ Sort Mix ⍵
}
Natural←{
ABC←abc←⊢
Digits←∊∘⎕D
CutOffs←1,2≠/Digits
Parts←CutOffs⊂⊢
ExecNums←{
⊃⊃⎕VFI ⍵:⍎⍵
⍵
}
NORM←Norm←ExecNums¨∘Parts¨
abc ⍺⍺ Sort Norm ⍵
}
Danish←{ ⍝ http://sproget.dk/raad-og-regler/Retskrivningsregler/retskrivningsregler/a7-1-6/a7-4-alfabetisk-rekkefolge
ABC←abc←⊖'ÁÀ' 'Ç' 'Ð' 'ÉÈË' 'Þ' 'ÍÌÏ' 'ÓÒ' 'Ú' 'ÝÜ' 'ÄǼ' 'ÖǾ' 'Ᾰ'VariantsOf'ACDEHIOUYÆØÅ'⊢' ',⎕A,'ÆØÅ'
NORM←Norm←'aa' 'Aa' 'AA' 'þ' 'Þ'⎕R'ӑ' 'Ӑ' 'Ӑ' 'tþ' 'TÞ' ⍝ n.b. not ligatures
abc ⍺⍺ Sort Norm ⍵
}
Finnish←{ ⍝ https://en.wikipedia.org/wiki/Finnish_orthography#Collation_order
ABC←abc←'DĐÐ' 'EÉÆŒ' 'LŁ' 'NŊ' 'OŒ' 'VW' 'SŠẞ' 'YÜŰ' 'ZŽ' 'ÖØÕŐ'VariantsOf'DELNOVSYZÖ'⊢' ',⎕A,'ÅÄÖ'~'W'
NORM←Norm←'AOS'ExpLigs'ÆŒẞ'
abc ⍺⍺ Sort Norm ⍵
}
German←{ ⍝ https://en.wikipedia.org/wiki/German_orthography#Sorting
ABC←abc←'aAäÄ' 'oOöÖ' 'ßẞsS' 'uUüÜ'VariantsOf'AOSU'⊢' ',⎕A
NORM←Norm←'sS'ExpLigs'ßẞ'
abc ⍺⍺ Sort Norm ⍵
}
:Section Utils
Under←{ ⍝ a.k.a. Dual
⍺←⊢
11::A⊣(∊A)←⍺ ⍺⍺∊A←⍵ ⍝ if function cannot be inverted, try acting on shape rather than data
2=⎕NC'⍺':⍵⍵⍣¯1⊢(⍵⍵ ⍺)⍺⍺(⍵⍵ ⍵)
⍵⍵⍣¯1 ⍺⍺ ⍵⍵ ⍵
}
AtUE←{ ⍝ @ Under ∊
⍺←⊢
⍺ ⍺⍺@⍵⍵ Under∊⍵
}
ExpLigs←{ ⍝ Expand Ligatures
from←,LoUp ⍵⍵
to←,LoUp ⍺⍺,¨⍵⍵
from ⎕R to⊢⍵
}
VariantsOf←{
base←' ',⍵⍵
add←spaces,⍺⍺
from←,¨base,'.'
to←'&',⍨base,¨add
Full from ⎕S to⊢' ',⍵
}
Sort←{
⍺←⊢
⍵⌷⍨⊂⍺ ⍺⍺ Mix ⍵⍵ ⍵
}
Mix←{ ⍝ ↑⍣≡ padding with ⎕UCS 0
' 'AtUE(=∘last)zero AtUE IsSp↑⍣≡last AtUE IsSp ⍵
}
(zero last)←⎕UCS 0 1114111 ⍝ first and last Uniocde code points
spaces←⊂'.''-/'
IsSp←' '=⊢
∇ f←LoUp ⍝ Map to lower and upper
:If 18≤⊃⊃1↓'.'⎕VFI⊃1↓# ⎕WG'APLVersion'
f←¯1 1∘.(,⎕C)⊢
:Else
f←0 1∘.(,819⌶)⊢
:EndIf
∇
Full←1 3 2⍉↑∘LoUp ⍝ Convert nested uppercase to full ⍋-style alphabet
:EndSection
:EndNamespace