Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Documentation update for release 0.1.2

  • Loading branch information...
commit 4f8f9451798412d7b748d78854447db9af1bb938 1 parent 6932dd7
Gregg Kellogg authored April 21, 2012
2  .gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9 9
   gem.homepage              = "http://github.com/gkellogg/json-ld"
10 10
   gem.license               = 'Public Domain' if gem.respond_to?(:license=)
11 11
   gem.summary               = "JSON-LD reader/writer for Ruby."
12  
-  gem.description           = gem.summary
  12
+  gem.description           = "JSON::LD parses and serializes JSON-LD into RDF and implements expansion, compaction and framing API interfaces."
13 13
   gem.rubyforge_project     = 'json-ld'
14 14
 
15 15
   gem.authors               = ['Gregg Kellogg']
1  Gemfile.lock
@@ -9,6 +9,7 @@ PATH
9 9
   remote: .
10 10
   specs:
11 11
     json-ld (0.1.2)
  12
+      backports
12 13
       json (>= 1.6.5)
13 14
       rdf (>= 0.3.5)
14 15
 
2  README
202  README.markdown
Source Rendered
@@ -4,7 +4,8 @@
4 4
 
5 5
 ## Features
6 6
 
7  
-JSON::LD parses and serializes [JSON-LD][] into statements or statements.
  7
+JSON::LD parses and serializes [JSON-LD][] into [RDF][] and implements
  8
+JSON::LD expansion, compaction and framing API interfaces.
8 9
 
9 10
 Install with `gem install json-ld`
10 11
 
@@ -13,13 +14,208 @@ Install with `gem install json-ld`
13 14
     require 'rubygems'
14 15
     require 'json/ld'
15 16
 
  17
+### Expand a Document
  18
+
  19
+    input = {
  20
+      "@context": {
  21
+        "name": "http://xmlns.com/foaf/0.1/name",
  22
+        "homepage": "http://xmlns.com/foaf/0.1/homepage",
  23
+        "avatar": "http://xmlns.com/foaf/0.1/avatar"
  24
+      },
  25
+      "name": "Manu Sporny",
  26
+      "homepage": "http://manu.sporny.org/",
  27
+      "avatar": "http://twitter.com/account/profile_image/manusporny"
  28
+    }
  29
+    JSON::LD::API.expand(input) =>
  30
+    
  31
+    [{
  32
+        "http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
  33
+        "http://xmlns.com/foaf/0.1/homepage": ["http://manu.sporny.org/"],
  34
+        "http://xmlns.com/foaf/0.1/avatar": ["http://twitter.com/account/profile_image/manusporny"]
  35
+    }]
  36
+
  37
+### Compact a Document
  38
+
  39
+    input = [{
  40
+        "http://xmlns.com/foaf/0.1/name": ["Manu Sporny"],
  41
+        "http://xmlns.com/foaf/0.1/homepage": ["http://manu.sporny.org/"],
  42
+        "http://xmlns.com/foaf/0.1/avatar": ["http://twitter.com/account/profile_image/manusporny"]
  43
+    }]
  44
+    
  45
+    context = {
  46
+      "@context": {
  47
+        "name": "http://xmlns.com/foaf/0.1/name",
  48
+        "homepage": "http://xmlns.com/foaf/0.1/homepage",
  49
+        "avatar": "http://xmlns.com/foaf/0.1/avatar"
  50
+      }
  51
+    }
  52
+    
  53
+    JSON::LD::API.compact(input, context) =>
  54
+    {
  55
+        "@context": {
  56
+            "avatar": "http://xmlns.com/foaf/0.1/avatar",
  57
+            "homepage": "http://xmlns.com/foaf/0.1/homepage",
  58
+            "name": "http://xmlns.com/foaf/0.1/name"
  59
+        },
  60
+        "avatar": "http://twitter.com/account/profile_image/manusporny",
  61
+        "homepage": "http://manu.sporny.org/",
  62
+        "name": "Manu Sporny"
  63
+    }
  64
+
  65
+### Frame a Document
  66
+
  67
