NAME

DTA::CAB::Format::JSON - Datum parser|formatter: JSON code via JSON::XS

SYNOPSIS

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);

DESCRIPTION

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.

Globals

Variable: @ISA

DTA::CAB::Format::JSON inherits from DTA::CAB::Format.

Filenames

DTA::CAB::Format::JSON registers the filename regex:

/\.(?i:json(?:[\.\-\_]xs)?)$/

with DTA::CAB::Format.

Constructors etc.

new
$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

Methods: Persistence

noSaveKeys
@keys = $class_or_obj->noSaveKeys();

Override returns list of keys not to be saved. This implementation returns qw(doc outbuf).

Methods: Input

iolayers
$fmt = $fmt->iolayers()

Override always returns ':raw'.

fromString
$fmt = $fmt->fromString(\$string)

Override: select input from the string $string.

fromFh($fh)
$fmt = $fmt->fromFh($fh)

Override calls $fmt->fromFh_str().

parseJsonString
$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.

parseDocument
$doc = $fmt->parseDocument();

Returns the current contents of $fmt->{doc}, e.g. the most recently parsed document.

Methods: Output

toFh
$fmt = $fmt->toFh($fh)
$fmt = $fmt->toFh($fh, $formatLevel)

Override: select output to filehandle $fh. Creates and caches $fmt->{jxs} as a side effect.

putToken
$fmt = $fmt->putToken($tok);

Override: writes a token to the output buffer (non-destructive on $tok).

putSentence
$fmt = $fmt->putSentence($sent);

Override: write a sentence to the outupt buffer (non-destructive on $sent).

putDocument
$fmt = $fmt->putDocument($doc);

Override: write a document to the outupt buffer (non-destructive on $doc).

EXAMPLE

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"
      }
   ]
}

AUTHOR

Bryan Jurish <moocow@cpan.org>

COPYRIGHT AND LICENSE

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.