Interset/Tagset/EN/Conll2009.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 83 CC 8 SCAR 26.2
CC
8
Cov
0%
_conll_to_penn
30.0
_penn_to_conll
20.0
decode
2.0
CRAP 13.8
1 # ABSTRACT: Driver for the English tagset of the CoNLL 2009 Shared Task.
2 # Copyright © 2009, 2014 Dan Zeman <zeman@ufal.mff.cuni.cz>
3  
4 package Lingua::Interset::Tagset::EN::Conll2009;
5 use strict;
6 use warnings;
7 our $VERSION = '3.014';
8  
9 use utf8;
10 use open ':utf8';
11 use namespace::autoclean;
12 use Moose;
13 extends 'Lingua::Interset::Tagset::EN::Penn';
14  
15  
16  
17 #------------------------------------------------------------------------------
18 # Decodes a physical tag (string) and returns the corresponding feature
19 # structure.
20 #------------------------------------------------------------------------------
21 sub decode
22 {
23 my $self = shift;
24 my $tag = shift;
25 my $penn = _conll_to_penn($tag);
26 my $fs = $self->SUPER::decode($penn);
27 # Here we could set $fs->set_tagset('en::conll2009') but we will not so that all
28 # the descendants of en::penn can share the same feature structures.
29 return $fs;
30 }
31  
32  
33  
34 #------------------------------------------------------------------------------
35 # Takes feature structure and returns the corresponding physical tag (string).
36 #------------------------------------------------------------------------------
37 sub encode
38 {
39 my $self = shift;
40 my $fs = shift; # Lingua::Interset::FeatureStructure
41 my $tag = $self->SUPER::encode($fs);
42 return _penn_to_conll($tag);
43 }
44  
45  
46  
47 #------------------------------------------------------------------------------
48 # Returns reference to list of known tags.
49 #------------------------------------------------------------------------------
50 sub list
51 {
52 my $self = shift;
53 my $list = $self->SUPER::list();
54 my @list = map {_penn_to_conll($_)} (@{$list});
55 return \@list;
56 }
57  
58  
59  
60 #------------------------------------------------------------------------------
61 # CoNLL 2009 tagsets in Interset are traditionally two values separated by
62 # tabs. The values come from the CoNLL 2009 columns POS and FEAT. For English,
63 # these values are trivially derived from the tagset of the Penn Treebank.
64 # This function translates Penn tags to CoNLL 2009.
65 #------------------------------------------------------------------------------
66 sub _penn_to_conll
67 {
68 my $penn = shift;
69 if($penn eq '-LRB-')
70 {
71 $penn = '(';
72 }
73 elsif($penn eq '-RRB-')
74 {
75 $penn = ')';
76 }
77 elsif($penn eq 'AFX')
78 {
79 $penn = 'PRF';
80 }
81 my $conll = "$penn\t_";
82 return $conll;
83 }
84  
85  
86  
87 #------------------------------------------------------------------------------
88 # This function translates CoNLL 2009 tags to Penn.
89 #------------------------------------------------------------------------------
90 sub _conll_to_penn
91 {
92 my $conll = shift;
93 # Do not die if you see bad input! This is not our problem. Decoders typically digest anything.
94 my $penn = $conll;
95 my @columns = split(/\t/, $conll);
96 if(scalar(@columns)==2)
97 {
98 $penn = $columns[0];
99 if($penn eq '(')
100 {
101 $penn = '-LRB-';
102 }
103 elsif($penn eq ')')
104 {
105 $penn = '-RRB-';
106 }
107 elsif($penn eq 'PRF')
108 {
109 $penn = 'AFX';
110 }
111 }
112 return $penn;
113 }
114  
115  
116  
117 1;
118  
119 __END__
120  
121 =pod
122  
123 =encoding UTF-8
124  
125 =head1 NAME
126  
127 Lingua::Interset::Tagset::EN::Conll2009 - Driver for the English tagset of the CoNLL 2009 Shared Task.
128  
129 =head1 VERSION
130  
131 version 3.014
132  
133 =head1 SYNOPSIS
134  
135 use Lingua::Interset::Tagset::EN::Conll2009;
136 my $driver = Lingua::Interset::Tagset::EN::Conll2009->new();
137 my $fs = $driver->decode("NN\t_");
138  
139 or
140  
141 use Lingua::Interset qw(decode);
142 my $fs = decode('en::conll2009', "NN\t_");
143  
144 =head1 DESCRIPTION
145  
146 Interset driver for the English tagset of the CoNLL 2009 Shared Task.
147 CoNLL 2009 tagsets in Interset are traditionally two values separated by tabs.
148 The values come from the CoNLL 2009 columns POS and FEAT. For English,
149 these values are trivially derived from the tagset of the Penn Treebank.
150 Thus this driver is only a translation layer above the C<en::penn> driver.
151  
152 =head1 SEE ALSO
153  
154 L<Lingua::Interset>,
155 L<Lingua::Interset::Tagset>,
156 L<Lingua::Interset::Tagset::EN::Penn>,
157 L<Lingua::Interset::FeatureStructure>
158  
159 =head1 AUTHOR
160  
161 Dan Zeman <zeman@ufal.mff.cuni.cz>
162  
163 =head1 COPYRIGHT AND LICENSE
164  
165 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
166  
167 This is free software; you can redistribute it and/or modify it under
168 the same terms as the Perl 5 programming language system itself.
169  
170 =cut