Coder Social home page Coder Social logo

perl-jsonld's Introduction

JSONLD

A Perl toolkit for interacting with JSON-LD data.

VERSION

This document describes JSONLD version 0.004_01.

SYNOPSIS

Command Line Tools

% jsonld-expand input.jsonld

Prints the JSON-LD 1.1 expansion of the data in input.jsonld to standard out.

% jsonld-compact input.jsonld

Prints the JSON-LD 1.1 compaction of the data in input.jsonld to standard out.

% jsonld-nq input.jsonld

Prints the JSON-LD 1.1 deserialization of the data in input.jsonld to standard out in the N-Quads format.

JSON-LD Perl API

use v5.14;
use JSON qw(decode_json);
use JSONLD;

my $infile = 'test.jsonld';
open(my $fh, '<:utf8', $infile) or die $!;
my $content   = do { local($/); <$fh> };
my $data = decode_json($content);

my $jld = JSONLD->new();
my $expanded  = $jld->expand($data);

DESCRIPTION

This module implements part of the JSON-LD 1.1 standard for manipulating JSON data as linked data.

This version provides full support for the JSON-LD 1.1 "Expansion" and "toRdf" transformations (the latter primarily being useful through a subclass of JSON-LD, such as that provided by LAtteanX::Parser::JSONLD). Partial support for the "Compaction" transformation is provided, but it contains many known deficiencies. Full support for "Compaction" may be forthcoming in a future release. No other JSON-LD transformation are supported at this time.

METHODS

expand( $data )

Returns the JSON-LD expansion of $data.

to_rdf( $data )

Returns the dataset generated by turning the JSON-LD expansion of $data into RDF.

Note: this method must be called on a JSONLD subclass which implements the RDF-related methods listed below. See AtteanX::Parser::JSONLD for an implementation of such a subclass.

  • default_graph()
  • new_dataset()
  • new_triple($s, $p, $o)
  • new_quad($s, $p, $o, $g)
  • new_iri($value)
  • new_graphname($value)
  • new_blank( [$id] )
  • new_lang_literal($value, $lang)
  • new_dt_literal($value, $datatype)
  • add_quad($quad, $dataset)

BUGS

Please report any bugs or feature requests to through the GitHub web interface at https://github.com/kasei/perl-jsonld/issues.

SEE ALSO

AUTHOR

Gregory Todd Williams [email protected]

COPYRIGHT

Copyright (c) 2019--2020 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl-jsonld's People

Contributors

kasei avatar manwar avatar

Stargazers

Patrick Hochstenbach avatar Zaki Mughal [sivoais] avatar Marcus Smith avatar

Watchers

 avatar James Cloos avatar

Forkers

manwar phochste

perl-jsonld's Issues

please tag releases

CPAN indicates there have been several releases, yet none is tagged here in git.

Please tag releases, to ease correlating CPAN with git.

Issue with document encoding

Example tool.pl:

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Printer;
use JSON;
use JSONLD;
use Perl6::Slurp qw(slurp);

if (@ARGV < 1) {
        print STDERR "Usage: $0 jsonld_file\n";
        exit 1;
}
my $jsonld_file = $ARGV[0];

my $jsonld = slurp($jsonld_file);

my $data = JSON->new()->boolean_values(0, 1)->decode($jsonld);

my $jld = JSONLD->new;
my $expanded  = $jld->expand($data);

p $expanded;

JSON-LD file example.jsonld:

{
    "@context": "https://ofn.gov.cz/adresy/2020-07-01/kontexty/adresa.jsonld",
    "typ": "Adresa",
    "název_obce": {
        "cs": "Horní Datová"
    },
    "název_ulice": {
        "cs": "Hlavní"
    },
    "číslo_domovní": 12,
    "typ_čísla_domovního": "č.p.",
    "psč": "33101",
    "poznámka": "dole u řeky"
}

When I run tool.pl exaple.jsonld output is:

Not a valid IRI? $VAR1 = "https://ofn.gov.cz/v\x{c4}\x{9b}c/2020-07-01/kontexty/v\x{c4}\x{9b}c.jsonld"; at /usr/share/perl5/IRI.pm line 255.

I was looking into it and the issue isn't in IRI, but probably in the encoding of the document.
I don't understand, why is there encode_utf8 in JSON decoding.
https://github.com/kasei/perl-jsonld/blob/master/lib/JSONLD.pm#L626
https://github.com/kasei/perl-jsonld/blob/master/lib/JSONLD.pm#L686
When I removed this encode(), library not fail on this IRI, but there are issues still. I believe.

README describes outdated release

README contains this:

This version (0.002) provides

Current release is 0.004 - did something improve since, or should the referenced version in README simply be bumped (or dropped, if not really maintained?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.