Skip to content

Commit f8fcb52

Browse files
committed
Finish 1.1.5.
* Fix odd case in fromRdf where rdf:nil is not used in a list, but is a vocabulary item, such as in the RDF vocabulary definition. * Support :unique_bnodes option to make sure that randomized BNode lables are generated when flattening or writing. * Minor update for in resource to see if a node is a node ref.
2 parents 4528f33 + 6397064 commit f8fcb52

File tree

13 files changed

+209
-32
lines changed

13 files changed

+209
-32
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ env:
55
- CI=true
66
rvm:
77
- 1.9.3
8-
- 2.0.0
8+
- 2.0
9+
- 2.1
910
- jruby-19mode
10-
- rbx
11+
- rbx-2
1112
cache: bundler

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212

1313
group :debug do
1414
gem "wirble"
15-
gem "byebug", :platforms => :mri_20
15+
gem "byebug", :platforms => [:mri_20, :mri_21]
1616
end
1717

1818
platforms :rbx do

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.4
1+
1.1.5

example-files/arnaud-lang.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
require 'json/ld'
3+
4+
context = JSON.parse %({
5+
"@vocab": "http://schema.org/" ,
6+
"dc": "http://purl.org/dc/elements/1.1/",
7+
"doag": "http://academy.dior.com/doag#",
8+
"dior": "http://academy.dior.com/terms#",
9+
"name": {
10+
"@container": "@language"
11+
}
12+
})
13+
14+
puts JSON::LD::API.compact("http://semio.dydra.com/arnaudlevy/dior-academy/seasons.jsonld?auth_token=rcelIAhAcmnYXv2A2rZ7", context).to_json(JSON::LD::JSON_STATE)

example-files/rdf.ttl

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
3+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
4+
@prefix dc: <http://purl.org/dc/elements/1.1/> .
5+
6+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> a owl:Ontology ;
7+
dc:title "The RDF Concepts Vocabulary (RDF)" ;
8+
dc:description "This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts." .
9+
10+
rdf:HTML a rdfs:Datatype ;
11+
rdfs:subClassOf rdfs:Literal ;
12+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
13+
rdfs:seeAlso <http://www.w3.org/TR/rdf11-concepts/#section-html> ;
14+
rdfs:label "HTML" ;
15+
rdfs:comment "The datatype of RDF literals storing fragments of HTML content" .
16+
17+
rdf:langString a rdfs:Datatype ;
18+
rdfs:subClassOf rdfs:Literal ;
19+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
20+
rdfs:seeAlso <http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal> ;
21+
rdfs:label "langString" ;
22+
rdfs:comment "The datatype of language-tagged string values" .
23+
24+
rdf:PlainLiteral a rdfs:Datatype ;
25+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
26+
rdfs:subClassOf rdfs:Literal ;
27+
rdfs:seeAlso <http://www.w3.org/TR/rdf-plain-literal/> ;
28+
rdfs:label "PlainLiteral" ;
29+
rdfs:comment "The class of plain (i.e. untyped) literal values, as used in RIF and OWL 2" .
30+
31+
rdf:type a rdf:Property ;
32+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
33+
rdfs:label "type" ;
34+
rdfs:comment "The subject is an instance of a class." ;
35+
rdfs:range rdfs:Class ;
36+
rdfs:domain rdfs:Resource .
37+
38+
rdf:Property a rdfs:Class ;
39+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
40+
rdfs:label "Property" ;
41+
rdfs:comment "The class of RDF properties." ;
42+
rdfs:subClassOf rdfs:Resource .
43+
44+
rdf:Statement a rdfs:Class ;
45+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
46+
rdfs:label "Statement" ;
47+
rdfs:subClassOf rdfs:Resource ;
48+
rdfs:comment "The class of RDF statements." .
49+
50+
rdf:subject a rdf:Property ;
51+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
52+
rdfs:label "subject" ;
53+
rdfs:comment "The subject of the subject RDF statement." ;
54+
rdfs:domain rdf:Statement ;
55+
rdfs:range rdfs:Resource .
56+
57+
rdf:predicate a rdf:Property ;
58+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
59+
rdfs:label "predicate" ;
60+
rdfs:comment "The predicate of the subject RDF statement." ;
61+
rdfs:domain rdf:Statement ;
62+
rdfs:range rdfs:Resource .
63+
64+
rdf:object a rdf:Property ;
65+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
66+
rdfs:label "object" ;
67+
rdfs:comment "The object of the subject RDF statement." ;
68+
rdfs:domain rdf:Statement ;
69+
rdfs:range rdfs:Resource .
70+
71+
rdf:Bag a rdfs:Class ;
72+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
73+
rdfs:label "Bag" ;
74+
rdfs:comment "The class of unordered containers." ;
75+
rdfs:subClassOf rdfs:Container .
76+
77+
rdf:Seq a rdfs:Class ;
78+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
79+
rdfs:label "Seq" ;
80+
rdfs:comment "The class of ordered containers." ;
81+
rdfs:subClassOf rdfs:Container .
82+
83+
rdf:Alt a rdfs:Class ;
84+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
85+
rdfs:label "Alt" ;
86+
rdfs:comment "The class of containers of alternatives." ;
87+
rdfs:subClassOf rdfs:Container .
88+
89+
rdf:value a rdf:Property ;
90+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
91+
rdfs:label "value" ;
92+
rdfs:comment "Idiomatic property used for structured values." ;
93+
rdfs:domain rdfs:Resource ;
94+
rdfs:range rdfs:Resource .
95+
96+
rdf:List a rdfs:Class ;
97+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
98+
rdfs:label "List" ;
99+
rdfs:comment "The class of RDF Lists." ;
100+
rdfs:subClassOf rdfs:Resource .
101+
102+
rdf:nil a rdf:List ;
103+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
104+
rdfs:label "nil" ;
105+
rdfs:comment "The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it." .
106+
107+
rdf:first a rdf:Property ;
108+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
109+
rdfs:label "first" ;
110+
rdfs:comment "The first item in the subject RDF list." ;
111+
rdfs:domain rdf:List ;
112+
rdfs:range rdfs:Resource .
113+
114+
rdf:rest a rdf:Property ;
115+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
116+
rdfs:label "rest" ;
117+
rdfs:comment "The rest of the subject RDF list after the first item." ;
118+
rdfs:domain rdf:List ;
119+
rdfs:range rdf:List .
120+
121+
rdf:XMLLiteral a rdfs:Datatype ;
122+
rdfs:subClassOf rdfs:Literal ;
123+
rdfs:isDefinedBy <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ;
124+
rdfs:label "XMLLiteral" ;
125+
rdfs:comment "The datatype of XML literal values." .

