| 1 | ## -*- Mode: CPerl -*- | ||
| 2 | ## | ||
| 3 | ## File: DTA::CAB::Analyzer::Dict::JsonCDB.pm | ||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||
| 5 | ## Description: generic analysis dictionary API using JSON values | ||
| 6 | |||
| 7 | package DTA::CAB::Analyzer::Dict::JsonCDB; | ||
| 8 | use DTA::CAB::Analyzer ':child'; | ||
| 9 | use DTA::CAB::Analyzer::Dict::Json; | ||
| 10 | use DTA::CAB::Analyzer::Dict::CDB; | ||
| 11 | use IO::File; | ||
| 12 | use Carp; | ||
| 13 | use utf8; | ||
| 14 | use strict; | ||
| 15 | |||
| 16 | ##============================================================================== | ||
| 17 | ## Globals | ||
| 18 | ##============================================================================== | ||
| 19 | |||
| 20 | our @ISA = qw(DTA::CAB::Analyzer::Dict::CDB DTA::CAB::Analyzer::Dict::Json); | ||
| 21 | |||
| 22 | ##============================================================================== | ||
| 23 | ## Constructors etc. | ||
| 24 | ##============================================================================== | ||
| 25 | |||
| 26 | ## $obj = CLASS_OR_OBJ->new(%args) | ||
| 27 | ## + object structure: | ||
| 28 | ## ( | ||
| 29 | ## ##-- Filename Options | ||
| 30 | ## dictFile => $filename, ##-- filename (default=undef): should be TT-dict with JSON-encoded hash values | ||
| 31 | ## | ||
| 32 | ## ##-- Analysis Output | ||
| 33 | ## label => $lab, ##-- analyzer label | ||
| 34 | ## analyzeCode => $code, ##-- pseudo-accessor to perform actual analysis for token ($_); see DTA::CAB::Analyzer::Dict for details | ||
| 35 | ## | ||
| 36 | ## ##-- Analysis Options | ||
| 37 | ## encoding => $enc, ##-- encoding of db file: OVERRIDE DEFAULT: 'raw' | ||
| 38 | ## keyEncoding => $enc, ##-- NEW: encoding of db file keys (default='UTF-8') | ||
| 39 | ## | ||
| 40 | ## ##-- Analysis objects | ||
| 41 | ## dbf => $dbf, ##-- underlying Lingua::TT::CDBFile object (default=undef) | ||
| 42 | ## dba => \%dba, ##-- args for Lingua::TT::CDBFile->new() | ||
| 43 | ## ) | ||
| 44 | sub new { | ||
| 45 | my $that = shift; | ||
| 46 | my $dic = $that->DTA::CAB::Analyzer::Dict::CDB::new( | ||
| 47 | ##-- filenames | ||
| 48 | dictFile => undef, | ||
| 49 | |||
| 50 | ##-- analysis output | ||
| 51 | label => 'dict_json', | ||
| 52 | analyzeCode => $DTA::CAB::Analyzer::Dict::Json::CODE_DEFAULT, | ||
| 53 | |||
| 54 | ##-- JSON parser (segfaults; see Analyzer::Dict::Json::jsonxs() method) | ||
| 55 | #jxs => __PACKAGE__->jsonxs, | ||
| 56 | |||
| 57 | ##-- user args | ||
| 58 | @_ | ||
| 59 | ); | ||
| 60 | return $dic; | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | ##============================================================================== | ||
| 66 | ## Methods: Embedded API | ||
| 67 | ##============================================================================== | ||
| 68 | |||
| 69 | ##-------------------------------------------------------------- | ||
| 70 | ## Methods: I/O: Input: all | ||
| 71 | |||
| 72 | ## $bool = $dic->ensureLoaded() | ||
| 73 | ## + ensures analyzer data is loaded from default files | ||
| 74 | sub ensureLoaded { | ||
| 75 | my $dic = shift; | ||
| 76 | my $rc = $dic->DTA::CAB::Analyzer::Dict::CDB::ensureLoaded(@_); | ||
| 77 | return $rc; | ||
| 78 | } | ||
| 79 | |||
| 80 | ##============================================================================== | ||
| 81 | ## Methods: Persistence | ||
| 82 | ##============================================================================== | ||
| 83 | |||
| 84 | ##====================================================================== | ||
| 85 | ## Methods: Persistence: Perl | ||
| 86 | |||
| 87 | ## @keys = $class_or_obj->noSaveKeys() | ||
| 88 | ## + returns list of keys not to be saved | ||
| 89 | sub noSaveKeys { | ||
| 90 | my $that = shift; | ||
| 91 | return ($that->DTA::CAB::Analyzer::Dict::CDB::noSaveKeys, | ||
| 92 | $that->DTA::CAB::Analyzer::Dict::Json::noSaveKeys, | ||
| 93 | ); | ||
| 94 | } | ||
| 95 | |||
| 96 | ## @keys = $class_or_obj->noSaveBinKeys() | ||
| 97 | sub noSaveBinKeys { | ||
| 98 | my $that = shift; | ||
| 99 | return ($that->DTA::CAB::Analyzer::Dict::CDB::noSaveBinKeys, | ||
| 100 | $that->DTA::CAB::Analyzer::Dict::Json::noSaveBinKeys, | ||
| 101 | ); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | ##============================================================================== | ||
| 106 | ## Methods: Analysis | ||
| 107 | ##============================================================================== | ||
| 108 | |||
| 109 | ##------------------------------------------------------------------------ | ||
| 110 | ## Methods: Analysis: v1.x: API | ||
| 111 | |||
| 112 | ## $doc = $anl->analyzeTypes($doc,\%types,\%opts) | ||
| 113 | ## + perform type-wise analysis of all (text) types in $doc->{types} | ||
| 114 | ## + INHERITED from Dict | ||
| 115 | |||
| 116 | ##------------------------------------------------------------------------ | ||
| 117 | ## Methods: Analysis: Utils | ||
| 118 | |||
| 119 | ## $prefix = $dict->analyzePre() | ||
| 120 | sub analyzePre { | ||
| 121 | my $dic = shift; | ||
| 122 | return $dic->DTA::CAB::Analyzer::Dict::Json::analyzePre(@_); | ||
| 123 | } | ||
| 124 | |||
| 125 | ## $coderef = $dict->analyzeCode() | ||
| 126 | ## $coderef = $dict->analyzeCode($code) | ||
| 127 | ## + inherited | ||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | 1; ##-- be happy | ||
| 132 | |||
| 133 | __END__ |