CAB/Analyzer/Morph/Helsinki/DE.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 59 CC 5 SCAR 28.7
CC
5
Cov
0%
analyzeTypes
30.0
new
2.0
BEGIN
2.0
CRAP 17.6
1 ### -*- Mode: CPerl -*-
2 ##
3 ## File: DTA::CAB::Analyzer::Morph::Helsinki::DE.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: morphological analysis via Gfsm automata, for use with Helsinki-style transducers (German)
6 ## + transducers available in HFST format from https://sourceforge.net/projects/hfst/files/resources/morphological-transducers/
7  
8 ##==============================================================================
9 ## Package: Analyzer::Morph
10 ##==============================================================================
11 package DTA::CAB::Analyzer::Morph::Helsinki::DE;
12 use DTA::CAB::Analyzer::Morph::Helsinki;
13 use Carp;
14 use strict;
15 our @ISA = qw(DTA::CAB::Analyzer::Morph::Helsinki);
16  
17 ## $obj = CLASS_OR_OBJ->new(%args)
18 ## + object structure: see DTA::CAB::Analyzer::Automaton::Gfsm
19 sub new {
20 my $that = shift;
21 my $aut = $that->SUPER::new(
22 ##-- defaults
23  
24 ##-- analysis selection
25 label => 'morph',
26 wantAnalysisLo => 0,
27 wantAnalysisLemma => 0, ##-- default=0
28 tolower => 0,
29 capsFallback => 1,
30  
31 ##-- verbosity
32 check_symbols => 0,
33  
34 ##-- language
35 helsinkiLang => 'de',
36  
37 ##-- user args
38 @_
39 );
40 return $aut;
41 }
42  
43 ##==============================================================================
44 ## Methods: Analysis: v1.x
45 ##==============================================================================
46  
47 ## $doc = $anl->analyzeTypes($doc,\%types,\%opts)
48 ## + perform type-wise analysis of all (text) types in %types (= %{$doc->{types}})
49 sub analyzeTypes {
50 my ($aut,$doc,$types,$opts) = @_;
51 return if (!$aut->DTA::CAB::Analyzer::Automaton::Gfsm::analyzeTypes($doc,$types,$opts));
52  
53 ##-- post-process: simulate TAGH-notation
54 my $label = $aut->{label};
55 my $null = [];
56 my ($w,$a,$hi,$tag,$lemma);
57 foreach $w (values %$types) {
58 foreach $a (@{$w->{$label}//$null}) {
59 $hi = $a->{hi};
60 if ($hi =~ /\[<\+([^>\]]+)>\]/) {
61 ##-- de_free (+tags,-features): "Haus[<NN>]Mann[<NN>]Kost[<+NN>][<Fem>][<Akk>][<Sg>]", "laufen[<+V>][<3>][<Sg>][<Pres>][<Ind>]"
62 $tag = $1;
63 $lemma = substr($hi, 0, $-[0]);
64 }
65 elsif ($hi =~ /((?:\\?\[\<?[^\<\>\[\]\/\\]+\>?\\?\]))$/) {
66 $tag = $1;
67 $lemma = substr($hi, 0, length($hi)-length($tag));
68 $tag =~ s/[\\\<\>\[\]\+]//g;
69 }
70 $lemma =~ s/(?:\[[^\+\]]*\]|\\)//g;
71 $lemma =~ s/\[([A-Z]+)\+\]/lc($1)."+"/eg;
72 $lemma =~ s/\[\+([A-Z]+)\]/"~".lc($1)/eg;
73 $a->{hi} = "$lemma\[_$tag]=$hi" if ($lemma || $tag);
74 }
75 }
76  
77 return $doc;
78 }
79  
80  
81 1; ##-- be happy
82  
83 __END__