NAME
Treex::Core::Scenario - a larger Treex processing unit, composed of blocks
VERSION
version 2.20150928
SYNOPSIS
use Treex::Core;
my $doc1, $doc2;
my $scenario = Treex::Core::Scenario->new(from_file => 'myscenario.scen' );
$scenario->run;
$scenario = Treex::Core::Scenario->new(from_string => 'W2A::EN::Segment language=en');
$scenario->start();
$scenario->apply_to_documents($doc1, $doc2);
$scenario->end();
DESCRIPTION
A Treex scenario consists of a sequence of (possibly parametrized) Treex blocks.
Scenarios can be described by a simple textual format, which is either passed directly to the scenario construction, or is contained in a text file whose name is passed.
The string description of scenarios looks as follows.
1) It contains a list of block names from which their 'Treex::Block::
' prefixes were removed.
2) The block names are separated by one or more white spaces.
3) The block names are listed in the same order in which they should be applied on data.
4) For each block, there can be one or more parameters specified, using the attribute=value
form.
5) Comments start with '#
' and end with the nearest newline character.
Scenario example:
# morphological analysis of an English text
Util::SetGlobal language=en selector=src
Read::Text
W2A::ResegmentSentences
W2A::EN::Tokenize
W2A::EN::NormalizeForms
W2A::EN::FixTokenization
W2A::EN::TagMorce
METHODS
Constructor
- my $scenario = Treex::Core::Scenario->new(from_string => 'W2A::Tokenize language=en W2A::Lemmatize' );
-
Constructor parameter
from_string
specifies the names of blocks which are to be executed (in the specified order) when the scenario is applied on a Treex::Core::Document object. - my $scenario = Treex::Core::Scenario->new(from_file => 'myscenario.scen' );
-
The scenario description is loaded from the file.
Running the scenario
- $scenario->run();
-
Run the scenario. One of the blocks (usually the first one) must be the document reader (see Treex::Core::DocumentReader) that produces the documents on which this scenario is applied.
- $scenario->apply_to_documents($treex_doc);
-
Apply this scenario to a Treex::Core::Document instance obtained from elsewhere. Please note that
start()
must be called before the first call to this method andend()
after the last call to this method.The scenario does not need to contain a document reader if documents are given explicitly.
- $scenario->start();
-
Apply
process_start()
to all blocks in the scenario. This is called automatically byrun()
, but must be called beforeapply_to_documents()
. - $scenario->end();
-
Apply
process_end()
to all blocks in the scenario. This is called automatically byrun()
, but must be called after calls toapply_to_documents()
.
Internal methods for loading scenarios
- _load_scenario_file($filename)
-
loads a scenario description from a file
- parse_scenario_string
-
parses a textual description of a scenario
- construct_scenario_string
-
constructs a scenario textual description from an existing scenario instance accepts named parameter multiline - when set, blocks are separated by newline instead of space
- load_blocks
-
use blocks and call their constructors can be used for preloading blocks for e.g. server applications when running scenario blocks are loaded automatically
- init
-
do all initialization so after this method scenario is ready to run currently just load blocks
- restart
-
resets the document reader, in future it will rebuild reloaded blocks
SEE ALSO
Treex::Core::Block Treex::Core
AUTHORS
Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>
Martin Popel <popel@ufal.mff.cuni.cz>
David Mareček <marecek@ufal.mff.cuni.cz>
Tomáš Kraut <kraut@ufal.mff.cuni.cz>
Martin Majliš <majlis@ufal.mff.cuni.cz>
Ondřej Dušek <odusek@ufal.mff.cuni.cz>
COPYRIGHT AND LICENSE
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.