NAME

Treex::Core::Node::Ordered

VERSION

version 0.06441

DESCRIPTION

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

ATTRIBUTES

ord

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

METHODS

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".

$node->shift_after_node($reference_node);

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

$node->shift_after_subtree($reference_node);

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

$node->shift_before_node($reference_node);

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

$node->shift_before_subtree($reference_node);

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

AUTHOR

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

COPYRIGHT AND LICENSE

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.