Treex::PML::Seq - sequence of PML values of various types
This class implements the data type 'sequence'. A sequence contains of zero or more elements (Treex::PML::Seq::Element), each consisting of a name and value. The ordering of elements in a sequence may be constrained by a regular-expression-like pattern operating on element names. Validation of a sequence against this constraint pattern is not automatic but can be performed at any time on demand.
NOTE: Don't call this constructor directly, use Treex::PML::Factory->createSeq() instead!
Create a new sequence (optionally populated with elements from a given
array_ref). Each element should be a Treex::PML::Element::Seq object. The
second optional argument is a regular expression constraint which can
be stored in the object and used later for validating content (see
validate() method below). The $reuse
argument is a boolean flag
indicating whether the passed array reference can be used directly (if
$reuse
is true) or copied (if $reuse
ise false).
Return a list of [ name, value ] pairs representing the sequence elements. If the optional $name argument is given, select only elements whose name is $name.
Like elements
without a name, only this method returns directly the
Treex::PML::List object associated with this sequence.
Return the regular expression constraint stored in the sequence object (if any).
Store a regular expression constraint in the sequence object. This expression can be used later to validate sequence content (see validate() method).
If no name is given, return a list of values of all elements of the sequence. If a name is given, return a list consisting of values of elements with the given name.
In array context, the returned value is a list, in scalar context the result is a Treex::PML::List object.
Return a list of names of all elements of the sequence. In array context, the returned value is a list, in scalar context the result is a Treex::PML::List object.
Return the element of the sequence on the position specified by a given index. Elements in the sequence are indexed as elements in Perl arrays, i.e. starting from $[, which defaults to 0 and nobody sane should ever want to change it.
Return the name of the element on a given position.
Return the value of the element on a given position.
If all element values are HASH-references, then it is possible to
store each element's name in its value under a given key (that is, to
delegate the name to the HASH value). The default value for key is
#name
. It is a fatal error to try to delegate names if some of the
values is not a HASH reference.
Check that content of the sequence satisfies a constraint specified
by means of a regular expression content_pattern
. If no content_pattern is
given, the one stored with the object is used (if any; otherwise undef
is returned).
Returns: 1 if the content satisfies the constraint, 0 otherwise.
Append a given name-value pair to the sequence.
Append a given Treex::PML::Seq::Element object to the sequence.
Prepend a given name-value pair to the sequence.
Unshift a given Treex::PML::Seq::Element object to the sequence.
Find and remove (all occurences) of a given Treex::PML::Seq::Element object in the sequence. Returns the number of elements removed.
Find and remove (all occurences) of a given Treex::PML::Seq::Element object in the sequence. Returns the number of elements removed.
Find and remove all elements with a given value. Returns the number of elements removed.
Search the sequence for a particular value and return the index of its first occurence in the sequence.
Note: Use $seq->elements_list->index_of($element) to search for a Treex::PML::Seq::Element.
Remove all values from the sequence.
This utility function converts a given sequence content pattern string into a Perl regular expression. The resulting expression matches a list of element 'tags', where a tag is an element name surrounded by < and >. For example, the content pattern 'A,#TEXT,(B+|C)*' translates roughly to '<A><\#TEXT>(?:(?:<B>)+(?:<C>))*' and matches (a substring of) each of the following strings:
'<A><#TEXT>' 'foo<A><#TEXT><B><B><C>bar' '<A><#TEXT><B><C><D>'
Copyright (C) 2006-2010 by Petr Pajas
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.