Tool/EnglishMorpho/Analysis.pm

filter: Statementstmt 16.1% 15 / 93 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 36.3% 4 / 11 Podpod 100% 1 / 1 totaltotal 10.7% 20 / 186 CC 33 SCAR 61.7
CC
33
Cov
9%
get_possible_tags
756.0
_load_dictionary
30.0
_load_list
12.0
CRAP 479.3
« Tool/EnglishMorpho/Lemmatizer.pm ↑ Summary Block/W2A/EN/FixTags.pm »
1 package Treex::Tool::EnglishMorpho::Analysis;
2 BEGIN {
3 1 ▶ $Treex::Tool::EnglishMorpho::Analysis::VERSION = '0.06903_1';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Treex::Core::Resource qw(require_file_from_share);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my @params = qw(my_dict big_dict preterites participles);
11 1 foreach my $param (@params) {
12 4 has $param => (
13 is => 'ro',
14 isa => 'HashRef',
15 lazy => 1,
16 builder => "_build_$param",
17 init_arg => undef,
18 );
19 }
20  
21 1 has 'data_dir' => (
22 is => 'ro',
23 isa => 'Str',
24 default => 'data/models/morpho_analysis/en',
25 );
26  
27 # --------- initialization ---------
28  
29 sub _build_my_dict {
30 0 ▶ my $self = shift;
Subroutine _build_my_dict: not called CC=1 SCAR=6.9
31 0 return $self->_load_dictionary( require_file_from_share( $self->data_dir . '/muj_slovnik.txt' ) );
32 }
33  
34 sub _build_big_dict {
35 0 ▶ my $self = shift;
Subroutine _build_big_dict: not called CC=1 SCAR=6.9
36 0 return $self->_load_dictionary( require_file_from_share( $self->data_dir . '/big_slovnik.txt' ) );
37 }
38  
39 sub _build_preterites {
40 0 ▶ my $self = shift;
Subroutine _build_preterites: not called CC=1 SCAR=6.9
41 0 return $self->_load_list( require_file_from_share( $self->data_dir . '/preterite.tsv' ) );
42 }
43  
44 sub _build_participles {
45 0 ▶ my $self = shift;
Subroutine _build_participles: not called CC=1 SCAR=6.9
46 0 return $self->_load_list( require_file_from_share( $self->data_dir . '/participle.tsv' ) );
47 }
48  
49 sub _load_dictionary {
50 0 ▶ my $self = shift;
Subroutine _load_dictionary: not called CC=5 SCAR=34.0
51 0 my $file = shift;
52 0 my $dict;
53 0 ▶ open my $DATA, '<', $file or treex_fatal("Can't open morphology file $file.");
Branch: 1 branch
BranchTrueFalseTotal
open my $DATA, "<", $file or treex_fatal("Can't open morphology file $file.") 0 0 0
54 LOAD:
55 0 ▶ while (<$DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $DATA)) 0 0 0
56 0 chomp;
57 0 ▶ next LOAD if $_ eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 0 0
58 0 my @items = split qr/ /, $_;
59 0 my $word = lc shift(@items);
60 0 foreach my $tag (@items) {
61 0 $dict->{$word}->{$tag} = 1;
62 }
63 }
64 0 close($DATA);
65 0 return $dict;
66 }
67  
68 sub _load_list {
69 0 ▶ my $self = shift;
Subroutine _load_list: not called CC=3 SCAR=24.8
70 0 my $file = shift;
71 0 my $list;
72 0 ▶ open my $DATA, '<', $file or treex_fatal("Can't open morphology file $file.");
Branch: 1 branch
BranchTrueFalseTotal
open my $DATA, "<", $file or treex_fatal("Can't open morphology file $file.") 0 0 0
73 0 ▶ while (<$DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $DATA)) 0 0 0
74 0 chomp;
75 0 $list->{$_} = 1;
76 }
77 0 close($DATA);
78 0 return $list;
79 }
80  
81 # --------- interface ---------
82  
83 sub get_possible_tags { ## no critic (Subroutines::ProhibitExcessComplexity) this is complex
84 0 ▶ my $self = shift;
Subroutine get_possible_tags: not called CC=27 SCAR=66.3
Pod documented
85 0 my $wordform = shift;
86 0 my $lowerform = lc($wordform);
87  
88 0 my %muj_slovnik = %{ $self->my_dict };
89 0 my %big_slovnik = %{ $self->big_dict };
90 0 my %past_slovesa = %{ $self->preterites };
91 0 my %partic_slovesa = %{ $self->participles };
92  
93 0 my @possible;
94  
95 0 ▶ if ( exists $muj_slovnik{$lowerform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $muj_slovnik{$lowerform}) { } 0 0 0
96 0 foreach my $tag ( keys %{ $muj_slovnik{$lowerform} } ) {
97 0 push @possible, $tag;
98 }
99 0 ▶ if ( $lowerform ne $wordform ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform ne $wordform) 0 0 0
100 0 push @possible, qw(NNP);
101 }
102 }
103 else { # neni ve slovniku uzavrenych trid
104 0 ▶ if ( exists $big_slovnik{$lowerform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $big_slovnik{$lowerform}) { } 0 0 0
105 0 foreach my $tag ( keys %{ $big_slovnik{$lowerform} } ) {
106 0 push @possible, $tag;
107 }
108 0 ▶ if ( $lowerform ne $wordform ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform ne $wordform) 0 0 0
109 0 push @possible, qw(NNP NNPS);
110 }
111 }
112 else {
113 0 push @possible, qw(FW JJ NN NNS RB);
114  
115 0 ▶ if (( $lowerform =~ /er$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /er$/ or $lowerform =~ /er-/ or $lowerform =~ /more-/ or $lowerform =~ /less-/) 0 0 0
Condition0%0/9
$lowerform =~ /er$/ or $lowerform =~ /er-/ or $lowerform =~ /more-/ or $lowerform =~ /less-/
l!l&&r!l&&!r
000
$lowerform =~ /er$/ or $lowerform =~ /er-/ or $lowerform =~ /more-/
l!l&&r!l&&!r
000
$lowerform =~ /er$/ or $lowerform =~ /er-/
l!l&&r!l&&!r
000
MC/DC0%0/4
$lowerform =~ /er$/ or $lowerform =~ /er-/ or $lowerform =~ /more-/ or $lowerform =~ /less-/
$lowerform =~ /er$/ $lowerform =~ /er-/ $lowerform =~ /more-/ $lowerform =~ /less-/
Truth table0%0/5
A or B or C or D
A= $lowerform =~ /er$/B= $lowerform =~ /er-/C= $lowerform =~ /more-/D= $lowerform =~ /less-/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
116 or ( $lowerform =~ /er-/ )
117 or
118 ( $lowerform =~ /more-/ ) or ( $lowerform =~ /less-/ )
119 )
120 {
121 0 push @possible, qw(JJR RBR);
122  
123 } # comparative
124 0 ▶ if (( $lowerform =~ /est$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /est$/ or $lowerform =~ /est-/ or $lowerform =~ /most-/ or $lowerform =~ /least-/) 0 0 0
Condition0%0/9
$lowerform =~ /est$/ or $lowerform =~ /est-/ or $lowerform =~ /most-/ or $lowerform =~ /least-/
l!l&&r!l&&!r
000
$lowerform =~ /est$/ or $lowerform =~ /est-/ or $lowerform =~ /most-/
l!l&&r!l&&!r
000
$lowerform =~ /est$/ or $lowerform =~ /est-/
l!l&&r!l&&!r
000
MC/DC0%0/4
$lowerform =~ /est$/ or $lowerform =~ /est-/ or $lowerform =~ /most-/ or $lowerform =~ /least-/
$lowerform =~ /est$/ $lowerform =~ /est-/ $lowerform =~ /most-/ $lowerform =~ /least-/
Truth table0%0/5
A or B or C or D
A= $lowerform =~ /est$/B= $lowerform =~ /est-/C= $lowerform =~ /most-/D= $lowerform =~ /least-/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
125 or ( $lowerform =~ /est-/ )
126 or
127 ( $lowerform =~ /most-/ ) or ( $lowerform =~ /least-/ )
128 )
129 {
130 0 push @possible, qw(JJS RBS);
131 } # superlative
132 0 ▶ if ( ( $lowerform =~ /ing$/ ) or ( $lowerform =~ /[^aeiouy]in$/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /ing$/ or $lowerform =~ /[^aeiouy]in$/) 0 0 0
Condition0%0/3
$lowerform =~ /ing$/ or $lowerform =~ /[^aeiouy]in$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$lowerform =~ /ing$/ or $lowerform =~ /[^aeiouy]in$/
$lowerform =~ /ing$/ $lowerform =~ /[^aeiouy]in$/
Truth table0%0/3
A or B
A= $lowerform =~ /ing$/B= $lowerform =~ /[^aeiouy]in$/
ABresult
1X1
011
000
133 0 push @possible, qw(VBG);
134 }
135 0 ▶ if ( $lowerform =~ /[^s]s$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /[^s]s$/) { } 0 0 0
136 0 push @possible, qw(VBZ);
137 } # 3. os
138 else {
139 0 push @possible, qw(VB VBP);
140 } # non-3. os
141  
142 0 ▶ if ( $lowerform ne $wordform ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lowerform ne $wordform) { } 0 0 0
elsif ($lowerform =~ /^[0-9']/) { } 0 0 0
143 0 push @possible, qw(NNP NNPS);
144 }
145 elsif ( $lowerform =~ /^[0-9']/ ) {
146 0 push @possible, qw(NNP);
147 }
148 0 ▶ if (( $lowerform =~ /[^a-zA-Z0-9]+/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /[^a-zA-Z0-9]+/ or $lowerform =~ /^&.*;$/) 0 0 0
Condition0%0/3
$lowerform =~ /[^a-zA-Z0-9]+/ or $lowerform =~ /^&.*;$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$lowerform =~ /[^a-zA-Z0-9]+/ or $lowerform =~ /^&.*;$/
$lowerform =~ /[^a-zA-Z0-9]+/ $lowerform =~ /^&.*;$/
Truth table0%0/3
A or B
A= $lowerform =~ /[^a-zA-Z0-9]+/B= $lowerform =~ /^&.*;$/
ABresult
1X1
011
000
149 or
150 ( $lowerform =~ /^&.*;$/ )
151 )
152 {
153 0 push @possible, qw(SYM);
154 }
155 0 ▶ if ( ( $lowerform =~ /[-0-9]+/ ) or ( $lowerform =~ /^[ixvcmd\.]+$/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /[-0-9]+/ or $lowerform =~ /^[ixvcmd\.]+$/) 0 0 0
Condition0%0/3
$lowerform =~ /[-0-9]+/ or $lowerform =~ /^[ixvcmd\.]+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$lowerform =~ /[-0-9]+/ or $lowerform =~ /^[ixvcmd\.]+$/
$lowerform =~ /[-0-9]+/ $lowerform =~ /^[ixvcmd\.]+$/
Truth table0%0/3
A or B
A= $lowerform =~ /[-0-9]+/B= $lowerform =~ /^[ixvcmd\.]+$/
ABresult
1X1
011
000
156 0 push @possible, qw(CD);
157 }
158 }
159 0 ▶ if ( exists $past_slovesa{$lowerform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $past_slovesa{$lowerform}) 0 0 0
160 0 push @possible, qw(VBD);
161 }
162 0 ▶ if ( exists $partic_slovesa{$lowerform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $partic_slovesa{$lowerform}) 0 0 0
163 0 push @possible, qw(VBN);
164 }
165 0 ▶ if ( $lowerform =~ /ed$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerform =~ /ed$/) 0 0 0
166 0 push @possible, qw(VBD VBN);
167 }
168 }
169 0 return @possible;
170 }
171  
172 1 1;
173  
174 =head1 NAME
175  
176 Treex::Tool::EnglishMorpho::Analysis - rule based morphological analyzer for English
177  
178  
179 =head1 VERSION
180  
181 version 0.06903_1
182  
183 =head1 SYNOPSIS
184  
185 use Treex::Tool::EnglishMorpho::Analysis;
186  
187 my $analyser = Treex::Tool::EnglishMorpho::Analysis->new();
188 foreach my $wordform (qw(John loves the yellow ball of his sister .)) {
189 my @tags = $analyser->get_possible_tags($wordform);
190 print "$wordform -> @tags\n";
191 }
192  
193  
194  
195 =head1 DESCRIPTION
196  
197 Method get_possible_tags($wordform) returns the list of PennTreebank-style
198 morphological tags for the given word form.
199  
200 =head1 METHODS
201  
202 =over 4
203  
204 =item get_possible_tags
205  
206 Given wordform returns list of possible POS tags.
207  
208 =back
209  
210 =head1 AUTHORS
211  
212 Johanka Drahomíra Doležalová
213  
214 Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>
215  
216 Tomáš Kraut <kraut@ufal.mff.cuni.cz>
217  
218 =head1 COPYRIGHT AND LICENSE
219  
220 Copyright © 2008-2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
221  
222 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Tool/EnglishMorpho/Lemmatizer.pm ↑ Summary Block/W2A/EN/FixTags.pm »