| 1 | ## -*- Mode: CPerl -*- | ||
| 2 | ## File: DTA::CAB::Chain::Tweet.pm | ||
| 3 | ## Author: Bryan Jurish <moocow@cpan.org> | ||
| 4 | ## Description: robust analysis: tweet-munging chain | ||
| 5 | |||
| 6 | package DTA::CAB::Chain::Tweet; | ||
| 7 | use DTA::CAB::Datum ':all'; | ||
| 8 | use DTA::CAB::Chain::Multi; | ||
| 9 | use IO::File; | ||
| 10 | use Carp; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | |||
| 14 | ##============================================================================== | ||
| 15 | ## Constants | ||
| 16 | ##============================================================================== | ||
| 17 | our @ISA = qw(DTA::CAB::Chain::Multi); | ||
| 18 | |||
| 19 | ##-- HACK: just inherit from DTA::CAB::Chain::DTA for now | ||
| 20 | |||
| 21 | ##============================================================================== | ||
| 22 | ## Constructors etc. | ||
| 23 | ##============================================================================== | ||
| 24 | |||
| 25 | ## $obj = CLASS_OR_OBJ->new(%args) | ||
| 26 | ## + object structure: HASH | ||
| 27 | sub new { | ||
| 28 | my $that = shift; | ||
| 29 | return $that->SUPER::new( | ||
| 30 | ##-- analyzers | ||
| 31 | xlit => DTA::CAB::Analyzer::Unicruft->new(), | ||
| 32 | lts => DTA::CAB::Analyzer::LTS->new(), | ||
| 33 | ## | ||
| 34 | morph => DTA::CAB::Analyzer::Morph->new(), | ||
| 35 | #mlatin=> DTA::CAB::Analyzer::Morph::Latin->new(), | ||
| 36 | #msafe => DTA::CAB::Analyzer::MorphSafe->new(), | ||
| 37 | rw => DTA::CAB::Analyzer::Rewrite->new(), | ||
| 38 | #rwsub => DTA::CAB::Analyzer::RewriteSub->new(), | ||
| 39 | ## | ||
| 40 | eqpho => DTA::CAB::Analyzer::EqPho->new(), ##-- default (FST) | ||
| 41 | #eqrw => DTA::CAB::Analyzer::EqRW->new(), ##-- default (FST) | ||
| 42 | ## | ||
| 43 | ## | ||
| 44 | dmoot => DTA::CAB::Analyzer::Moot::DynLex->new(), ##-- moot n-gram disambiguator | ||
| 45 | #moot => DTA::CAB::Analyzer::Moot->new(), ##-- moot tagger | ||
| 46 | |||
| 47 | ##-- user args | ||
| 48 | @_, | ||
| 49 | |||
| 50 | ##-- overrides | ||
| 51 | chains => undef, ##-- see setupChains() method | ||
| 52 | chain => undef, ##-- see setupChains() method | ||
| 53 | ); | ||
| 54 | |||
| 55 | } | ||
| 56 | |||
| 57 | ##============================================================================== | ||
| 58 | ## Methods: Chain selection | ||
| 59 | ##============================================================================== | ||
| 60 | |||
| 61 | ## $ach = $ach->setupChains() | ||
| 62 | ## + setup default named sub-chains in $ach->{chains} | ||
| 63 | ## + override | ||
| 64 | sub setupChains { | ||
| 65 | my $ach = shift; | ||
| 66 | my @akeys = grep {UNIVERSAL::isa($ach->{$_},'DTA::CAB::Analyzer')} keys(%$ach); | ||
| 67 | my $chains = $ach->{chains} = | ||
| 68 | { | ||
| 69 | (map {("sub.$_"=>[$ach->{$_}])} @akeys), ##-- sub.xlit, sub.lts, ... | ||
| 70 | ## | ||
| 71 | 'default.xlit' =>[@$ach{qw(xlit)}], | ||
| 72 | 'default.lts' =>[@$ach{qw(xlit lts)}], | ||
| 73 | 'default.morph' =>[@$ach{qw(xlit morph)}], | ||
| 74 | 'default.rw' =>[@$ach{qw(xlit rw)}], | ||
| 75 | 'default.base' =>[@$ach{qw(xlit lts morph)}], | ||
| 76 | 'default.type' =>[@$ach{qw(xlit lts morph rw)}], | ||
| 77 | ## | ||
| 78 | 'noexpand' =>[@$ach{qw(xlit lts morph rw)}], | ||
| 79 | 'expand' =>[@$ach{qw(xlit lts morph rw eqpho)}], | ||
| 80 | 'default' =>[@$ach{qw(xlit lts morph rw eqpho dmoot)}], | ||
| 81 | 'all' =>[@$ach{qw(xlit lts morph rw eqpho dmoot)}], | ||
| 82 | }; | ||
| 83 | |||
| 84 | ##-- sanitize chains | ||
| 85 | foreach (values %{$ach->{chains}}) { | ||
| 86 | @$_ = grep {ref($_)} @$_; | ||
| 87 | } | ||
| 88 | |||
| 89 | ##-- set default chain | ||
| 90 | $ach->{chain} = $ach->{chains}{default}; | ||
| 91 | |||
| 92 | ##-- force default labels | ||
| 93 | $ach->{$_}{label} = $_ foreach (grep {UNIVERSAL::isa($ach->{$_},'DTA::CAB::Analyzer')} keys(%$ach)); | ||
| 94 | return $ach; | ||
| 95 | } | ||
| 96 | |||
| 97 | ##============================================================================== | ||
| 98 | ## Analysis: Utilities | ||
| 99 | ##============================================================================== | ||
| 100 | |||
| 101 | BEGIN { *_parseAnalysis = \&DTA::CAB::Analyzer::Moot::parseAnalysis; } | ||
| 102 | |||
| 103 | ## @analyses = CLASS::dmootTagsGet($tok) | ||
| 104 | ## + for 'dmoot' analyzer (DTA::CAB::Analyzer::Moot::DynLex) 'analyzeTagsGet' pseudo-accessor | ||
| 105 | ## + utility for disambiguation using @$tok{qw(text xlit eqpho rw)} fields by default | ||
| 106 | ## + returns only $tok->{xlit} field if "$tok->{toktyp}" is true | ||
| 107 | sub dmootTagsGet { | ||
| 108 | return | ||
| 109 | ($_[0]{xlit} ? (_parseAnalysis($_[0]{xlit}{latin1Text},src=>'xlit')) : _parseAnalysis($_[0]{text},src=>'text')) | ||
| 110 | if ($_[0]{toktyp}); | ||
| 111 | return | ||
| 112 | (($_[0]{xlit} ? (_parseAnalysis($_[0]{xlit}{latin1Text},src=>'xlit')) : _parseAnalysis($_[0]{text},src=>'text')), | ||
| 113 | ($_[0]{eqpho} ? (map {_parseAnalysis($_,src=>'eqpho')} @{$_[0]{eqpho}}) : qw()), | ||
| 114 | ($_[0]{rw} ? (map {_parseAnalysis($_,src=>'rw')} @{$_[0]{rw}}) : qw()), | ||
| 115 | ); | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | 1; ##-- be happy | ||
| 120 | |||
| 121 | __END__ |