| 1 | ## -*- Mode: CPerl -*- | ||
| 2 | ## | ||
| 3 | ## File: DTA::CAB::Analyzer::DTAMapClass.pm | ||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||
| 5 | ## Description: post-processing for DTA chain: mapping class | ||
| 6 | ## + sets $tok->{mapclass} | ||
| 7 | |||
| 8 | package DTA::CAB::Analyzer::DTAMapClass; | ||
| 9 | use DTA::CAB::Analyzer ':child'; | ||
| 10 | use Carp; | ||
| 11 | use strict; | ||
| 12 | our @ISA = qw(DTA::CAB::Analyzer); | ||
| 13 | |||
| 14 | ##====================================================================== | ||
| 15 | ## Methods | ||
| 16 | |||
| 17 | ## $obj = CLASS_OR_OBJ->new(%args) | ||
| 18 | ## + object structure, %args: | ||
| 19 | ## mootLabel => $label, ##-- label for Moot tagger object (default='moot') | ||
| 20 | ## lz => $lemmatizer, ##-- DTA::CAB::Analyzer::Lemmatizer sub-object | ||
| 21 | sub new { | ||
| 22 | my $that = shift; | ||
| 23 | my $asub = $that->SUPER::new( | ||
| 24 | ##-- analysis selection | ||
| 25 | label => 'mapclass', | ||
| 26 | xyTags => {map {($_=>undef)} qw(XY FM NE), '@UNKNOWN'}, ##-- if these tags are assigned, use literal text and not dmoot normalization | ||
| 27 | |||
| 28 | ##-- user args | ||
| 29 | @_ | ||
| 30 | ); | ||
| 31 | return $asub; | ||
| 32 | } | ||
| 33 | |||
| 34 | ## $bool = $anl->doAnalyze(\%opts, $name) | ||
| 35 | ## + override: only allow analyzeSentences() | ||
| 36 | sub doAnalyze { | ||
| 37 | my $anl = shift; | ||
| 38 | return 0 if (defined($_[1]) && $_[1] ne 'Sentences'); | ||
| 39 | return $anl->SUPER::doAnalyze(@_); | ||
| 40 | } | ||
| 41 | |||
| 42 | ## $doc = $anl->Sentences($doc,\%opts) | ||
| 43 | ## + post-processing for 'moot' object | ||
| 44 | sub analyzeSentences { | ||
| 45 | my ($asub,$doc,$opts) = @_; | ||
| 46 | return $doc if (!$asub->enabled($opts)); | ||
| 47 | |||
| 48 | ##-- common variables | ||
| 49 | my $label = $asub->{label}; | ||
| 50 | my $xytags = $asub->{xyTags}; | ||
| 51 | |||
| 52 | my ($old,$new,$xlit, $moota,$mootxy); | ||
| 53 | foreach (map {@{$_->{tokens}}} @{$doc->{body}}) { | ||
| 54 | $old = $_->{text}; | ||
| 55 | $new = $_->{moot} ? $_->{moot}{word} : ($_->{dmoot} ? $_->{dmoot}{tag} : $xlit); | ||
| 56 | $xlit = $_->{xlit} ? $_->{xlit}{latin1Text} : $old; | ||
| 57 | if ($_->{moot}) { | ||
| 58 | $moota = $_->{moot}{analyses} && @{$_->{moot}{analyses}}; | ||
| 59 | $mootxy = exists($xytags->{$_->{moot}{tag}}); | ||
| 60 | } else { | ||
| 61 | ($moota,$mootxy) = (undef,1); | ||
| 62 | } | ||
| 63 | |||
| 64 | $_->{$label} = | ||
| 65 | join(",", | ||
| 66 | ($_->{exlex} ? '+' : '-').'exlex', | ||
| 67 | ($new eq $old ? '+' : '-').'id', | ||
| 68 | ($new eq $xlit ? '+' : '-').'xid', | ||
| 69 | ($_->{msafe} ? '+' : '-').'msafe', | ||
| 70 | ($moota ? '+' : '-').'moota', | ||
| 71 | ($mootxy ? '+' : '-').'mootxy', | ||
| 72 | ); | ||
| 73 | } | ||
| 74 | |||
| 75 | ##-- return | ||
| 76 | return $doc; | ||
| 77 | } | ||
| 78 | |||
| 79 | 1; ##-- be happy | ||
| 80 | |||
| 81 | __END__ |