Block/W2A/TagMorphoDiTa.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Block/W2A/Segment.pm ↑ Summary Tool/Tagger/Role.pm »
1 package Treex::Block::W2A::TagMorphoDiTa;
2 $Treex::Block::W2A::TagMorphoDiTa::VERSION = '2.20151102';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use Treex::Tool::Tagger::MorphoDiTa;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 extends 'Treex::Block::W2A::Tag';
9  
10 has 'known_models' => (
11 is => 'rw',
12 isa => 'HashRef',
13 default => sub {{
14 cs => 'data/models/morphodita/cs/czech-morfflex-pdt-131112.tagger-best_accuracy',
15 en => 'data/models/morphodita/en/english-morphium-wsj-140407.tagger',
16 }},
17 );
18  
19 has 'model' => (
20 is => 'ro',
21 isa => 'Str',
22 predicate => 'has_model'
23 );
24  
25 has 'using_lang_model' => (
26 is => 'ro',
27 isa => 'Str',
28 predicate => 'has_using_lang_model'
29 );
30  
31 sub _build_tagger {
32 my ($self) = @_;
33 if ($self->has_model) {
34 $self->_args->{model} = $self->model;
35 }
36 elsif ($self->has_using_lang_model) {
37 $self->_args->{model} = $self->known_models()->{$self->using_lang_model};
38 }
39 else {
40 log_fatal('Model path (model=path/to/model) or language (using_lang_model=XX) must be set!');
41 }
42 return Treex::Tool::Tagger::MorphoDiTa->new($self->_args);
43 }
44  
45 after 'process_atree' => sub {
46 my ($self, $atree) = @_;
47  
48 my @nodes = $atree->get_descendants({ordered=>1});
49  
50 # It is legal to have a tree with no nodes (e.g. for non 1-1 aligned sentences),
51 # so just skip such sentences (and do not log_fatal if no lemmas are found).
52 return if !@nodes;
53  
54 my $forms_rf = [map { $_->form } @nodes];
55  
56 my $guessed = $self->tagger->is_guessed($forms_rf);
57 for (my $i = 0; $i < @nodes; $i++) {
58 $nodes[$i]->wild->{lemma_guessed} = $guessed->[$i];
59 }
60 };
61  
62 1;
63  
64  
65 __END__
« Block/W2A/Segment.pm ↑ Summary Tool/Tagger/Role.pm »