+    input = {
  68
+      "@context": {
  69
+        "Book":         "http://example.org/vocab#Book",
  70
+        "Chapter":      "http://example.org/vocab#Chapter",
  71
+        "contains":     {"@id": "http://example.org/vocab#contains", "@type": "@id"},
  72
+        "creator":      "http://purl.org/dc/terms/creator",
  73
+        "description":  "http://purl.org/dc/terms/description",
  74
+        "Library":      "http://example.org/vocab#Library",
  75
+        "title":        "http://purl.org/dc/terms/title"
  76
+      },
  77
+      "@graph":
  78
+      [{
  79
+        "@id": "http://example.com/library",
  80
+        "@type": "Library",
  81
+        "contains": "http://example.org/library/the-republic"
  82
+      },
  83
+      {
  84
+        "@id": "http://example.org/library/the-republic",
  85
+        "@type": "Book",
  86
+        "creator": "Plato",
  87
+        "title": "The Republic",
  88
+        "contains": "http://example.org/library/the-republic#introduction"
  89
+      },
  90
+      {
  91
+        "@id": "http://example.org/library/the-republic#introduction",
  92
+        "@type": "Chapter",
  93
+        "description": "An introductory chapter on The Republic.",
  94
+        "title": "The Introduction"
  95
+      }]
  96
+    }
  97
+    
  98
+    frame = {
  99
+      "@context": {
  100
+        "Book":         "http://example.org/vocab#Book",
  101
+        "Chapter":      "http://example.org/vocab#Chapter",
  102
+        "contains":     "http://example.org/vocab#contains",
  103
+        "creator":      "http://purl.org/dc/terms/creator",
  104
+        "description":  "http://purl.org/dc/terms/description",
  105
+        "Library":      "http://example.org/vocab#Library",
  106
+        "title":        "http://purl.org/dc/terms/title"
  107
+      },
  108
+      "@type": "Library",
  109
+      "contains": {
  110
+        "@type": "Book",
  111
+        "contains": {
  112
+          "@type": "Chapter"
  113
+        }
  114
+      }
  115
+    }
  116
+    JSON::LD.frame(input, frame) =>
  117
+    {
  118
+      "@context": {
  119
+        "Book": "http://example.org/vocab#Book",
  120
+        "Chapter": "http://example.org/vocab#Chapter",
  121
+        "contains": "http://example.org/vocab#contains",
  122
+        "creator": "http://purl.org/dc/terms/creator",
  123
+        "description": "http://purl.org/dc/terms/description",
  124
+        "Library": "http://example.org/vocab#Library",
  125
+        "title": "http://purl.org/dc/terms/title"
  126
+      },
  127
+      "@graph": [
  128
+        {
  129
+          "@id": "http://example.com/library",
  130
+          "@type": "Library",
  131
+          "contains": {
  132
+            "@id": "http://example.org/library/the-republic",
  133
+            "@type": "Book",
  134
+            "contains": {
  135
+              "@id": "http://example.org/library/the-republic#introduction",
  136
+              "@type": "Chapter",
  137
+              "description": "An introductory chapter on The Republic.",
  138
+              "title": "The Introduction"
  139
+            },
  140
+            "creator": "Plato",
  141
+            "title": "The Republic"
  142
+          }
  143
+        }
  144
+      ]
  145
+    }
  146
+
  147
+### Turn JSON-LD into RDF (Turtle)
  148
+
  149
+    input = {
  150
+      "@context": {
  151
+        "":       "http://manu.sporny.org/",
  152
+        "foaf":   "http://xmlns.com/foaf/0.1/"
  153
+      },
  154
+      "@id":       "http://example.org/people#joebob",
  155
+      "@type":          "foaf:Person",
  156
+      "foaf:name":      "Joe Bob",
  157
+      "foaf:nick":      { "@list": [ "joe", "bob", "jaybe" ] }
  158
+    }
  159
+    
  160
+    JSON::LD::API.toRDF(input) =>
  161
+    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
  162
+
  163
+    <http://example.org/people#joebob> a foaf:Person;
  164
+       foaf:name "Joe Bob";
  165
+       foaf:nick ("joe" "bob" "jaybe") .
  166
+
  167
+### Turn RDF into JSON-LD
  168
+
  169
+    input =
  170
+    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
  171
+
  172
+    <http://manu.sporny.org/#me> a foaf:Person;
  173
+       foaf:knows [ a foaf:Person;
  174
+         foaf:name "Gregg Kellogg"];
  175
+       foaf:name "Manu Sporny" .
  176
+    
  177
+    context =
  178
+    {
  179
+      "@context": {
  180
+        "":       "http://manu.sporny.org/",
  181
+        "foaf":   "http://xmlns.com/foaf/0.1/"
  182
+      }
  183
+    }
  184
+
  185
+    JSON::LD::fromRDF(input, context) =>
  186
+    {
  187
+      "@context": {
  188
+        "":       "http://manu.sporny.org/",
  189
+        "foaf":   "http://xmlns.com/foaf/0.1/"
  190
+      },
  191
+      "@id":       ":#me",
  192
+      "@type":          "foaf:Person",
  193
+      "foaf:name":      "Manu Sporny",
  194
+      "foaf:knows": {
  195
+        "@type":          "foaf:Person",
  196
+        "foaf:name":      "Gregg Kellogg"
  197
+      }
  198
+    }
  199
