Skip to content

ruby-rdf/yaml-ld

Repository files navigation

YAML-LD reader/writer

Ruby YAML-LD reader/writer for RDF.rb

Gem Version Build Status Coverage Status Gitter chat

Features

YAML_LD parses and serializes YAML-LD into RDF.

As the specification is under development, this gem should be considered experimental and is subject to change at any time.

YAML-LD documents may use frames or contexts described either using JSON-LD or YAML-LD.

  • Process YAML-LD source using JSON-LD Context or Frame.
  • Process JSON-LD source using YAML-LD Context or Frame.

Examples

require 'rubygems'
require 'yaml\_ld'

Expand a YAML-LD Document

input = StringIO.new(%(
"@context":
  "@vocab": http://xmlns.com/foaf/0.1/
name: Gregg Kellogg
homepage: https://greggkellogg.net
depiction: http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8
))

YAML_LD::API.expand(input) # => %(
%YAML 1.2
---
- http://xmlns.com/foaf/0.1/name:
  - "@value": Gregg Kellogg
  http://xmlns.com/foaf/0.1/homepage:
  - "@value": https://greggkellogg.net
  http://xmlns.com/foaf/0.1/depiction:
  - "@value": http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8
)

Expand a YAML-LD Document to JSON-LD

input = StringIO.new(%(
"@context":
  "@vocab": http://xmlns.com/foaf/0.1/
name: Gregg Kellogg
homepage: https://greggkellogg.net
depiction: http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8
))

YAML_LD::API.expand(input, serializer: JSON::LD::API.method(:serializer)) # => %(
[
  {
    "http://xmlns.com/foaf/0.1/name": [{ "@value": "Gregg Kellogg" }],
    "http://xmlns.com/foaf/0.1/homepage": [{ "@value": "https://greggkellogg.net" }],
    "http://xmlns.com/foaf/0.1/depiction": [{
      "@value": "http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8"
    }]
  }
]
)

Expand a JSON-LD Document to YAML-LD

input = StringIO.new(%(
{
  "@context": {
    "@vocab":"http://xmlns.com/foaf/0.1/"
  },
  "name": "Gregg Kellogg",
  "homepage": "https://greggkellogg.net",
  "depiction": "http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8"
}
))

YAML_LD::API.expand(input, content_type: 'application/ld+json') # => %(
%YAML 1.2
---
- http://xmlns.com/foaf/0.1/name:
  - "@value": Gregg Kellogg
  http://xmlns.com/foaf/0.1/homepage:
  - "@value": https://greggkellogg.net
  http://xmlns.com/foaf/0.1/depiction:
  - "@value": http://www.gravatar.com/avatar/42f948adff3afaa52249d963117af7c8
  )

Implementation

The gem largely acts as a front-end for the JSON-LD gem with differences largely in the serialization format only.

In addition to the input, both a context and frame may be specified using either JSON-LD or YAML-LD.

Dependencies

Ubuntu limitation

As of October 2023, Ubuntu distributions are running with libyaml 0.2.1, which does not support YAML 1.2. The minimum version needed is libyaml 0.2.5.

Installation

The recommended installation method is via RubyGems. To install the latest official release of the JSON-LD gem, do:

% [sudo] gem install yaml-ld

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/ruby-rdf/yaml-ld.git

Mailing List

Author

Contributing

  • Do your best to adhere to the existing coding conventions and idioms.
  • Don't use hard tabs, and don't leave trailing whitespace on any line.
  • Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.
  • Don't touch the json-ld.gemspec, VERSION or AUTHORS files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.
  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you, which you will be asked to agree to on the first commit to a repo within the organization. Note that the agreement applies to all repos in the Ruby RDF organization.

License

This is free and unencumbered public domain software. For more information, see https://unlicense.org/ or the accompanying {file:UNLICENSE} file.