rdf 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS +1 -1
- data/README.md +43 -9
- data/VERSION +1 -1
- data/etc/doap.nt +74 -80
- data/lib/rdf.rb +13 -11
- data/lib/rdf/mixin/enumerable.rb +1 -0
- data/lib/rdf/mixin/queryable.rb +8 -0
- data/lib/rdf/mixin/writable.rb +7 -0
- data/lib/rdf/model/dataset.rb +1 -1
- data/lib/rdf/model/graph.rb +3 -0
- data/lib/rdf/model/statement.rb +30 -7
- data/lib/rdf/model/uri.rb +2 -2
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples.rb +6 -4
- data/lib/rdf/ntriples/reader.rb +25 -3
- data/lib/rdf/ntriples/writer.rb +9 -0
- data/lib/rdf/query.rb +4 -1
- data/lib/rdf/query/hash_pattern_normalizer.rb +9 -8
- data/lib/rdf/query/pattern.rb +49 -16
- data/lib/rdf/query/solution.rb +20 -1
- data/lib/rdf/query/solutions.rb +15 -5
- data/lib/rdf/query/variable.rb +17 -5
- data/lib/rdf/reader.rb +65 -20
- data/lib/rdf/repository.rb +19 -12
- data/lib/rdf/util/cache.rb +2 -2
- data/lib/rdf/vocab/owl.rb +401 -86
- data/lib/rdf/vocab/rdfs.rb +81 -18
- data/lib/rdf/vocab/rdfv.rb +122 -1
- data/lib/rdf/vocab/writer.rb +41 -3
- data/lib/rdf/vocab/xsd.rb +202 -1
- data/lib/rdf/vocabulary.rb +69 -11
- data/lib/rdf/writer.rb +21 -5
- metadata +4 -4
data/lib/rdf/vocabulary.rb
CHANGED
@@ -58,6 +58,9 @@ module RDF
|
|
58
58
|
class Vocabulary
|
59
59
|
extend ::Enumerable
|
60
60
|
|
61
|
+
autoload :Format, 'rdf/vocab/writer'
|
62
|
+
autoload :Writer, 'rdf/vocab/writer'
|
63
|
+
|
61
64
|
class << self
|
62
65
|
##
|
63
66
|
# Enumerates known RDF vocabulary classes.
|
@@ -67,16 +70,68 @@ module RDF
|
|
67
70
|
# @return [Enumerator]
|
68
71
|
def each(&block)
|
69
72
|
if self.equal?(Vocabulary)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
if @vocabs
|
74
|
+
@vocabs.select(&:name).each(&block)
|
75
|
+
else
|
76
|
+
# This is needed since all vocabulary classes are defined using
|
77
|
+
# Ruby's autoloading facility, meaning that `@@subclasses` will be
|
78
|
+
# empty until each subclass has been touched or require'd.
|
79
|
+
RDF::VOCABS.each { |v, p| RDF.const_get(p[:class_name].to_sym) unless v == :rdf }
|
80
|
+
@@subclasses.select(&:name).each(&block)
|
81
|
+
end
|
75
82
|
else
|
76
83
|
__properties__.each(&block)
|
77
84
|
end
|
78
85
|
end
|
79
86
|
|
87
|
+
##
|
88
|
+
# A hash of all vocabularies by prefix showing relevant URI and associated vocabulary Class Name
|
89
|
+
# @return [Hash{Symbol => Hash{Symbol => String}}]
|
90
|
+
def vocab_map
|
91
|
+
VOCABS
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Return the vocabulary based on it's class_name symbol
|
96
|
+
#
|
97
|
+
# @param [Symbol] sym
|
98
|
+
# @return [RDF::Vocabulary]
|
99
|
+
def from_sym(sym)
|
100
|
+
RDF.const_get(sym.to_sym)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Limits iteration over vocabularies to just those selected
|
105
|
+
#
|
106
|
+
# @example limit to set of vocabularies by symbol
|
107
|
+
# RDF::Vocabulary.limit_vocabs(:rdf, :rdfs
|
108
|
+
# RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
|
109
|
+
# # => 'rdfs:Resource'
|
110
|
+
#
|
111
|
+
# @example limit to set of vocabularies by class name
|
112
|
+
# RDF::Vocabulary.limit_vocabs(RDF::RDFV, RDF::RDFS)
|
113
|
+
# RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
|
114
|
+
# # => 'rdfs:Resource'
|
115
|
+
#
|
116
|
+
# @param [Array<symbol, RDF::Vocabulary>] vocabs
|
117
|
+
# A list of vocabularies (symbols or classes) which may
|
118
|
+
# be returned by {Vocabulary.each}. Also limits
|
119
|
+
# vocabularies that will be inspeced for other methods.
|
120
|
+
# Set to nil, or an empty array to reset.
|
121
|
+
# @return [Array<RDF::Vocabulary>]
|
122
|
+
def limit_vocabs(*vocabs)
|
123
|
+
@vocabs = if Array(vocabs).empty?
|
124
|
+
nil
|
125
|
+
else
|
126
|
+
vocabs.map do |vocab|
|
127
|
+
vocab = :rdfv if vocab == :rdf
|
128
|
+
vocab.is_a?(Symbol) && RDF::VOCABS.key?(vocab) ?
|
129
|
+
RDF.const_get(RDF::VOCABS[vocab][:class_name].to_sym) :
|
130
|
+
vocab
|
131
|
+
end.compact
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
80
135
|
##
|
81
136
|
# Is this a strict vocabulary, or a liberal vocabulary allowing arbitrary properties?
|
82
137
|
def strict?; false; end
|
@@ -291,7 +346,8 @@ module RDF
|
|
291
346
|
prefix, suffix = pname.to_s.split(":", 2)
|
292
347
|
if prefix == "rdf"
|
293
348
|
RDF[suffix]
|
294
|
-
elsif
|
349
|
+
elsif vocab_detail = RDF::Vocabulary.vocab_map[prefix.to_sym]
|
350
|
+
vocab = RDF::Vocabulary.from_sym(vocab_detail[:class_name])
|
295
351
|
suffix.to_s.empty? ? vocab.to_uri : vocab[suffix]
|
296
352
|
else
|
297
353
|
(RDF::Vocabulary.find_term(pname) rescue nil) || RDF::URI(pname, validate: true)
|
@@ -817,11 +873,10 @@ module RDF
|
|
817
873
|
# @return [RDF::Vocabulary]
|
818
874
|
attr_reader :vocab
|
819
875
|
|
820
|
-
#
|
821
|
-
#
|
876
|
+
# Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF.
|
877
|
+
# @return [Hash{Symbol,Resource => Term, #to_s}]
|
822
878
|
attr_reader :attributes
|
823
879
|
|
824
|
-
|
825
880
|
##
|
826
881
|
# @overload new(uri, attributes:, **options)
|
827
882
|
# @param [URI, String, #to_s] uri
|
@@ -882,7 +937,10 @@ module RDF
|
|
882
937
|
#
|
883
938
|
# @return [RDF::URI]
|
884
939
|
def dup
|
885
|
-
|
940
|
+
term = super.extend(Term)
|
941
|
+
term.instance_variable_set(:@vocab, vocab)
|
942
|
+
term.instance_variable_set(:@attributes, attributes)
|
943
|
+
term
|
886
944
|
end
|
887
945
|
|
888
946
|
##
|
@@ -943,7 +1001,7 @@ module RDF
|
|
943
1001
|
##
|
944
1002
|
# Values of an attributes as {RDF::Value}
|
945
1003
|
#
|
946
|
-
# @
|
1004
|
+
# @param [Symbol] prop
|
947
1005
|
# @return [RDF::Value, Array<RDF::Value>]
|
948
1006
|
def attribute_value(prop)
|
949
1007
|
values = attributes[prop]
|
data/lib/rdf/writer.rb
CHANGED
@@ -511,11 +511,12 @@ module RDF
|
|
511
511
|
# @since 0.3.0
|
512
512
|
def format_term(term, **options)
|
513
513
|
case term
|
514
|
-
when String
|
515
|
-
when RDF::List
|
516
|
-
when RDF::Literal
|
517
|
-
when RDF::URI
|
518
|
-
when RDF::Node
|
514
|
+
when String then format_literal(RDF::Literal(term, **options), **options)
|
515
|
+
when RDF::List then format_list(term, **options)
|
516
|
+
when RDF::Literal then format_literal(term, **options)
|
517
|
+
when RDF::URI then format_uri(term, **options)
|
518
|
+
when RDF::Node then format_node(term, **options)
|
519
|
+
when RDF::Statement then format_rdfstar(term, **options)
|
519
520
|
else nil
|
520
521
|
end
|
521
522
|
end
|
@@ -562,6 +563,21 @@ module RDF
|
|
562
563
|
format_term(value.subject, **options)
|
563
564
|
end
|
564
565
|
|
566
|
+
##
|
567
|
+
# Formats a referenced triple.
|
568
|
+
#
|
569
|
+
# @example
|
570
|
+
# <<<s> <p> <o>>> <p> <o> .
|
571
|
+
#
|
572
|
+
# @param [RDF::Statement] value
|
573
|
+
# @param [Hash{Symbol => Object}] options = ({})
|
574
|
+
# @return [String]
|
575
|
+
# @raise [NotImplementedError] unless implemented in subclass
|
576
|
+
# @abstract
|
577
|
+
def format_rdfstar(value, **options)
|
578
|
+
raise NotImplementedError.new("#{self.class}#format_statement") # override in subclasses
|
579
|
+
end
|
580
|
+
|
565
581
|
protected
|
566
582
|
|
567
583
|
##
|
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: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: link_header
|
@@ -279,7 +279,7 @@ files:
|
|
279
279
|
- lib/rdf/vocab/xsd.rb
|
280
280
|
- lib/rdf/vocabulary.rb
|
281
281
|
- lib/rdf/writer.rb
|
282
|
-
homepage: https://
|
282
|
+
homepage: https://github.com/ruby-rdf/rdf
|
283
283
|
licenses:
|
284
284
|
- Unlicense
|
285
285
|
metadata:
|
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
- !ruby/object:Gem::Version
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
|
-
rubygems_version: 3.1.
|
306
|
+
rubygems_version: 3.1.3
|
307
307
|
signing_key:
|
308
308
|
specification_version: 4
|
309
309
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|