+
  200
+## RDF Reader and Writer
  201
+{JSON::LD} also acts as a normal RDF reader and writer, using the standard RDF.rb reader/writer interfaces:
  202
+
  203
+    graph = RDF::Graph.load("etc/doap.jsonld", :format => :jsonld)
  204
+    graph.dump(:jsonld, :standard_prefixes => true)
  205
+
16 206
 ## Documentation
17  
-Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-ld/0.0.4/file/README)
  207
+Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-ld/file/README.markdown)
18 208
 
19 209
 ### Principle Classes
20 210
 * {JSON::LD}
  211
+  * {JSON::LD::API}
  212
+  * {JSON::LD::Compact}
  213
+  * {JSON::LD::EvaluationContext}
21 214
   * {JSON::LD::Format}
  215
+  * {JSON::LD::Frame}
  216
+  * {JSON::LD::FromTriples}
22 217
   * {JSON::LD::Reader}
  218
+  * {JSON::LD::Triples}
23 219
   * {JSON::LD::Writer}
24 220
 
25 221
 ## Dependencies
@@ -70,4 +266,4 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
70 266
 [PDD]:              http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
71 267
 [RDF.rb]:           http://rdf.rubyforge.org/
72 268
 [Backports]:        http://rubygems.org/gems/backports
73  
-[JSON-LD]:          http://json-ld.org/spec/ED/20110507/
  269
+[JSON-LD]:          http://json-ld.org/spec/latest/
2  VERSION
... ...
@@ -1 +1 @@
1  
-0.1.1
  1
