rdf 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +49 -32
- data/VERSION +1 -1
- data/lib/rdf.rb +7 -0
- data/lib/rdf/cli.rb +1 -1
- data/lib/rdf/format.rb +95 -0
- data/lib/rdf/graph.rb +8 -0
- data/lib/rdf/literal.rb +66 -1
- data/lib/rdf/node.rb +34 -4
- data/lib/rdf/ntriples.rb +12 -0
- data/lib/rdf/ntriples/format.rb +13 -0
- data/lib/rdf/ntriples/reader.rb +87 -0
- data/lib/rdf/ntriples/writer.rb +50 -0
- data/lib/rdf/query.rb +212 -0
- data/lib/rdf/query/pattern.rb +152 -0
- data/lib/rdf/query/solution.rb +139 -0
- data/lib/rdf/query/variable.rb +145 -0
- data/lib/rdf/reader.rb +7 -31
- data/lib/rdf/reader/ntriples.rb +4 -85
- data/lib/rdf/repository.rb +3 -1
- data/lib/rdf/statement.rb +54 -11
- data/lib/rdf/uri.rb +19 -0
- data/lib/rdf/value.rb +53 -2
- data/lib/rdf/version.rb +1 -1
- data/lib/rdf/vocabulary.rb +17 -0
- data/lib/rdf/writer.rb +16 -38
- data/lib/rdf/writer/ntriples.rb +4 -49
- metadata +21 -2
data/lib/rdf/statement.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
module RDF
|
2
2
|
##
|
3
3
|
# An RDF statement.
|
4
|
+
#
|
5
|
+
# @example Creating an RDF statement
|
6
|
+
# s = RDF::URI.new("http://gemcutter.org/gems/rdf")
|
7
|
+
# p = RDF::DC.creator
|
8
|
+
# o = RDF::URI.new("http://ar.to/#self")
|
9
|
+
# RDF::Statement.new(s, p, o)
|
10
|
+
#
|
11
|
+
# @example Creating an RDF statement with a context
|
12
|
+
# RDF::Statement.new(s, p, o, :context => uri)
|
13
|
+
#
|
14
|
+
# @example Creating an RDF statement from a `Hash`
|
15
|
+
# RDF::Statement.new({
|
16
|
+
# :subject => RDF::URI.new("http://gemcutter.org/gems/rdf"),
|
17
|
+
# :predicate => RDF::DC.creator,
|
18
|
+
# :object => RDF::URI.new("http://ar.to/#self"),
|
19
|
+
# })
|
20
|
+
#
|
4
21
|
class Statement < Value
|
5
22
|
# @return [Object]
|
6
23
|
attr_accessor :id
|
@@ -18,14 +35,35 @@ module RDF
|
|
18
35
|
attr_accessor :object
|
19
36
|
|
20
37
|
##
|
21
|
-
# @
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
# @overload initialize(options = {})
|
39
|
+
# @param [Hash{Symbol => Object}] options
|
40
|
+
# @option options [Resource] :subject (nil)
|
41
|
+
# @option options [URI] :predicate (nil)
|
42
|
+
# @option options [Value] :object (nil)
|
43
|
+
# @option options [Resource] :context (nil)
|
44
|
+
#
|
45
|
+
# @overload initialize(subject, predicate, object, options = {})
|
46
|
+
# @param [Resource] subject
|
47
|
+
# @param [URI] predicate
|
48
|
+
# @param [Value] object
|
49
|
+
# @param [Hash{Symbol => Object}] options
|
50
|
+
# @option options [Resource] :context (nil)
|
51
|
+
def initialize(subject = nil, predicate = nil, object = nil, options = {})
|
52
|
+
case subject
|
53
|
+
when Hash
|
54
|
+
options = subject
|
55
|
+
subject = options.delete(:subject)
|
56
|
+
predicate = options.delete(:predicate)
|
57
|
+
object = options.delete(:object)
|
58
|
+
initialize(subject, predicate, object, options)
|
59
|
+
else
|
60
|
+
@id = options.delete(:id) if options.has_key?(:id)
|
61
|
+
@context = options.delete(:context) || options.delete(:graph)
|
62
|
+
@options = options
|
63
|
+
@subject = subject
|
64
|
+
@predicate = predicate
|
65
|
+
@object = object
|
66
|
+
end
|
29
67
|
end
|
30
68
|
|
31
69
|
##
|
@@ -136,9 +174,14 @@ module RDF
|
|
136
174
|
alias_method :to_ary, :to_triple
|
137
175
|
|
138
176
|
##
|
139
|
-
#
|
140
|
-
|
141
|
-
|
177
|
+
# Returns the components of this statement as a `Hash`.
|
178
|
+
#
|
179
|
+
# @param [Symbol] subject_key
|
180
|
+
# @param [Symbol] predicate_key
|
181
|
+
# @param [Symbol] object_key
|
182
|
+
# @return [Hash{Symbol => Value}]
|
183
|
+
def to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object)
|
184
|
+
{subject_key => subject, predicate_key => predicate, object_key => object}
|
142
185
|
end
|
143
186
|
|
144
187
|
##
|
data/lib/rdf/uri.rb
CHANGED
@@ -3,6 +3,15 @@ require 'addressable/uri'
|
|
3
3
|
module RDF
|
4
4
|
##
|
5
5
|
# A Uniform Resource Identifier (URI).
|
6
|
+
#
|
7
|
+
# @example Creating a URI reference
|
8
|
+
# uri = RDF::URI.new("http://rdf.rubyforge.org/")
|
9
|
+
#
|
10
|
+
# @example Getting the string representation of a URI
|
11
|
+
# uri.to_s #=> "http://rdf.rubyforge.org/"
|
12
|
+
#
|
13
|
+
# @see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier
|
14
|
+
# @see http://addressable.rubyforge.org/
|
6
15
|
class URI < Node
|
7
16
|
##
|
8
17
|
# @param [String] uri
|
@@ -21,6 +30,16 @@ module RDF
|
|
21
30
|
end
|
22
31
|
|
23
32
|
##
|
33
|
+
# Returns `true`.
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
def uri?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns `false`.
|
42
|
+
#
|
24
43
|
# @return [Boolean]
|
25
44
|
def anonymous?
|
26
45
|
false
|
data/lib/rdf/value.rb
CHANGED
@@ -3,11 +3,62 @@ module RDF
|
|
3
3
|
# An RDF value.
|
4
4
|
#
|
5
5
|
# @abstract
|
6
|
+
# @see Graph
|
7
|
+
# @see Literal
|
8
|
+
# @see Node
|
9
|
+
# @see Resource
|
10
|
+
# @see Statement
|
11
|
+
# @see URI
|
6
12
|
class Value
|
7
|
-
# Prevent instantiation of this class.
|
13
|
+
# Prevent the instantiation of this class.
|
8
14
|
private_class_method :new
|
9
15
|
|
10
16
|
##
|
17
|
+
# Returns `true` if this value is a graph.
|
18
|
+
#
|
19
|
+
# @return [Boolean]
|
20
|
+
def graph?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns `true` if this value is a literal.
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
def literal?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Returns `true` if this value is a blank node.
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
def node?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns `true` if this value is a URI.
|
42
|
+
#
|
43
|
+
# @return [Boolean]
|
44
|
+
def uri?
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :iri?, :uri?
|
49
|
+
|
50
|
+
##
|
51
|
+
# Compares this value to `other` for sorting purposes.
|
52
|
+
#
|
53
|
+
# @param [Object] other
|
54
|
+
# @return [Integer] -1, 0, 1
|
55
|
+
def <=>(other)
|
56
|
+
self.to_s <=> other.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Returns a developer-readable representation of this value.
|
61
|
+
#
|
11
62
|
# @return [String]
|
12
63
|
def inspect
|
13
64
|
sprintf("#<%s:%#0x(%s)>", self.class.name, object_id, to_s)
|
@@ -16,7 +67,7 @@ module RDF
|
|
16
67
|
private
|
17
68
|
|
18
69
|
def self.inherited(child) #:nodoc:
|
19
|
-
# Enable instantiation of subclasses.
|
70
|
+
# Enable the instantiation of any subclasses.
|
20
71
|
child.send(:public_class_method, :new)
|
21
72
|
super
|
22
73
|
end
|
data/lib/rdf/version.rb
CHANGED
data/lib/rdf/vocabulary.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
module RDF
|
2
2
|
##
|
3
3
|
# An RDF vocabulary.
|
4
|
+
#
|
5
|
+
# @example Using pre-defined RDF vocabularies
|
6
|
+
# include RDF
|
7
|
+
# DC.title #=> RDF::URI("http://purl.org/dc/terms/title")
|
8
|
+
# FOAF.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
|
9
|
+
# RDFS.seeAlso #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
|
10
|
+
# RSS.title #=> RDF::URI("http://purl.org/rss/1.0/title")
|
11
|
+
# OWL.sameAs #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
|
12
|
+
# XSD.dateTime #=> RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
|
13
|
+
#
|
14
|
+
# @example Using ad-hoc RDF vocabularies
|
15
|
+
# foaf = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
|
16
|
+
# foaf.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
|
17
|
+
# foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
|
18
|
+
# foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
|
19
|
+
#
|
20
|
+
# @see http://www.w3.org/TR/curie/
|
4
21
|
class Vocabulary
|
5
22
|
##
|
6
23
|
# @return [String]
|
data/lib/rdf/writer.rb
CHANGED
@@ -4,15 +4,10 @@ module RDF
|
|
4
4
|
#
|
5
5
|
# @abstract
|
6
6
|
class Writer
|
7
|
-
autoload :NTriples, 'rdf/writer/ntriples'
|
7
|
+
autoload :NTriples, 'rdf/writer/ntriples' # @deprecated
|
8
8
|
|
9
9
|
include Enumerable
|
10
10
|
|
11
|
-
@@subclasses = []
|
12
|
-
@@file_extensions = {}
|
13
|
-
@@content_types = {}
|
14
|
-
@@content_encoding = {}
|
15
|
-
|
16
11
|
##
|
17
12
|
# Enumerates known RDF writer classes.
|
18
13
|
#
|
@@ -22,23 +17,12 @@ module RDF
|
|
22
17
|
!block_given? ? @@subclasses : @@subclasses.each { |klass| yield klass }
|
23
18
|
end
|
24
19
|
|
25
|
-
##
|
26
|
-
# Returns the list of known MIME content types.
|
27
|
-
def self.content_types
|
28
|
-
@@content_types
|
29
|
-
end
|
30
|
-
|
31
|
-
##
|
32
|
-
# Returns the list of known file extensions.
|
33
|
-
def self.file_extensions
|
34
|
-
@@file_extensions
|
35
|
-
end
|
36
|
-
|
37
20
|
##
|
38
21
|
# Returns the RDF writer class for the given format.
|
39
22
|
def self.for(format)
|
40
23
|
klass = case format.to_s.downcase.to_sym
|
41
|
-
when :ntriples then RDF::Writer
|
24
|
+
when :ntriples then RDF::NTriples::Writer
|
25
|
+
else nil # FIXME
|
42
26
|
end
|
43
27
|
end
|
44
28
|
|
@@ -149,25 +133,6 @@ module RDF
|
|
149
133
|
|
150
134
|
protected
|
151
135
|
|
152
|
-
def self.inherited(child) #:nodoc:
|
153
|
-
@@subclasses << child
|
154
|
-
super
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.content_type(type, options = {})
|
158
|
-
@@content_types[type] ||= []
|
159
|
-
@@content_types[type] << self
|
160
|
-
|
161
|
-
if options[:extension]
|
162
|
-
extensions = [options[:extension]].flatten.map { |ext| ext.to_sym }
|
163
|
-
extensions.each { |ext| @@file_extensions[ext] = type }
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def self.content_encoding(encoding)
|
168
|
-
@@content_encoding[self] = encoding.to_sym
|
169
|
-
end
|
170
|
-
|
171
136
|
def puts(*args)
|
172
137
|
@output.puts(*args)
|
173
138
|
end
|
@@ -214,6 +179,19 @@ module RDF
|
|
214
179
|
"\"#{string}\""
|
215
180
|
end
|
216
181
|
|
182
|
+
private
|
183
|
+
|
184
|
+
@@subclasses = [] # @private
|
185
|
+
|
186
|
+
def self.inherited(child) # @private
|
187
|
+
@@subclasses << child
|
188
|
+
super
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.format(klass)
|
192
|
+
# TODO
|
193
|
+
end
|
194
|
+
|
217
195
|
end
|
218
196
|
|
219
197
|
class WriterError < IOError; end
|
data/lib/rdf/writer/ntriples.rb
CHANGED
@@ -1,50 +1,5 @@
|
|
1
|
-
module RDF
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
# @see <http://www.w3.org/TR/rdf-testcases/#ntriples>
|
6
|
-
class NTriples < Writer
|
7
|
-
content_type 'text/plain', :extension => :nt
|
8
|
-
content_encoding 'ascii'
|
9
|
-
|
10
|
-
##
|
11
|
-
# @param [String] text
|
12
|
-
# @return [void]
|
13
|
-
def write_comment(text)
|
14
|
-
puts "# #{text}"
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
# @param [Resource] subject
|
19
|
-
# @param [URI] predicate
|
20
|
-
# @param [Value] object
|
21
|
-
# @return [void]
|
22
|
-
def write_triple(subject, predicate, object)
|
23
|
-
s = format_uri(subject)
|
24
|
-
p = format_uri(predicate)
|
25
|
-
o = object.kind_of?(RDF::URI) ? format_uri(object) : format_literal(object)
|
26
|
-
puts "%s %s %s ." % [s, p, o]
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# @param [node] Resource
|
31
|
-
# @return [void]
|
32
|
-
def format_uri(node)
|
33
|
-
"<%s>" % uri_for(node)
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# @param [String, Literal] literal
|
38
|
-
# @return [void]
|
39
|
-
def format_literal(literal) # TODO
|
40
|
-
#if literal.kind_of?(RDF::Literal)
|
41
|
-
# text = quoted(escaped(literal.value))
|
42
|
-
# text << "@#{literal.language}" if literal.language
|
43
|
-
# text << "^^<#{uri_for(literal.type)}>" if literal.type
|
44
|
-
# text
|
45
|
-
#else
|
46
|
-
quoted(escaped(literal.to_s))
|
47
|
-
#end
|
48
|
-
end
|
1
|
+
module RDF
|
2
|
+
class Writer
|
3
|
+
NTriples = RDF::NTriples::Writer # @deprecated
|
49
4
|
end
|
50
|
-
end
|
5
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-30 00:00:00 +01:00
|
13
13
|
default_executable: rdf
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.2.9
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.2
|
34
|
+
version:
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: addressable
|
27
37
|
type: :runtime
|
@@ -58,9 +68,18 @@ files:
|
|
58
68
|
- bin/rdf-subjects
|
59
69
|
- lib/df.rb
|
60
70
|
- lib/rdf/cli.rb
|
71
|
+
- lib/rdf/format.rb
|
61
72
|
- lib/rdf/graph.rb
|
62
73
|
- lib/rdf/literal.rb
|
63
74
|
- lib/rdf/node.rb
|
75
|
+
- lib/rdf/ntriples/format.rb
|
76
|
+
- lib/rdf/ntriples/reader.rb
|
77
|
+
- lib/rdf/ntriples/writer.rb
|
78
|
+
- lib/rdf/ntriples.rb
|
79
|
+
- lib/rdf/query/pattern.rb
|
80
|
+
- lib/rdf/query/solution.rb
|
81
|
+
- lib/rdf/query/variable.rb
|
82
|
+
- lib/rdf/query.rb
|
64
83
|
- lib/rdf/reader/ntriples.rb
|
65
84
|
- lib/rdf/reader.rb
|
66
85
|
- lib/rdf/repository.rb
|