File Coverage

blib/lib/Lingua/YaTeA/ParsingPatternRecordSet.pm
Criterion Covered Total %
statement 45 54 83.3
branch 4 6 66.6
condition n/a
subroutine 12 14 85.7
pod 9 9 100.0
total 70 83 84.3


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::ParsingPatternRecordSet;
2 5     5   29 use strict;
  5         10  
  5         137  
3 5     5   21 use warnings;
  5         10  
  5         106  
4              
5 5     5   1587 use Lingua::YaTeA::ParsingPatternRecord;
  5         14  
  5         50  
6 5     5   124 use Lingua::YaTeA::ParsingPattern;
  5         9  
  5         14  
7 5     5   1891 use Lingua::YaTeA::ParsingPatternParser;
  5         11  
  5         37  
8              
9             our $max_content_words = 0;
10              
11             our $VERSION=$Lingua::YaTeA::VERSION;
12              
13             sub new
14             {
15 4     4 1 12 my ($class,$file_path,$tag_set,$message_set,$display_language) = @_;
16 4         10 my $this = {};
17 4         11 bless ($this,$class);
18 4         22 $this->{PARSING_RECORDS} = {};
19 4         17 $this->loadPatterns($file_path,$tag_set,$message_set,$display_language);
20 4         667 return $this;
21             }
22              
23             sub loadPatterns
24             {
25 4     4 1 12 my ($this,$file_path,$tag_set,$message_set,$display_language) = @_;
26            
27 4         23 my $fh = FileHandle->new("<$file_path");
28              
29              
30 4         334 my $parser = Lingua::YaTeA::ParsingPatternParser->new();
31              
32 4         36 $parser->YYData->{PPRS} = $this;
33 4         58 $parser->YYData->{FH} = $fh;
34 4         28 $parser->YYData->{CANDIDATES} = $tag_set->getTagList("CANDIDATES");
35 4         25 $parser->YYData->{PREPOSITIONS} = $tag_set->getTagList("PREPOSITIONS");
36 4         24 $parser->YYData->{DETERMINERS} = $tag_set->getTagList("DETERMINERS");
37              
38 4         48 $parser->YYParse(yylex => \&Lingua::YaTeA::ParsingPatternParser::_Lexer, yyerror => \&Lingua::YaTeA::ParsingPatternParser::_Error);
39              
40             # print STDERR "nberr: " . $parser->YYNberr() ."\n";
41             }
42              
43              
44             sub checkContentWords
45             {
46 280     280 1 1403 my ($this,$num_content_words,$num_line) = @_;
47 280 50       578 if($num_content_words == 0)
48             {
49 0         0 die "No content word in pattern line " . $num_line . "\n";
50             }
51             }
52              
53             sub addPattern
54             {
55 280     280 1 1649 my ($this,$pattern) = @_;
56 280         333 my $record;
57 280 50       535 if (! $this->existRecord($pattern->getPOSSequence))
58             {
59 280         471 $record = $this->addRecord($pattern->getPOSSequence);
60             }
61             else
62             {
63 0         0 $record = $this->getRecord($pattern->getPOSSequence);
64             }
65 280         602 $record->addPattern($pattern);
66             }
67              
68             sub getRecord
69             {
70 0     0 1 0 my ($this,$name) = @_;
71 0         0 return $this->{PARSING_RECORDS}->{$name};
72             }
73              
74             sub addRecord
75             {
76 280     280 1 418 my ($this,$name) = @_;
77 280         627 $this->{PARSING_RECORDS}->{$name} = Lingua::YaTeA::ParsingPatternRecord->new($name);
78              
79             }
80              
81             sub existRecord
82             {
83 353     353 1 577 my ($this,$name) = @_;
84 353 100       795 if (exists $this->{PARSING_RECORDS}{$name})
85             {
86 46         152 return $this->{PARSING_RECORDS}{$name};
87             }
88 307         575 return 0;
89             }
90              
91             sub getRecordSet
92             {
93 4828     4828 1 6584 my ($this) = @_;
94 4828         13010 return $this->{PARSING_RECORDS};
95            
96             }
97              
98              
99             sub print
100             {
101 0     0 1   my ($this) = @_;
102 0           my $record;
103 0           foreach $record (values %{$this->getRecordSet})
  0            
104             {
105 0           $record->print;
106             }
107             }
108              
109              
110              
111             1;
112              
113              
114             __END__