Interset/Tagset/MUL/Upos.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 89 CC 1 SCAR 6.9
CC
1
Cov
0%
get_tagset_id
2.0
decode
2.0
list
2.0
CRAP 2.0
1 # ABSTRACT: Driver for the Universal Part-of-Speech Tagset, version 2014-10-01, part of Universal Dependencies.
2 # http://universaldependencies.github.io/docs/
3 # Copyright © 2014 Dan Zeman <zeman@ufal.mff.cuni.cz>
4  
5 package Lingua::Interset::Tagset::MUL::Upos;
6 use strict;
7 use warnings;
8 our $VERSION = '3.014';
9  
10 use utf8;
11 use open ':utf8';
12 use namespace::autoclean;
13 use Moose;
14 extends 'Lingua::Interset::Atom';
15  
16  
17  
18 #------------------------------------------------------------------------------
19 # Returns the tagset id that should be set as the value of the 'tagset' feature
20 # during decoding. Every derived class must (re)define this method! The result
21 # should correspond to the last two parts in package name, lowercased.
22 # Specifically, it should be the ISO 639-2 language code, followed by '::' and
23 # a language-specific tagset id. Example: 'cs::multext'.
24 #------------------------------------------------------------------------------
25 sub get_tagset_id
26 {
27 return 'mul::upos';
28 }
29  
30  
31  
32 #------------------------------------------------------------------------------
33 # This block will be called before object construction. It will build the
34 # decoding and encoding maps for this particular tagset.
35 # Then it will pass all the attributes to the constructor.
36 #------------------------------------------------------------------------------
37 around BUILDARGS => sub
38 {
39 my $orig = shift;
40 my $class = shift;
41 # Call the default BUILDARGS in Moose::Object. It will take care of distinguishing between a hash reference and a plain hash.
42 my $attr = $class->$orig(@_);
43 # Construct decode_map in the form expected by Atom.
44 my %dm =
45 (
46 # adjective
47 'ADJ' => ['pos' => 'adj'],
48 # adposition (preposition or postposition)
49 'ADP' => ['pos' => 'adp'],
50 # adverb
51 'ADV' => ['pos' => 'adv'],
52 # auxiliary verb
53 'AUX' => ['pos' => 'verb', 'verbtype' => 'aux'],
54 # coordinating conjunction (CONJ in UD v1, CCONJ since UD v2)
55 'CCONJ' => ['pos' => 'conj', 'conjtype' => 'coor'],
56 'CONJ' => ['pos' => 'conj', 'conjtype' => 'coor'],
57 # determiner
58 'DET' => ['pos' => 'adj', 'prontype' => 'prn'],
59 # interjection
60 'INTJ' => ['pos' => 'int'],
61 # common noun
62 'NOUN' => ['pos' => 'noun', 'nountype' => 'com'],
63 # cardinal number (but not an indefinite quantifier)
64 'NUM' => ['pos' => 'num', 'numtype' => 'card'],
65 # particle
66 'PART' => ['pos' => 'part'],
67 # pronoun
68 'PRON' => ['pos' => 'noun', 'prontype' => 'prn'],
69 # proper noun
70 'PROPN' => ['pos' => 'noun', 'nountype' => 'prop'],
71 # punctuation
72 'PUNCT' => ['pos' => 'punc'],
73 # subordinating conjunction
74 'SCONJ' => ['pos' => 'conj', 'conjtype' => 'sub'],
75 # symbol
76 'SYM' => ['pos' => 'sym'],
77 # verb (non-auxiliary, all tenses and modes)
78 'VERB' => ['pos' => 'verb'],
79 # other: foreign words, unanalyzable tokens
80 'X' => []
81 );
82 # Construct encode_map in the form expected by Atom.
83 my %em =
84 (
85 'pos' => { 'verb' => { 'verbtype' => { 'aux' => 'AUX',
86 '@' => 'VERB' }},
87 'noun' => { 'prontype' => { '' => { 'nountype' => { 'prop' => 'PROPN', ###!!! a co kdyz je to adj,noun???
88 '@' => 'NOUN' }},
89 '@' => 'PRON' }},
90 'adj' => { 'adjtype' => { 'pdt' => 'DET',
91 '@' => { 'prontype' => { '' => 'ADJ',
92 '@' => 'DET' }}}},
93 'num' => { 'prontype' => { '' => 'NUM',
94 '@' => 'DET' }},
95 'adv' => 'ADV',
96 'adp' => 'ADP',
97 'conj' => { 'conjtype' => { 'sub' => 'SCONJ',
98 '@' => 'CCONJ' }},
99 # Make sure that RP particles from the Penn Treebank and separable verb prefixes from German STTS
100 # do not end up as PART; UD clearly documents that they should be ADP or ADV.
101 'part' => { 'parttype' => { 'vbp' => 'ADP',
102 '@' => 'PART' }},
103 'int' => 'INTJ',
104 'punc' => 'PUNCT',
105 'sym' => 'SYM',
106 '@' => 'X' }
107 );
108 # Now add the references to the attribute hash.
109 $attr->{surfeature} = 'pos';
110 $attr->{decode_map} = \%dm;
111 $attr->{encode_map} = \%em;
112 return $attr;
113 };
114  
115  
116  
117 #------------------------------------------------------------------------------
118 # Decodes a physical tag (string) and returns the corresponding feature
119 # structure. In addition to Atom, we just need to identify the tagset of
120 # origin (it is not crucial because we do not use the 'other' feature but it
121 # is customary).
122 #------------------------------------------------------------------------------
123 sub decode
124 {
125 my $self = shift;
126 my $tag = shift;
127 my $fs = $self->SUPER::decode($tag);
128 $fs->set_tagset('mul::upos');
129 return $fs;
130 }
131  
132  
133  
134 #------------------------------------------------------------------------------
135 # Returns reference to list of known tags, useful for testing. The Atom class
136 # will generate the list for us but we have to remove CONJ from the list
137 # because we do not want to preserve it on the output.
138 #------------------------------------------------------------------------------
139 sub list
140 {
141 my $self = shift;
142 my $list = $self->SUPER::list();
143 my @without_conj = grep {$_ ne 'CONJ'} (@{$list});
144 return \@without_conj;
145 }
146  
147  
148  
149 1;
150  
151 __END__
152  
153 =pod
154  
155 =encoding UTF-8
156  
157 =head1 NAME
158  
159 Lingua::Interset::Tagset::MUL::Upos - Driver for the Universal Part-of-Speech Tagset, version 2014-10-01, part of Universal Dependencies.
160  
161 =head1 VERSION
162  
163 version 3.014
164  
165 =head1 SYNOPSIS
166  
167 use Lingua::Interset::Tagset::MUL::Upos;
168 my $driver = Lingua::Interset::Tagset::MUL::Upos->new();
169 my $fs = $driver->decode('NOUN');
170  
171 or
172  
173 use Lingua::Interset qw(decode);
174 my $fs = decode('mul::upos', 'NOUN');
175  
176 =head1 DESCRIPTION
177  
178 Interset driver for the Universal Part-of-Speech Tagset
179 as of its extended version for the Universal Dependencies (2014-10-01),
180 see L<http://universaldependencies.github.io/docs/>.
181  
182 =head1 SEE ALSO
183  
184 L<Lingua::Interset>
185 L<Lingua::Interset::Tagset>,
186 L<Lingua::Interset::Tagset::MUL::Google>,
187 L<Lingua::Interset::Tagset::MUL::Uposf>,
188 L<Lingua::Interset::Atom>,
189 L<Lingua::Interset::FeatureStructure>
190  
191 =head1 AUTHOR
192  
193 Dan Zeman <zeman@ufal.mff.cuni.cz>
194  
195 =head1 COPYRIGHT AND LICENSE
196  
197 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
198  
199 This is free software; you can redistribute it and/or modify it under
200 the same terms as the Perl 5 programming language system itself.
201  
202 =cut