DTA-CAB

 view release on metacpan or  search on metacpan

CAB/Analyzer.pm  view on Meta::CPAN

## DESCRIPTION: DTA::CAB::Analyzer: Methods: Analysis: Closure Utilities (optional)
=pod

=head2 Methods: Analysis: Closure Utilities (optional)

=over 4

=item analyzeClosure

 \&closure = $anl->analyzeClosure($which);

Optional utility for closure-based analysis.
Returns cached $anl-E<gt>{"_analyze${which}"} if present;
otherwise calls $anl-E<gt>getAnalyzeClosure($which) & caches result.

=item getAnalyzeClosure

 \&closure = $anl->getAnalyzeClosure($which);

Returns closure \&closure for analyzing data of type "$which"
(e.g. Word, Type, Token, Sentence, Document, ...).
Default implementation calls $anl-E<gt>getAnalyze"${which}"Closure() if
available, otherwise croak()s.

=item accessClosure

 $closure = $anl->accessClosure(\&codeRef,    %opts);
 $closure = $anl->accessClosure( $methodName, %opts);
 $closure = $anl->accessClosure( $codeString, %opts);

Returns accessor-closure $closure for $anl.
Passed argument can be one of the following:

=over 4

=item $codeRef

a CODE ref resolves to itself

=item $methodName

a method name resolves to $anl-E<gt>can($methodName)

=item $codeString

any other string resolves to 'sub { $codeString }';
which may reference the closure variable $anl

=back

Additional options for $codeString pseudo-accessors can be passed in %opts:

 pre => $prefix,     ##-- compiles as "${prefix}; sub {$code}"
 vars => \@vars,     ##-- compiles as 'my ('.join(',',@vars).'); '."sub {$code}"

=back

=cut

##----------------------------------------------------------------
## DESCRIPTION: DTA::CAB::Analyzer: Methods: Analysis: Closure Utilities: Macros
=pod

=head3 Methods: Analysis: Closure Utilities: Macros

In order to facilitate development of analyzer-local accessor code in string form,
the following "macros" are defined as exportable functions.  Their arguments and
return values are B<strings> suitable for inclusion in acccessor macros.  These
macros are exported by the tags ':access', ':child', and ':all'.

=over 4

=item _am_xlit

 PACKAGE::_am_xlit($tokvar='$_');

access-closure macro: get xlit or text for token $$tokvar;
evaluates to a string:
($$tokvar-E<gt>{xlit} ? $$tokvar-E<gt>{xlit}{latin1Text} : $$tokvar-E<gt>{text})

=item _am_lts

 PACKAGE::_am_lts($tokvar='$_');

access-closure macro for first LTS analysis of token $$tokvar;
evaluates to string:
($$tokvar-E<gt>{lts} && @{$$tokvar-E<gt>{lts}} ? $$tokvar-E<gt>{lts}[0]{hi} : $$tokvar-E<gt>{text})

=item _am_tt_list

 PACKAGE::_am_tt_list($ttvar='$_');

access-closure macro for a TT-style list of strings $$ttvar;
evaluates to a list: split(/\\t/,$$ttvar)

=item _am_tt_fst

 PACKAGE::_am_tt_fst($ttvar='$_');

(formerly mutliply defined in sub-packages as SUBPACKAGE::parseFstString())

access-closure macro for a single TT-style FST analysis $$ttvar;
evaluates to a FST-analysis hash {hi=E<gt>$hi,w=E<gt>$w,lo=E<gt>$lo,lemma=E<gt>$lemma}:

    (
     $$ttvar =~ /^(?:(.*?) \: )?(?:(.*?) \@ )?(.*?)(?: \<([\d\.\+\-eE]+)\>)?$/
     ? {(defined($1) ? (lo=>$1) : qw()), (defined($2) ? (lemma=>$2) : qw()), hi=>$3, w=>($4||0)}
     : {hi=>$$ttvar}
    )

=item _am_id_fst

 PACKAGE::_am_id_fst($tokvar='$_', $wvar='0');

access-closure macro for a identity FST analysis;
evaluates to a single fst analysis hash:
{hi=E<gt>_am_xlit($tokvar), w=E<gt>$$wvar}

=item _am_tt_fst_list

 PACKAGE::_am_tt_fst_list($ttvar='$_');

access-closure macro for a list of TT-style FST analyses $$ttvar;
evaluates to a list of fst analysis hashes:



( run in 1.350 second using v1.01-cache-2.11-cpan-98e64b0badf )