+0.1.2
44  etc/doap.jsonld
... ...
@@ -1,31 +1,33 @@
1 1
 {
2  
-    "@context": {
3  
-        "dc":       "http://purl.org/dc/terms/",
4  
-        "doap": "http://usefulinc.com/ns/doap#",
5  
-        "foaf": "http://xmlns.com/foaf/0.1/",
6  
-        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
7  
-        "xsd":      "http://www.w3.org/2001/XMLSchema#",
8  
-        "dc:creator": {"@type": "@id"},
9  
-        "doap:created": {"@type": "xsd:date"},
10  
-        "doap:homepage": {"@type": "@id"},
11  
-        "doap:bug-database": {"@type": "@id"},
12  
-        "doap:blog": {"@type": "@id"},
13  
-        "doap:developer": {"@type": "@id"},
14  
-        "doap:maintainer": {"@type": "@id"},
15  
-        "doap:documenter": {"@type": "@id"},
16  
-        "doap:license": {"@type": "@id"},
17  
-        "foaf:maker": {"@type": "@id"},
18  
-        "foaf:mbox": {"@type": "@id"},
19  
-        "foaf:made": {"@type": "@id"},
20  
-        "rdfs:isDefinedBy": {"@type": "@id"}
  2
+  "@context": {
  3
+      "dc":       "http://purl.org/dc/terms/",
  4
+      "doap": "http://usefulinc.com/ns/doap#",
  5
+      "foaf": "http://xmlns.com/foaf/0.1/",
  6
+      "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
  7
+      "xsd":      "http://www.w3.org/2001/XMLSchema#",
  8
+      "dc:creator": {"@type": "@id"},
  9
+      "doap:created": {"@type": "xsd:date"},
  10
+      "doap:homepage": {"@type": "@id"},
  11
+      "doap:bug-database": {"@type": "@id"},
  12
+      "doap:blog": {"@type": "@id"},
  13
+      "doap:developer": {"@type": "@id"},
  14
+      "doap:maintainer": {"@type": "@id"},
  15
+      "doap:documenter": {"@type": "@id"},
  16
+      "doap:license": {"@type": "@id"},
  17
+      "doap:description": {"@language": "en"},
  18
+      "doap:shortdesc": {"@language": "en"},
  19
+      "foaf:maker": {"@type": "@id"},
  20
+      "foaf:mbox": {"@type": "@id"},
  21
+      "foaf:made": {"@type": "@id"},
  22
+      "rdfs:isDefinedBy": {"@type": "@id"}
21 23
     },
22 24
     "@id":                "http://rubygems.org/gems/json-ld",
23 25
     "@type":              "doap:Project",
24 26
     "doap:name":          "JSON::LD",
25 27
     "doap:homepage":      "http://github.com/gkellogg/json-ld/",
26 28
     "doap:license":       "http://creativecommons.org/licenses/publicdomain/",
27  
-    "doap:shortdesc":     { "@value": "JSON-LD support for RDF.rb.", "@language": "en"},
28  
-    "doap:description":   { "@value": "RDF.rb plugin for parsing/serializing JSON-LD data.", "@language": "en"},
  29
+    "doap:shortdesc":     "JSON-LD support for RDF.rb.",
  30
+    "doap:description":   "RDF.rb plugin for parsing/serializing JSON-LD data.",
29 31
     "doap:created":       "2011-05-07",
30 32
     "doap:platform":      "Ruby",
31 33
     "doap:bug-database":  "http://github.com/gkellogg/json-ld/issues",
4  lib/json/ld/evaluation_context.rb
@@ -810,8 +810,8 @@ def bnode(value = nil)
810 810
     # is lowest when the relative match between the term and the value
811 811
     # is closest.
812 812
     #
813  
-    # @property [String] term
814  
-    # @property [Object] value
  813
+    # @param [String] term
  814
+    # @param [Object] value
815 815
     # @return [Integer]
816 816
     def term_rank(term, value)
817 817
       debug("term rank") { "term: #{term.inspect}, value: #{value.inspect}"}
2  lib/json/ld/from_rdf.rb
@@ -5,7 +5,7 @@ module FromTriples
5 5
     include Utils
6 6
 
7 7
     ##
8  
-    # Generate a JSON-LD array representation from an array of {RDF::Statement}.
  8
+    # Generate a JSON-LD array representation from an array of `RDF::Statement`.
9 9
     # Representation is in expanded form
10 10
     #
11 11
     # @param [Array<RDF::Statement>] input
2  lib/json/ld/to_rdf.rb
@@ -169,7 +169,7 @@ def node
169 169
     # @param [RDF::Term] object the object of the statement
170 170
     # @param [RDF::Resource] name the named graph context of the statement
171 171
     # @yield :statement
172  
-    # @yieldParams [RDF::Statement] :statement
  172
+    # @yieldparam [RDF::Statement] :statement
173 173
     def add_quad(path, subject, predicate, object, name)
174 174
       predicate = RDF.type if predicate == '@type'
175 175
       object = RDF::URI(object.to_s) if object.literal? && predicate == RDF.type
5  lib/json/ld/utils.rb
@@ -65,9 +65,10 @@ def depth(options = {})
65 65
   end
66 66
 
67 67
   ##
68  
-  # Utility class for mapping old blank node identifiers, or unnamed blank nodes to new identifiers
  68
+  # Utility class for mapping old blank node identifiers, or unnamed blank
  69
+  # nodes to new identifiers
69 70
   class BlankNodeNamer < Hash
70  
-    # @prefix [String] prefix
  71
+    # @param [String] prefix
71 72
     def initialize(prefix)
72 73
       @prefix = "_:#{prefix}0"
73 74
       super
8  script/parse
@@ -18,26 +18,24 @@ def run(input, options)
18 18
   if options[:expand]
19 19
     output = JSON::LD::API.expand(input, nil, nil, options)
20 20
     secs = Time.new - start
21  
-    options[:output].puts output
  21
+    options[:output].puts output.to_json(JSON_STATE)
22 22
     puts "Expanded in #{secs} seconds."
23 23
   elsif options[:compact]
24 24
     output = JSON::LD::API.compact(input, options[:context], nil, options)
25 25
     secs = Time.new - start
26  
-    puts output.inspect
  26
+    puts output.to_json(JSON_STATE)
27 27
     puts "Compacted in #{secs} seconds."
28 28
   elsif options[:frame]
29 29
     output = JSON::LD::API.frame(input, options[:frame], nil, options)
30 30
     secs = Time.new - start
31  
-    puts output.inspect
  31
+    puts output.to_json(JSON_STATE)
32 32
     puts "Framed in #{secs} seconds."
33 33
   else
34 34
     r = reader_class.new(input, options[:parser_options])
35 35
     g = RDF::Repository.new << r
36 36
     secs = Time.new - start
37 37
     num = g.count
38  
-    puts "prefixes: #{r.prefixes.inspect}"
39 38
     parser_options = options[:parser_options].merge(:prefixes => r.prefixes, :standard_prefixes => true)
40  
-    puts "begin dump: #{parser_options.inspect}"
41 39
     options[:output].puts g.dump(options[:output_format], parser_options)
42 40
     puts
43 41
     puts "Parsed #{num} statements in #{secs} seconds @ #{num/secs} statements/second."
2  spec/to_rdf_spec.rb
@@ -5,7 +5,7 @@
5 5
 describe JSON::LD::API do
6 6
   before(:each) { @debug = []}
7 7
 
8  
-  context ".statements" do
  8
+  context ".toRDF" do
9 9
     context "unnamed nodes" do
10 10
       {
11 11
         "no @id" => [

0 notes on commit 4f8f945

Please sign in to comment.
Something went wrong with that request. Please try again.