| 1 | #################################################################### | ||
| 2 | # | ||
| 3 | # This file was generated using Parse::Yapp version 1.05. | ||
| 4 | # | ||
| 5 | # Don't edit this file, use source file instead. | ||
| 6 | # | ||
| 7 | # ANY CHANGE MADE HERE WILL BE LOST ! | ||
| 8 | # | ||
| 9 | #################################################################### | ||
| 10 | package Alvis::NLPPlatform::ParseConstituents; | ||
| 11 | use vars qw ( @ISA ); | ||
| 12 | use strict; | ||
| 13 | |||
| 14 | @ISA= qw ( Parse::Yapp::Driver ); | ||
| 15 | use Parse::Yapp::Driver; | ||
| 16 | |||
| 17 | #line 12 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 18 | |||
| 19 | use Alvis::NLPPlatform; | ||
| 20 | use Data::Dumper; | ||
| 21 | use warnings; | ||
| 22 | |||
| 23 | |||
| 24 | our $VERSION=$Alvis::NLPPlatform::VERSION; | ||
| 25 | |||
| 26 | my $doc_hash; | ||
| 27 | my $decal_phrase_idx; | ||
| 28 | |||
| 29 | my $debug_mode=0; | ||
| 30 | my $lconst = 0; | ||
| 31 | my $nconst; | ||
| 32 | |||
| 33 | my @tab_nconst; | ||
| 34 | # my @tab_type; | ||
| 35 | # my @tab_string; | ||
| 36 | my $tab_type_ref; | ||
| 37 | my $tab_string_ref; | ||
| 38 | |||
| 39 | my $lastword=""; | ||
| 40 | |||
| 41 | my $word_id_np_ref; | ||
| 42 | |||
| 43 | my $word_count; | ||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | sub new { | ||
| 48 | my($class)=shift; | ||
| 49 | ref($class) | ||
| 50 | and $class=ref($class); | ||
| 51 | |||
| 52 | my($self)=$class->SUPER::new( yyversion => '1.05', | ||
| 53 | yystates => | ||
| 54 | [ | ||
| 55 | {#State 0 | ||
| 56 | DEFAULT => -1, | ||
| 57 | GOTOS => { | ||
| 58 | 'input' => 1 | ||
| 59 | } | ||
| 60 | }, | ||
| 61 | {#State 1 | ||
| 62 | ACTIONS => { | ||
| 63 | '' => 4, | ||
| 64 | 'OPEN' => 2, | ||
| 65 | "\n" => 6, | ||
| 66 | 'error' => 7 | ||
| 67 | }, | ||
| 68 | GOTOS => { | ||
| 69 | 'open' => 3, | ||
| 70 | 'constituent' => 5, | ||
| 71 | 'line' => 8 | ||
| 72 | } | ||
| 73 | }, | ||
| 74 | {#State 2 | ||
| 75 | DEFAULT => -12 | ||
| 76 | }, | ||
| 77 | {#State 3 | ||
| 78 | ACTIONS => { | ||
| 79 | 'OPEN' => 2, | ||
| 80 | 'WORD' => 9, | ||
| 81 | 'error' => 13 | ||
| 82 | }, | ||
| 83 | GOTOS => { | ||
| 84 | 'open' => 3, | ||
| 85 | 'constituent' => 10, | ||
| 86 | 'word' => 11, | ||
| 87 | 'constituent_content' => 12, | ||
| 88 | 'chunk' => 14 | ||
| 89 | } | ||
| 90 | }, | ||
| 91 | {#State 4 | ||
| 92 | DEFAULT => 0 | ||
| 93 | }, | ||
| 94 | {#State 5 | ||
| 95 | ACTIONS => { | ||
| 96 | "\n" => 15 | ||
| 97 | } | ||
| 98 | }, | ||
| 99 | {#State 6 | ||
| 100 | DEFAULT => -3 | ||
| 101 | }, | ||
| 102 | {#State 7 | ||
| 103 | ACTIONS => { | ||
| 104 | "\nline: " => 17, | ||
| 105 | "\nconstituents: " => 16, | ||
| 106 | "\nopen: " => 18 | ||
| 107 | } | ||
| 108 | }, | ||
| 109 | {#State 8 | ||
| 110 | DEFAULT => -2 | ||
| 111 | }, | ||
| 112 | {#State 9 | ||
| 113 | DEFAULT => -19 | ||
| 114 | }, | ||
| 115 | {#State 10 | ||
| 116 | DEFAULT => -9 | ||
| 117 | }, | ||
| 118 | {#State 11 | ||
| 119 | ACTIONS => { | ||
| 120 | 'OPEN' => -17, | ||
| 121 | 'WORD' => 9, | ||
| 122 | 'error' => 19, | ||
| 123 | 'CLOSE' => -17 | ||
| 124 | }, | ||
| 125 | GOTOS => { | ||
| 126 | 'word' => 11, | ||
| 127 | 'chunk' => 20 | ||
| 128 | } | ||
| 129 | }, | ||
| 130 | {#State 12 | ||
| 131 | ACTIONS => { | ||
| 132 | 'OPEN' => 2, | ||
| 133 | 'WORD' => 9, | ||
| 134 | 'error' => 24, | ||
| 135 | 'CLOSE' => 21 | ||
| 136 | }, | ||
| 137 | GOTOS => { | ||
| 138 | 'open' => 3, | ||
| 139 | 'close' => 22, | ||
| 140 | 'constituent' => 10, | ||
| 141 | 'word' => 11, | ||
| 142 | 'constituent_content' => 23, | ||
| 143 | 'chunk' => 14 | ||
| 144 | } | ||
| 145 | }, | ||
| 146 | {#State 13 | ||
| 147 | ACTIONS => { | ||
| 148 | "\nchunk: " => 26, | ||
| 149 | "\nconstituents: " => 16, | ||
| 150 | "\nconstituent_content: " => 27, | ||
| 151 | "\nopen: " => 18, | ||
| 152 | "\nword: " => 25 | ||
| 153 | } | ||
| 154 | }, | ||
| 155 | {#State 14 | ||
| 156 | DEFAULT => -8 | ||
| 157 | }, | ||
| 158 | {#State 15 | ||
| 159 | DEFAULT => -4 | ||
| 160 | }, | ||
| 161 | {#State 16 | ||
| 162 | DEFAULT => -7 | ||
| 163 | }, | ||
| 164 | {#State 17 | ||
| 165 | DEFAULT => -5 | ||
| 166 | }, | ||
| 167 | {#State 18 | ||
| 168 | DEFAULT => -13 | ||
| 169 | }, | ||
| 170 | {#State 19 | ||
| 171 | ACTIONS => { | ||
| 172 | "\nchunk: " => 26, | ||
| 173 | "\nword: " => 25 | ||
| 174 | } | ||
| 175 | }, | ||
| 176 | {#State 20 | ||
| 177 | DEFAULT => -16 | ||
| 178 | }, | ||
| 179 | {#State 21 | ||
| 180 | DEFAULT => -14 | ||
| 181 | }, | ||
| 182 | {#State 22 | ||
| 183 | DEFAULT => -6 | ||
| 184 | }, | ||
| 185 | {#State 23 | ||
| 186 | ACTIONS => { | ||
| 187 | 'OPEN' => 2, | ||
| 188 | 'WORD' => 9, | ||
| 189 | 'error' => 13, | ||
| 190 | 'CLOSE' => -10 | ||
| 191 | }, | ||
| 192 | GOTOS => { | ||
| 193 | 'open' => 3, | ||
| 194 | 'constituent' => 10, | ||
| 195 | 'word' => 11, | ||
| 196 | 'constituent_content' => 23, | ||
| 197 | 'chunk' => 14 | ||
| 198 | } | ||
| 199 | }, | ||
| 200 | {#State 24 | ||
| 201 | ACTIONS => { | ||
| 202 | "\nchunk: " => 26, | ||
| 203 | "\nconstituents: " => 16, | ||
| 204 | "\nclose: " => 28, | ||
| 205 | "\nconstituent_content: " => 27, | ||
| 206 | "\nopen: " => 18, | ||
| 207 | "\nword: " => 25 | ||
| 208 | } | ||
| 209 | }, | ||
| 210 | {#State 25 | ||
| 211 | DEFAULT => -20 | ||
| 212 | }, | ||
| 213 | {#State 26 | ||
| 214 | DEFAULT => -18 | ||
| 215 | }, | ||
| 216 | {#State 27 | ||
| 217 | DEFAULT => -11 | ||
| 218 | }, | ||
| 219 | {#State 28 | ||
| 220 | DEFAULT => -15 | ||
| 221 | } | ||
| 222 | ], | ||
| 223 | yyrules => | ||
| 224 | [ | ||
| 225 | [#Rule 0 | ||
| 226 | '$start', 2, undef | ||
| 227 | ], | ||
| 228 | [#Rule 1 | ||
| 229 | 'input', 0, undef | ||
| 230 | ], | ||
| 231 | [#Rule 2 | ||
| 232 | 'input', 2, | ||
| 233 | sub | ||
| 234 | #line 43 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 235 | { push(@{$_[1]},$_[2]); $_[1] } | ||
| 236 | ], | ||
| 237 | [#Rule 3 | ||
| 238 | 'line', 1, | ||
| 239 | sub | ||
| 240 | #line 46 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 241 | { $_[1] } | ||
| 242 | ], | ||
| 243 | [#Rule 4 | ||
| 244 | 'line', 2, undef | ||
| 245 | ], | ||
| 246 | [#Rule 5 | ||
| 247 | 'line', 2, | ||
| 248 | sub | ||
| 249 | #line 48 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 250 | { $_[0]->YYErrok } | ||
| 251 | ], | ||
| 252 | [#Rule 6 | ||
| 253 | 'constituent', 3, undef | ||
| 254 | ], | ||
| 255 | [#Rule 7 | ||
| 256 | 'constituent', 2, | ||
| 257 | sub | ||
| 258 | #line 52 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 259 | { $_[0]->YYErrok } | ||
| 260 | ], | ||
| 261 | [#Rule 8 | ||
| 262 | 'constituent_content', 1, | ||
| 263 | sub | ||
| 264 | #line 56 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 265 | {$_[1];} | ||
| 266 | ], | ||
| 267 | [#Rule 9 | ||
| 268 | 'constituent_content', 1, undef | ||
| 269 | ], | ||
| 270 | [#Rule 10 | ||
| 271 | 'constituent_content', 2, undef | ||
| 272 | ], | ||
| 273 | [#Rule 11 | ||
| 274 | 'constituent_content', 2, | ||
| 275 | sub | ||
| 276 | #line 59 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 277 | { $_[0]->YYErrok } | ||
| 278 | ], | ||
| 279 | [#Rule 12 | ||
| 280 | 'open', 1, | ||
| 281 | sub | ||
| 282 | #line 63 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 283 | { | ||
| 284 | # open constituent | ||
| 285 | if($lconst>0){ | ||
| 286 | push @{$$tab_string_ref[$tab_nconst[$lconst]]} , "phrase" . ($decal_phrase_idx+$$nconst+1) ; | ||
| 287 | } | ||
| 288 | $lconst++; | ||
| 289 | $$nconst++; | ||
| 290 | $tab_nconst[$lconst]=$$nconst; | ||
| 291 | |||
| 292 | # get type | ||
| 293 | $$tab_type_ref[$tab_nconst[$lconst]]=$_[1]; | ||
| 294 | |||
| 295 | print STDERR "*** DEBUG *** Opened constituent $$nconst with type ".$_[1]."\n" unless ($debug_mode==0); | ||
| 296 | |||
| 297 | } | ||
| 298 | ], | ||
| 299 | [#Rule 13 | ||
| 300 | 'open', 2, | ||
| 301 | sub | ||
| 302 | #line 78 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 303 | { $_[0]->YYErrok } | ||
| 304 | ], | ||
| 305 | [#Rule 14 | ||
| 306 | 'close', 1, | ||
| 307 | sub | ||
| 308 | #line 81 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 309 | { | ||
| 310 | # check type | ||
| 311 | print STDERR $_[1] unless ($debug_mode==0); | ||
| 312 | if($_[1] ne $$tab_type_ref[$tab_nconst[$lconst]]){ | ||
| 313 | print STDERR "Error found at level $lconst: types don't match!\n"; | ||
| 314 | exit 0; | ||
| 315 | } | ||
| 316 | # remove ending space | ||
| 317 | # $$tab_string_ref[$tab_nconst[$lconst]] =~ s/\s+$//sgo; | ||
| 318 | # close constituent | ||
| 319 | print STDERR "*** DEBUG *** Closing constituent $tab_nconst[$lconst]\n" unless ($debug_mode==0); | ||
| 320 | $lconst--; | ||
| 321 | } | ||
| 322 | ], | ||
| 323 | [#Rule 15 | ||
| 324 | 'close', 2, | ||
| 325 | sub | ||
| 326 | #line 94 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 327 | { $_[0]->YYErrok } | ||
| 328 | ], | ||
| 329 | [#Rule 16 | ||
| 330 | 'chunk', 2, undef | ||
| 331 | ], | ||
| 332 | [#Rule 17 | ||
| 333 | 'chunk', 1, undef | ||
| 334 | ], | ||
| 335 | [#Rule 18 | ||
| 336 | 'chunk', 2, | ||
| 337 | sub | ||
| 338 | #line 98 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 339 | { $_[0]->YYErrok } | ||
| 340 | ], | ||
| 341 | [#Rule 19 | ||
| 342 | 'word', 1, | ||
| 343 | sub | ||
| 344 | #line 101 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 345 | { | ||
| 346 | print STDERR "*** DEBUG *** Found string '".$_[1] . "'\n" unless ($debug_mode==0); | ||
| 347 | if((defined $$tab_string_ref[$tab_nconst[$lconst]]) | ||
| 348 | &&(scalar(@{$$tab_string_ref[$tab_nconst[$lconst]]}) != 0)){ | ||
| 349 | print STDERR "*** DEBUG *** Appended to previously found string\n" unless ($debug_mode==0); | ||
| 350 | # $$tab_string_ref[$tab_nconst[$lconst]].=$_[0]->text; | ||
| 351 | if(($_[1] eq $lastword) || ($_[1]=~/^\./)){ | ||
| 352 | }else{ | ||
| 353 | push @{$$tab_string_ref[$tab_nconst[$lconst]]}, "word" . $$word_id_np_ref ; | ||
| 354 | $$word_id_np_ref++; | ||
| 355 | $lastword=$_[1]; | ||
| 356 | } | ||
| 357 | }else{ | ||
| 358 | # $$tab_string_ref[$tab_nconst[$lconst]]=$_[0]->text; | ||
| 359 | if(!(($_[1] eq $lastword)||($_[1] =~ /^\./))){ | ||
| 360 | $lastword=$_[1]; | ||
| 361 | my @tmp; | ||
| 362 | push @tmp, "word" . $$word_id_np_ref; | ||
| 363 | $$tab_string_ref[$tab_nconst[$lconst]]=\@tmp; | ||
| 364 | $$word_id_np_ref++; | ||
| 365 | }else{ | ||
| 366 | } | ||
| 367 | } | ||
| 368 | } | ||
| 369 | ], | ||
| 370 | [#Rule 20 | ||
| 371 | 'word', 2, | ||
| 372 | sub | ||
| 373 | #line 125 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 374 | { $_[0]->YYErrok } | ||
| 375 | ] | ||
| 376 | ], | ||
| 377 | @_); | ||
| 378 | bless($self,$class); | ||
| 379 | } | ||
| 380 | |||
| 381 | #line 128 "lib/Alvis/NLPPlatform/ParseConstituents.yp" | ||
| 382 | |||
| 383 | |||
| 384 | |||
| 385 | |||
| 386 | sub _Error { | ||
| 387 | exists $_[0]->YYData->{ERRMSG} | ||
| 388 | and do { | ||
| 389 | print $_[0]->YYData->{ERRMSG}; | ||
| 390 | delete $_[0]->YYData->{ERRMSG}; | ||
| 391 | return; | ||
| 392 | }; | ||
| 393 | # print "Syntax error...\n"; | ||
| 394 | } | ||
| 395 | |||
| 396 | sub _Lexer { | ||
| 397 | my($parser)=shift; | ||
| 398 | |||
| 399 | |||
| 400 | $doc_hash = $parser->YYData->{DOC_HASH} or return('',undef); | ||
| 401 | $decal_phrase_idx = $parser->YYData->{DECAL_PHRASE_IDX} or return('',undef); | ||
| 402 | $word_id_np_ref = $parser->YYData->{WORD_ID_NP_REF} or return('',undef); | ||
| 403 | |||
| 404 | $tab_type_ref = $parser->YYData->{TAB_TYPE_REF}; | ||
| 405 | $tab_string_ref = $parser->YYData->{TAB_STRING_REF}; | ||
| 406 | |||
| 407 | # $lconst = $parser->YYData->{LCONST_REF}; | ||
| 408 | $nconst = $parser->YYData->{NCONST_REF}; | ||
| 409 | |||
| 410 | $word_count=$$word_id_np_ref; | ||
| 411 | |||
| 412 | # $parser->YYData->{INPUT} | ||
| 413 | # or $parser->YYData->{INPUT} = "[PP of [NP two transcription factors factors NP] PP]\n" | ||
| 414 | # or return('',undef); | ||
| 415 | # $parser->YYData->{INPUT} = $parser->YYData->{CONSTITUENT_STRING}; | ||
| 416 | # or return('',undef); | ||
| 417 | |||
| 418 | # chomp $parser->YYData->{INPUT}; | ||
| 419 | # chop $parser->YYData->{INPUT}; | ||
| 420 | # print STDERR $parser->YYData->{INPUT}; | ||
| 421 | # print STDERR ";;\n"; | ||
| 422 | |||
| 423 | # print STDERR "==>"; | ||
| 424 | # print STDERR $parser->YYData->{CONSTITUENT_STRING}; | ||
| 425 | # print STDERR "\n"; | ||
| 426 | |||
| 427 | # print STDERR "$lconst : $$nconst\n"; | ||
| 428 | |||
| 429 | $parser->YYData->{CONSTITUENT_STRING}=~s/^[ \t]*#.*//; | ||
| 430 | $parser->YYData->{CONSTITUENT_STRING}=~s/^[ \t]*//; | ||
| 431 | my $open = '\[([A-Z]+)'; | ||
| 432 | my $close = '([A-Z]+)\]'; | ||
| 433 | my $word = '([^\s\]\[]+)'; | ||
| 434 | |||
| 435 | for ($parser->YYData->{CONSTITUENT_STRING}) { | ||
| 436 | s/^$open// and return ('OPEN', $1); | ||
| 437 | s/^$close// and return ('CLOSE', $1); | ||
| 438 | s/^$word// and return('WORD', $1); | ||
| 439 | s/^(.)//s and return($1,$1); | ||
| 440 | |||
| 441 | } | ||
| 442 | |||
| 443 | } | ||
| 444 | |||
| 445 | |||
| 446 | 1; |