Word/Stem.pm

filter: Statementstmt 41.8% 18 / 43 Branchbran 16.6% 5 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 4 totaltotal 32.5% 27 / 83 CC 16 SCAR 31.9
CC
16
Cov
32%
five
56.0
six
12.0
stem
11.7
CRAP 24.4
↑ Summary Word.pm »
1 package Lingua::AR::Word;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 ▶sub stem{
Subroutine stem: called CC=6 SCAR=24.6
Pod undocumented
8  
9 1 my $stem;
10 1 my $word=shift;
11  
12  
13 #let's strip down every prefix and suffix I'm aware of.
14 #(actually suffixes relative to people like possessive adjs are NOT chopped)
15  
16 1 ▶ if($word=~/^( #the prefixes
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^( #the prefixes [\x{648}\x{641}\x{628}]*\x{627}\x{644}| [\x{628}\x{64a}\x{644}\x{645}\x{62a}\x{648}\x{633}\x{646}]*\x{62a}| [\x{628}\x{644}\x{648}\x{643}\x{641}]*\x{645}| [\x{627}\x{644}]*\x{644}|[ \x{648}\x{644}\x{633}\x{641}]*\x{64a}|[ \x{648}\x{641}\x{644}\x{628}]*\x{627}| ) (.*?) # the stem ( # the suffixes \x{627}\x{62a}| \x{648}\x{627}| \x{62a}\x{627}| \x{648}\x{646}| \x{648}\x{647}| \x{627}\x{646}| \x{62a}\x{64a}| \x{62a}\x{647}| \x{62a}\x{645}| \x{643}\x{645}| \x{647}[\x{646}\x{645}]*| \x{647}\x{627}| \x{64a}\x{629}| \x{62a}\x{643}| \x{646}\x{627}| \x{64a}[\x{646}\x{647}]*| [\x{629}\x{647}\x{64a}\x{627}]| ) $/x) 1 0 1
17 [وفب]*ال|
18 [بيلمتوسن]*ت|
19 [بلوكف]*م|
20 [ال]*ل|[
21 ولسف]*ي|[
22 وفلب]*ا|
23 )
24 (.*?) # the stem
25 ( # the suffixes
26 ات|
27 وا|
28 تا|
29 ون|
30 وه|
31 ان|
32 تي|
33 ته|
34 تم|
35 كم|
36 ه[نم]*|
37 ها|
38 ية|
39 تك|
40 نا|
41 ي[نه]*|
42 [ةهيا]|
43 )
44 $/x)
45 {
46 1 $word=$2;
47 }
48  
49 #let's strip down all other unnecessary letters according to the length of the word
50 1 ▶ if(length($word)==3){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word == 3) { } 0 1 1
51 0 $stem=$word;
52 }
53 else{
54 1 ▶ if(length($word)==4){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word == 4) { } 1 0 1
55 1 $stem=&four($word);
56 }
57 else{
58 0 ▶ if(length($word)==5){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word == 5) { } 0 0 0
59 0 $stem=&five($word);
60 }
61 else{
62 0 ▶ if(length($word)==6){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word == 6) { } 0 0 0
63 0 $stem=&six($word);
64 }
65 else{
66 0 $stem="NotFound";
67 }
68 }
69 }
70 }
71  
72 1 return $stem;
73 }
74  
75 1 ▶sub four{
Subroutine four: called CC=3 SCAR=13.3
Pod undocumented
76 1 my $word=shift;
77
78 1 ▶ if($word=~/(.)(.)(ا|ي|و)(.)/){
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ /(.)(.)(\x{627}|\x{64a}|\x{648})(.)/) { } 0 1 1
elsif ($word =~ /(.)(\x{627}|\x{648}|\x{637}|\x{64a})(.)(.)/) { } 1 0 1
79 0 $word=$1.$2.$4;
80 }
81 elsif ($word=~/(.)(ا|و|ط|ي)(.)(.)/){
82 1 $word=$1.$3.$4;
83 }
84 else{
85 0 $word="NotFound";
86 }
87 }
88  
89 0 ▶sub five{
Subroutine five: not called CC=7 SCAR=40.3
Pod undocumented
90 0 my $word=shift;
91
92 0 ▶ if($word=~/(.)(.)(ا)(ا)(.)/){
Branch: 6 branches
BranchTrueFalseTotal
if ($word =~ /(.)(.)(\x{627})(\x{627})(.)/) { } 0 0 0
elsif ($word =~ /(.)(\x{62a}|\x{64a})(.)(\x{627})(.)/) { } 0 0 0
elsif ($word =~ /(.)(\x{648})(\x{627})(.)(.)/) { } 0 0 0
elsif ($word =~ /(.)(\x{627})(.)(\x{64a}|\x{648})(.)/) { } 0 0 0
elsif ($word =~ /(.)(.)(.)(\x{627}|\x{64a}|\x{648})(.)/) { } 0 0 0
elsif ($word =~ /(.)(.)(\x{627}|\x{64a})(.)(.)/) { } 0 0 0
93 0 $word=$1.$2.$5;
94 }
95 elsif ($word=~/(.)(ت|ي)(.)(ا)(.)/){
96 0 $word=$1.$3.$5;
97 }
98 elsif ($word=~/(.)(و)(ا)(.)(.)/){
99 0 $word=$1.$4.$5;
100 }
101 elsif ($word=~/(.)(ا)(.)(ي|و)(.)/){
102 0 $word=$1.$3.$5;
103 }
104 elsif ($word=~/(.)(.)(.)(ا|ي|و)(.)/){
105 0 $word=$1.$2.$3.$5;
106 0 $word=&four($word);
107 }
108 elsif ($word=~/(.)(.)(ا|ي)(.)(.)/){
109 0 $word=$1.$2.$4.$5;
110 0 $word=&four($word);
111 }
112 else{
113 0 $word="NotFound";
114 }
115 }
116  
117 0 ▶sub six{
Subroutine six: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my $word=shift;
119
120 0 ▶ if($word=~/(.)(و)(ا)(.)(ي)(.)/){
Branch: 2 branches
BranchTrueFalseTotal
if ($word =~ /(.)(\x{648})(\x{627})(.)(\x{64a})(.)/) { } 0 0 0
elsif ($word =~ /(.)(.)(\x{627})(.)(\x{64a})(.)/) { } 0 0 0
121 0 $word=$1.$4.$6;
122 }
123 elsif ($word=~/(.)(.)(ا)(.)(ي)(.)/){
124 0 $word=$1.$2.$4.$6;
125 0 $word=&four($word);
126 }
127 else{
128 0 $word="NotFound";
129 }
130 }
131  
132 1 1;
133 __END__
↑ Summary Word.pm »