File Coverage

blib/lib/Lingua/YaTeA/ForbiddenStructureStartOrEnd.pm
Criterion Covered Total %
statement 88 95 92.6
branch 16 22 72.7
condition 12 30 40.0
subroutine 16 17 94.1
pod 10 10 100.0
total 142 174 81.6


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::ForbiddenStructureStartOrEnd;
2 5     5   32 use strict;
  5         12  
  5         137  
3 5     5   27 use warnings;
  5         10  
  5         145  
4 5     5   35 use Lingua::YaTeA::ForbiddenStructure;
  5         19  
  5         59  
5 5     5   2084 use Lingua::YaTeA::LinguisticItem;
  5         12  
  5         71  
6 5     5   2117 use Lingua::YaTeA::TriggerSet;
  5         14  
  5         83  
7 5     5   137 use UNIVERSAL;
  5         11  
  5         25  
8 5     5   149 use Scalar::Util qw(blessed);
  5         9  
  5         4828  
9              
10              
11             our @ISA = qw(Lingua::YaTeA::ForbiddenStructure);
12             our $VERSION=$Lingua::YaTeA::VERSION;
13              
14             sub new
15             {
16 28     28 1 67 my ($class,$infos_a,$triggers) = @_;
17 28         80 my ($form,$items_a) = $class->parse($infos_a->[0]);
18 28         104 my $this = $class->SUPER::new($form);
19 28         53 bless ($this,$class);
20 28         59 $this->{POSITION} = $infos_a->[1];
21 28         50 $this->{ITEMS} = $items_a;
22 28         147 $triggers->addTrigger($this);
23 28         91 return $this;
24             }
25              
26             sub getFirstItem
27             {
28 28     28 1 50 my ($this) = @_;
29 28 100       62 if($this->isStart)
30             {
31 12         31 return $this->getItemSet->[0];
32             }
33 16 50       44 if($this->isEnd)
34             {
35 16         41 return $this->getItemSet->[$#{$this->getItemSet}];
  16         37  
36             }
37             }
38              
39              
40             sub getItemSet
41             {
42 140     140 1 246 my ($this) = @_;
43 140         497 return $this->{ITEMS};
44             }
45              
46             sub parse
47             {
48 28     28 1 59 my ($class,$string) = @_;
49 28         74 my @elements = split / /, $string;
50 28         102 my $element;
51             my $i_form;
52 28         0 my $fs_form;
53 28         0 my $type;
54 28         44 my $rank = 0;
55 28         45 my @items;
56              
57 28         60 foreach $element (@elements){
58 40         145 $element =~ /^([^\\]+)\\(.+)$/;
59 40         89 $i_form = $1;
60 40         77 $type =$2;
61 40         132 push @items, Lingua::YaTeA::LinguisticItem->new($type,$i_form);
62 40 100       104 if($rank == 0){
63            
64             }
65 40         76 $fs_form .= $i_form . " ";
66 40         69 $rank++;
67             }
68 28         105 $fs_form =~ s/ $//;
69 28         95 return ($fs_form,\@items);
70             }
71              
72              
73              
74             sub getItem
75             {
76 96     96 1 227 my ($this,$index) = @_;
77 96         189 return $this->getItemSet->[$index];
78             }
79              
80             sub isStart
81             {
82 78     78 1 179 my ($this) = @_;
83 78 100       164 if($this->getPosition eq "START")
84             {
85 58         177 return 1;
86             }
87 20         71 return 0;
88             }
89              
90             sub isEnd
91             {
92 20     20 1 48 my ($this) = @_;
93 20 50       40 if($this->getPosition eq "END")
94             {
95 20         77 return 1;
96             }
97 0         0 return 0;
98             }
99              
100             sub getPosition
101             {
102 98     98 1 189 my ($this) = @_;
103 98         297 return $this->{POSITION};
104             }
105              
106              
107              
108              
109              
110             sub apply
111             {
112 50     50 1 99 my ($this,$words_a) = @_;
113 50         94 my $i;
114             my $j;
115            
116 50         73 $i = 0;
117 50         82 $j = 0;
118 50         67 my $to_delete;
119            
120 50 100       117 if($this->isStart){
121 46         112 while ($j < $this->getLength)
122             {
123              
124             # warn "ref: " . ref($words_a->[$i]) . "\n";
125 92 50 33     560 if ((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::TestifiedTermMark')))
126             {
127 0         0 return;
128             #return $to_delete;
129             }
130             else
131             {
132 92 100 33     766 if
      33        
      66        
      66        
133             (
134             (((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::ForbiddenStructureStartOrEnd'))))
135             ||
136             (
137             (((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::WordFromCorpus'))))
138             &&
139             ($this->getItem($j)->matchesWord($words_a->[$i]))
140             )
141             )
142             {
143 46         74 $i++;
144 46         79 $j++;
145 46         154 $to_delete++;
146             }
147             else
148             {
149 46         142 return;
150             }
151             }
152             }
153             }
154 4 50       26 if($this->isEnd)
155             {
156 4         13 $i = $#$words_a;
157 4         13 $j = $this->getLength -1;
158 4         18 while ($j >= 0)
159             {
160            
161 4 50 33     42 if((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::TestifiedTermMark')))
162             {
163 0         0 return;
164             }
165             else
166             {
167            
168 4 50 33     137 if
      33        
      33        
      33        
169             (
170             (((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::ForbiddenStructureStartOrEnd'))))
171             ||
172             (
173             (((blessed($words_a->[$i])) && ($words_a->[$i]->isa('Lingua::YaTeA::WordFromCorpus'))))
174             &&
175             ($this->getItem($j)->matchesWord($words_a->[$i]))
176             )
177             )
178             {
179 4         12 $i--;
180 4         9 $j--;
181 4         16 $to_delete++;
182             }
183             else
184             {
185 0         0 return;
186             }
187             }
188             }
189             }
190 4         15 return $to_delete;
191             }
192              
193             sub print
194             {
195 0     0 1   my ($this) = @_;
196 0           print $this->{FORM} . "\n";
197 0           print $this->{POSITION} . "\n";
198             }
199              
200             1;
201              
202             __END__