Permalink
Browse files

Documentation update for release 0.1.2

  • Loading branch information...
gkellogg committed Apr 21, 2012
1 parent 6932dd7 commit 4f8f9451798412d7b748d78854447db9af1bb938
Showing with 237 additions and 39 deletions.
  1. +1 −1 .gemspec
  2. +1 −0 Gemfile.lock
  3. +1 −1 README
  4. +199 −3 README.markdown
  5. +1 −1 VERSION
  6. +23 −21 etc/doap.jsonld
  7. +2 −2 lib/json/ld/evaluation_context.rb
  8. +1 −1 lib/json/ld/from_rdf.rb
  9. +1 −1 lib/json/ld/to_rdf.rb
  10. +3 −2 lib/json/ld/utils.rb
  11. +3 −5 script/parse
  12. +1 −1 spec/to_rdf_spec.rb
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
gem.homepage = "http://github.com/gkellogg/json-ld"
gem.license = 'Public Domain' if gem.respond_to?(:license=)
gem.summary = "JSON-LD reader/writer for Ruby."
- gem.description = gem.summary
+ gem.description = "JSON::LD parses and serializes JSON-LD into RDF and implements expansion, compaction and framing API interfaces."
gem.rubyforge_project = 'json-ld'
gem.authors = ['Gregg Kellogg']
View
@@ -9,6 +9,7 @@ PATH
remote: .
specs:
json-ld (0.1.2)
+ backports
json (>= 1.6.5)
rdf (>= 0.3.5)
View
2 README
View
@@ -4,7 +4,8 @@
## Features
-JSON::LD parses and serializes [JSON-LD][] into statements or statements.
+JSON::LD parses and serializes [JSON-LD][] into [RDF][] and implements
+JSON::LD expansion, compaction and framing API interfaces.
Install with `gem install json-ld`
@@ -13,13 +14,208 @@ Install with `gem install json-ld`
require 'rubygems'
require 'json/ld'
+### Expand a Document
+
+ input = {
+ "@context": {
+ "name": "http://xmlns.com/foaf/0.1/name",
+ "homepage": "http://xmlns.com/foaf/0.1/homepage",
+ "avatar": "http://xmlns.com/foaf/0.1/avatar"
+ },
+ "name": "Manu Sporny",
+ "homepage": "http://manu.sporny.org/",
+ "avatar": "http://twitter.com/account/profile_image/manusporny"
+ }
+ JSON::LD::API.expand(input) =>
+
+ [{
+ "http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
+ "http://xmlns.com/foaf/0.1/homepage": ["http://manu.sporny.org/"],
+ "http://xmlns.com/foaf/0.1/avatar": ["http://twitter.com/account/profile_image/manusporny"]
+ }]
+
+### Compact a Document
+
+ input = [{
+ "http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
+ "http://xmlns.com/foaf/0.1/homepage": ["http://manu.sporny.org/"],
+ "http://xmlns.com/foaf/0.1/avatar": ["http://twitter.com/account/profile_image/manusporny"]
+ }]
+
+ context = {
+ "@context": {
+ "name": "http://xmlns.com/foaf/0.1/name",
+ "homepage": "http://xmlns.com/foaf/0.1/homepage",
+ "avatar": "http://xmlns.com/foaf/0.1/avatar"
+ }
+ }
+
+ JSON::LD::API.compact(input, context) =>
+ {
+ "@context": {
+ "avatar": "http://xmlns.com/foaf/0.1/avatar",
+ "homepage": "http://xmlns.com/foaf/0.1/homepage",
+ "name": "http://xmlns.com/foaf/0.1/name"
+ },
+ "avatar": "http://twitter.com/account/profile_image/manusporny",
+ "homepage": "http://manu.sporny.org/",
+ "name": "Manu Sporny"
+ }
+
+### Frame a Document
+
+ input = {
+ "@context": {
+ "Book": "http://example.org/vocab#Book",
+ "Chapter": "http://example.org/vocab#Chapter",
+ "contains": {"@id": "http://example.org/vocab#contains", "@type": "@id"},
+ "creator": "http://purl.org/dc/terms/creator",
+ "description": "http://purl.org/dc/terms/description",
+ "Library": "http://example.org/vocab#Library",
+ "title": "http://purl.org/dc/terms/title"
+ },
+ "@graph":
+ [{
+ "@id": "http://example.com/library",
+ "@type": "Library",
+ "contains": "http://example.org/library/the-republic"
+ },
+ {
+ "@id": "http://example.org/library/the-republic",
+ "@type": "Book",
+ "creator": "Plato",
+ "title": "The Republic",
+ "contains": "http://example.org/library/the-republic#introduction"
+ },
+ {
+ "@id": "http://example.org/library/the-republic#introduction",
+ "@type": "Chapter",
+ "description": "An introductory chapter on The Republic.",
+ "title": "The Introduction"
+ }]
+ }
+
+ frame = {
+ "@context": {
+ "Book": "http://example.org/vocab#Book",
+ "Chapter": "http://example.org/vocab#Chapter",
+ "contains": "http://example.org/vocab#contains",
+ "creator": "http://purl.org/dc/terms/creator",
+ "description": "http://purl.org/dc/terms/description",
+ "Library": "http://example.org/vocab#Library",
+ "title": "http://purl.org/dc/terms/title"
+ },
+ "@type": "Library",
+ "contains": {
+ "@type": "Book",
+ "contains": {
+ "@type": "Chapter"
+ }
+ }
+ }
+ JSON::LD.frame(input, frame) =>
+ {
+ "@context": {
+ "Book": "http://example.org/vocab#Book",
+ "Chapter": "http://example.org/vocab#Chapter",
+ "contains": "http://example.org/vocab#contains",
+ "creator": "http://purl.org/dc/terms/creator",
+ "description": "http://purl.org/dc/terms/description",
+ "Library": "http://example.org/vocab#Library",
+ "title": "http://purl.org/dc/terms/title"
+ },
+ "@graph": [
+ {
+ "@id": "http://example.com/library",
+ "@type": "Library",
+ "contains": {
+ "@id": "http://example.org/library/the-republic",
+ "@type": "Book",
+ "contains": {
+ "@id": "http://example.org/library/the-republic#introduction",
+ "@type": "Chapter",
+ "description": "An introductory chapter on The Republic.",
+ "title": "The Introduction"
+ },
+ "creator": "Plato",
+ "title": "The Republic"
+ }
+ }
+ ]
+ }
+
+### Turn JSON-LD into RDF (Turtle)
+
+ input = {
+ "@context": {
+ "": "http://manu.sporny.org/",
+ "foaf": "http://xmlns.com/foaf/0.1/"
+ },
+ "@id": "http://example.org/people#joebob",
+ "@type": "foaf:Person",
+ "foaf:name": "Joe Bob",
+ "foaf:nick": { "@list": [ "joe", "bob", "jaybe" ] }
+ }
+
+ JSON::LD::API.toRDF(input) =>
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
+
+ <http://example.org/people#joebob> a foaf:Person;
+ foaf:name "Joe Bob";
+ foaf:nick ("joe" "bob" "jaybe") .
+
+### Turn RDF into JSON-LD
+
+ input =
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
+
+ <http://manu.sporny.org/#me> a foaf:Person;
+ foaf:knows [ a foaf:Person;
+ foaf:name "Gregg Kellogg"];
+ foaf:name "Manu Sporny" .
+
+ context =
+ {
+ "@context": {
+ "": "http://manu.sporny.org/",
+ "foaf": "http://xmlns.com/foaf/0.1/"
+ }
+ }
+
+ JSON::LD::fromRDF(input, context) =>
+ {
+ "@context": {
+ "": "http://manu.sporny.org/",
+ "foaf": "http://xmlns.com/foaf/0.1/"
+ },
+ "@id": ":#me",
+ "@type": "foaf:Person",
+ "foaf:name": "Manu Sporny",
+ "foaf:knows": {
+ "@type": "foaf:Person",
+ "foaf:name": "Gregg Kellogg"
+ }
+ }
+
+## RDF Reader and Writer
+{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
+
+ graph = RDF::Graph.load("etc/doap.jsonld", :format => :jsonld)
+ graph.dump(:jsonld, :standard_prefixes => true)
+
## Documentation
-Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-ld/0.0.4/file/README)
+Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-ld/file/README.markdown)
### Principle Classes
* {JSON::LD}
+ * {JSON::LD::API}
+ * {JSON::LD::Compact}
+ * {JSON::LD::EvaluationContext}
* {JSON::LD::Format}
+ * {JSON::LD::Frame}
+ * {JSON::LD::FromTriples}
* {JSON::LD::Reader}
+ * {JSON::LD::Triples}
* {JSON::LD::Writer}
## Dependencies
@@ -70,4 +266,4 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
[RDF.rb]: http://rdf.rubyforge.org/
[Backports]: http://rubygems.org/gems/backports
-[JSON-LD]: http://json-ld.org/spec/ED/20110507/
+[JSON-LD]: http://json-ld.org/spec/latest/
View
@@ -1 +1 @@
-0.1.1
+0.1.2
View
@@ -1,31 +1,33 @@
{
- "@context": {
- "dc": "http://purl.org/dc/terms/",
- "doap": "http://usefulinc.com/ns/doap#",
- "foaf": "http://xmlns.com/foaf/0.1/",
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
- "xsd": "http://www.w3.org/2001/XMLSchema#",
- "dc:creator": {"@type": "@id"},
- "doap:created": {"@type": "xsd:date"},
- "doap:homepage": {"@type": "@id"},
- "doap:bug-database": {"@type": "@id"},
- "doap:blog": {"@type": "@id"},
- "doap:developer": {"@type": "@id"},
- "doap:maintainer": {"@type": "@id"},
- "doap:documenter": {"@type": "@id"},
- "doap:license": {"@type": "@id"},
- "foaf:maker": {"@type": "@id"},
- "foaf:mbox": {"@type": "@id"},
- "foaf:made": {"@type": "@id"},
- "rdfs:isDefinedBy": {"@type": "@id"}
+ "@context": {
+ "dc": "http://purl.org/dc/terms/",
+ "doap": "http://usefulinc.com/ns/doap#",
+ "foaf": "http://xmlns.com/foaf/0.1/",
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
+ "dc:creator": {"@type": "@id"},
+ "doap:created": {"@type": "xsd:date"},
+ "doap:homepage": {"@type": "@id"},
+ "doap:bug-database": {"@type": "@id"},
+ "doap:blog": {"@type": "@id"},
+ "doap:developer": {"@type": "@id"},
+ "doap:maintainer": {"@type": "@id"},
+ "doap:documenter": {"@type": "@id"},
+ "doap:license": {"@type": "@id"},
+ "doap:description": {"@language": "en"},
+ "doap:shortdesc": {"@language": "en"},
+ "foaf:maker": {"@type": "@id"},
+ "foaf:mbox": {"@type": "@id"},
+ "foaf:made": {"@type": "@id"},
+ "rdfs:isDefinedBy": {"@type": "@id"}
},
"@id": "http://rubygems.org/gems/json-ld",
"@type": "doap:Project",
"doap:name": "JSON::LD",
"doap:homepage": "http://github.com/gkellogg/json-ld/",
"doap:license": "http://creativecommons.org/licenses/publicdomain/",
- "doap:shortdesc": { "@value": "JSON-LD support for RDF.rb.", "@language": "en"},
- "doap:description": { "@value": "RDF.rb plugin for parsing/serializing JSON-LD data.", "@language": "en"},
+ "doap:shortdesc": "JSON-LD support for RDF.rb.",
+ "doap:description": "RDF.rb plugin for parsing/serializing JSON-LD data.",
"doap:created": "2011-05-07",
"doap:platform": "Ruby",
"doap:bug-database": "http://github.com/gkellogg/json-ld/issues",
@@ -810,8 +810,8 @@ def bnode(value = nil)
# is lowest when the relative match between the term and the value
# is closest.
#
- # @property [String] term
- # @property [Object] value
+ # @param [String] term
+ # @param [Object] value
# @return [Integer]
def term_rank(term, value)
debug("term rank") { "term: #{term.inspect}, value: #{value.inspect}"}
View
@@ -5,7 +5,7 @@ module FromTriples
include Utils
##
- # Generate a JSON-LD array representation from an array of {RDF::Statement}.
+ # Generate a JSON-LD array representation from an array of `RDF::Statement`.
# Representation is in expanded form
#
# @param [Array<RDF::Statement>] input
View
@@ -169,7 +169,7 @@ def node
# @param [RDF::Term] object the object of the statement
# @param [RDF::Resource] name the named graph context of the statement
# @yield :statement
- # @yieldParams [RDF::Statement] :statement
+ # @yieldparam [RDF::Statement] :statement
def add_quad(path, subject, predicate, object, name)
predicate = RDF.type if predicate == '@type'
object = RDF::URI(object.to_s) if object.literal? && predicate == RDF.type
View
@@ -65,9 +65,10 @@ def depth(options = {})
end
##
- # Utility class for mapping old blank node identifiers, or unnamed blank nodes to new identifiers
+ # Utility class for mapping old blank node identifiers, or unnamed blank
+ # nodes to new identifiers
class BlankNodeNamer < Hash
- # @prefix [String] prefix
+ # @param [String] prefix
def initialize(prefix)
@prefix = "_:#{prefix}0"
super
View
@@ -18,26 +18,24 @@ def run(input, options)
if options[:expand]
output = JSON::LD::API.expand(input, nil, nil, options)
secs = Time.new - start
- options[:output].puts output
+ options[:output].puts output.to_json(JSON_STATE)
puts "Expanded in #{secs} seconds."
elsif options[:compact]
output = JSON::LD::API.compact(input, options[:context], nil, options)
secs = Time.new - start
- puts output.inspect
+ puts output.to_json(JSON_STATE)
puts "Compacted in #{secs} seconds."
elsif options[:frame]
output = JSON::LD::API.frame(input, options[:frame], nil, options)
secs = Time.new - start
- puts output.inspect
+ puts output.to_json(JSON_STATE)
puts "Framed in #{secs} seconds."
else
r = reader_class.new(input, options[:parser_options])
g = RDF::Repository.new << r
secs = Time.new - start
num = g.count
- puts "prefixes: #{r.prefixes.inspect}"
parser_options = options[:parser_options].merge(:prefixes => r.prefixes, :standard_prefixes => true)
- puts "begin dump: #{parser_options.inspect}"
options[:output].puts g.dump(options[:output_format], parser_options)
puts
puts "Parsed #{num} statements in #{secs} seconds @ #{num/secs} statements/second."
View
@@ -5,7 +5,7 @@
describe JSON::LD::API do
before(:each) { @debug = []}
- context ".statements" do
+ context ".toRDF" do
context "unnamed nodes" do
{
"no @id" => [

0 comments on commit 4f8f945

Please sign in to comment.