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 74 $Treex::Core::Types::VERSION = '2.20151210';
3 74 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 74 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 74 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 74 ▶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 sub layers {
24 2 ▶ return qw(A T P N);
Subroutine layers: called CC=1 SCAR=0.0
Pod documented
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 74 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 and 639-3
43 # Added code for Modern Greek which comes under ISO 639-3 (but normally it is encoded using ISO 639-1 'el')
44 74 ▶use Locale::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 74 my %EXTRA_LANG_CODES = (
46 'bxr' => "Buryat",
47 'dsb' => "Lower Sorbian",
48 'ell' => "Modern Greek", # ISO 639-3
49 'got' => "Gothic", # ISO 639-2
50 'grc' => "Ancient Greek", # ISO 639-2
51 'hit' => "Hittite", # ISO 639-2
52 'hsb' => "Upper Sorbian",
53 'hak' => "Hakka",
54 'kaa' => "Karakalpak",
55 'ku-latn' => "Kurdish in Latin script",
56 'ku-arab' => "Kurdish in Arabic script",
57 'ku-cyrl' => "Kurdish in Cyrillic script",
58 'nan' => "Taiwanese",
59 'rmy' => "Romany",
60 'sah' => "Yakut",
61 'und' => "unknown", # ISO 639-2 code for undetermined/unknown language
62 'xal' => "Kalmyk",
63 'yue' => "Cantonese",
64 'mul' => "multiple languages", # ISO 639-2 code
65 );
66  
67 74 my %IS_LANG_CODE = map { $_ => 1 } ( all_language_codes(), keys %EXTRA_LANG_CODES );
68  
69 subtype 'Treex::Type::LangCode'
70 => as 'Str'
71 64 ▶ => where { defined $IS_LANG_CODE{$_} }
Subroutine __ANON__: called CC=1 SCAR=0.0
72 0 ▶=> message {'LangCode must be valid ISO 639-1 code. E.g. en, de, cs'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
73 11 ▶sub is_lang_code { return $IS_LANG_CODE{ $_[0] }; }
Subroutine is_lang_code: called CC=1 SCAR=0.0
Pod documented
74  
75 sub get_lang_name {
76 0 ▶ my $code = shift;
Subroutine get_lang_name: not called CC=2 SCAR=17.9
Pod documented
77 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
78 }
79 74 1;
80 __END__
81  
82 =encoding utf-8
83  
84 =head1 NAME
85  
86 Treex::Core::Types - types used in Treex framework
87  
88 =head1 VERSION
89  
90 version 2.20151210
91  
92 =head1 DESCRIPTION
93  
94 =head1 TYPES
95  
96 =over 4
97  
98 =item Treex::Type::NonNegativeInt
99  
100 0, 1, 2, ...
101  
102 =item Treex::Type::Layer
103  
104 one of: P, T, A, N
105 case insensitive
106  
107 =item Treex::Type::Selector
108  
109 Selector - only alphanumeric characters, may be empty
110  
111 =item Treex::Type::LangCode
112  
113 ISO 639-1 code
114  
115 =item Treex::Type::ZoneCode
116  
117 Combination of LangCode and Selector, e.g. "en_src"
118  
119 =item Treex::Type::Message
120  
121 just nonempty string, future constraints may be set
122  
123 =item Treex::Type::Id
124  
125 identifier, prepared for future constraints, now it is any string
126  
127 =back
128  
129 =head1 METHODS
130  
131 =over 4
132  
133 =item get_lang_name
134  
135 Returns language name for given LangCode
136  
137 =item is_lang_code
138  
139 Checks whether given argument is valid LangCode
140  
141 =item layers
142  
143 Returns array of layers available in Treex, now (A, T, P, N)
144  
145 =back
146  
147 =head1 AUTHOR
148  
149 Tomáš Kraut <kraut@ufal.mff.cuni.cz>
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
154  
155 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Treex/Tool/Probe.pm ↑ Summary Treex/Block/Util/SetGlobal.pm »