rdf 0.1.0 → 0.1.1
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 +7 -9
- data/VERSION +1 -1
- data/etc/doap.nt +7 -0
- data/lib/rdf/ntriples/format.rb +7 -0
- data/lib/rdf/ntriples/reader.rb +17 -2
- data/lib/rdf/ntriples/writer.rb +55 -14
- data/lib/rdf/version.rb +1 -1
- metadata +48 -23
data/README
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
RDF.rb: RDF
|
2
|
-
|
1
|
+
RDF.rb: RDF for Ruby
|
2
|
+
====================
|
3
3
|
|
4
|
-
This is a pure-Ruby library for working with Resource Description Framework
|
5
|
-
(RDF) data.
|
4
|
+
This is a pure-Ruby library for working with [Resource Description Framework
|
5
|
+
(RDF)][RDF] data.
|
6
6
|
|
7
7
|
* <http://github.com/bendiken/rdf>
|
8
|
-
|
9
|
-
### About the Resource Description Framework (RDF)
|
10
|
-
|
11
|
-
* <http://www.w3.org/RDF/>
|
12
|
-
* <http://en.wikipedia.org/wiki/Resource_Description_Framework>
|
8
|
+
* <http://blog.datagraph.org/2010/03/rdf-for-ruby>
|
13
9
|
|
14
10
|
Examples
|
15
11
|
--------
|
@@ -162,3 +158,5 @@ License
|
|
162
158
|
|
163
159
|
RDF.rb is free and unencumbered public domain software. For more
|
164
160
|
information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
|
161
|
+
|
162
|
+
[RDF]: http://www.w3.org/RDF/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/etc/doap.nt
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
<http://ar.to/#self> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
|
2
|
+
<http://ar.to/#self> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <http://datagraph.org/bendiken/foaf> .
|
3
|
+
<http://ar.to/#self> <http://xmlns.com/foaf/0.1/homepage> <http://ar.to/> .
|
2
4
|
<http://ar.to/#self> <http://xmlns.com/foaf/0.1/made> <http://rubygems.org/gems/rdf> .
|
3
5
|
<http://ar.to/#self> <http://xmlns.com/foaf/0.1/mbox> <mailto:arto.bendiken@gmail.com> .
|
4
6
|
<http://ar.to/#self> <http://xmlns.com/foaf/0.1/name> "Arto Bendiken" .
|
5
7
|
<http://bhuga.net/#ben> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
|
8
|
+
<http://bhuga.net/#ben> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <http://datagraph.org/bhuga/foaf> .
|
9
|
+
<http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/homepage> <http://bhuga.net/> .
|
6
10
|
<http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/mbox> <mailto:blavender@gmail.com> .
|
7
11
|
<http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/name> "Ben Lavender" .
|
8
12
|
<http://rubygems.org/gems/rdf> <http://purl.org/dc/terms/creator> <http://ar.to/#self> .
|
9
13
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://ar.to/> .
|
14
|
+
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://blog.datagraph.org/> .
|
10
15
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/bendiken/rdf/issues> .
|
16
|
+
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#category> <http://dbpedia.org/resource/Resource_Description_Framework> .
|
11
17
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#created> "2007-10-23" .
|
12
18
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#description> "RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data."@en .
|
13
19
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#developer> <http://ar.to/#self> .
|
@@ -20,5 +26,6 @@
|
|
20
26
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#name> "RDF.rb" .
|
21
27
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#platform> "Ruby" .
|
22
28
|
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#shortdesc> "A Ruby library for working with Resource Description Framework (RDF) data."@en .
|
29
|
+
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#vendor> <http://datagraph.org/> .
|
23
30
|
<http://rubygems.org/gems/rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://usefulinc.com/ns/doap#Project> .
|
24
31
|
<http://rubygems.org/gems/rdf> <http://xmlns.com/foaf/0.1/maker> <http://ar.to/#self> .
|
data/lib/rdf/ntriples/format.rb
CHANGED
@@ -2,6 +2,13 @@ module RDF::NTriples
|
|
2
2
|
##
|
3
3
|
# N-Triples format specification.
|
4
4
|
#
|
5
|
+
# @example Obtaining an RDF/NTriples format class
|
6
|
+
# RDF::Format.for(:ntriples) #=> RDF::NTriples::Format
|
7
|
+
# RDF::Format.for("etc/doap.nt")
|
8
|
+
# RDF::Format.for(:file_name => "etc/doap.nt")
|
9
|
+
# RDF::Format.for(:file_extension => "nt")
|
10
|
+
# RDF::Format.for(:content_type => "text/plain")
|
11
|
+
#
|
5
12
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
6
13
|
class Format < RDF::Format
|
7
14
|
content_type 'text/plain', :extension => :nt
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -2,8 +2,23 @@ module RDF::NTriples
|
|
2
2
|
##
|
3
3
|
# N-Triples parser.
|
4
4
|
#
|
5
|
-
# @example
|
6
|
-
# RDF::
|
5
|
+
# @example Obtaining an RDF/NTriples reader class
|
6
|
+
# RDF::Reader.for(:ntriples) #=> RDF::NTriples::Reader
|
7
|
+
# RDF::Reader.for("etc/doap.nt")
|
8
|
+
# RDF::Reader.for(:file_name => "etc/doap.nt")
|
9
|
+
# RDF::Reader.for(:file_extension => "nt")
|
10
|
+
# RDF::Reader.for(:content_type => "text/plain")
|
11
|
+
#
|
12
|
+
# @example Parsing RDF statements from an NTriples file
|
13
|
+
# RDF::NTriples::Reader.open("etc/doap.nt") do |reader|
|
14
|
+
# reader.each_statement do |statement|
|
15
|
+
# puts statement.inspect
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @example Parsing RDF statements from an NTriples string
|
20
|
+
# data = StringIO.new(File.read("etc/doap.nt"))
|
21
|
+
# RDF::NTriples::Reader.new(data) do |reader|
|
7
22
|
# reader.each_statement do |statement|
|
8
23
|
# puts statement.inspect
|
9
24
|
# end
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -2,6 +2,27 @@ module RDF::NTriples
|
|
2
2
|
##
|
3
3
|
# N-Triples serializer.
|
4
4
|
#
|
5
|
+
# @example Obtaining an NTriples writer class
|
6
|
+
# RDF::Writer.for(:ntriples) #=> RDF::NTriples::Writer
|
7
|
+
# RDF::Writer.for("etc/test.nt")
|
8
|
+
# RDF::Writer.for(:file_name => "etc/test.nt")
|
9
|
+
# RDF::Writer.for(:file_extension => "nt")
|
10
|
+
# RDF::Writer.for(:content_type => "text/plain")
|
11
|
+
#
|
12
|
+
# @example Serializing RDF statements into an NTriples file
|
13
|
+
# RDF::NTriples::Writer.open("etc/test.nt") do |writer|
|
14
|
+
# graph.each_statement do |statement|
|
15
|
+
# writer << statement
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @example Serializing RDF statements into an NTriples string
|
20
|
+
# RDF::NTriples::Writer.buffer do |writer|
|
21
|
+
# graph.each_statement do |statement|
|
22
|
+
# writer << statement
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
5
26
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
6
27
|
class Writer < RDF::Writer
|
7
28
|
format RDF::NTriples::Format
|
@@ -12,7 +33,7 @@ module RDF::NTriples
|
|
12
33
|
# @param [String] text
|
13
34
|
# @return [void]
|
14
35
|
def write_comment(text)
|
15
|
-
puts "# #{text}"
|
36
|
+
puts "# #{text.chomp}" # TODO: correctly output multi-line comments
|
16
37
|
end
|
17
38
|
|
18
39
|
##
|
@@ -23,44 +44,64 @@ module RDF::NTriples
|
|
23
44
|
# @param [RDF::Value] object
|
24
45
|
# @return [void]
|
25
46
|
def write_triple(subject, predicate, object)
|
26
|
-
puts
|
47
|
+
puts format_triple(subject, predicate, object)
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Returns the N-Triples representation of a statement.
|
52
|
+
#
|
53
|
+
# @param [RDF::Statement] statement
|
54
|
+
# @return [String]
|
55
|
+
def format_statement(statement)
|
56
|
+
format_triple(*statement.to_triple)
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Returns the N-Triples representation of a triple.
|
61
|
+
#
|
62
|
+
# @param [RDF::Resource] subject
|
63
|
+
# @param [RDF::URI] predicate
|
64
|
+
# @param [RDF::Value] object
|
65
|
+
# @return [String]
|
66
|
+
def format_triple(subject, predicate, object)
|
67
|
+
"%s %s %s ." % [subject, predicate, object].map { |value| format_value(value) }
|
27
68
|
end
|
28
69
|
|
29
70
|
##
|
30
71
|
# Returns the N-Triples representation of a blank node.
|
31
72
|
#
|
32
|
-
# @param [RDF::Node]
|
73
|
+
# @param [RDF::Node] node
|
33
74
|
# @param [Hash{Symbol => Object}] options
|
34
75
|
# @return [String]
|
35
|
-
def format_node(
|
76
|
+
def format_node(node, options = {})
|
36
77
|
"_:%s" % node.id
|
37
78
|
end
|
38
79
|
|
39
80
|
##
|
40
81
|
# Returns the N-Triples representation of a URI reference.
|
41
82
|
#
|
42
|
-
# @param [RDF::URI]
|
83
|
+
# @param [RDF::URI] literal
|
43
84
|
# @param [Hash{Symbol => Object}] options
|
44
85
|
# @return [String]
|
45
|
-
def format_uri(
|
46
|
-
"<%s>" % uri_for(
|
86
|
+
def format_uri(uri, options = {})
|
87
|
+
"<%s>" % uri_for(uri)
|
47
88
|
end
|
48
89
|
|
49
90
|
##
|
50
91
|
# Returns the N-Triples representation of a literal.
|
51
92
|
#
|
52
|
-
# @param [RDF::Literal, String, #to_s]
|
93
|
+
# @param [RDF::Literal, String, #to_s] literal
|
53
94
|
# @param [Hash{Symbol => Object}] options
|
54
95
|
# @return [String]
|
55
|
-
def format_literal(
|
56
|
-
case
|
96
|
+
def format_literal(literal, options = {})
|
97
|
+
case literal
|
57
98
|
when RDF::Literal
|
58
|
-
text = quoted(escaped(
|
59
|
-
text << "@#{
|
60
|
-
text << "^^<#{uri_for(
|
99
|
+
text = quoted(escaped(literal.value))
|
100
|
+
text << "@#{literal.language}" if literal.has_language?
|
101
|
+
text << "^^<#{uri_for(literal.datatype)}>" if literal.has_datatype?
|
61
102
|
text
|
62
103
|
else
|
63
|
-
quoted(escaped(
|
104
|
+
quoted(escaped(literal.to_s))
|
64
105
|
end
|
65
106
|
end
|
66
107
|
end
|
data/lib/rdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Arto Bendiken
|
@@ -10,49 +15,65 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-14 00:00:00 +01:00
|
14
19
|
default_executable: rdf
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: rdf-spec
|
18
|
-
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
25
|
requirements:
|
22
26
|
- - ">="
|
23
27
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: 0.1.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
26
35
|
- !ruby/object:Gem::Dependency
|
27
36
|
name: rspec
|
28
|
-
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
39
|
requirements:
|
32
40
|
- - ">="
|
33
41
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
version: 1.3.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
36
49
|
- !ruby/object:Gem::Dependency
|
37
50
|
name: yard
|
38
|
-
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
53
|
requirements:
|
42
54
|
- - ">="
|
43
55
|
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
- 5
|
59
|
+
- 3
|
44
60
|
version: 0.5.3
|
45
|
-
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
46
63
|
- !ruby/object:Gem::Dependency
|
47
64
|
name: addressable
|
48
|
-
|
49
|
-
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
67
|
requirements:
|
52
68
|
- - ">="
|
53
69
|
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 2
|
72
|
+
- 1
|
73
|
+
- 1
|
54
74
|
version: 2.1.1
|
55
|
-
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
56
77
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
|
57
78
|
email: arto.bendiken@gmail.com
|
58
79
|
executables:
|
@@ -128,18 +149,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
149
|
requirements:
|
129
150
|
- - ">="
|
130
151
|
- !ruby/object:Gem::Version
|
152
|
+
segments:
|
153
|
+
- 1
|
154
|
+
- 8
|
155
|
+
- 2
|
131
156
|
version: 1.8.2
|
132
|
-
version:
|
133
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
158
|
requirements:
|
135
159
|
- - ">="
|
136
160
|
- !ruby/object:Gem::Version
|
161
|
+
segments:
|
162
|
+
- 0
|
137
163
|
version: "0"
|
138
|
-
version:
|
139
164
|
requirements: []
|
140
165
|
|
141
166
|
rubyforge_project: rdf
|
142
|
-
rubygems_version: 1.3.
|
167
|
+
rubygems_version: 1.3.6
|
143
168
|
signing_key:
|
144
169
|
specification_version: 3
|
145
170
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|