| 1 | # ABSTRACT: Driver for the English tagset of the CoNLL 2007 Shared Task. | ||
| 2 | # Copyright © 2007, 2014 Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 3 | |||
| 4 | package Lingua::Interset::Tagset::EN::Conll; | ||
| 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::conll') 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 tagsets in Interset are traditionally three values separated by tabs. | ||
| 62 | # The values come from the CoNLL columns CPOS, 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. | ||
| 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 | my $penn2 = substr($penn, 0, 2); | ||
| 78 | my $conll = "$penn2\t$penn\t_"; | ||
| 79 | return $conll; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | #------------------------------------------------------------------------------ | ||
| 85 | # This function translates CoNLL tags to Penn. | ||
| 86 | #------------------------------------------------------------------------------ | ||
| 87 | sub _conll_to_penn | ||
| 88 | { | ||
| 89 | my $conll = shift; | ||
| 90 | # Do not die if you see bad input! This is not our problem. Decoders typically digest anything. | ||
| 91 | my $penn = $conll; | ||
| 92 | my @columns = split(/\t/, $conll); | ||
| 93 | if(scalar(@columns)==3) | ||
| 94 | { | ||
| 95 | $penn = $columns[1]; | ||
| 96 | if($penn eq '(') | ||
| 97 | { | ||
| 98 | $penn = '-LRB-'; | ||
| 99 | } | ||
| 100 | elsif($penn eq ')') | ||
| 101 | { | ||
| 102 | $penn = '-RRB-'; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | return $penn; | ||
| 106 | } | ||
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | 1; | ||
| 111 | |||
| 112 | __END__ | ||
| 113 | |||
| 114 | =pod | ||
| 115 | |||
| 116 | =encoding UTF-8 | ||
| 117 | |||
| 118 | =head1 NAME | ||
| 119 | |||
| 120 | Lingua::Interset::Tagset::EN::Conll - Driver for the English tagset of the CoNLL 2007 Shared Task. | ||
| 121 | |||
| 122 | =head1 VERSION | ||
| 123 | |||
| 124 | version 3.014 | ||
| 125 | |||
| 126 | =head1 SYNOPSIS | ||
| 127 | |||
| 128 | use Lingua::Interset::Tagset::EN::Conll; | ||
| 129 | my $driver = Lingua::Interset::Tagset::EN::Conll->new(); | ||
| 130 | my $fs = $driver->decode("NN\tNN\t_"); | ||
| 131 | |||
| 132 | or | ||
| 133 | |||
| 134 | use Lingua::Interset qw(decode); | ||
| 135 | my $fs = decode('en::conll', "NN\tNN\t_"); | ||
| 136 | |||
| 137 | =head1 DESCRIPTION | ||
| 138 | |||
| 139 | Interset driver for the English tagset of the CoNLL 2007 Shared Task. | ||
| 140 | CoNLL tagsets in Interset are traditionally three values separated by tabs. | ||
| 141 | The values come from the CoNLL columns CPOS, POS and FEAT. For English, | ||
| 142 | these values are trivially derived from the tagset of the Penn Treebank. | ||
| 143 | Thus this driver is only a translation layer above the C<en::penn> driver. | ||
| 144 | |||
| 145 | =head1 SEE ALSO | ||
| 146 | |||
| 147 | L<Lingua::Interset>, | ||
| 148 | L<Lingua::Interset::Tagset>, | ||
| 149 | L<Lingua::Interset::Tagset::EN::Penn>, | ||
| 150 | L<Lingua::Interset::FeatureStructure> | ||
| 151 | |||
| 152 | =head1 AUTHOR | ||
| 153 | |||
| 154 | Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 155 | |||
| 156 | =head1 COPYRIGHT AND LICENSE | ||
| 157 | |||
| 158 | This software is copyright (c) 2019 by Univerzita Karlova (Charles University). | ||
| 159 | |||
| 160 | This is free software; you can redistribute it and/or modify it under | ||
| 161 | the same terms as the Perl 5 programming language system itself. | ||
| 162 | |||
| 163 | =cut |