Alvis-NLPPlatform

 view release on metacpan or  search on metacpan

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

	    # 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};

    $word_count=$$word_id_np_ref;

#     $parser->YYData->{INPUT}
#     or $parser->YYData->{INPUT} = "[PP of [NP two transcription factors factors NP] PP]\n"
#     or  return('',undef);
#      $parser->YYData->{INPUT} = $parser->YYData->{CONSTITUENT_STRING};
#  or  return('',undef);

#     chomp $parser->YYData->{INPUT};
#     chop $parser->YYData->{INPUT};
#     print STDERR $parser->YYData->{INPUT};
#     print STDERR ";;\n";

#     print STDERR "==>";
#     print STDERR $parser->YYData->{CONSTITUENT_STRING};
#     print STDERR "\n";

#      print STDERR "$lconst : $$nconst\n";

    $parser->YYData->{CONSTITUENT_STRING}=~s/^[ \t]*#.*//;
    $parser->YYData->{CONSTITUENT_STRING}=~s/^[ \t]*//;
    my $open = '\[([A-Z]+)';
    my $close = '([A-Z]+)\]';
    my $word = '([^\s\]\[]+)';

    for ($parser->YYData->{CONSTITUENT_STRING}) {
        s/^$open// and return ('OPEN', $1);
        s/^$close// and return ('CLOSE', $1);
	s/^$word// and return('WORD', $1);



( run in 1.271 second using v1.01-cache-2.11-cpan-39bf76dae61 )