lib/Lingua/Ogmios/NLPWrappers/PatternParser.yp

filter: Statementstmt 23.4% 19 / 81 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 5.5% 2 / 36 Podpod 100% 1 / 1 totaltotal 14.3% 22 / 153 CC 18 SCAR 44.2
CC
18
Cov
17%
_Lexer
272.0
_Error
6.0
new
3.3
CRAP 83.4
« blib/lib/Lingua/Ogmios/NLPWrappers/StanfordParser.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Distribution.pm »
1 #
2 # ParsingPatternParser.yp
3 #
4 # used to generate Lingua::YaTeA::ParsingPatternParser.pm
5 #
6 # Use: yapp -m 'Lingua::Ogmios::NLPWrappers::PatternParser' -o lib/Lingua/Ogmios/NLPWrappers/PatternParser.pm lib/Lingua/Ogmios/NLPWrappers/PatternParser.yp
7 #
8 # Parse::Yapp input grammar for parsing the yatea PArsint patterns
9 #
10 #
11 #
12 %{
13 6 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 my $node_set = [];
17 my $node;
18 my @node_stack;
19 my @uncomplete;
20 my @parse;
21  
22 my $action;
23  
24  
25 my $num_content_words;
26 my @pos_sequence;
27 my $priority;
28  
29 my $distance;
30  
31 my $pos_sequence;
32 my $pattern;
33 my $parse;
34 my $num_line = 1;
35 %}
36  
37 0 ▶%%
Subroutine new: not called CC=2 SCAR=12.0
Pod documented
38 0  
39 0 ▶input: #empty
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 0 0
40 0 ▶ | input line { # print STDERR "INPUT $_[2] \n";
Subroutine __ANON__: not called CC=1 SCAR=0.0
41 }
42 ;
43  
44 6 ▶line: '\n' { $_[1] }
Subroutine __ANON__: not called CC=1 SCAR=0.0
45 0 ▶ | pattern DISTANCE ACTION '\n' {
Subroutine __ANON__: not called CC=1 SCAR=0.0
46 # print STDERR "=>$_[1] ($action)\n";
47 6 $_[0]->YYData->{PPRS}->addSynPattern($node_set, $action, $distance);
48 6 @$node_set = ();
49 }
50 0 ▶ | { #print STDERR "START\n";
Subroutine __ANON__: not called CC=1 SCAR=0.0
51 6 $node = $node_set;
52 0 ▶ } SYN_DEP phrase DISTANCE ACTION '\n' {
Subroutine __ANON__: not called CC=1 SCAR=0.0
53 6 push @$node, shift @$node;
54 # print "++>$_[1] ($action)\n";
55 6 $_[0]->YYData->{PPRS}->addSynPattern($node_set, $action, $distance);
56 6 @$node_set = ();
57 }
58 6 ▶ | error '\nline:' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=0.0
59 ;
60  
61 # patternaction: {print STDERR "start\n";
62 # }
63 # pattern ACTION
64 # | error '\patternaction: ' { $_[0]->YYErrok }
65 # ;
66  
67 0 ▶pattern: { #print STDERR "START\n";
Subroutine __ANON__: not called CC=1 SCAR=0.0
68 6 $node = $node_set;
69 }
70 | pattern SEMTYPE
71 | pattern CHUNK
72 | pattern REGEXP
73 | pattern POSTAG
74 | pattern TERM
75 | pattern TERMCONTENT
76 | pattern WORD
77 6 ▶ | error '\npattern: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=0.0
78 ;
79  
80 0 ▶ACTION: ACTION_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=0.0
81 6 $action = $_[1];
82 # print STDERR "ACTION: $action\n";
83 }
84 6 ▶ | error '\nACTION: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=0.0
85 ;
86  
87 0 ▶DISTANCE: DISTANCE_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=0.0
88 6 $distance = $_[1];
89 # print STDERR "DISTANCE: $distance\n";
90 }
91 0 ▶ | error '\nDISTANCE: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 ;
93  
94 0 ▶SEMTYPE: SEMTYPE_TAG {
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 # print STDERR "SEMTYPE $_[1]\n";
96 0 push @$node, {'type' => 'semtype',
97 'semtype' => $_[1]};
98 }
99 0 ▶ | error '\nSEMTYPE: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 ;
101  
102 0 ▶POSTAG: POSTAG_TAG {
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 # print STDERR "POSTAG $_[1]\n";
104 0 push @$node, {'type' => 'postag',
105 'postag' => $_[1]};
106 }
107 0 ▶ | error '\nPOSTAG: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 ;
109  
110 0 ▶REGEXP: REGEXP_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 # print STDERR "REGEXP $_[1]\n";
112 0 push @$node, {'type' => 'word_re',
113 'word_re' => $_[1]};
114 }
115 0 ▶ | error '\nREGEXP: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 ;
117  
118 0 ▶WORD: WORD_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 # print STDERR "WORD $_[1]\n";
120 0 push @$node, {'type' => 'word',
121 'word' => $_[1]};
122 }
123 0 ▶ | error '\nWORD: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 ;
125  
126 0 ▶TERM: TERM_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
127 # print STDERR "TERM $_[1]\n";
128 0 push @$node, {'type' => 'term',
129 'term' => $_[1]};
130 }
131 0 ▶ | error '\nTERM: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 ;
133  
134 0 ▶TERMCONTENT: TERMCONTENT_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
135 # print STDERR "TERMCONTENT $_[1]\n";
136 0 push @$node, {'type' => 'termContent',
137 'termContent' => $_[1]};
138 }
139 0 ▶ | error '\nTERM_CONTENT: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 ;
141  
142 0 ▶SYN_DEP: SYNDEP_SEQ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
143 # print STDERR "SYNDEP $_[1]\n";
144 0 push @$node, {'type' => 'syndep',
145 'syndep' => $_[1]};
146 }
147 0 ▶ | error '\nSYNDEP: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 ;
149  
150  
151  
152 0 ▶CHUNK: OPEN_CHUNK { my $nodetmp = [];
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 0 push @node_stack, $node;
154 0 push @$node, {'type' => 'chunk',
155 'chunk' => $nodetmp };
156 0 $node = $nodetmp;
157 0 ▶ } SYN_DEP phrase CLOSE_CHUNK {
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 # print STDERR "CHUNK $_[3]\n";
159 0 push @$node, shift @$node;
160 0 $node = pop @node_stack;
161 }
162 0 ▶ | error '\nCHUNK: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 ;
164  
165  
166 0 ▶phrase: {# print STDERR "phrase\n";
Subroutine __ANON__: not called CC=1 SCAR=0.0
167 }
168 | phrase REGEXP
169 | phrase SEMTYPE
170 | phrase POSTAG
171 | phrase TERM
172 | phrase TERMCONTENT
173 | phrase WORD
174 0 ▶ | error '\nphrase: ' { $_[0]->YYErrok }
Subroutine __ANON__: not called CC=1 SCAR=6.9
175 0 ;
176  
177 %%
178 0  
179  
180  
181 0 ▶sub _Error {
Subroutine _Error: not called CC=2 SCAR=17.9
182 exists $_[0]->YYData->{ERRMSG}
183 0 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]->YYData->{"ERRMSG"} and do { print $_[0]->YYData->{"ERRMSG"}; delete $_[0]->YYData->{"ERRMSG"}; return } 0 0 0
184 0 print $_[0]->YYData->{ERRMSG};
185 0 delete $_[0]->YYData->{ERRMSG};
186 0 return;
187 };
188 0 print STDERR "Syntax error.\n";
189 0 print "Syntax error.\n";
190 }
191  
192 0 ▶sub _Lexer {
Subroutine _Lexer: not called CC=16 SCAR=56.1
193 0 my($parser)=shift;
194  
195 0 my $fh = $parser->YYData->{FH};
196  
197 0 my $semtype = '(@semtype\(([^\)]+)\))';
198 0 my $openchunk = '(\[)';
199 0 my $closechunk = '(\])';
200 0 my $syn_dep = '(@syndep\(([^\)]+)\))';
201 0 my $postag = '(@postag\(([^\)]+)\))';
202 # my $regexp = '(@re_begin(.*?)@re_end)';
203 0 my $regexp = '(@word_re(\(.*?\))@)';
204 0 my $termcontent = '(@term\(([^\)]+)\))';
205 0 my $term = '(@term@)';
206 0 my $word = '([^ \|\n\]]+)';
207 0 my $action = '(\|\|\s*([^\n]+))';
208 0 my $distance = '(\|\|\s*([0-9]+))';
209  
210 $parser->YYData->{INPUT}
211 or $parser->YYData->{INPUT} = <$fh>
212 0 ▶ or return('', undef);
Branch: 1 branch
BranchTrueFalseTotal
$parser->YYData->{"INPUT"} or $parser->YYData->{"INPUT"} = readline $fh or return "", undef 0 0 0
Condition0%0/3
$parser->YYData->{"INPUT"} or $parser->YYData->{"INPUT"} = readline $fh
l!l&&r!l&&!r
000
MC/DC0%0/2
$parser->YYData->{"INPUT"} or $parser->YYData->{"INPUT"} = readline $fh
$parser->YYData->{"INPUT"} $parser->YYData->{"INPUT"} = readline $fh
Truth table0%0/3
A or B
A= $parser->YYData->{"INPUT"}B= $parser->YYData->{"INPUT"} = readline $fh
ABresult
1X1
011
000
213  
214 0 $parser->YYData->{INPUT} =~ s/^[ \t]*#.*//;
215 0 $parser->YYData->{INPUT} =~ s/^[ \t]*//;
216  
217 # warn "==>" . $parser->YYData->{INPUT} . ";\n";
218 # print "==>" . $parser->YYData->{INPUT} . ";\n";
219  
220 0 for ($parser->YYData->{INPUT}) {
221 0 ▶ s/^$semtype\s*// and return ('SEMTYPE_TAG', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$semtype\s*// and return "SEMTYPE_TAG", $2 0 0 0
222 0 ▶ s/^$openchunk\s*// and return ('OPEN_CHUNK', $1);
Branch: 1 branch
BranchTrueFalseTotal
s/^$openchunk\s*// and return "OPEN_CHUNK", $1 0 0 0
223 0 ▶ s/^$closechunk// and return('CLOSE_CHUNK', $1);
Branch: 1 branch
BranchTrueFalseTotal
s/^$closechunk// and return "CLOSE_CHUNK", $1 0 0 0
224 0 ▶ s/^$syn_dep// and return('SYNDEP_SEQ', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$syn_dep// and return "SYNDEP_SEQ", $2 0 0 0
225 0 ▶ s/^$postag// and return('POSTAG_TAG', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$postag// and return "POSTAG_TAG", $2 0 0 0
226 0 ▶ s/^$regexp// and return('REGEXP_SEQ', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$regexp// and return "REGEXP_SEQ", $2 0 0 0
227 0 ▶ s/^$termcontent// and return('TERMCONTENT_SEQ', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$termcontent// and return "TERMCONTENT_SEQ", $2 0 0 0
228 0 ▶ s/^$term// and return('TERM_SEQ', $1);
Branch: 1 branch
BranchTrueFalseTotal
s/^$term// and return "TERM_SEQ", $1 0 0 0
229 0 ▶ s/^$distance// and return('DISTANCE_SEQ', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$distance// and return "DISTANCE_SEQ", $2 0 0 0
230 0 ▶ s/^$action// and return('ACTION_SEQ', $2);
Branch: 1 branch
BranchTrueFalseTotal
s/^$action// and return "ACTION_SEQ", $2 0 0 0
231 0 ▶ s/^$word// and return('WORD_SEQ', $1);
Branch: 1 branch
BranchTrueFalseTotal
s/^$word// and return "WORD_SEQ", $1 0 0 0
232 0 ▶ s/^(.)//s and return($1,$1);
Branch: 1 branch
BranchTrueFalseTotal
s/^(.)//s and return $1, $1 0 0 0
233 }
234 }
235  
236 # sub Run {
237 # my($self)=shift;
238 # $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
239 # }
240  
241 # my($parsingpattern)=new ParsingPatternParser;
242 # $parsingpattern->Run;
243  
244  
245 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/StanfordParser.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Distribution.pm »