| 1 | ## -*- Mode: CPerl -*- | ||
| 2 | ## | ||
| 3 | ## File: DTA::CAB::Analyzer::Alias.pm | ||
| 4 | ## Author: Bryan Jurish <moocow@uni-potsdam.de> | ||
| 5 | ## Description: analyzer alias | ||
| 6 | |||
| 7 | ##============================================================================== | ||
| 8 | ## Package: Analyzer::Morph | ||
| 9 | ##============================================================================== | ||
| 10 | package DTA::CAB::Analyzer::Alias; | ||
| 11 | use DTA::CAB::Analyzer; | ||
| 12 | use Carp; | ||
| 13 | use strict; | ||
| 14 | our @ISA = qw(DTA::CAB::Analyzer); | ||
| 15 | |||
| 16 | ## $obj = CLASS_OR_OBJ->new(%args) | ||
| 17 | ## + object structure: see DTA::CAB::Analyzer | ||
| 18 | ## + new keys | ||
| 19 | ## a => $subAnalyzer, ##-- aliased sub-analyzer (workhorse) | ||
| 20 | sub new { | ||
| 21 | my $that = shift; | ||
| 22 | my $anl = $that->SUPER::new( | ||
| 23 | ##-- overrides | ||
| 24 | #tolower => 1, | ||
| 25 | |||
| 26 | ##-- analysis selection | ||
| 27 | label => undef, | ||
| 28 | a => undef, | ||
| 29 | |||
| 30 | ##-- user args | ||
| 31 | @_ | ||
| 32 | ); | ||
| 33 | return $aut; | ||
| 34 | } | ||
| 35 | |||
| 36 | ## $label = $anl->defaultLabel() | ||
| 37 | ## + default label for this class | ||
| 38 | ## + default is final component of perl class-name | ||
| 39 | sub defaultLabel { | ||
| 40 | my $anl = shift; | ||
| 41 | my $lab = $anl->SUPER::defaultLabel(); | ||
| 42 | $lab .= "->".$anl->{a}{label} if ($anl->{a}); | ||
| 43 | return $lab; | ||
| 44 | } | ||
| 45 | |||
| 46 | ## $bool = $anl->ensureLoaded() | ||
| 47 | ## + ensures analysis data is loaded from default files | ||
| 48 | ## + default version always returns true | ||
| 49 | sub ensureLoaded { | ||
| 50 | return $_[0]{a}->ensureLoaded() if ($_[0]{a}); | ||
| 51 | return 1; | ||
| 52 | } | ||
| 53 | |||
| 54 | ## @keys = $class_or_obj->noSaveKeys() | ||
| 55 | ## + returns list of keys not to be saved | ||
| 56 | ## + default just greps for CODE-refs | ||
| 57 | sub noSaveKeys { | ||
| 58 | my $anl = shift; | ||
| 59 | return ($anl->SUPER::noSaveKeys(),'a'); | ||
| 60 | } | ||
| 61 | |||
| 62 | ## @keys = $class_or_obj->noSaveBinKeys() | ||
| 63 | ## + returns list of keys not to be saved for binary mode | ||
| 64 | ## + default just greps for CODE-refs | ||
| 65 | sub noSaveBinKeys { | ||
| 66 | my $anl = shift; | ||
| 67 | return ($anl->SUPER::noSaveBinKeys(),'a'); | ||
| 68 | } | ||
| 69 | |||
| 70 | ##------------------------------------------------------------------------ | ||
| 71 | ## Methods: Analysis: v1.x: Utils | ||
| 72 | |||
| 73 | ## $bool = $anl->canAnalyze(); | ||
| 74 | ## + returns true iff analyzer can perform its function (e.g. data is loaded & non-empty) | ||
| 75 | ## + default implementation always returns true | ||
| 76 | ## + override calls $anl->{a}->canAnalyze | ||
| 77 | sub canAnalyze { | ||
| 78 | return $_[0]{a} ? $_[0]{a}->canAnalyze : 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | ## $bool = $anl->doAnalyze(\%opts, $name) | ||
| 82 | ## + alias for $anl->can("analyze${name}") && (!exists($opts{"doAnalyze${name}"}) || $opts{"doAnalyze${name}"}) | ||
| 83 | ## + inherited from Analyzer | ||
| 84 | |||
| 85 | ## $bool = $anl->enabled(\%opts) | ||
| 86 | ## + returns true if analyzer SHOULD operate, acording to %opts | ||
| 87 | ## + default returns: | ||
| 88 | ## (!defined($anl->{enabled}) || $anl->{enabled}) ##-- globally enabled | ||
| 89 | ## && | ||
| 90 | ## (!$opts || !defined($opts{"${lab}_enabled"} || $opts{"${lab}_enabled"}) ##-- ... and locally enabled | ||
| 91 | ## + inherited from Analyzer | ||
| 92 | |||
| 93 | |||
| 94 | ##------------------------------------------------------------------------ | ||
| 95 | ## Methods: Analysis: v1.x: API | ||
| 96 | |||
| 97 | ## $val = $anl->analyzeAnything($methodName,$defaultReturnVal,\%opts,\@subMethodArgs) | ||
| 98 | ## + wrapper for Analyzer::analyzeXYZ() methods | ||
| 99 | sub analyzeAnything { | ||
| 100 | my ($anl,$method,$x,$opts,$args) = @_; | ||
| 101 | return $x if (!$anl->{a} || !$anl->enabled($opts)); | ||
| 102 | return $anl->{a}->can($method)->(@$args); | ||
| 103 | } | ||
| 104 | |||
| 105 | ## $doc = $anl->analyzeDocument($doc,\%opts) | ||
| 106 | sub analyzeDocument { return $_[0]->analyzeAnything('analyzeDocument',@_[1,2],[@_[1..$#_]]); } | ||
| 107 | |||
| 108 | ## $doc = $anl->analyzeTypes($doc,\%types,\%opts) | ||
| 109 | sub analyzeTypes { return $_[0]->analyzeAnything('analyzeTypes',@_[1,3],[@_[1..$#_]]); } | ||
| 110 | |||
| 111 | ## $doc = $anl->analyzeSentences($doc,\%opts) | ||
| 112 | sub analyzeSentences { return $_[0]->analyzeAnything('analyzeSentences',@_[1,2],[@_[1..$#_]]); } | ||
| 113 | |||
| 114 | ## $doc = $anl->analyzeLocal($doc,\%opts) | ||
| 115 | sub analyzeLocal { return $_[0]->analyzeAnything('analyzeLocal',@_[1,2],[@_[1..$#_]]); } | ||
| 116 | |||
| 117 | ## $doc = $anl->analyzeClean($doc,\%opts) | ||
| 118 | sub analyzClean { return $_[0]->analyzeClean('analyzeClean',@_[1,2],[@_[1..$#_]]); } | ||
| 119 | |||
| 120 | |||
| 121 | 1; ##-- be happy | ||
| 122 | |||
| 123 | __END__ |