rdf-json 0.2.0 → 0.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/CREDITS ADDED
File without changes
data/README CHANGED
@@ -1,8 +1,8 @@
1
1
  RDF/JSON Support for RDF.rb
2
2
  ===========================
3
3
 
4
- This is an [RDF.rb][] plugin that adds support for parsing/serializing the
5
- [RDF/JSON][] serialization format.
4
+ This is an [RDF.rb][] plugin that adds support for parsing/serializing
5
+ [RDF/JSON][], a simple JSON-based RDF serialization format.
6
6
 
7
7
  * <http://github.com/bendiken/rdf-json>
8
8
  * <http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby>
@@ -19,8 +19,8 @@ Documentation
19
19
  Dependencies
20
20
  ------------
21
21
 
22
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.2.0)
23
- * [JSON](http://rubygems.org/gems/json_pure) (>= 1.4.3)
22
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.0)
23
+ * [JSON](http://rubygems.org/gems/json_pure) (>= 1.4.2)
24
24
 
25
25
  Installation
26
26
  ------------
@@ -37,21 +37,31 @@ To get a local working copy of the development repository, do:
37
37
 
38
38
  % git clone git://github.com/bendiken/rdf-json.git
39
39
 
40
- Alternatively, you can download the latest development version as a tarball
41
- as follows:
40
+ Alternatively, download the latest development version as a tarball as
41
+ follows:
42
42
 
43
43
  % wget http://github.com/bendiken/rdf-json/tarball/master
44
44
 
45
+ Mailing List
46
+ ------------
47
+
48
+ * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
49
+
45
50
  Author
46
51
  ------
47
52
 
48
- * [Arto Bendiken](mailto:arto.bendiken@gmail.com) - <http://ar.to/>
53
+ * [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
54
+
55
+ Contributors
56
+ ------------
57
+
58
+ Refer to the accompanying {file:CREDITS} file.
49
59
 
50
60
  License
51
61
  -------
52
62
 
53
- `RDF::JSON` is free and unencumbered public domain software. For more
54
- information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
63
+ This is free and unencumbered public domain software. For more information,
64
+ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
55
65
 
56
66
  [RDF.rb]: http://rdf.rubyforge.org/
57
67
  [RDF/JSON]: http://n2.talis.com/wiki/RDF_JSON_Specification
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0.pre
data/lib/rdf/json.rb CHANGED
@@ -42,5 +42,5 @@ module RDF
42
42
  autoload :Reader, 'rdf/json/reader'
43
43
  autoload :Writer, 'rdf/json/writer'
44
44
  autoload :VERSION, 'rdf/json/version'
45
- end # module JSON
46
- end # module RDF
45
+ end # JSON
46
+ end # RDF
@@ -51,7 +51,7 @@ module RDF::JSON
51
51
  # Any RDF/JSON-compatible class must implement `#to_rdf_json`:
52
52
  to_rdf_json.to_json
53
53
  end
54
- end
54
+ end # Value
55
55
 
56
56
  ##
57
57
  # RDF/JSON extensions for `RDF::Node`.
@@ -63,7 +63,7 @@ module RDF::JSON
63
63
  def to_rdf_json
64
64
  {:type => :bnode, :value => to_s}
65
65
  end
66
- end
66
+ end # Node
67
67
 
68
68
  ##
69
69
  # RDF/JSON extensions for `RDF::URI`.
@@ -75,7 +75,7 @@ module RDF::JSON
75
75
  def to_rdf_json
76
76
  {:type => :uri, :value => to_s}
77
77
  end
78
- end
78
+ end # URI
79
79
 
80
80
  ##
81
81
  # RDF/JSON extensions for `RDF::Literal`.
@@ -94,7 +94,7 @@ module RDF::JSON
94
94
  {:type => :literal, :value => value.to_s}
95
95
  end
96
96
  end
97
- end
97
+ end # Literal
98
98
 
99
99
  ##
100
100
  # RDF/JSON extensions for `RDF::Statement`.
@@ -106,7 +106,7 @@ module RDF::JSON
106
106
  def to_rdf_json
107
107
  {subject.to_s => {predicate.to_s => [object.to_rdf_json]}}
108
108
  end
109
- end
109
+ end # Statement
110
110
 
111
111
  ##
112
112
  # RDF/JSON extensions for `RDF::Enumerable`.
@@ -135,20 +135,38 @@ module RDF::JSON
135
135
  end
136
136
  json
137
137
  end
138
- end
138
+ end # Enumerable
139
139
 
140
140
  ##
141
141
  # RDF/JSON extensions for `RDF::Graph`.
142
142
  module Graph
143
143
  include Enumerable
144
- end
144
+ end # Graph
145
145
 
146
146
  ##
147
147
  # RDF/JSON extensions for `RDF::Repository`.
148
148
  module Repository
149
149
  include Enumerable
150
- end
151
- end # module Extensions
150
+ end # Repository
151
+
152
+ ##
153
+ # RDF/JSON extensions for `RDF::Transaction`.
154
+ module Transaction
155
+ ##
156
+ # Returns the serialized JSON representation of this object.
157
+ #
158
+ # @return [String]
159
+ def to_json
160
+ json = options.dup.to_hash rescue {}
161
+ json.merge!({
162
+ :graph => graph ? graph.to_uri.to_s : nil,
163
+ :delete => deletes.to_rdf_json,
164
+ :insert => inserts.to_rdf_json,
165
+ })
166
+ json.to_json
167
+ end
168
+ end # Transaction
169
+ end # Extensions
152
170
 
153
171
  Extensions.install!
154
- end # module RDF::JSON
172
+ end # RDF::JSON
@@ -2,6 +2,9 @@ module RDF::JSON
2
2
  ##
3
3
  # RDF/JSON format specification.
4
4
  #
5
+ # @example Loading RDF/JSON format support
6
+ # require 'rdf/json'
7
+ #
5
8
  # @example Obtaining an RDF/JSON format class
6
9
  # RDF::Format.for(:json) #=> RDF::JSON::Format
7
10
  # RDF::Format.for("etc/doap.json")
@@ -18,5 +21,5 @@ module RDF::JSON
18
21
  writer { RDF::JSON::Writer }
19
22
 
20
23
  require 'json'
21
- end # class Format
22
- end # module RDF::JSON
24
+ end # Format
25
+ end # RDF::JSON
@@ -2,6 +2,9 @@ module RDF::JSON
2
2
  ##
3
3
  # RDF/JSON parser.
4
4
  #
5
+ # @example Loading RDF/JSON parsing support
6
+ # require 'rdf/json'
7
+ #
5
8
  # @example Obtaining an RDF/JSON reader class
6
9
  # RDF::Reader.for(:json) #=> RDF::JSON::Reader
7
10
  # RDF::Reader.for("etc/doap.json")
@@ -29,6 +32,8 @@ module RDF::JSON
29
32
  format RDF::JSON::Format
30
33
 
31
34
  ##
35
+ # The graph constructed when parsing.
36
+ #
32
37
  # @return [RDF::Graph]
33
38
  attr_reader :graph
34
39
 
@@ -43,7 +48,7 @@ module RDF::JSON
43
48
  super do
44
49
  @graph = RDF::Graph.new
45
50
 
46
- JSON.parse(@input.read).each do |subject, predicates|
51
+ ::JSON.parse(@input.read).each do |subject, predicates|
47
52
  subject = parse_subject(subject)
48
53
  predicates.each do |predicate, objects|
49
54
  predicate = parse_predicate(predicate)
@@ -65,8 +70,8 @@ module RDF::JSON
65
70
  # @return [RDF::Resource]
66
71
  def parse_subject(subject)
67
72
  case subject
68
- when /^_:/ then RDF::Node.new(subject[2..-1])
69
- else RDF::URI.new(subject)
73
+ when /^_:/ then parse_node(subject)
74
+ else parse_uri(subject)
70
75
  end
71
76
  end
72
77
 
@@ -76,8 +81,8 @@ module RDF::JSON
76
81
  # @param [String] predicate
77
82
  # @return [RDF::URI]
78
83
  def parse_predicate(predicate)
79
- # TODO: optional support for CURIE predicates (issue #1 on GitHub).
80
- RDF::URI.intern(predicate)
84
+ # TODO: optional support for CURIE predicates? (issue #1 on GitHub).
85
+ parse_uri(predicate, :intern => true)
81
86
  end
82
87
 
83
88
  ##
@@ -86,44 +91,80 @@ module RDF::JSON
86
91
  # @param [Hash{String => Object}] object
87
92
  # @return [RDF::Value]
88
93
  def parse_object(object)
89
- raise RDF::ReaderError.new, "missing 'type' key in #{object.inspect}" unless object.has_key?('type')
90
- raise RDF::ReaderError.new, "missing 'value' key in #{object.inspect}" unless object.has_key?('value')
94
+ raise RDF::ReaderError, "missing 'type' key in #{object.inspect}" unless object.has_key?('type')
95
+ raise RDF::ReaderError, "missing 'value' key in #{object.inspect}" unless object.has_key?('value')
91
96
 
92
97
  case type = object['type']
93
98
  when 'bnode'
94
- RDF::Node.new(object['value'][2..-1])
99
+ parse_node(object['value'])
95
100
  when 'uri'
96
- RDF::URI.new(object['value'])
101
+ parse_uri(object['value'])
97
102
  when 'literal'
98
- RDF::Literal.new(object['value'], {
103
+ literal = RDF::Literal.new(object['value'], {
99
104
  :language => object['lang'],
100
105
  :datatype => object['datatype'],
101
106
  })
107
+ literal.validate! if validate?
108
+ literal.canonicalize! if canonicalize?
109
+ literal
102
110
  else
103
111
  raise RDF::ReaderError, "expected 'type' to be 'bnode', 'uri', or 'literal', but got #{type.inspect}"
104
112
  end
105
113
  end
106
114
 
115
+ ##
116
+ # Parses an RDF/JSON blank node string into an `RDF::Node` instance.
117
+ #
118
+ # @param [String] string
119
+ # @return [RDF::Node]
120
+ def parse_node(string)
121
+ RDF::Node.new(string[2..-1]) # strips off the initial '_:'
122
+ end
123
+ alias_method :parse_bnode, :parse_node
124
+
125
+ ##
126
+ # Parses an RDF/JSON URI string into an `RDF::URI` instance.
127
+ #
128
+ # @param [String] string
129
+ # @param [Hash{Symbol => Object}] options
130
+ # @option options [Boolean] :intern (false)
131
+ # @return [RDF::URI]
132
+ def parse_uri(string, options = {})
133
+ uri = RDF::URI.send(intern = intern? && options[:intern] ? :intern : :new, string)
134
+ uri.validate! if validate?
135
+ uri.canonicalize! if canonicalize? && !intern
136
+ uri
137
+ end
138
+
107
139
  ##
108
140
  # @private
109
141
  # @see RDF::Reader#each_graph
110
142
  # @since 0.2.0
111
143
  def each_graph(&block)
112
- block_given? ? @block.call(@graph) : enum_for(:each_graph).extend(RDF::Countable)
144
+ if block_given?
145
+ block.call(@graph)
146
+ end
147
+ enum_graph
113
148
  end
114
149
 
115
150
  ##
116
151
  # @private
117
152
  # @see RDF::Reader#each_statement
118
153
  def each_statement(&block)
119
- block_given? ? @graph.each_statement(&block) : enum_for(:each_statement).extend(RDF::Countable)
154
+ if block_given?
155
+ @graph.each_statement(&block)
156
+ end
157
+ enum_statement
120
158
  end
121
159
 
122
160
  ##
123
161
  # @private
124
- # @see RDF::Reader#each_statement
162
+ # @see RDF::Reader#each_triple
125
163
  def each_triple(&block)
126
- block_given? ? @graph.each_triple(&block) : enum_for(:each_triple).extend(RDF::Countable)
164
+ if block_given?
165
+ @graph.each_triple(&block)
166
+ end
167
+ enum_triple
127
168
  end
128
- end # class Reader
129
- end # module RDF::JSON
169
+ end # Reader
170
+ end # RDF::JSON
@@ -1,9 +1,9 @@
1
1
  module RDF; module JSON
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 2
4
+ MINOR = 3
5
5
  TINY = 0
6
- EXTRA = nil
6
+ EXTRA = :pre
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
9
9
 
@@ -2,6 +2,9 @@ module RDF::JSON
2
2
  ##
3
3
  # RDF/JSON serializer.
4
4
  #
5
+ # @example Loading RDF/JSON serialization support
6
+ # require 'rdf/json'
7
+ #
5
8
  # @example Obtaining an RDF/JSON writer class
6
9
  # RDF::Writer.for(:json) #=> RDF::JSON::Writer
7
10
  # RDF::Writer.for("etc/test.json")
@@ -86,5 +89,5 @@ module RDF::JSON
86
89
  else RDF::Literal.new(value).to_json
87
90
  end
88
91
  end
89
- end # class Writer
90
- end # module RDF::JSON
92
+ end # Writer
93
+ end # RDF::JSON
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-json
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ - pre
10
+ version: 0.3.0.pre
10
11
  platform: ruby
11
12
  authors:
12
13
  - Arto Bendiken
@@ -14,36 +15,37 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-18 00:00:00 +02:00
18
+ date: 2010-11-19 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: rdf-spec
22
+ name: json_pure
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - ~>
26
+ - - ">="
26
27
  - !ruby/object:Gem::Version
27
28
  segments:
28
- - 0
29
+ - 1
30
+ - 4
29
31
  - 2
30
- - 0
31
- version: 0.2.0
32
- type: :development
32
+ version: 1.4.2
33
+ type: :runtime
33
34
  version_requirements: *id001
34
35
  - !ruby/object:Gem::Dependency
35
- name: rspec
36
+ name: rdf
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - ">="
40
+ - - "="
40
41
  - !ruby/object:Gem::Version
41
42
  segments:
42
- - 1
43
+ - 0
43
44
  - 3
44
45
  - 0
45
- version: 1.3.0
46
- type: :development
46
+ - pre
47
+ version: 0.3.0.pre
48
+ type: :runtime
47
49
  version_requirements: *id002
48
50
  - !ruby/object:Gem::Dependency
49
51
  name: yard
@@ -54,38 +56,39 @@ dependencies:
54
56
  - !ruby/object:Gem::Version
55
57
  segments:
56
58
  - 0
57
- - 5
58
59
  - 6
59
- version: 0.5.6
60
+ - 0
61
+ version: 0.6.0
60
62
  type: :development
61
63
  version_requirements: *id003
62
64
  - !ruby/object:Gem::Dependency
63
- name: rdf
65
+ name: rspec
64
66
  prerelease: false
65
67
  requirement: &id004 !ruby/object:Gem::Requirement
66
68
  requirements:
67
- - - ~>
69
+ - - ">="
68
70
  - !ruby/object:Gem::Version
69
71
  segments:
72
+ - 1
73
+ - 3
70
74
  - 0
71
- - 2
72
- - 0
73
- version: 0.2.0
74
- type: :runtime
75
+ version: 1.3.0
76
+ type: :development
75
77
  version_requirements: *id004
76
78
  - !ruby/object:Gem::Dependency
77
- name: json_pure
79
+ name: rdf-spec
78
80
  prerelease: false
79
81
  requirement: &id005 !ruby/object:Gem::Requirement
80
82
  requirements:
81
- - - ~>
83
+ - - "="
82
84
  - !ruby/object:Gem::Version
83
85
  segments:
84
- - 1
85
- - 4
86
+ - 0
86
87
  - 3
87
- version: 1.4.3
88
- type: :runtime
88
+ - 0
89
+ - pre
90
+ version: 0.3.0.pre
91
+ type: :development
89
92
  version_requirements: *id005
90
93
  description: RDF.rb plugin for parsing/serializing RDF/JSON data.
91
94
  email: public-rdf-ruby@w3.org
@@ -97,6 +100,7 @@ extra_rdoc_files: []
97
100
 
98
101
  files:
99
102
  - AUTHORS
103
+ - CREDITS
100
104
  - README
101
105
  - UNLICENSE
102
106
  - VERSION
@@ -127,11 +131,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
131
  version: 1.8.1
128
132
  required_rubygems_version: !ruby/object:Gem::Requirement
129
133
  requirements:
130
- - - ">="
134
+ - - ">"
131
135
  - !ruby/object:Gem::Version
132
136
  segments:
133
- - 0
134
- version: "0"
137
+ - 1
138
+ - 3
139
+ - 1
140
+ version: 1.3.1
135
141
  requirements: []
136
142
 
137
143
  rubyforge_project: rdf