| 1 | ## -*- Mode: CPerl -*- | ||||||||||||
| 2 | ## | ||||||||||||
| 3 | ## File: DTA::CAB::Format::CSV1g.pm | ||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||
| 5 | ## Description: Datum parser: concise minimal-output human-readable text, unigrams | ||||||||||||
| 6 | |||||||||||||
| 7 | package DTA::CAB::Format::CSV1g; | ||||||||||||
| 8 | 1 | ▶ | use DTA::CAB::Format::CSV; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | ##============================================================================== | ||||||||||||
| 13 | ## Globals | ||||||||||||
| 14 | ##============================================================================== | ||||||||||||
| 15 | |||||||||||||
| 16 | 1 | our @ISA = qw(DTA::CAB::Format::CSV); | |||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||
| 19 | 1 | DTA::CAB::Format->registerFormat(name=>__PACKAGE__, filenameRegex=>qr/(?i:\.(?:csv|cab\-csv)[\.\-]?1g)$/); | |||||||||||
| 20 | 1 | DTA::CAB::Format->registerFormat(name=>__PACKAGE__, short=>$_) foreach qw(csv1g csv-1g csv.1g); | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | ##============================================================================== | ||||||||||||
| 24 | ## Constructors etc. | ||||||||||||
| 25 | ##============================================================================== | ||||||||||||
| 26 | |||||||||||||
| 27 | ## $fmt = CLASS_OR_OBJ->new(%args) | ||||||||||||
| 28 | ## + object structure: assumed HASH | ||||||||||||
| 29 | ## ( | ||||||||||||
| 30 | ## ##---- Input | ||||||||||||
| 31 | ## doc => $doc, ##-- buffered input document | ||||||||||||
| 32 | ## | ||||||||||||
| 33 | ## ##---- Output | ||||||||||||
| 34 | ## level => $formatLevel, ##-- output formatting level: | ||||||||||||
| 35 | ## ## 0: text, xlit, canon, tag, lemma | ||||||||||||
| 36 | ## ## 1: text, xlit, canon, tag, lemma, details | ||||||||||||
| 37 | ## #outbuf => $stringBuffer, ##-- buffered output | ||||||||||||
| 38 | ## | ||||||||||||
| 39 | ## ##---- Common | ||||||||||||
| 40 | ## utf8 => $bool, ##-- default: 1 | ||||||||||||
| 41 | ## ) | ||||||||||||
| 42 | ## + inherited from DTA::CAB::Format::TT via CSV | ||||||||||||
| 43 | |||||||||||||
| 44 | ##============================================================================== | ||||||||||||
| 45 | ## Methods: Persistence | ||||||||||||
| 46 | ##============================================================================== | ||||||||||||
| 47 | |||||||||||||
| 48 | ##============================================================================== | ||||||||||||
| 49 | ## Methods: Input | ||||||||||||
| 50 | ##============================================================================== | ||||||||||||
| 51 | |||||||||||||
| 52 | ##-------------------------------------------------------------- | ||||||||||||
| 53 | ## Methods: Input: Local | ||||||||||||
| 54 | |||||||||||||
| 55 | ## $fmt = $fmt->parseTextString(\$string) | ||||||||||||
| 56 | 1 | ▶ | BEGIN { *parseTTString = \&parseCsvString; } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | 0 | ▶ | sub parseCsvString { | ||||||||||
|
Subroutine
parseCsvString: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||
| 58 | 0 | my ($fmt,$src) = @_; | |||||||||||
| 59 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 0 | $$src =~ s|^([^\t]*)\t([^\t]+)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t\r\n]*)(?:\t([^\t\r\n]*))?$|$2\t[xlit] $3\t[dmoot/tag] $4\t[moot/word] $4\t[moot/tag] $5\t[moot/lemma] $6\t[moot/details] $7\t[freq] $1|mg; | |||||||||||
| 61 | 0 | return DTA::CAB::Format::TT::parseTTString($fmt,$src); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | ##============================================================================== | ||||||||||||
| 65 | ## Methods: Output | ||||||||||||
| 66 | ##============================================================================== | ||||||||||||
| 67 | |||||||||||||
| 68 | ##-------------------------------------------------------------- | ||||||||||||
| 69 | ## Methods: Output: Generic | ||||||||||||
| 70 | |||||||||||||
| 71 | ## $ext = $fmt->defaultExtension() | ||||||||||||
| 72 | ## + returns default filename extension for this format | ||||||||||||
| 73 | 0 | ▶ | sub defaultExtension { return '.csv.1g'; } | ||||||||||
|
Subroutine
defaultExtension: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | |||||||||||||
| 75 | ##-------------------------------------------------------------- | ||||||||||||
| 76 | ## Methods: Output: output selection | ||||||||||||
| 77 | |||||||||||||
| 78 | ## \$buf = $fmt->token2buf($tok,\$buf) | ||||||||||||
| 79 | ## + buffer output for a single token | ||||||||||||
| 80 | ## + override implements CSV format | ||||||||||||
| 81 | 0 | ▶ | sub token2buf { | ||||||||||
|
Subroutine
token2buf: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 82 | 0 | ▶ | my $bufr = ($_[2] ? $_[2] : \(my $buf='')); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | ▶ | $$bufr = ($_[1]{freq}//0)."\t".${$_[0]->SUPER::token2buf($_[1])}; | ||||||||||
|
Condition0%0/2
$_[1]{"freq"} // 0
MC/DC0%0/1
$_[1]{"freq"} // 0
$_[1]{"freq"}
Truth table0%0/2
A
A= $_[1]{"freq"}
| |||||||||||||
| 84 | 0 | return $bufr; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 1 | 1; ##-- be happy | |||||||||||
| 88 | |||||||||||||
| 89 | __END__ | ||||||||||||