Treex/Core/Types.pm

filter: Statementstmt 72.7% 32 / 44 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 10 / 20 Podpod 100% 3 / 3 totaltotal 56.2% 45 / 80 CC 4 SCAR 10.9
CC
4
Cov
59%
__ANON__
12.0
get_lang_name
6.0
__ANON__
2.0
CRAP 3.0
« Treex/Tool/Probe.pm ↑ Summary Treex/Block/Util/SetGlobal.pm »
1 package Treex::Core::Types;
2 73 $Treex::Core::Types::VERSION = '2.20210102';
3 73 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 73 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 73 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 73 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 subtype 'Treex::Type::NonNegativeInt'
9 => as 'Int'
10 251 ▶ => where { $_ >= 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
11 0 ▶=> message {"$_ isn't non-negative"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 subtype 'Treex::Type::Selector'
14 => as 'Str'
15 64 ▶ => where {m/^[a-z\d]*$/i}
Subroutine __ANON__: called CC=1 SCAR=0.0
16 0 ▶=> message {"Selector must =~ /^[a-z\\d]*\$/i. You've provided $_"}; #TODO: this message is not printed
Subroutine __ANON__: not called CC=1 SCAR=1.2
17  
18 subtype 'Treex::Type::Layer'
19 => as 'Str'
20 0 ▶ => where {m/^[ptan]$/i}
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶=> message {"Layer must be one of: [P]hrase structure, [T]ectogrammatical, [A]nalytical, [N]amed entities, you've provided $_"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
22  
23 2 ▶sub layers {
Subroutine layers: called CC=1 SCAR=0.0
Pod documented
24 2 return qw(A T P N);
25 }
26  
27 subtype 'Treex::Type::Message' #nonempty string
28 => as 'Str'
29 0 ▶ => where { $_ ne q{} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶=> message {'Message must be nonempty'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
31  
32 #preparation for possible future constraints
33 73 subtype 'Treex::Type::Id'
34 => as 'Str';
35  
36 # TODO: Should this be named ZoneCode or ZoneLabel?
37 subtype 'Treex::Type::ZoneCode'
38 => as 'Str'
39 0 ▶ => where { my ( $l, $s ) = split /_/, $_; is_lang_code($l) && ( !defined $s || $s =~ /^[a-z\d]*$/i ) }
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
is_lang_code($l) and !defined($s) || $s =~ /^[a-z\d]*$/i 0 0 0
Condition0%0/6
is_lang_code($l) && (!defined($s) || $s =~ /^[a-z\d]*$/i)
!ll&&!rl&&r
000
not defined $s or $s =~ /^[a-z\d]*$/i
l!l&&r!l&&!r
000
MC/DC0%0/3
is_lang_code($l) && (!defined($s) || $s =~ /^[a-z\d]*$/i)
is_lang_code($l) not defined $s $s =~ /^[a-z\d]*$/i
Truth table0%0/4
A && not(B) or C
A= is_lang_code($l)B= not defined $sC= $s =~ /^[a-z\d]*$/i
ABCresult
0XX0
1000
11X1
1011
40 0 ▶=> message {'ZoneCode must be LangCode or LangCode_Selector, e.g. "en_src"'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
41  
42 # ISO 639-1 language code with some extensions from ISO 639-2, 639-3 and ISO 15924 (script names).
43 # Added code for Modern Greek which comes under ISO 639-3 (but normally it is encoded using ISO 639-1 'el').
44 73 ▶use Locale::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 73 my %EXTRA_LANG_CODES = (
46 'abq' => "Abaza",
47 'aii' => "Assyrian",
48 'ajp' => "South Levantine Arabic",
49 'akk' => "Akkadian",
50 'apu' => "Apurina", # Apurinã
51 'aqz' => "Akuntsu",
52 'bho' => "Bhojpuri",
53 'bxr' => "Buryat",
54 'ckb' => "Sorani", # Central Kurdish
55 'ckt' => "Chukchi",
56 'cop' => "Coptic", # ISO 639-2
57 'dbl' => "Dyirbal",
58 'dsb' => "Lower Sorbian",
59 'ell' => "Modern Greek", # ISO 639-3
60 'fro' => "Old French",
61 'got' => "Gothic", # ISO 639-2
62 'grc' => "Ancient Greek", # ISO 639-2
63 'gsw' => "Swiss German",
64 'gun' => "Mbya Guarani",
65 'hit' => "Hittite", # ISO 639-2
66 'hsb' => "Upper Sorbian",
67 'hak' => "Hakka",
68 'kaa' => "Karakalpak",
69 'kfm' => "Khunsari",
70 'kmr' => "Kurmanji", # Northern Kurdish
71 'koi' => "Komi Permyak",
72 'kpv' => "Komi Zyrian",
73 'krl' => "Karelian",
74 'ku-latn' => "Kurdish in Latin script",
75 'ku-arab' => "Kurdish in Arabic script",
76 'ku-cyrl' => "Kurdish in Cyrillic script",
77 'lzh' => "Classical Chinese",
78 'mdf' => "Moksha",
79 'mga' => "Middle Irish",
80 'mul' => "multiple languages", # ISO 639-2 code
81 'myu' => "Munduruku", # Mundurukú
82 'myv' => "Erzya",
83 'nan' => "Taiwanese",
84 'ndg' => "Ndengeleko",
85 'nyq' => "Nayini",
86 'olo' => "Livvi", # Olonets Karelian
87 'orv' => "Old Russian",
88 'otk' => "Old Turkish",
89 'pcm' => "Nigerian Pidgin (Naija)",
90 'pgl' => "Archaic Irish",
91 'rmy' => "Romany",
92 'qhe' => "Hindi-English", # used in UD bilingual corpora
93 'qtd' => "Turkish-German", # used in UD bilingual corpora
94 'quz' => "Cusco Quechua",
95 'sah' => "Yakut",
96 'sga' => "Old Irish",
97 'sme' => "North Sami",
98 'sms' => "Skolt Sami",
99 'soj' => "Soi",
100 'swl' => "Swedish Sign Language",
101 'tpn' => "Tupinamba", # Tupinambá
102 'und' => "unknown", # ISO 639-2 code for undetermined/unknown language
103 'xal' => "Kalmyk",
104 'wbp' => "Warlpiri",
105 'yii' => "Yidiny",
106 'yue' => "Cantonese",
107 );
108  
109 73 my %IS_LANG_CODE = map { $_ => 1 } ( all_language_codes(), keys %EXTRA_LANG_CODES );
110  
111 subtype 'Treex::Type::LangCode'
112 => as 'Str'
113 64 ▶ => where { defined $IS_LANG_CODE{$_} }
Subroutine __ANON__: called CC=1 SCAR=0.0
114 0 ▶=> message {'LangCode must be valid ISO 639-1 code. E.g. en, de, cs'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
115 11 ▶sub is_lang_code { return $IS_LANG_CODE{ $_[0] }; }
Subroutine is_lang_code: called CC=1 SCAR=0.0
Pod documented
116  
117 0 ▶sub get_lang_name {
Subroutine get_lang_name: not called CC=2 SCAR=17.9
Pod documented
118 0 my $code = shift;
119 0 ▶ return exists $EXTRA_LANG_CODES{$code} ? $EXTRA_LANG_CODES{$code} : code2language($code);
Branch: 1 branch
BranchTrueFalseTotal
exists $EXTRA_LANG_CODES{$code} ? : 0 0 0
120 }
121 73 1;
122 __END__
« Treex/Tool/Probe.pm ↑ Summary Treex/Block/Util/SetGlobal.pm »