<<

NAME

Udapi::Core::Node - representation of a node in a dependency tree

SYNOPSIS

 # New nodes via constructor (used only in special cases)
 use Udapi::Core::Node;
 my $node = Udapi::Core::Node->new(
   form=>'dogs', lemma=>'dog', upos=>'NOUN', xpos=>'NNS',
   feats=>'Number=Plur', deprel='nubj', misc=>'SpaceAfter=No');

 # New nodes via create_child (the usual way)
 my $root = $bundle->create_tree($zone);
 my $node = $root->create_child(form=>'dogs', lemma=>'dog');
 my $child = $node->create_child(form=>'old', upos=>'ADJ');

 # Access to attributes
 my $lemma = $node->lemma;
 my ($deprel, $deps) = $node->get_attrs('deprel', 'deps');
 $child->set_lemma('old');

 # Access to containers and meta-info
 my $bundle   = $node->bundle;
 my $doc      = $node->document;
 my $zone     = $node->zone;    # e.g. en_gold
 my $address  = $node->address; # e.g. 123/en_gold#4

 # Access to topology
 my $root     = $node->root;
 my $boolean  = $node->is_root;
 my $parent   = $node->parent;
 my @children = $node->children;
 my @descs    = $node->descendants;
 my $first_ch = $node->children({first_only=>1});
 my $last_des = $node->descendants({last_only=>1});
 if (!$node->is_descendant_of($another_node)){
     $another_node->set_parent($node);
 }
 $child->remove(); # delete with all its descendants
 $child->remove({children=>'rehang_warn'});

 # Access to word order
 my $nth_token_in_tree = $node->ord;
 if ($node->precedes($another_node)){
     $node->shift_after_node($another_node);
 }
 $node->shift_before_subtree($another_node, {without_children=>1});
 $another_node = $node->next_node;
 $another_node = $node->prev_node;

DESCRIPTION

This class represents a Udapi node. Udapi trees (contained in bundles) are formed by nodes and edges. Attributes can be stored only in nodes. The (technical) root of the tree is of type Udapi::Core::Node::Root, but all the node's methods can be called also on root.

Construction

new

my $node = Udapi::Core::Node->new(%attributes);

Nodes can be created with the constructor new, but such nodes do not have any parent and are not part of any tree, so they should be first added to some tree using set_parent, otherwise some methods may not work as expected. The %attributes is a hash of attribute names and values. Possible attribute names are:

AUTHOR

Martin Popel <popel@ufal.mff.cuni.cz>

COPYRIGHT AND LICENSE

Copyright © 2016 by Institute of Formal and Applied Linguistics, Charles University in Prague

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

<<