::JSON.pm
## Author: Bryan Jurish <moocow@cpan.org>
## Description: collocation db, source document, JSON
package DiaColloDB::Document::JSON;
use DiaColloDB::Document;
use DiaColloDB::Utils qw(:json)
$ext = $doc->extension()
## + default extension, for Corpus::Compiled
sub extension {
return '.json';
}
##--------------------------------------------------------------
## API: I/O: parse
## $boo
$doc->{label} = ref($file) ? "$file" : $file;
my $data = loadJsonFile($file);
$doc->logconfess("fromFile(): failed to load JSON object from '$file'")
if (!UNIVERSAL::isa($data,'HASH'));
@
ColloDB::PackedFile;
use DiaColloDB::PackedFile::MMap;
use DiaColloDB::Utils qw(:fcntl :env :run :json :pack);
use Fcntl qw(:DEFAULT :seek);
use strict;
##============================================
ic: HTTP wrappers
## $obj_or_undef = $cli->jget($url,\%query_form,$class)
## + wrapper for http json GET requests
sub jget {
my ($cli,$url,$form,$class) = @_;
my $uri = URI->new($url // $cli->{u
>content_ref;
return $class->loadJsonString($cref,utf8=>!utf8::is_utf8($$cref));
}
## $obj_or_undef = $cli->jpost($url,\%query_form,$class)
## + wrapper for json http POST requests
sub jpost {
m
} = $rsp->status_line;
return undef;
}
my $cref = $rsp->content_ref;
return $class->loadJsonString($cref,utf8=>!utf8::is_utf8($$cref));
}
##-------------------------------------------------
: $DiaColloDB::threads::MODULE);
##-- avoid heinous death with JSON::XS backend using threads
$DDC::Client::JSON_BACKEND = 'JSON::PP';
}
##=====================================================
olloDB::Profile::Multi->xkeys(\@mps);
#$cli->trace("extend(): xkeys=", DiaColloDB::Utils::saveJsonString($xkeys, utf8=>0));
#$cli->trace("extend(): N.pre=", join('+',map {$_->{profiles}[0]{N}}
$_[1]);
$sub->extend($rel,%opts,strings=>1,score=>'f',cutoff=>'',fill=>1,slice2keys=>JSON::to_json($xkeys->[$_[1]], {allow_nonref=>1}))
or $_[0]->logconfess("extend() failed for client ur
##========================================================================
## I/O: JSON
*TO_JSON = \&TO_JSON__table;
##=======================================================================
k-best trimming,
stringification,
basic algebraic manipulation,
and serialization (text, HTML, or JSON).
=cut
##----------------------------------------------------------------
## DESCRIPTION: DiaCo
I/O: JSON
=pod
=head2 I/O: JSON
=over 4
=item TO_JSON__table
$thingy = $obj->TO_JSON__table()
test alternative JSON format (small but slow).
=item TO_JSON__flat
$thingy = $obj->TO_JSON__flat
ColloDB::MultiMapFile::MMap;
use DiaColloDB::MultiMapFile;
use DiaColloDB::Utils qw(:fcntl :file :json :pack);
use File::Map qw(map_handle);
use strict;
##============================================
en it as one
return $cli->open_rcfile($cli->{url},%opts)
if (!-d $path && !-e "$path/header.json");
$cli->{db} = DiaColloDB->new(%dbopts,dbdir=>$path)
or $cli->logconfess("open_file() fai
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Globals & Constants
=pod
=head2 Globals & Constants
=over 4
=item Variable: @ISA
DiaColloDB:
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Constructors etc.
=pod
=head2 Constructors etc.
=over 4
=item new
$doc = CLASS_OR_OBJECT->n
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: API: I/O: parse
=pod
=head2 API: I/O: parse
=over 4
=item fromFile
$bool = $doc->fromFile($
to a
local non-directory path. Configuration files accepted by this method
are expected to be in JSON format as accepted by
L<DiaColloDB::Persistent::readHeaderFile()|DiaColloDB::Persistent/readHeade
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Globals & Constants
=pod
=head2 Globals & Constants
=over 4
=item Variable: @ISA
DiaColloDB:
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Constructors etc.
=pod
=head2 Constructors etc.
=over 4
=item new
$doc = CLASS_OR_OBJECT->n
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: API: I/O: parse
=pod
=head2 API: I/O: parse
=over 4
=item fromFile
$bool = $doc->fromFile($
=>($rel->{ddcTimeout}//300),
connect=>{PeerAddr=>$server,PeerPort=>$port},
mode=>'json',
%opts
);
}
##--------------------------------------------------------------
##
DDC server on $rel->{ddcServer}: $!")
if (!defined($cli->{sock}));
my $result = $cli->queryJson($qstr);
$rel->logconfess($coldb->{error}="$logas ERROR: DDC query failed: ".($result->{error_}
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Globals & Constants
=pod
=head2 Globals & Constants
=over 4
=item Variable: @ISA
DiaColloDB:
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: Constructors etc.
=pod
=head2 Constructors etc.
=over 4
=item new
$doc = CLASS_OR_OBJECT->n
-----------------------------------------------------------
## DESCRIPTION: DiaColloDB::Document::JSON: API: I/O: parse
=pod
=head2 API: I/O: parse
=over 4
=item fromFile
$bool = $doc->fromFile($
=====================
## NAME
=pod
=head1 NAME
DiaColloDB::Document::JSON - diachronic collocation db, source document, raw JSON
=cut
##============================================================
==================================================
## PRELIMINARIES
use DiaColloDB::Document::JSON;
##========================================================================
## Constructors e
DESCRIPTION
DiaColloDB::Document::JSON
provides a L<DiaColloDB::Document|DiaColloDB::Document>-compliant API
for parsing corpus files in raw L<JSON|http://www.json.org> format,
assuming the stored d
B::Corpus;
use DiaColloDB::Document;
use DiaColloDB::Document::DDCTabs;
use DiaColloDB::Document::JSON;
use DiaColloDB::Document::Storable;
#use DiaColloDB::Document::TCF; ##-- only loaded on request
#&& !$opts{glob}
&& -e "$sources->[0]/header.json"
)) {
require DiaColloDB::Corpus::Compiled;
bless($corpus,'DiaCo
=========
## I/O: JSON
$thingy = $obj->TO_JSON();
$str = $obj->saveJsonString(%opts);
$bool = $obj->saveJsonFile($filename_or_handle, %opts);
$obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts)
;
$obj = $CLASS_OR_OBJECT->loadJsonString( $string,%opts);
$obj = $CLASS_OR_OBJECT->loadJsonFile($filename_or_handle,%opts);
##====================================================================
ble methods for
determining disk usage and file timestamps,
text I/O,
and object metadata I/O via JSON header files.
=cut
##----------------------------------------------------------------
## DESCRI
elation;
use DiaColloDB::Relation::TDF::Query;
use DiaColloDB::Utils qw(:pack :fcntl :file :math :json :list :pdl :temp :env :run :jobs :sort);
use DiaColloDB::PackedFile;
#use DiaColloDB::Temp::Hash;
>vlog($logCreate, "$logas: processing input documents [NA=$NA, NC=$nfiles]");
my $json = DiaColloDB::Utils->jsonxs();
my $minDocSize = $vs->{minDocSize} = max2(($vs->{minDocSize}//0),1);
my $m
upgrades applied to $dbdir
## + list is created by parsing "upgraded" field from "$dbdir/header.json"
## + if the upgrade-item "by" keyword inherits from DiaColloDB::Upgrade::Base,
## a new obje
plied to C<$dbdir>.
Returned list is created by parsing C<"upgraded"> field from C<"$dbdir/header.json">.
If the upgrade-item C<"by"> keyword is the name of a package inheriting from L<DiaColloDB::Upg
B<OR>
a JSON-string encoding such a HASH-ref.
Options C<%opts> are as for the L<profile()|/profile> method (mostly ignored),
and also:
slice2keys => \%slice2keys, ##-- target f2-items or JSON-string
===================================================
## JSON: load
$data = PACKAGE::loadJsonString( $string,%opts);
$data = PACKAGE::loadJsonFile($filename_or_handle,%opts);
##=================
=======================================================
## JSON: save
$str = PACKAGE::saveJsonString($data);
$bool = PACKAGE::saveJsonFile($data,$filename_or_handle,%opts);
##=================
qw(fcflags fcgetfl fcread fcwrite fctrunc fccreat fcperl fcopen)],
json => [qw(loadJsonString loadJsonFile saveJsonString saveJsonFile)],
sort => [qw(csort_to csortuc_to sortCmd)],
run => [qw(c