The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Treex::Core::Phrase::BaseNTerm

VERSION

version 2.20151216

DESCRIPTION

BaseNTerm is an abstract class that defines the basic interface of nonterminal phrases. The general nonterminal phrase, NTerm, is derived from BaseNTerm. So are some special cases of nonterminals, such as PP. (They cannot be derived from NTerm because they implement certain parts of the interface differently.)

See also Treex::Core::Phrase and Treex::Core::Phrase::NTerm.

ATTRIBUTES

_dependents_ref

Reference to array of sub-Phrases (children) of this phrase that do not belong to the core of the phrase. By default the core contains only the head child. However, some specialized subclasses may define a larger core where two or more children have a special status, but only one of them can be the head.

dead

Most non-terminal phrases cannot exist without children. If we want to change the class of a non-terminal phrase, we construct an object of the new class and move the children there from the old one. But the old object will not be physically destroyed until it gets out of scope. So we will mark it as “dead”. If anyone tries to use the dead object, an exception will be thrown.

METHODS

A sub-Phrase of this phrase that is at the moment considered the head phrase (in the sense of dependency syntax). A general NTerm phrase just has a head attribute. Special cases of nonterminals may have multiple children with special behavior, and they may choose which one of these children shall be head under the current annotation style.

dependents

Returns the list of dependents of the phrase. The only difference from the getter _dependents_ref() is that the getter returns a reference to the array of dependents, while this method returns a list of dependents. Hence this method is more similar to the other methods that return lists of children.

nonhead_children

Returns the list of non-head children of the phrase. By default these are the dependents. However, in special nonterminal phrases there may be children that are neither head nor dependents.

core_children

Returns the list of the children of the phrase that are not dependents. By default this is just the head child. However, in specialized nonterminal phrases there may be other children that have a special status but are not the current head.

children

Returns the list of all children of the phrase, i.e. core children and dependents.

order_phrases

Sorts a list of phrases according to the word order of their head nodes. All methods that return lists of children (dependents(), nonhead_children(), core_children(), children()) can be asked to sort the list using this method. The following calling styles are possible:

  my @ordered_children = $phrase->children({'ordered' => 1});
  my @ordered_children = $phrase->children('ordered' => 1);
  my @ordered_children = $phrase->children('ordered');
deprel

Returns the type of the dependency relation of the phrase to the governing phrase. A general nonterminal phrase has the same deprel as its head child.

set_deprel

Sets a new type of the dependency relation of the phrase to the governing phrase. For nonterminal phrases the label is propagated to one (or several) of their children. It is not propagated to the underlying dependency tree (the project_dependencies() method would have to be called to achieve that).

replace_child
  $nonterminal->replace_child ($old_child, $new_child);

Replaces a child by another phrase. This method will work with any child, including the core children. The core children cannot be undefined but if we immediately replace them by a new child, the phrase will remain valid.

replace_core_child

Same as replace_child() but used with core children only. If we know that we are replacing a core child, it is more efficient to call directly this method. If we do not know what type of child we have, we can call the more general replace_child() and it will decide.

BaseNTerm::replace_core_child() is an abstract method that must be defined in every derived class.

detach_children_and_die
  my $parent = $phrase->parent();
  my $replacement = new Treex::Core::Phrase::PP (...);
  my @children = $phrase->detach_children_and_die();
  $parent->replace_child ($phrase, $replacement);

Detaches all children (including core children) and then marks itself as dead so that it cannot be used any more. This method should be called when we want to replace a non-terminal phrase by a new phrase of a different class. The method will not detach the dying phrase from its parent! That could kill the parent too (if the dying phrase is a core child) but we probably want the parent to survive and to replace the dying child by a new phrase we create. However, it is the caller's responsibility to modify the parent immediately.

project_dependencies

Recursively projects dependencies between the head and the dependents back to the underlying dependency structure.

as_string

Returns a textual representation of the phrase and all subphrases. Useful for debugging.

AUTHORS

Daniel Zeman <zeman@ufal.mff.cuni.cz>

COPYRIGHT AND LICENSE

Copyright © 2013, 2015 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.