| 1 | # ABSTRACT: Driver for the Universal Part-of-Speech Tagset + Universal Features, version 2014-10-01, part of Universal Dependencies. | ||
| 2 | # http://universaldependencies.github.io/docs/ | ||
| 3 | # Copyright © 2014, 2015 Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 4 | |||
| 5 | package Lingua::Interset::Tagset::MUL::Uposf; | ||
| 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 | use Lingua::Interset::FeatureStructure; | ||
| 15 | extends 'Lingua::Interset::Tagset'; | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | has 'upos_driver' => ( isa => 'Lingua::Interset::Tagset::MUL::Upos', is => 'ro', default => sub { new Lingua::Interset::Tagset::MUL::Upos } ); | ||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | #------------------------------------------------------------------------------ | ||
| 24 | # Returns the tagset id that should be set as the value of the 'tagset' feature | ||
| 25 | # during decoding. Every derived class must (re)define this method! The result | ||
| 26 | # should correspond to the last two parts in package name, lowercased. | ||
| 27 | # Specifically, it should be the ISO 639-2 language code, followed by '::' and | ||
| 28 | # a language-specific tagset id. Example: 'cs::multext'. | ||
| 29 | #------------------------------------------------------------------------------ | ||
| 30 | sub get_tagset_id | ||
| 31 | { | ||
| 32 | return 'mul::uposf'; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | #------------------------------------------------------------------------------ | ||
| 38 | # Decodes a physical tag (string) and returns the corresponding feature | ||
| 39 | # structure. | ||
| 40 | #------------------------------------------------------------------------------ | ||
| 41 | sub decode | ||
| 42 | { | ||
| 43 | my $self = shift; | ||
| 44 | my $tag = shift; | ||
| 45 | # There are two parts separated by a tabulator: part-of-speech tag and features. | ||
| 46 | my ($pos, $features) = split(/\t/, $tag); | ||
| 47 | my $fs = $self->upos_driver()->decode($pos); | ||
| 48 | $fs->set_tagset('mul::uposf'); | ||
| 49 | if(defined($features) && $features ne '' && $features ne '_') | ||
| 50 | { | ||
| 51 | my @features = split(/\|/, $features); | ||
| 52 | $fs->add_ufeatures(@features); | ||
| 53 | } | ||
| 54 | return $fs; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | #------------------------------------------------------------------------------ | ||
| 60 | # Takes feature structure and returns the corresponding physical tag (string). | ||
| 61 | #------------------------------------------------------------------------------ | ||
| 62 | sub encode | ||
| 63 | { | ||
| 64 | my $self = shift; | ||
| 65 | my $fs = shift; # Lingua::Interset::FeatureStructure | ||
| 66 | my $pos = $self->upos_driver()->encode($fs); | ||
| 67 | my @features = $fs->get_ufeatures(); | ||
| 68 | my $tag; | ||
| 69 | if(@features) | ||
| 70 | { | ||
| 71 | $tag = "$pos\t".join('|', @features); | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | $tag = "$pos\t_"; | ||
| 76 | } | ||
| 77 | return $tag; | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | #------------------------------------------------------------------------------ | ||
| 83 | # Returns reference to list of known tags. | ||
| 84 | # We return the list of the universal part-of-speech tags, without features. | ||
| 85 | # In future we may want to add all combinations of features observed in corpora | ||
| 86 | # of various languages. | ||
| 87 | #------------------------------------------------------------------------------ | ||
| 88 | sub list | ||
| 89 | { | ||
| 90 | my $self = shift; | ||
| 91 | my $list = $self->upos_driver()->list(); | ||
| 92 | my @list = map {$_ eq 'NUM' ? "NUM\tNumType=Card" : "$_\t_"} (@{$list}); | ||
| 93 | return \@list; | ||
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | 1; | ||
| 99 | |||
| 100 | __END__ | ||
| 101 | |||
| 102 | =pod | ||
| 103 | |||
| 104 | =encoding UTF-8 | ||
| 105 | |||
| 106 | =head1 NAME | ||
| 107 | |||
| 108 | Lingua::Interset::Tagset::MUL::Uposf - Driver for the Universal Part-of-Speech Tagset + Universal Features, version 2014-10-01, part of Universal Dependencies. | ||
| 109 | |||
| 110 | =head1 VERSION | ||
| 111 | |||
| 112 | version 3.014 | ||
| 113 | |||
| 114 | =head1 SYNOPSIS | ||
| 115 | |||
| 116 | use Lingua::Interset::Tagset::MUL::Uposf; | ||
| 117 | my $driver = Lingua::Interset::Tagset::MUL::Uposf->new(); | ||
| 118 | my $fs = $driver->decode("NOUN\tCase=Nom|Gender=Masc|Number=Sing"); | ||
| 119 | |||
| 120 | or | ||
| 121 | |||
| 122 | use Lingua::Interset qw(decode); | ||
| 123 | my $fs = decode('mul::uposf', "NOUN\tCase=Nom|Gender=Masc|Number=Sing"); | ||
| 124 | |||
| 125 | =head1 DESCRIPTION | ||
| 126 | |||
| 127 | Interset driver for the Universal Part-of-Speech Tagset + Universal Features | ||
| 128 | as of its extended version for the Universal Dependencies (2014-10-01), | ||
| 129 | see L<http://universaldependencies.github.io/docs/>. | ||
| 130 | |||
| 131 | =head1 SEE ALSO | ||
| 132 | |||
| 133 | L<Lingua::Interset> | ||
| 134 | L<Lingua::Interset::Tagset>, | ||
| 135 | L<Lingua::Interset::Tagset::MUL::Upos>, | ||
| 136 | L<Lingua::Interset::Atom>, | ||
| 137 | L<Lingua::Interset::FeatureStructure> | ||
| 138 | |||
| 139 | =head1 AUTHOR | ||
| 140 | |||
| 141 | Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 142 | |||
| 143 | =head1 COPYRIGHT AND LICENSE | ||
| 144 | |||
| 145 | This software is copyright (c) 2019 by Univerzita Karlova (Charles University). | ||
| 146 | |||
| 147 | This is free software; you can redistribute it and/or modify it under | ||
| 148 | the same terms as the Perl 5 programming language system itself. | ||
| 149 | |||
| 150 | =cut |