rdf 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- 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/README
CHANGED
@@ -42,7 +42,7 @@ Examples
|
|
42
42
|
|
43
43
|
### Reading N-Triples data
|
44
44
|
|
45
|
-
RDF::Reader
|
45
|
+
RDF::NTriples::Reader.open("spec/data/test.nt") do |reader|
|
46
46
|
reader.each_statement do |statement|
|
47
47
|
puts statement.inspect
|
48
48
|
end
|
@@ -55,47 +55,51 @@ Documentation
|
|
55
55
|
|
56
56
|
### RDF Objects
|
57
57
|
|
58
|
-
*
|
59
|
-
*
|
60
|
-
*
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
58
|
+
* {RDF::Graph}
|
59
|
+
* {RDF::Literal}
|
60
|
+
* {RDF::Node}
|
61
|
+
* {RDF::Resource}
|
62
|
+
* {RDF::Statement}
|
63
|
+
* {RDF::URI}
|
64
|
+
* {RDF::Value}
|
65
65
|
|
66
66
|
### RDF Serialization
|
67
67
|
|
68
|
-
*
|
69
|
-
*
|
68
|
+
* {RDF::Format}
|
69
|
+
* {RDF::Reader}
|
70
|
+
* {RDF::Writer}
|
70
71
|
|
71
|
-
### RDF
|
72
|
+
### RDF Serialization Formats
|
72
73
|
|
73
|
-
*
|
74
|
-
* [RDF::DC](http://rdf.rubyforge.org/RDF/DC.html) - Dublin Core (DC)
|
75
|
-
* [RDF::DOAP](http://rdf.rubyforge.org/RDF/DOAP.html) - Description of a Project (DOAP)
|
76
|
-
* [RDF::EXIF](http://rdf.rubyforge.org/RDF/EXIF.html) - Exchangeable Image File Format (EXIF)
|
77
|
-
* [RDF::FOAF](http://rdf.rubyforge.org/RDF/FOAF.html) - Friend of a Friend (FOAF)
|
78
|
-
* [RDF::HTTP](http://rdf.rubyforge.org/RDF/HTTP.html) - Hypertext Transfer Protocol (HTTP)
|
79
|
-
* [RDF::OWL](http://rdf.rubyforge.org/RDF/OWL.html) - Web Ontology Language (OWL)
|
80
|
-
* [RDF::RDFS](http://rdf.rubyforge.org/RDF/RDFS.html) - RDF Schema (RDFS)
|
81
|
-
* [RDF::RSS](http://rdf.rubyforge.org/RDF/RSS.html) - RDF Site Summary (RSS)
|
82
|
-
* [RDF::SIOC](http://rdf.rubyforge.org/RDF/SIOC.html) - Semantically-Interlinked Online Communities (SIOC)
|
83
|
-
* [RDF::SKOS](http://rdf.rubyforge.org/RDF/SKOS.html) - Simple Knowledge Organization System (SKOS)
|
84
|
-
* [RDF::WOT](http://rdf.rubyforge.org/RDF/WOT.html) - Web of Trust (WOT)
|
85
|
-
* [RDF::XHTML](http://rdf.rubyforge.org/RDF/XHTML.html) - Extensible HyperText Markup Language (XHTML)
|
86
|
-
* [RDF::XSD](http://rdf.rubyforge.org/RDF/XSD.html) - XML Schema (XSD)
|
74
|
+
* {RDF::NTriples}
|
87
75
|
|
88
|
-
|
89
|
-
--------
|
76
|
+
### RDF Storage
|
90
77
|
|
91
|
-
|
78
|
+
* {RDF::Repository}
|
92
79
|
|
93
|
-
|
80
|
+
### RDF Querying
|
94
81
|
|
95
|
-
|
96
|
-
|
82
|
+
* {RDF::Query}
|
83
|
+
* {RDF::Query::Pattern}
|
84
|
+
* {RDF::Query::Solution}
|
85
|
+
* {RDF::Query::Variable}
|
97
86
|
|
98
|
-
|
87
|
+
### RDF Vocabularies
|
88
|
+
|
89
|
+
* {RDF::CC} - Creative Commons (CC)
|
90
|
+
* {RDF::DC} - Dublin Core (DC)
|
91
|
+
* {RDF::DOAP} - Description of a Project (DOAP)
|
92
|
+
* {RDF::EXIF} - Exchangeable Image File Format (EXIF)
|
93
|
+
* {RDF::FOAF} - Friend of a Friend (FOAF)
|
94
|
+
* {RDF::HTTP} - Hypertext Transfer Protocol (HTTP)
|
95
|
+
* {RDF::OWL} - Web Ontology Language (OWL)
|
96
|
+
* {RDF::RDFS} - RDF Schema (RDFS)
|
97
|
+
* {RDF::RSS} - RDF Site Summary (RSS)
|
98
|
+
* {RDF::SIOC} - Semantically-Interlinked Online Communities (SIOC)
|
99
|
+
* {RDF::SKOS} - Simple Knowledge Organization System (SKOS)
|
100
|
+
* {RDF::WOT} - Web of Trust (WOT)
|
101
|
+
* {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
|
102
|
+
* {RDF::XSD} - XML Schema (XSD)
|
99
103
|
|
100
104
|
Dependencies
|
101
105
|
------------
|
@@ -110,6 +114,18 @@ official release from Gemcutter, do:
|
|
110
114
|
|
111
115
|
% [sudo] gem install rdf
|
112
116
|
|
117
|
+
Download
|
118
|
+
--------
|
119
|
+
|
120
|
+
To get a local working copy of the development repository, do:
|
121
|
+
|
122
|
+
% git clone git://github.com/bendiken/rdf.git
|
123
|
+
|
124
|
+
Alternatively, you can download the latest development version as a tarball
|
125
|
+
as follows:
|
126
|
+
|
127
|
+
% wget http://github.com/bendiken/rdf/tarball/master
|
128
|
+
|
113
129
|
Resources
|
114
130
|
---------
|
115
131
|
|
@@ -122,6 +138,7 @@ Resources
|
|
122
138
|
See also
|
123
139
|
--------
|
124
140
|
|
141
|
+
* [RDFS.rb](http://rdfs.rubyforge.org/)
|
125
142
|
* [RDFize](http://rdfize.rubyforge.org/)
|
126
143
|
* [RDFbus](http://rdfbus.rubyforge.org/)
|
127
144
|
* [RDFcache](http://rdfcache.rubyforge.org/)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/rdf.rb
CHANGED
@@ -11,12 +11,19 @@ module RDF
|
|
11
11
|
autoload :Value, 'rdf/value'
|
12
12
|
|
13
13
|
# RDF serialization
|
14
|
+
autoload :Format, 'rdf/format'
|
14
15
|
autoload :Reader, 'rdf/reader'
|
15
16
|
autoload :Writer, 'rdf/writer'
|
16
17
|
|
18
|
+
# RDF serialization formats
|
19
|
+
autoload :NTriples, 'rdf/ntriples'
|
20
|
+
|
17
21
|
# RDF storage
|
18
22
|
autoload :Repository, 'rdf/repository'
|
19
23
|
|
24
|
+
# RDF querying
|
25
|
+
autoload :Query, 'rdf/query'
|
26
|
+
|
20
27
|
# RDF vocabularies
|
21
28
|
autoload :Vocabulary, 'rdf/vocabulary'
|
22
29
|
autoload :CC, 'rdf/vocabulary/cc'
|
data/lib/rdf/cli.rb
CHANGED
data/lib/rdf/format.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module RDF
|
2
|
+
##
|
3
|
+
# An RDF serialization format.
|
4
|
+
class Format
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
##
|
8
|
+
# Enumerates known RDF format classes.
|
9
|
+
#
|
10
|
+
# @yield [klass]
|
11
|
+
# @yieldparam [Class]
|
12
|
+
def self.each(&block)
|
13
|
+
!block_given? ? @@subclasses : @@subclasses.each { |klass| yield klass } # FIXME: Enumerator
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Returns the list of known MIME content types.
|
18
|
+
#
|
19
|
+
# @return [Hash{String => Array<Class>}]
|
20
|
+
def self.content_types
|
21
|
+
@@content_types
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns the list of known file extensions.
|
26
|
+
#
|
27
|
+
# @return [Hash{Symbol => String}]
|
28
|
+
def self.file_extensions
|
29
|
+
@@file_extensions
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# @param [Symbol] format
|
34
|
+
# @return [Class]
|
35
|
+
def self.for(format)
|
36
|
+
klass = case format.to_s.downcase.to_sym
|
37
|
+
when :ntriples then RDF::NTriples::Format
|
38
|
+
else nil # FIXME
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# @yield [format]
|
44
|
+
# @yieldparam [Format]
|
45
|
+
def initialize(options = {}, &block)
|
46
|
+
@options = options
|
47
|
+
|
48
|
+
if block_given?
|
49
|
+
case block.arity
|
50
|
+
when 1 then block.call(self)
|
51
|
+
else instance_eval(&block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
@@subclasses = [] # @private
|
59
|
+
@@file_extensions = {} # @private
|
60
|
+
@@content_types = {} # @private
|
61
|
+
@@content_encoding = {} # @private
|
62
|
+
|
63
|
+
def self.inherited(child) # @private
|
64
|
+
@@subclasses << child
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.require(library)
|
69
|
+
# TODO
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.content_type(type, options = {})
|
73
|
+
@@content_types[type] ||= []
|
74
|
+
@@content_types[type] << self
|
75
|
+
|
76
|
+
if options[:extension]
|
77
|
+
extensions = [options[:extension]].flatten.map { |ext| ext.to_sym }
|
78
|
+
extensions.each { |ext| @@file_extensions[ext] = type }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.content_encoding(encoding)
|
83
|
+
@@content_encoding[self] = encoding.to_sym
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.reader(klass)
|
87
|
+
# TODO
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.writer(klass)
|
91
|
+
# TODO
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
data/lib/rdf/graph.rb
CHANGED
data/lib/rdf/literal.rb
CHANGED
@@ -1,6 +1,43 @@
|
|
1
1
|
module RDF
|
2
2
|
##
|
3
3
|
# An RDF literal.
|
4
|
+
#
|
5
|
+
# @example Creating a plain literal
|
6
|
+
# value = RDF::Literal.new("Hello, world!")
|
7
|
+
# value.plain? #=> true
|
8
|
+
#
|
9
|
+
# @example Creating a language-tagged literal (1)
|
10
|
+
# value = RDF::Literal.new("Hello!", :language => :en)
|
11
|
+
# value.language? #=> true
|
12
|
+
# value.language #=> :en
|
13
|
+
#
|
14
|
+
# @example Creating a language-tagged literal (2)
|
15
|
+
# RDF::Literal.new("Wazup?", :language => :"en-US")
|
16
|
+
# RDF::Literal.new("Hej!", :language => :sv)
|
17
|
+
# RDF::Literal.new("¡Hola!", :language => :es)
|
18
|
+
#
|
19
|
+
# @example Creating an explicitly datatyped literal
|
20
|
+
# value = RDF::Literal.new("2009-12-31", :datatype => RDF::XSD.date)
|
21
|
+
# value.datatype? #=> true
|
22
|
+
# value.datatype #=> RDF::XSD.date
|
23
|
+
#
|
24
|
+
# @example Creating an implicitly datatyped literal
|
25
|
+
# value = RDF::Literal.new(Date.today)
|
26
|
+
# value.datatype? #=> true
|
27
|
+
# value.datatype #=> RDF::XSD.date
|
28
|
+
#
|
29
|
+
# @example Creating implicitly datatyped literals
|
30
|
+
# RDF::Literal.new(false).datatype #=> XSD.boolean
|
31
|
+
# RDF::Literal.new(true).datatype #=> XSD.boolean
|
32
|
+
# RDF::Literal.new(123).datatype #=> XSD.int
|
33
|
+
# RDF::Literal.new(9223372036854775807).datatype #=> XSD.long
|
34
|
+
# RDF::Literal.new(3.1415).datatype #=> XSD.double
|
35
|
+
# RDF::Literal.new(Time.now).datatype #=> XSD.dateTime
|
36
|
+
# RDF::Literal.new(Date.new(2010)).datatype #=> XSD.date
|
37
|
+
# RDF::Literal.new(DateTime.new(2010)).datatype #=> XSD.dateTime
|
38
|
+
#
|
39
|
+
# @see http://www.w3.org/TR/rdf-concepts/#section-Literals
|
40
|
+
# @see http://www.w3.org/TR/rdf-concepts/#section-Datatypes-intro
|
4
41
|
class Literal < Value
|
5
42
|
# @return [String] The normalized string representation of the value.
|
6
43
|
attr_accessor :value
|
@@ -49,6 +86,14 @@ module RDF
|
|
49
86
|
@value = @value.to_s
|
50
87
|
end
|
51
88
|
|
89
|
+
##
|
90
|
+
# Returns `true`.
|
91
|
+
#
|
92
|
+
# @return [Boolean]
|
93
|
+
def literal?
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
52
97
|
##
|
53
98
|
# @return [Boolean]
|
54
99
|
def eql?(other)
|
@@ -72,18 +117,38 @@ module RDF
|
|
72
117
|
end
|
73
118
|
|
74
119
|
##
|
120
|
+
# Returns `true` if this is a plain literal.
|
121
|
+
#
|
75
122
|
# @return [Boolean]
|
123
|
+
# @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
|
76
124
|
def plain?
|
77
125
|
language.nil? && datatype.nil?
|
78
126
|
end
|
79
127
|
|
80
128
|
##
|
129
|
+
# Returns `true` if this is a language-tagged literal.
|
130
|
+
#
|
81
131
|
# @return [Boolean]
|
82
|
-
|
132
|
+
# @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
|
133
|
+
def language?
|
134
|
+
!language.nil?
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Returns `true` if this is a datatyped literal.
|
139
|
+
#
|
140
|
+
# @return [Boolean]
|
141
|
+
# @see http://www.w3.org/TR/rdf-concepts/#dfn-typed-literal
|
142
|
+
def datatype?
|
83
143
|
!datatype.nil?
|
84
144
|
end
|
85
145
|
|
146
|
+
alias_method :typed?, :datatype?
|
147
|
+
alias_method :datatyped?, :datatype?
|
148
|
+
|
86
149
|
##
|
150
|
+
# Returns a string representation of this literal.
|
151
|
+
#
|
87
152
|
# @return [String]
|
88
153
|
def to_s
|
89
154
|
quoted = value # FIXME
|
data/lib/rdf/node.rb
CHANGED
@@ -1,29 +1,59 @@
|
|
1
1
|
module RDF
|
2
2
|
##
|
3
3
|
# An RDF blank node, also known as an unlabeled node.
|
4
|
+
#
|
5
|
+
# @example Creating a blank node with an implicit identifier
|
6
|
+
# bnode = RDF::Node.new
|
7
|
+
#
|
8
|
+
# @example Creating a blank node with an UUID identifier (1)
|
9
|
+
# require 'uuid'
|
10
|
+
# bnode = RDF::Node.new(UUID.generate)
|
11
|
+
#
|
12
|
+
# @example Creating a blank node with an UUID identifier (2)
|
13
|
+
# require 'uuidtools'
|
14
|
+
# bnode = RDF::Node.new(UUIDTools::UUID.random_create)
|
15
|
+
#
|
16
|
+
# @see http://github.com/assaf/uuid
|
17
|
+
# @see http://uuidtools.rubyforge.org/
|
4
18
|
class Node < Resource
|
5
19
|
# @return [String]
|
6
20
|
attr_accessor :id
|
7
21
|
|
8
22
|
##
|
9
|
-
# @param [#to_s]
|
23
|
+
# @param [#to_s] id
|
10
24
|
def initialize(id = nil)
|
11
25
|
@id = (id || object_id).to_s
|
12
26
|
end
|
13
27
|
|
14
28
|
##
|
29
|
+
# Returns `true`.
|
30
|
+
#
|
15
31
|
# @return [Boolean]
|
16
|
-
def
|
32
|
+
def node?
|
33
|
+
true
|
34
|
+
end
|
17
35
|
|
18
36
|
##
|
37
|
+
# Returns `true`.
|
38
|
+
#
|
19
39
|
# @return [Boolean]
|
20
|
-
def
|
40
|
+
def anonymous?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
alias_method :unlabeled?, :anonymous?
|
21
45
|
|
22
46
|
##
|
47
|
+
# Returns `false`.
|
48
|
+
#
|
23
49
|
# @return [Boolean]
|
24
|
-
def
|
50
|
+
def labeled?
|
51
|
+
!unlabeled?
|
52
|
+
end
|
25
53
|
|
26
54
|
##
|
55
|
+
# Returns a string representation of this blank node.
|
56
|
+
#
|
27
57
|
# @return [String]
|
28
58
|
def to_s
|
29
59
|
"_:%s" % id.to_s
|
data/lib/rdf/ntriples.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module RDF
|
2
|
+
##
|
3
|
+
# N-Triples serialization format.
|
4
|
+
#
|
5
|
+
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
6
|
+
# @see http://en.wikipedia.org/wiki/N-Triples
|
7
|
+
module NTriples
|
8
|
+
autoload :Format, 'rdf/ntriples/format'
|
9
|
+
autoload :Reader, 'rdf/ntriples/reader'
|
10
|
+
autoload :Writer, 'rdf/ntriples/writer'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RDF module NTriples
|
2
|
+
##
|
3
|
+
# N-Triples format specification.
|
4
|
+
#
|
5
|
+
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
6
|
+
class Format < RDF::Format
|
7
|
+
content_type 'text/plain', :extension => :nt
|
8
|
+
content_encoding 'ascii'
|
9
|
+
|
10
|
+
reader RDF::NTriples::Reader
|
11
|
+
writer RDF::NTriples::Format
|
12
|
+
end
|
13
|
+
end end
|