View on
Zdeněk Žabokrtský > Treex-Core-0.08399 > Treex::Core::Node::Ordered



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.08399   Source   Latest Release: Treex-Core-2.20160630




version 0.08399


Moose role for nodes which can/should be ordered by the attribute ord (usually following the word order).



The ordering attribute, ordinal number of a node. The ordering should be without gaps, so

    print join ' ', map {$_->ord} $root->get_descendants({ordered=>1});
    # should print
    # 1 2 3 ... number_of_descendants


Access to nodes ordering

my $boolean = $node->precedes($another_node);

Does this node precede $another_node?

my $following_node = $node->get_next_node();

Return the closest following node (according to the ordering attribute) or undef if $node is the last one in the tree.

my $preceding_node = $node->get_prev_node();

Return the closest preceding node (according to the ordering attribute) or undef if $node is the first one in the tree.

Reordering nodes

Next four methods for changing the order of nodes (the word order defined by the attribute ord) have an optional argument $arg_ref for specifying switches. So far there is only one switch - without_children which is by default set to 0. It means that the default behavior is to shift the node with all its descendants. Only if you want to leave the position of the descendants unchanged and shift just the node, use e.g.

 $node->shift_after_node($reference_node, {without_children=>1});

Shifting involves only changing the ordering attribute (ord) of nodes. There is no rehanging (changing parents). The node which is going to be shifted must be already added to the tree and the reference node must be in the same tree.

For languages with left-to-right script: after means "to the right of" and before means "to the left of".


Shifts (changes the ord of) the node just behind the reference node.


Shifts (changes the ord of) the node behind the subtree of the reference node.


Shifts (changes the ord of) the node just in front of the reference node.


Shifts (changes the ord of) the node in front of the subtree of the reference node.


my $nonproj = $node->is_nonprojective();

Return 1 if the node is attached to its parent nonprojectively, i.e. there is at least one node between this node and its parent that is not descendant of the parent. Return 0 otherwise.


Martin Popel <>


Copyright © 2011 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.

syntax highlighting: