lib/Treex/Core/Types.pm

filter: Statementstmt 71.1% 32 / 45 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 45.0% 9 / 20 Podpod 100% 3 / 3 totaltotal 54.3% 44 / 81 CC 4 SCAR 11.1
CC
4
Cov
58%
__ANON__
12.0
get_lang_name
6.0
__ANON__
2.0
CRAP 3.0
« lib/Treex/Core/BundleZone.pm ↑ Summary lib/Treex/Block/Util/SetGlobal.pm »
1 package Treex::Core::Types;
2 {
3 86 $Treex::Core::Types::VERSION = '0.08633_1';
4 }
5 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 86 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 86 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 86 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 subtype 'Treex::Type::NonNegativeInt'
11 => as 'Int'
12 223 ▶ => where { $_ >= 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
13 0 ▶=> message {"$_ isn't non-negative"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
14  
15 subtype 'Treex::Type::Selector'
16 => as 'Str'
17 127 ▶ => where {m/^[a-z\d]*$/i}
Subroutine __ANON__: called CC=1 SCAR=0.0
18 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
19  
20 subtype 'Treex::Type::Layer'
21 => as 'Str'
22 0 ▶ => where {m/^[ptan]$/i}
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 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
24  
25 sub layers {
26 2 ▶ return qw(A T P N);
Subroutine layers: called CC=1 SCAR=0.0
Pod documented
27 }
28  
29 subtype 'Treex::Type::Message' #nonempty string
30 => as 'Str'
31 0 ▶ => where { $_ ne q{} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 ▶=> message {'Message must be nonempty'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
33  
34 #preparation for possible future constraints
35 86 subtype 'Treex::Type::Id'
36 => as 'Str';
37  
38 # TODO: Should this be named ZoneCode or ZoneLabel?
39 subtype 'Treex::Type::ZoneCode'
40 => as 'Str'
41 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
42 0 ▶=> message {'ZoneCode must be LangCode or LangCode_Selector, e.g. "en_src"'};
Subroutine __ANON__: not called CC=1 SCAR=1.2
43  
44 # ISO 639-1 language code with some extensions from ISO 639-2
45 # Added code for Modern Greek which comes under ISO 639-3
46 86 ▶use Locale::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 86 my %EXTRA_LANG_CODES = (
48 'bxr' => "Buryat",
49 'dsb' => "Lower Sorbian",
50 'ell' => "Modern Greek", # ISO 639-3
51 'grc' => "Ancient Greek",# ISO 639-2 code
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 86 my %IS_LANG_CODE = map { $_ => 1 } ( all_language_codes(), keys %EXTRA_LANG_CODES );
68  
69 subtype 'Treex::Type::LangCode'
70 => as 'Str'
71 121 ▶ => 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 0 ▶sub is_lang_code { return $IS_LANG_CODE{ $_[0] }; }
Subroutine is_lang_code: not called CC=1 SCAR=6.9
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 86 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 0.08633_1
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.
« lib/Treex/Core/BundleZone.pm ↑ Summary lib/Treex/Block/Util/SetGlobal.pm »