Lingua-YaTeA

 view release on metacpan or  search on metacpan

lib/Lingua/YaTeA/Tree.pm  view on Meta::CPAN

}



sub fillNodeLeaves
{
    my ($this) = @_;
    $this->getNodeSet->fillNodeLeaves($this->getIndexSet);
}

sub getIndexSet
{
    my ($this) = @_;
    return $this->{INDEX_SET};
}

sub getNodeSet
{
    my ($this) = @_;

#     print STDERR "gNS1\n";

    return $this->{NODE_SET};
}


sub setSimplifiedIndexSet
{
    my ($this,$original) = @_;
    $this->{SIMPLIFIED_INDEX_SET} = $original->copy;
}

sub copy
{
    my ($this) = @_;
    my $new = Lingua::YaTeA::Tree->new;
    if(defined $this->getNodeSet)
    {
	$new->{NODE_SET} = $this->getNodeSet->copy;
    	$new->{HEAD} = $new->setHead;
    }
    $new->{INDEX_SET} = $this->getIndexSet->copy;
    $new->{SIMPLIFIED_INDEX_SET} = $this->getSimplifiedIndexSet->copy;
    return $new;
}


sub getSimplifiedIndexSet
{
    my ($this) = @_;
    return $this->{SIMPLIFIED_INDEX_SET};
}


sub getRoot
{
    my ($this) = @_;
    return $this->getNodeSet->getRoot;
}

sub updateRoot
{
    my ($this) = @_;
    $this->getNodeSet->updateRoot;
}





sub setNodeSet
{
    my ($this,$node_set) = @_;
    $this->{NODE_SET} = $node_set;
}


sub addNodes
{
    my ($this,$node_set) = @_;
    $this->getNodeSet->addNodes($node_set);
   
}



sub print
{
    my ($this,$words_a,$fh) = @_;
    if(!defined $fh)
    {
	$fh = \*STDERR;
    }
    print $fh $this . "\n";
    print $fh "index set ";
    $this->getIndexSet->print($fh);
    print $fh "\n";
    if(defined $this->getSimplifiedIndexSet)
    {
	print $fh "simplified index set ";
	$this->getSimplifiedIndexSet->print($fh);
	print $fh "\n";
    }
    print $fh "node set : ";
    if(defined $this->getNodeSet)
    {
	$this->getNodeSet->printAllNodes($words_a,$fh);
    }
}


sub printParenthesised
{
    my ($this,$words_a,$fh) = @_;
   # print "(" . $this . ")";
    $this->getNodeSet->printParenthesised($words_a,$fh);
}


sub getHead
{

lib/Lingua/YaTeA/Tree.pm  view on Meta::CPAN

    my @contexts;
    my $place;
    my $above;
    my $below;
    my $tree_save = $this->copy;
    my $added_save = $added_node_set->copy;
    my $sub_index_set_save = $index_set->copy;
    my $added_index_set_save = $added_index_set->copy;
    my $depth = 0;
    if($mode =~ /INSERTION/)
    {
	if($mode =~ /REVERSED/)
	{
	    ($above,$place) =  $added_node_set->getRoot->searchLeaf($pivot,\$depth);
	    $below = $root;	    
	}
	else
	{
	    ($above,$place) = $root->searchLeaf($pivot,\$depth);
	    $below = $added_node_set->getRoot;
	}
	my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
	push @contexts, $context;
    }
    else
    {

	if($mode !~ /MIDDLE/)
	{
	    ($above,$place) = $added_node_set->getRoot->searchLeaf($pivot,\$depth);
	    $below = $root;
	    my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
	    push @contexts, $context;
	    if($root->{"LINKED_TO_ISLAND"} == 0) # conserver cette condion ?
	    {
		my $tree2 = $tree_save->copy;

		my $added2 = $added_save->copy;
		($above,$place) =   $tree2->getNodeSet->getNodeWithPivot($pivot);
		$below = $added2->searchRootNodeForLeaf($pivot);
		if (defined $below) { # Added by Thierry 02/03/2007
		    my $context2 = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$tree2, "INDEX_SET"=>$sub_index_set_save, "ADDED_NODE_SET"=>$added2, "ADDED_INDEX_SET"=>$added_index_set_save};
		    push @contexts, $context2;
		}
	    }
	}
	
	else
	{
	    ($above,$place) =  $added_node_set->getRoot->searchLeaf($pivot,\$depth);
	    $below = $this->getNodeSet->searchRootNodeForLeaf($pivot);
	    if (defined $below) { # Added by Thierry 02/03/2007
		my $context = {"ABOVE"=>$above, "PLACE"=>$place, "BELOW" => $below, "TREE"=>$this, "INDEX_SET"=>$index_set, "ADDED_NODE_SET"=>$added_node_set, "ADDED_INDEX_SET"=>$added_index_set};
		push @contexts, $context;
	    }
	}
    }
    return \@contexts;
}

sub updateIndexes
{
    my ($this,$phrase_index_set,$words_a) = @_;
    my $heads_h;
    my $index_set = Lingua::YaTeA::IndexSet->new;
    my $simplified_index_set = $phrase_index_set->copy;
    $this->getNodeSet->fillIndexSet($index_set);
    

    $heads_h = $this->getNodeSet->searchHeads($words_a);
    if ($simplified_index_set->simplifyWithSeveralPivots($index_set,$this->getNodeSet,$this,$heads_h) == -1 ) {return -1;}

    @{$this->getIndexSet->getIndexes} = @{$index_set->getIndexes};
    @{$this->getSimplifiedIndexSet->getIndexes} = @{$simplified_index_set->getIndexes};
}

1;

__END__

=head1 NAME

Lingua::YaTeA::Tree - Perl extension for ???

=head1 SYNOPSIS

  use Lingua::YaTeA::Tree;
  Lingua::YaTeA::Tree->();

=head1 DESCRIPTION


=head1 METHODS


=head2 new()


=head2 setHead()


=head2 setReliability()


=head2 fillNodeLeaves()


=head2 getIndexSet()


=head2 getNodeSet()


=head2 setSimplifiedIndexSet()


=head2 copy()


=head2 getSimplifiedIndexSet()



( run in 2.892 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )