Treex::Core::Node - smallest unit that holds information in Treex
version 2.20160630
This class represents a Treex node. Treex trees (contained in bundles) are formed by nodes and edges. Attributes can be attached only to nodes. Edge's attributes must be stored as the lower node's attributes. Tree's attributes must be stored as attributes of the root node.
Creates a new node as a child of an existing node. Some of its attribute can be filled. Direct calls of node constructors (->new) should be avoided.
->new
Returns the Treex::Core::Bundle object in which the node's tree is contained.
Returns the Treex::Core::Document object in which the node's tree is contained.
Return the layer of this node (a, t, n or p).
Return the zone (Treex::Core::BundleZone) to which this node (and the whole tree) belongs.
shortcut for $lang_code = $node->get_zone()->language
$lang_code = $node->get_zone()->language
shortcut for $selector = $node->get_zone()->selector
$selector = $node->get_zone()->selector
Returns the value of the node attribute of the given name.
Sets the given attribute of the node with the given value. If the attribute name is id, then the document's indexing table is updated. If value of the type List is to be filled, then $value must be a reference to the array of values.
id
List
$value
If value of the given attribute is reference (or list of references), it returns the appropriate node (or a reference to the list of nodes).
Sets the given attribute with id (list of ids) of the given node (list of nodes).
If the given attribute is list, the given value is appended to it.
Get more attributes at once. If the last argument is {undefs=>$value}, all undefs are substituted by a $value (typically the value is an empty string).
{undefs=>$value}
Returns the parent node, or undef if there is none (if $node itself is the root)
undef
$node
Makes $node a child of $parent_node.
$parent_node
Deletes a node. Node identifier is removed from the document indexing table. The removed node cannot be further used.
Optional argument children in $arg_ref can specify what to do with children (and all descendants, i.e. the subtree rooted by the given node) if present: remove, remove_warn, rehang, rehang_warn. The default is remove -- remove recursively. rehang means reattach the children of $node to the parent of $node. The _warn variants will in addition produce a warning.
children
$arg_ref
remove
remove_warn
rehang
rehang_warn
_warn
Returns the root of the node's tree.
Returns true if the node has no parent.
true
Returns true if the node has no children.
Tests whether $node1 is among transitive descendants of $node2;
$node1
$node2
Next three methods (for access to children / descendants / siblings) have an optional argument $arg_ref for specifying switches. By adding some switches, you can modify the behavior of these methods. See "Switches" for examples.
Returns an array of child nodes.
Returns an array of descendant nodes ('transitive children').
Returns an array of nodes sharing the parent with the current node.
Currently there are 6 switches:
ordered
preceding_only, following_only
first_only, last_only
add_self
Names of variables in the examples suppose a language with left-to-right script.
my @ordered_descendants = $node->get_descendants({ordered=>1}); my @self_and_left_children = $node->get_children({preceding_only=>1, add_self=>1}); my @ordered_self_and_children = $node->get_children({ordered=>1, add_self=>1}); my $leftmost_child = $node->get_children({first_only=>1}); my @ordered_siblings = $node->get_siblings({ordered=>1}); my $left_neighbor = $node->get_siblings({preceding_only=>1, last_only=>1}); my $right_neighbor = $node->get_siblings({following_only=>1, first_only=>1}); my $leftmost_sibling_or_self = $node->get_siblings({add_self=>1, first_only=>1});
first_only and last_only switches makes the method return just one item - a scalar, even if combined with the add_self switch.
first_only
last_only
Specifying (first|last|preceding|following)_only implies ordered, so explicit addition of ordered gives a warning.
(first|last|preceding|following)_only
Specifying both preceding_only and following_only gives an error (same for combining first_only and last_only).
preceding_only
following_only
There are shortcuts for comfort of those who use left-to-right scripts:
Returns the rightmost node from the set of left siblings (the nearest left sibling). Actually, this is shortcut for $node->get_siblings({preceding_only=>1, last_only=>1}).
$node->get_siblings({preceding_only=>1, last_only=>1})
Returns the leftmost node from the set of right siblings (the nearest right sibling). Actually, this is shortcut for $node->get_siblings({following_only=>1, first_only=>1}).
$node->get_siblings({following_only=>1, first_only=>1})
If a node has no PML type, then its type is detected (according to the node's location) and filled by the PML interface.
Returns an array of nodes referencing this node with the given reference type (e.g. 'alignment', 'a/lex.rf' etc.).
Generate new (= so far unindexed) identifier (to be used when creating new nodes). The new identifier is derived from the identifier of the root ($node->root), by adding suffix x1 (or x2, if ...x1 has already been indexed, etc.) to the root's id.
$node->root
x1
x2
...x1
Return the depth of the node. The root has depth = 0, its children have depth = 1 etc.
Return the node address, i.e. file name and node's position within the file, similarly to TrEd's FPosition() (but the value is only returned, not printed).
FPosition()
This is the internal implementation of overloaded == operator, which checks whether $node == $another_node (the object instance must be identical).
==
$node == $another_node
This is the internal implementation of overloaded stringification, so you can use e.g. print "There is a node $node.". It returns the id ($node-id>), but the behavior may be overridden in subclasses. See overload pragma for details about overloading operators in Perl.
print "There is a node $node."
$node-
Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>
Martin Popel <popel@ufal.mff.cuni.cz>
David Mareček <marecek@ufal.mff.cuni.cz>
Daniel Zeman <zeman@ufal.mff.cuni.cz>
Ondřej Dušek <odusek@ufal.mff.cuni.cz>
Copyright © 2011-2012 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.
To install Treex::Core, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Treex::Core
CPAN shell
perl -MCPAN -e shell install Treex::Core
For more information on module installation, please visit the detailed CPAN module installation guide.