writing: reformat phnx data (prefixless row names)
[sheet.git] / keyboard.eng.inc.pl
1 use Unicode::Normalize qw( NFKD );
2 use Text::Unidecode qw( unidecode );
3
4 my %g; # present group classes
5 {
6         rows => [0, 1],
7         def => {
8                 '' => {
9                         map {
10                                 my $v = $rows{$_};
11                                 my $class = (
12                                           !defined $v || $_ eq $v ? 1 # identical
13                                         : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
14                                         : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
15                                         : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
16                                         : NFKD($v) =~ /\Q$_/ ? 2 # decomposed equivalent
17                                         : unidecode($v) =~ /\Q$_\E+/i ? 4 # transliterated
18                                         : $v =~ /^\p{Latin}/ ? 5 # latin script
19                                         : 6
20                                 );
21                                 $g{$class} = 1;
22                                 $_ => "g$class"
23                         } keys %rows
24                 },
25         },
26         key => \%rows,
27         flag => {
28                 g1 => ['unaltered', "same results as without modifier"],
29                 g2 => ['accented', "decomposes to the original letter with a combining accent"],
30                 g4 => ['similar', "transliterates (mostly) into the unmodified letter"],
31                 g5 => ['latin', "a different (accented) latin letter"],
32                 g6 => ['symbol', "other character not directly deducible from key"],
33                 g7 => ['punctuation', "(punctuation) mark"],
34                         !$g{9} ? () : (
35                 g8 => ['mark', "modifier letter or mark (spacing diacritic)"],
36                 g9 => ['combining', "diacritical mark to be combined with a following character"],
37                         ),
38         },
39 }