| 1 | package Treex::Tool::EnglishMorpho::Lemmatizer; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | $Treex::Tool::EnglishMorpho::Lemmatizer::VERSION = '0.06903_1'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Treex::Core::Resource qw(require_file_from_share); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | has 'exceptions_filename' => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | return require_file_from_share('/data/models/lemmatizer/en/exceptions.tsv'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | has 'negation_filename' => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | return require_file_from_share('/data/models/lemmatizer/en/negation'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | has 'exceptions' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | builder => '_build_exceptions', | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | has 'negation' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | builder => '_build_negation', | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | has 'cut_negation' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | reader => 'cut_negation', | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | has 'lowercase_proper_names' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | reader => 'lowercase_proper_names', | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | my $V = qr/[aeiou]/; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | my $VY = qr/[aeiouy]/; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | my $C = qr/[bcdfghjklmnpqrstvwxyz]/; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my $CXY = qr/[bcdfghjklmnpqrstvwxz]/; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my $S = qr/([sxz]|[cs]h)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | my $S2 = qr/(ss|zz)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | my $PRE = qr/(be|ex|in|mis|pre|pro|re)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | #The most importat sub: | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | #Input: word form and POS tag (Penn style) | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #Output: lemma and was_negative_prefix | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub lemmatize { | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my ( $self, $word, $tag ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lemmatize: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $negative_prefix = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( ( $tag !~ /^NNP/ || $self->lowercase_proper_names ) && $word ne 'I' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
!($tag =~ /^NNP/) || $self->lowercase_proper_names and $word ne "I"
not $tag =~ /^NNP/ or $self->lowercase_proper_names
MC/DC0%0/3
!($tag =~ /^NNP/) || $self->lowercase_proper_names and $word ne "I"
not $tag =~ /^NNP/
$self->lowercase_proper_names
$word ne "I"
Truth table0%0/5
not(A) or B and C
A= not $tag =~ /^NNP/B= $self->lowercase_proper_namesC= $word ne "I"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $word = lc $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $entry = $self->exceptions->{$tag}{$word}; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($entry) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return @$entry; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( $self->cut_negation ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ( $word, $negative_prefix ) = $self->_cut_negative_prefix( $word, $tag ); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return ( $self->_lemmatize_by_rules( $word, $tag ), $negative_prefix ); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub _cut_negative_prefix { | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my ( $self, $word, $tag ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cut_negative_prefix: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # We are interested only in adjectives, adverbs and nouns. | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # English verbs are negated usually by "not" (don't,...). | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Proper nouns (NNP,NNPS) are also left unchanged (Disney, Intel, Irvin... Non-IBM). | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation
MC/DC0%0/2
$tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation
$tag =~ /^(J.*|R.*|NN|NNS)$/
$word =~ $self->negation
Truth table0%0/3
A and B
A= $tag =~ /^(J.*|R.*|NN|NNS)$/B= $word =~ $self->negation
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $word =~ s/^(un|in|im|non-?|dis-?|il|ir)//; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return ( $word, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return ( $word, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | sub _lemmatize_NNS_NNPS { | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_NNS_NNPS: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return $word if $word =~ s/men$/man/; #over 600 words (in BNC) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return $word if $word =~ s/shoes$/shoe/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $word if $word =~ s/wives$/wife/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $word if $word =~ s/(${C}us)es$/$1/; #buses bonuses | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return $word if $word =~ s/(${V}se)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return $word if $word =~ s/(.${CXY}z)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return $word if $word =~ s/(${VY}ze)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return $word if $word =~ s/($S2)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return $word if $word =~ s/(.${V}rse)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return $word if $word =~ s/onses$/onse/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return $word if $word =~ s/($S)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $word if $word =~ s/(.$C)ies$/$1y/; #ponies vs ties | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return $word if $word =~ s/(${CXY}o)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return $word if $word =~ s/s$//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub _lemmatize_VBG { ## no critic (Subroutines::ProhibitExcessComplexity) this is complex | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_VBG: not called CC=34 SCAR=70.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $word if $word =~ s/(${CXY}z)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return $word if $word =~ s/(${VY}z)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $word if $word =~ s/($S2)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return $word if $word =~ s/($C${V}ll)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return $word if $word =~ s/($C${V}($CXY)\2)ing$/$1/; #cancel-ling vs call-ing - exception is needed | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return $word if $word =~ s/^($CXY)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C${V}ng)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return $word if $word =~ s/icking$/ick/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return $word if $word =~ s/(${C}in)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $word if $word =~ s/($C$V[npwx])ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return $word if $word =~ s/(qu$V${C})ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return $word if $word =~ s/(u${V}d)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return $word if $word =~ s/(${C}let)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C+[ei]t)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return $word if $word =~ s/([ei]t)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | return $word if $word =~ s/($PRE$CXY${CXY}eat)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return $word if $word =~ s/($V$CXY${CXY}eat)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return $word if $word =~ s/(.[eo]at)ing$/$1/; #treating vs creating | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return $word if $word =~ s/(.${V}at)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $word if $word =~ s/($V$V[cgsv])ing$/$1e/; #announcing increasing | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return $word if $word =~ s/($V$V$C)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return $word if $word =~ s/(.[rw]l)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return $word if $word =~ s/(.th)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return $word if $word =~ s/($CXY[cglsv])ing$/$1e/; #involving | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $word if $word =~ s/($CXY$CXY)ing$/$1/; #reporting | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return $word if $word =~ s/uing$/ue/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return $word if $word =~ s/($VY$VY)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $word if $word =~ s/ying$/y/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return $word if $word =~ s/(${CXY}o)ing$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C+or)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return $word if $word =~ s/($C[clt]or)ing$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return $word if $word =~ s/([eo]r)ing$/$1/; #offering | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return $word if $word =~ s/ing$/e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub _lemmatize_VBD_VBN { ## no critic (Subroutines::ProhibitExcessComplexity) this is complex | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_VBD_VBN: not called CC=33 SCAR=70.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return $word if $word =~ s/en$/e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return $word if $word =~ s/(${CXY}z)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $word if $word =~ s/(${VY}z)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return $word if $word =~ s/($S2)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return $word if $word =~ s/($C${V}ll)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return $word if $word =~ s/($C${V}($CXY)\2)ed$/$1/; #cancel-led vs call-ed - wordlist is needed | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $word if $word =~ s/^($CXY)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C${V}ng)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | return $word if $word =~ s/icked$/ick/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return $word if $word =~ s/(${C}(in|[clnt]or))ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $word if $word =~ s/($C$V[npwx])ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C+or)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | return $word if $word =~ s/([eo]r)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return $word if $word =~ s/(${C})ied$/$1y/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | return $word if $word =~ s/(qu$V${C})ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return $word if $word =~ s/(u${V}d)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return $word if $word =~ s/(${C}let)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return $word if $word =~ s/^($PRE*$C+[ei]t)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return $word if $word =~ s/([ei]t)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | return $word if $word =~ s/($PRE$CXY${CXY}eat)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $word if $word =~ s/($V$CXY${CXY}eat)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return $word if $word =~ s/(.[eo]at)ed$/$1/; #treated vs created | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return $word if $word =~ s/(.${V}at)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return $word if $word =~ s/($V$V[cgsv])ed$/$1e/; #announced | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | return $word if $word =~ s/($V$V$C)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return $word if $word =~ s/(.[rw]l)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $word if $word =~ s/(.th)ed$/$1e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $word if $word =~ s/ued$/ue/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | return $word if $word =~ s/($CXY[cglsv])ed$/$1e/; #involved | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | return $word if $word =~ s/($CXY$CXY)ed$/$1/; #reported | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return $word if $word =~ s/($VY$VY)ed$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return $word if $word =~ s/ed$/e/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | sub _lemmatize_VBZ { | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_VBZ: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | return $word if $word =~ s/(${V}se)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return $word if $word =~ s/(.${CXY}z)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | return $word if $word =~ s/(${VY}ze)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return $word if $word =~ s/($S2)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | return $word if $word =~ s/(.${V}rse)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return $word if $word =~ s/onses$/onse/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return $word if $word =~ s/($S)es$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | return $word if $word =~ s/(.$C)ies$/$1y/; #tries, relies vs lies | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return $word if $word =~ s/(${CXY}o)es$/$1/; #does, undergoes | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return $word if $word =~ s/(.)s$/$1/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _lemmatize_JJR_RBR { | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_JJR_RBR: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | return $word if $word =~ s/([^e]ll)er$/$1/; #smaller | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | return $word if $word =~ s/($C)\1er$/$1/; #bigger | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return $word if $word =~ s/ier$/y/; #earlier | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return $word if $word =~ s/($V$V$C)er$/$1/; #weaker | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return $word if $word =~ s/($C$V[npwx])er$/$1/; #lower | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return $word if $word =~ s/($V$C)er$/$1e/; #nicer wider | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | return $word if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])er$/$1e/; #larger,stranger vs stronger, younger | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | return $word if $word =~ s/([ue])er$/$1e/; #freer | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return $word if $word =~ s/er$//; #harder | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub _lemmatize_JJS_RBS { | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | my ( $self, $word ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_JJS_RBS: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return $word if $word =~ s/([^e]ll)est$/$1/; #smallest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | return $word if $word =~ s/(.)\1est$/$1/; #biggest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return $word if $word =~ s/iest$/y/; #earliest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return $word if $word =~ s/($V$V$C)est$/$1/; #weakest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | return $word if $word =~ s/($C$V[npwx])est$/$1/; #lowest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return $word if $word =~ s/($V$C)est$/$1e/; #nicest widest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return $word if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])est$/$1e/; #largest vs strongest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return $word if $word =~ s/(.{3,})est$/$1/; #hardest | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | sub _lemmatize_by_rules { | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my ( $self, $word, $tag ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lemmatize_by_rules: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $lemma = $tag =~ /NNP?S/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ? $self->_lemmatize_NNS_NNPS($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | : $tag =~ /^VBG/ ? $self->_lemmatize_VBG($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | : $tag =~ /VB[DN]/ ? $self->_lemmatize_VBD_VBN($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | : $tag eq 'VBZ' ? $self->_lemmatize_VBZ($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | : $tag =~ /JJR|RBR/ ? $self->_lemmatize_JJR_RBR($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | : $tag =~ /JJS|RBS/ ? $self->_lemmatize_JJS_RBS($word) | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | : $word | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | return $word if $lemma eq ''; # Otherwise e.g. "est"->"" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return $lemma; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | sub _build_exceptions { | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_exceptions: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my %exceptions; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | log_debug( $self->exceptions_filename ); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | open my $ex_file, "<:encoding(utf-8)", $self->exceptions_filename or log_fatal($!); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | while (<$ex_file>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my ( $word, $tag, $lemma, $negative_prefix ) = split /\t/; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $negative_prefix = ( defined $negative_prefix and $negative_prefix eq '1' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $negative_prefix && $negative_prefix eq '1'
MC/DC0%0/2
defined $negative_prefix && $negative_prefix eq '1'
defined $negative_prefix
$negative_prefix eq '1'
Truth table0%0/3
A && B
A= defined $negative_prefixB= $negative_prefix eq '1'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $exceptions{$tag}{$word} = [ $lemma, $negative_prefix ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | close $ex_file; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return \%exceptions; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | sub _build_negation { | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_negation: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $pattern = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my @lines = read_file( $self->negation_filename, binmode => ':encoding(utf-8)', err_mode => 'log_fatal' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # or log_fatal('Cannot load lemmatization exceptions from ' . $self->negation_filename); | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | chomp(@lines); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $pattern = join '|', @lines; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | #$pattern =~ s/-/\-/g; | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $negation = qr/^($pattern)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return $negation; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | Cutting off negative prefixes is quite discutable. | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | Even if we filter out cases when: | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | a) a word starts with (un|in|im|dis|il|ir) but it is not a prefix (Intel, disaster,...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | b) it is a prefix but not negative (indoor, impress,...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | Still there are other cases, when etymologicaly it is a negative prefix, but... | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | unease, uneasily, uneasiness,... is definitelly not a negation of ease, easily, easiness | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | indiscriminately ?? | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | indiscriminate ?? | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | Treex::Tool::EnglishMorpho::Lemmatizer - rule based lemmatizer for English | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | version 0.06903_1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | use Treex::Tool::EnglishMorpho::Lemmatizer; | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | my ($word, $tag) = qw( goes VBZ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | my ($lemma, $neg) = Treex::Tool::EnglishMorpho::Lemmatizer::lemmatize($word, $tag); | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =item lemmatize | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | Accepts pair of word and tag. | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | Produces pair with its lemma and indication if word was negation | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | Covers: | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | =item * noun -s (dogs -> dog, ponies -> pony,..., mice -> mouse) | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | =item * verb -s (does -> do,...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =item * verb -ing | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =item * verb -ed, -en | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | =item * adjective/adverb -er | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =item * adjective/adverb -est | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =item * cut off negative prefixes (un|in|im|non|dis|il|ir) | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | =head2 Input requirements | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | =item Tokenization | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | I<doesn't> should be tokenized as two words: I<does> and I<n't> | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | (It will be lemmatized as I<do> and I<not>). | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =item Tagging | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | Correct tagging (Penn style) is quite crucial for Lemmatizer to work. | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | For example it doesn't change words with tags NN and NNP | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | (it changes only NNS and NNPS). So (I<pence>, NN) -> I<pence>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | but (I<pence>, NNS) -> I<penny>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | =head2 Differences from the previous implementation | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | Modul C<PEDT::MorphologyAnalysis> uses Morpha (written in Flex) | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | and in some cases gives different lemmatization. | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | =item Adverbs and adjectives. | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Morpha leaves comparatives and superlatives unchanged. | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | C<PEDT::MorphologyAnalysis> does only basic analysis (I<later> -> I<lat>). | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | =item Capitalization of proper names | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =item Changes of NN | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | =item Latin words | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | Declination of words with latin origin is not covered by any Lemmatizer | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | rules on purpose. | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | There are few widely known english words with latin origin which are | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | (or should be) covered by exception files (f.e. indices NNS -> index). | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | In my opinion, it is better, especially for translation purposes, | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | to leave the other latin words unchanged. Mostly they will have the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | form also in the target language (biological terms like Spheniscidae). | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | BTW: Errors made by Morpha latin fallbacks are sometimes funny: | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | sci-fi -> sci-fus, Mitsubishi -> mitsubishus, Shanghai -> shanghaus,... | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | =item * this POD documentation !!! | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | =item * better list of exceptions | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | =item * change exceptions format from tsv to stored perl hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | =head1 AUTHO | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | Martin Popel <popel@ufal.mff.cuni.cz> | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | Copyright © 2008 - 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||