| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||
| 3 | ## File: DTA::CAB::Datum.pm | ||||||||||||||||||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||
| 5 | ## Description: generic API for data (tokens,sentences,documents,...) passed to/from DTA::CAB::Analyzer | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package DTA::CAB::Datum; | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DTA::CAB::Logger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | ##============================================================================== | ||||||||||||||||||||||||||||
| 14 | ## Globals | ||||||||||||||||||||||||||||
| 15 | ##============================================================================== | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | our @ISA = qw(Exporter DTA::CAB::Logger); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our @EXPORT = qw(toToken toSentence toDocument); | |||||||||||||||||||||||||||
| 20 | 1 | our @EXPORT_OK = @EXPORT; | |||||||||||||||||||||||||||
| 21 | 1 | our %EXPORT_TAGS = (all=>\@EXPORT_OK); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | ##============================================================================== | ||||||||||||||||||||||||||||
| 24 | ## Constructors etc. | ||||||||||||||||||||||||||||
| 25 | ##============================================================================== | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | ## $dat = $CLASS_OR_OBJECT->new(%args) | ||||||||||||||||||||||||||||
| 28 | ## + %$dat, %args: | ||||||||||||||||||||||||||||
| 29 | ## _attrs => \%attrs, ##-- scalar attributes ($key=>$val,...), e.g. for xml pass-through | ||||||||||||||||||||||||||||
| 30 | ## _dtrs => \@dtrs, ##-- structural daughters (DTA::CAB::Datum objects), e.g. for xml pass-through | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return bless {@_[1..$#_]}, ref($_[0])||$_[0]; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ##============================================================================== | ||||||||||||||||||||||||||||
| 36 | ## Utilities | ||||||||||||||||||||||||||||
| 37 | ##============================================================================== | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | ## $tok = CLASS::toToken($tok) | ||||||||||||||||||||||||||||
| 40 | ## $tok = CLASS::toToken($text) | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | ## + creates a new token object or returns its argument | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub toToken { | ||||||||||||||||||||||||||
|
Subroutine
toToken: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | # return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Token')); | ||||||||||||||||||||||||||||
| 45 | # return bless({text=>$_[0]},'DTA::CAB::Token') if (!ref($_[0])); | ||||||||||||||||||||||||||||
| 46 | # return bless($_[0],'DTA::CAB::Token') if (ref($_[0]) eq 'HASH' && exists($_[0]{text})); | ||||||||||||||||||||||||||||
| 47 | # return DTA::CAB::Token->new(@_); ##-- default | ||||||||||||||||||||||||||||
| 48 | ##-- | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Token')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return {text=>$_[0]} if (!ref($_[0])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $_[0] if (ref($_[0]) eq 'HASH' && exists($_[0]{text})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"text"}
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"text"}
ref $_[0] eq "HASH"
exists $_[0]{"text"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"text"}
| |||||||||||||||||||||||||||||
| 52 | 0 | return DTA::CAB::Token->new(@_); ##-- default | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | ## $sent = CLASS::toSentence($sent) | ||||||||||||||||||||||||||||
| 56 | ## $sent = CLASS::toSentence(\@tokens) | ||||||||||||||||||||||||||||
| 57 | ## + creates a new sentence object or returns its argument | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub toSentence { | ||||||||||||||||||||||||||
|
Subroutine
toSentence: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | # return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Sentence')); | ||||||||||||||||||||||||||||
| 60 | # return bless({tokens=>$_[0]},'DTA::CAB::Sentence') if (UNIVERSAL::isa($_[0],'ARRAY')); | ||||||||||||||||||||||||||||
| 61 | # return bless($_[0],'DTA::CAB::Sentence') if (ref($_[0]) eq 'HASH' && exists($_[0]{tokens})); | ||||||||||||||||||||||||||||
| 62 | # return DTA::CAB::Sentence->new(@_); ##-- default | ||||||||||||||||||||||||||||
| 63 | ##-- | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Sentence')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return {tokens=>$_[0]} if (UNIVERSAL::isa($_[0],'ARRAY')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $_[0] if (ref($_[0]) eq 'HASH' && exists($_[0]{tokens})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"tokens"}
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"tokens"}
ref $_[0] eq "HASH"
exists $_[0]{"tokens"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"tokens"}
| |||||||||||||||||||||||||||||
| 67 | 0 | return DTA::CAB::Sentence->new(@_); ##-- default | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | ## $doc = CLASS::toDocument($doc) | ||||||||||||||||||||||||||||
| 71 | ## $doc = CLASS::toDocument(\@sents) | ||||||||||||||||||||||||||||
| 72 | ## + creates a new document object or returns its argument | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub toDocument { | ||||||||||||||||||||||||||
|
Subroutine
toDocument: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $_[0] if (UNIVERSAL::isa($_[0],'DTA::CAB::Document')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return bless({body=>$_[0]},'DTA::CAB::Document') if (UNIVERSAL::isa($_[0],'ARRAY')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return bless($_[0],'DTA::CAB::Document') if (ref($_[0]) eq 'HASH' && exists($_[0]{body})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] eq "HASH" and exists $_[0]{"body"}
MC/DC0%0/2
ref $_[0] eq "HASH" and exists $_[0]{"body"}
ref $_[0] eq "HASH"
exists $_[0]{"body"}
Truth table0%0/3
A and B
A= ref $_[0] eq "HASH"B= exists $_[0]{"body"}
| |||||||||||||||||||||||||||||
| 77 | 0 | return DTA::CAB::Document->new(@_); ##-- default | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | ## $thingy = $obj->TO_JSON() | ||||||||||||||||||||||||||||
| 82 | ## + annoying wrapper for JSON::XS | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub TO_JSON { | ||||||||||||||||||||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 0 | return { %{$_[0]} }; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||