DTA::CAB::Format::JSON - Datum parser|formatter: JSON code via JSON::XS
use DTA::CAB::Format::JSON;
$fmt = DTA::CAB::Format::JSON->new(%args);
##========================================================================
## Methods: Input
$fmt = $fmt->parseJsonString($str); ##-- guts
$doc = $fmt->parseDocument();
##========================================================================
## Methods: Output
$fmt = $fmt->toFh($fh);
$fmt = $fmt->putToken($tok);
$fmt = $fmt->putSentence($sent);
$fmt = $fmt->putDocument($doc);
DTA::CAB::Format::JSON::XS is a DTA::CAB::Format datum parser/formatter which reads & writes data as JSON::XS code using the JSON::XS module.
DTA::CAB::Format::JSON inherits from DTA::CAB::Format.
DTA::CAB::Format::JSON registers the filename regex:
/\.(?i:json(?:[\.\-\_]xs)?)$/
with DTA::CAB::Format.
$fmt = CLASS_OR_OBJ->new(%args);
Constructor.
%args, %$fmt:
##---- Input
doc => $doc, ##-- buffered input document
##
##---- INHERITED from DTA::CAB::Format
#utf8 => $bool, ##-- output is always UTF-8
level => $formatLevel, ##-- sets $jsonxs->pretty() level
@keys = $class_or_obj->noSaveKeys();
Override returns list of keys not to be saved. This implementation returns qw(doc outbuf)
.
$fmt = $fmt->iolayers()
Override always returns ':raw'.
$fmt = $fmt->fromString(\$string)
Override: select input from the string $string.
$fmt = $fmt->fromFh($fh)
Override calls $fmt->fromFh_str().
$fmt = $fmt->parseJsonString($str);
Evaluates $str as JSON code, which is expected to return a DTA::CAB::Document object (or something which can be massaged into one), and sets $fmt->{doc} to this new document object.
$doc = $fmt->parseDocument();
Returns the current contents of $fmt->{doc}, e.g. the most recently parsed document.
$fmt = $fmt->toFh($fh)
$fmt = $fmt->toFh($fh, $formatLevel)
Override: select output to filehandle $fh. Creates and caches $fmt->{jxs} as a side effect.
$fmt = $fmt->putToken($tok);
Override: writes a token to the output buffer (non-destructive on $tok).
$fmt = $fmt->putSentence($sent);
Override: write a sentence to the outupt buffer (non-destructive on $sent).
$fmt = $fmt->putDocument($doc);
Override: write a document to the outupt buffer (non-destructive on $doc).
An example file in the format accepted/generated by this module is:
{
"body" : [
{
"tokens" : [
{
"moot" : {
"tag" : "PWAV",
"word" : "wie",
"lemma" : "wie"
},
"lang" : [
"de"
],
"msafe" : "1",
"errid" : "ec",
"exlex" : "wie",
"text" : "wie",
"hasmorph" : "1",
"xlit" : {
"latin1Text" : "wie",
"isLatinExt" : "1",
"isLatin1" : "1"
}
},
{
"text" : "oede",
"msafe" : "0",
"moot" : {
"lemma" : "öde",
"tag" : "ADJD",
"word" : "öde"
},
"xlit" : {
"isLatin1" : "1",
"latin1Text" : "oede",
"isLatinExt" : "1"
}
},
{
"text" : "!",
"errid" : "ec",
"exlex" : "!",
"xlit" : {
"isLatinExt" : "1",
"latin1Text" : "!",
"isLatin1" : "1"
},
"moot" : {
"lemma" : "!",
"tag" : "$.",
"word" : "!"
},
"msafe" : "1"
}
],
"lang" : "de"
}
]
}
Bryan Jurish <moocow@cpan.org>
Copyright (C) 2010-2019 by Bryan Jurish
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.1 or, at your option, any later version of Perl 5 you may have available.