json-ld.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |gem|
2727

2828
gem.required_ruby_version = '>= 1.9.2'
2929
gem.requirements = []
30-
gem.add_runtime_dependency 'rdf', '~> 1.1'
30+
gem.add_runtime_dependency 'rdf', '~> 1.1', '>= 1.1.4'
3131
gem.add_development_dependency 'equivalent-xml' , '~> 0.4'
3232
gem.add_development_dependency 'open-uri-cached', '~> 0.0', '>= 0.0.5'
3333
gem.add_development_dependency 'yard' , '~> 0.8'

lib/json/ld/api.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ class API
7272
# If set to `true`, the JSON-LD processor will treat `rdf:type` like a normal property instead of using `@type`.
7373
# @option options [Boolean] :rename_bnodes (true)
7474
# Rename bnodes as part of expansion, or keep them the same.
75+
# @option options [Boolean] :unique_bnodes (false)
76+
# Use unique bnode identifiers, defaults to using the identifier which the node was originall initialized with (if any).
7577
# @yield [api]
7678
# @yieldparam [API]
7779
def initialize(input, context, options = {}, &block)
7880
@options = {:compactArrays => true}.merge(options)
7981
@options[:validate] = true if @options[:processingMode] == "json-ld-1.0"
8082
@options[:documentLoader] ||= self.class.method(:documentLoader)
8183
options[:rename_bnodes] ||= true
82-
@namer = options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new
84+
@namer = options[:unique_bnodes] ? BlankNodeUniqer.new : (options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
8385
@value = case input
8486
when Array, Hash then input.dup
8587
when IO, StringIO

lib/json/ld/from_rdf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def from_statements(input)
6262
next unless nil_var = graph_object[RDF.nil.to_s]
6363

6464
# For each item usage in the usages member of nil, perform the following steps:
65-
nil_var[:usages].each do |usage|
65+
nil_var.fetch(:usages, []).each do |usage|
6666
node, property, head = usage[:node], usage[:property], usage[:value]
6767
list, list_nodes = [], []
6868

lib/json/ld/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def update_obj(obj, reference_map)
167167
when Array
168168
obj.map {|o| update_obj(o, reference_map)}
169169
when Hash
170-
if obj.node_ref?
170+
if node_reference?(obj)
171171
reference_map[obj['id']] ||= Resource.new(obj,
172172
:context => @context_name,
173173
:clean => false,

lib/json/ld/utils.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ def get_name(old = "")
163163
end
164164
end
165165

166+
class BlankNodeUniqer < BlankNodeMapper
167+
##
168+
# Use the uniquely generated bnodes, rather than a sequence
169+
# @param [String] old ("")
170+
# @return [String]
171+
def get_sym(old = "")
172+
old = old.to_s.sub(/_:/, '')
173+
if old && self.has_key?(old)
174+
self[old]
175+
elsif !old.empty?
176+
self[old] = RDF::Node.new.to_unique_base[2..-1]
177+
else
178+
RDF::Node.new.to_unique_base[2..-1]
179+
end
180+
end
181+
end
182+
166183
class BlankNodeNamer < BlankNodeMapper
167184
# @param [String] prefix
168185
def initialize(prefix)

0 commit comments

Comments
 (0)