Alvis-NLPPlatform

 view release on metacpan or  search on metacpan

lib/Alvis/NLPPlatform/ParseConstituents.pm  view on Meta::CPAN

####################################################################
#
#    This file was generated using Parse::Yapp version 1.05.
#
#        Don't edit this file, use source file instead.
#
#             ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package Alvis::NLPPlatform::ParseConstituents;
use vars qw ( @ISA );
use strict;

@ISA= qw ( Parse::Yapp::Driver );
use Parse::Yapp::Driver;

#line 12 "lib/Alvis/NLPPlatform/ParseConstituents.yp"

    use Alvis::NLPPlatform;
    use Data::Dumper;
    use warnings;


    our $VERSION=$Alvis::NLPPlatform::VERSION;

    my $doc_hash;
    my $decal_phrase_idx;

    my $debug_mode=0;
    my $lconst = 0;
    my $nconst;

    my @tab_nconst;
#     my @tab_type;
#     my @tab_string;
    my $tab_type_ref;
    my $tab_string_ref;

    my $lastword="";

    my $word_id_np_ref;

    my $word_count;



sub new {
        my($class)=shift;
        ref($class)
    and $class=ref($class);

    my($self)=$class->SUPER::new( yyversion => '1.05',
                                  yystates =>
[
	{#State 0
		DEFAULT => -1,
		GOTOS => {
			'input' => 1
		}
	},
	{#State 1
		ACTIONS => {
			'' => 4,
			'OPEN' => 2,
			"\n" => 6,
			'error' => 7
		},
		GOTOS => {
			'open' => 3,
			'constituent' => 5,
			'line' => 8
		}
	},
	{#State 2
		DEFAULT => -12
	},
	{#State 3
		ACTIONS => {
			'OPEN' => 2,
			'WORD' => 9,
			'error' => 13
		},
		GOTOS => {
			'open' => 3,
			'constituent' => 10,
			'word' => 11,
			'constituent_content' => 12,
			'chunk' => 14
		}

lib/Alvis/NLPPlatform/ParseConstituents.pm  view on Meta::CPAN

{ push(@{$_[1]},$_[2]); $_[1] }
	],
	[#Rule 3
		 'line', 1,
sub
#line 46 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[1] }
	],
	[#Rule 4
		 'line', 2, undef
	],
	[#Rule 5
		 'line', 2,
sub
#line 48 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 6
		 'constituent', 3, undef
	],
	[#Rule 7
		 'constituent', 2,
sub
#line 52 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 8
		 'constituent_content', 1,
sub
#line 56 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{$_[1];}
	],
	[#Rule 9
		 'constituent_content', 1, undef
	],
	[#Rule 10
		 'constituent_content', 2, undef
	],
	[#Rule 11
		 'constituent_content', 2,
sub
#line 59 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 12
		 'open', 1,
sub
#line 63 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{
	    # open constituent
	    if($lconst>0){
		push @{$$tab_string_ref[$tab_nconst[$lconst]]} , "phrase" . ($decal_phrase_idx+$$nconst+1) ;
	    }
	    $lconst++;
	    $$nconst++;
	    $tab_nconst[$lconst]=$$nconst;

	    # get type
	    $$tab_type_ref[$tab_nconst[$lconst]]=$_[1];

	    print STDERR "*** DEBUG *** Opened constituent $$nconst with type ".$_[1]."\n" unless ($debug_mode==0);

	}
	],
	[#Rule 13
		 'open', 2,
sub
#line 78 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 14
		 'close', 1,
sub
#line 81 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{
	    # check type
    print STDERR $_[1] unless ($debug_mode==0);
	    if($_[1] ne $$tab_type_ref[$tab_nconst[$lconst]]){
		print STDERR "Error found at level $lconst: types don't match!\n";
		exit 0;
	    }
	    # remove ending space
#	    $$tab_string_ref[$tab_nconst[$lconst]] =~ s/\s+$//sgo;
	    # close constituent
	    print STDERR "*** DEBUG *** Closing constituent $tab_nconst[$lconst]\n" unless ($debug_mode==0);
	    $lconst--;
	}
	],
	[#Rule 15
		 'close', 2,
sub
#line 94 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 16
		 'chunk', 2, undef
	],
	[#Rule 17
		 'chunk', 1, undef
	],
	[#Rule 18
		 'chunk', 2,
sub
#line 98 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	],
	[#Rule 19
		 'word', 1,
sub
#line 101 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{
	    print STDERR "*** DEBUG *** Found string '".$_[1] . "'\n" unless ($debug_mode==0);
	    if((defined $$tab_string_ref[$tab_nconst[$lconst]])
                &&(scalar(@{$$tab_string_ref[$tab_nconst[$lconst]]}) != 0)){
		print STDERR "*** DEBUG *** Appended to previously found string\n" unless ($debug_mode==0);
#		$$tab_string_ref[$tab_nconst[$lconst]].=$_[0]->text;
		if(($_[1] eq $lastword) || ($_[1]=~/^\./)){
		}else{
		    push @{$$tab_string_ref[$tab_nconst[$lconst]]}, "word" . $$word_id_np_ref ;
		    $$word_id_np_ref++;
		    $lastword=$_[1];
		}
	    }else{
#		$$tab_string_ref[$tab_nconst[$lconst]]=$_[0]->text;
		if(!(($_[1] eq $lastword)||($_[1] =~ /^\./))){
		    $lastword=$_[1];
		    my @tmp;
		    push @tmp, "word" . $$word_id_np_ref;
		    $$tab_string_ref[$tab_nconst[$lconst]]=\@tmp;
		    $$word_id_np_ref++;
		}else{
		}
	    }
	}
	],
	[#Rule 20
		 'word', 2,
sub
#line 125 "lib/Alvis/NLPPlatform/ParseConstituents.yp"
{ $_[0]->YYErrok }
	]
],
                                  @_);
    bless($self,$class);
}

#line 128 "lib/Alvis/NLPPlatform/ParseConstituents.yp"




sub _Error {
        exists $_[0]->YYData->{ERRMSG}
    and do {
        print $_[0]->YYData->{ERRMSG};
        delete $_[0]->YYData->{ERRMSG};
        return;
    };
#    print "Syntax error...\n";
}

sub _Lexer {
    my($parser)=shift;


    $doc_hash = $parser->YYData->{DOC_HASH} or  return('',undef);
    $decal_phrase_idx = $parser->YYData->{DECAL_PHRASE_IDX} or  return('',undef);
    $word_id_np_ref = $parser->YYData->{WORD_ID_NP_REF} or  return('',undef);

    $tab_type_ref = $parser->YYData->{TAB_TYPE_REF};
    $tab_string_ref = $parser->YYData->{TAB_STRING_REF};

    # $lconst = $parser->YYData->{LCONST_REF};
    $nconst = $parser->YYData->{NCONST_REF};



( run in 0.481 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )