NAME
Treex::Core::Node::Ordered
VERSION
version 2.20150928
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. - my @nodes_in_between = $node->get_nodes_between($other_node);
-
Return nodes that lie between
$node
and$other_node
, ordered, exclusive. (The returned array may be empty.)$node
and$other_node
can be given in any order, i.e. the result of$node->get_nodes_between($other_node)
is the same as the result of$other_node->get_nodes_between($node)
.
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.
Nonprojectivity
- 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.
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.