Treex::Core::Document - representation of a text and its linguistic analyses in the Treex framework


version 0.05222


A document consists of a sequence of bundles, mirroring a sequence of natural language sentences (typically, but not necessarily, originating from the same text). Attributes (attribute-value pairs) can be attached to a document as a whole.


Treex::Core::Document's instances have the following attributes:


Textual description of the file's content that is stored in the file.


The attributes can be accessed using semi-affordance accessors: getters have the same names as attributes, while setters start with 'set_'. For example by getter path() and setter set_path($path)



my $new_document = Treex::Core::Document->new;

creates a new empty document object.

my $new_document = Treex::Core::Document->new( { pmldoc => $pmldoc } );

creates a Treex::Core::Document instance from an already existing Treex::PML::Document instance

my $new_document = Treex::Core::Document->new( { filename => $filename } );

loads a Treex::Core::Document instance from a .treex file

Access to zones

Document zones are instances of Treex::Core::DocZone, parametrized by language code and possibly also by another free label called selector, whose purpose is to distinguish zones for the same language but from a different source.

my $zone = $doc->create_zone( $langcode, ?$selector );
my $zone = $doc->get_zone( $langcode, ?$selector );
my $zone = $doc->get_or_create_zone( $langcode, ?$selector );

Access to bundles

my @bundles = $document->get_bundles();

Returns the array of bundles contained in the document.

my $new_bundle = $document->create_bundle();

Creates a new empty bundle and appends it at the end of the document.

my $new_bundle = $document->new_bundle_before( $existing_bundle );

Creates a new empty bundle and inserts it in front of the existing bundle.

my $new_bundle = $document->new_bundle_after( $existing_bundle );

Creates a new empty bundle and inserts it after the existing bundle.

Node indexing

$document->index_node_by_id( $id, $node );

The node is added to the id2node hash table (as mentioned above, it is done automatically in $node->set_attr() if the attribute name is 'id'). When using undef in the place of the second argument, the entry for the given id is deleted from the hash.

my $node = $document->get_node_by_id( $id );

Return the node which has the value $id in its 'id' attribute, no matter to which tree and to which bundle in the given document the node belongs to.

It is prohibited in Treex for IDs to point outside of the current document. In rare cases where your data has such links, we recommend you to split the documents differently or hack it by dropping the problematic links.

$document->id_is_indexed( $id );

Return true if the given id is already present in the indexing table.


Return the array of all node identifiers indexed in the document.


my $filename = $doc->full_filename;

full filename without the extension


Zdeněk Žabokrtský <>

Martin Popel <>


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.