rdf 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 523f47ae54751bebd787e2c6e89a873c9840a864
4
- data.tar.gz: 983597fbc20f6f76112c305fc1381cd121f0460a
3
+ metadata.gz: 3b35c022bb44e2984bddf19489cd1f4735c03b75
4
+ data.tar.gz: 720f825d01d2c76aca6e27e0b1ad2101beebc362
5
5
  SHA512:
6
- metadata.gz: 5a2ac12b5cf718284a678b37c1fab90b2d8e169f719dfc24af2ec1a4a2094672008d69bf3c8c8af3e4d4c67083a1e86966b237d9f68a13aa663f9e867dfae54b
7
- data.tar.gz: a9791dc9db755abdb52811f0a238c1294e830fe3d4f4fe0f7451e3bdc6734bca379a384e300fe0ee77c059749b55506dce5ae6be033c2de1cfbfb13a3f0f6550
6
+ metadata.gz: fab5abcd8aa2c90c9ab0a4ddd8fe33c25bd83cb0a5e2451fb64e7e0b00c19354aff75f8aa51fa228ebdf3c8522d3b1e19ff02bad2be809e302532a38d11ebb80
7
+ data.tar.gz: e73edad908ae432613d5f4cfd2e712fa933fb0b75f185acf8731a9948de8bd8c9e1679a39faefbb5457a55a5c0ee0d16717ec84363d2ca518cfe0538c8afc331
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
data/bin/rdf CHANGED
@@ -26,4 +26,5 @@ end
26
26
 
27
27
  abort options.banner if ARGV.empty? && !options.options[:evaluate]
28
28
 
29
- RDF::CLI.exec(ARGV, options.options)
29
+ # Add option_parser to parsed options to enable help
30
+ RDF::CLI.exec(ARGV, options.options.merge(option_parser: options))
@@ -8,7 +8,7 @@ begin
8
8
  require 'linkeddata'
9
9
  rescue LoadError
10
10
  # Silently load without linkeddata, but try some others
11
- %w(reasoner rdfa rdfxml turtle json/ld ld/patch).each do |ser|
11
+ %w(reasoner rdfa rdfxml turtle vocab json/ld ld/patch).each do |ser|
12
12
  begin
13
13
  require ser.include?('/') ? ser : "rdf/#{ser}"
14
14
  rescue LoadError
@@ -345,16 +345,16 @@ module RDF
345
345
  cmds, args = args.partition {|e| commands.include?(e.to_s)}
346
346
 
347
347
  if cmds.empty?
348
- usage(options)
348
+ usage(options.fetch(:option_parser, self.options))
349
349
  abort "No command given"
350
350
  end
351
351
 
352
352
  if cmds.first == 'help'
353
353
  on_cmd = cmds[1]
354
354
  if on_cmd && COMMANDS.fetch(on_cmd.to_sym, {})[:help]
355
- usage(self.options, banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
355
+ usage(options.fetch(:option_parser, self.options), banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
356
356
  else
357
- usage(self.options)
357
+ usage(options.fetch(:option_parser, self.options))
358
358
  end
359
359
  return
360
360
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module RDF
2
3
  ##
3
4
  # An RDF list.
@@ -344,12 +345,7 @@ module RDF
344
345
  # @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-unshift
345
346
  #
346
347
  def unshift(value)
347
- value = case value
348
- when nil then RDF.nil
349
- when RDF::Term then value
350
- when Array then RDF::List.new(subject: nil, graph: graph, values: value)
351
- else value
352
- end
348
+ value = normalize_value(value)
353
349
 
354
350
  new_subject, old_subject = RDF::Node.new, subject
355
351
 
@@ -407,12 +403,7 @@ module RDF
407
403
  # @return [RDF::List]
408
404
  # @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-3C-3C
409
405
  def <<(value)
410
- value = case value
411
- when nil then RDF.nil
412
- when RDF::Value then value
413
- when Array then RDF::List.new(subject: nil, graph: graph, values: value)
414
- else value
415
- end
406
+ value = normalize_value(value)
416
407
 
417
408
  if empty?
418
409
  @subject = new_subject = RDF::Node.new
@@ -547,12 +538,11 @@ module RDF
547
538
  # RDF::List[1, 2, 3].fetch(4, nil) #=> nil
548
539
  # RDF::List[1, 2, 3].fetch(4) { |n| n*n } #=> 16
549
540
  #
550
- # @return [RDF::Term]
541
+ # @return [RDF::Term, nil]
551
542
  # @see http://ruby-doc.org/core-1.9/classes/Array.html#M000420
552
543
  def fetch(index, default = UNSET)
553
- each.with_index do |v, i|
554
- return v if i == index
555
- end
544
+ val = at(index)
545
+ return val unless val.nil?
556
546
 
557
547
  case
558
548
  when block_given? then yield index
@@ -568,12 +558,10 @@ module RDF
568
558
  # RDF::List[1, 2, 3].at(0) #=> 1
569
559
  # RDF::List[1, 2, 3].at(4) #=> nil
570
560
  #
571
- # @return [RDF::Term]
561
+ # @return [RDF::Term, nil]
572
562
  # @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-at
573
563
  def at(index)
574
- each.with_index do |v, i|
575
- return v if i == index
576
- end
564
+ each.with_index { |v, i| return v if i == index }
577
565
  return nil
578
566
  end
579
567
 
@@ -943,5 +931,21 @@ module RDF
943
931
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, join(', '))
944
932
  end
945
933
  end
934
+
935
+ private
936
+
937
+ ##
938
+ # Normalizes `Array` to `RDF::List` and `nil` to `RDF.nil`.
939
+ #
940
+ # @param value [Object]
941
+ # @return [RDF::Value, Object] normalized value
942
+ def normalize_value(value)
943
+ case value
944
+ when nil then RDF.nil
945
+ when RDF::Value then value
946
+ when Array then RDF::List.new(subject: nil, graph: graph, values: value)
947
+ else value
948
+ end
949
+ end
946
950
  end
947
951
  end
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @since 0.2.1
13
13
  class Double < Numeric
14
14
  DATATYPE = RDF::XSD.double
15
- GRAMMAR = /^NaN|(?:[\+\-]?(?:INF|(?:\d+(\.\d*)?([eE][\+\-]?\d+)?)))$/.freeze
15
+ GRAMMAR = /^(?:NaN|(?:[\+\-]?(?:INF|(?:\d+(\.\d*)?([eE][\+\-]?\d+)?))))$/.freeze
16
16
 
17
17
  ##
18
18
  # @param [Float, #to_f] value
@@ -1235,7 +1235,7 @@ module RDF
1235
1235
 
1236
1236
  value = value.to_hash if value.respond_to?(:to_hash)
1237
1237
  self.query = case value
1238
- when Array
1238
+ when Array, Hash
1239
1239
  value.map do |(k,v)|
1240
1240
  k = normalize_segment(k.to_s, UNRESERVED)
1241
1241
  if v.nil?
@@ -1250,21 +1250,6 @@ module RDF
1250
1250
  end.join("&")
1251
1251
  end
1252
1252
  end
1253
- when Hash
1254
- value.map do |k, v|
1255
- k = normalize_segment(k.to_s, UNRESERVED)
1256
- if v.nil?
1257
- k
1258
- else
1259
- Array(v).map do |vv|
1260
- if vv === TrueClass
1261
- k
1262
- else
1263
- "#{k}=#{normalize_segment(vv.to_s, UNRESERVED)}"
1264
- end
1265
- end.join("&")
1266
- end
1267
- end
1268
1253
  else
1269
1254
  raise TypeError,
1270
1255
  "Can't convert #{value.class} into Hash."
@@ -113,26 +113,6 @@ module RDF
113
113
  # @since 2.0.0
114
114
  attr_reader :changes
115
115
 
116
- ##
117
- # RDF statements to delete when executed.
118
- #
119
- # @deprecated
120
- # @return [RDF::Enumerable]
121
- def deletes
122
- warn "[DEPRECATION] Transaction#deletes now uses keyword arguments. Called from #{Gem.location_of_caller.join(':')}"
123
- self.changes.deletes
124
- end
125
-
126
- ##
127
- # RDF statements to insert when executed.
128
- #
129
- # @deprecated
130
- # @return [RDF::Enumerable]
131
- def inserts
132
- warn "[DEPRECATION] Transaction#inserts now uses keyword arguments. Called from #{Gem.location_of_caller.join(':')}"
133
- self.changes.inserts
134
- end
135
-
136
116
  ##
137
117
  # Any additional options for this transaction.
138
118
  #
@@ -13,37 +13,37 @@ module RDF
13
13
  term :Alt,
14
14
  comment: %(The class of containers of alternatives.).freeze,
15
15
  label: "Alt".freeze,
16
- "rdfs:isDefinedBy" => %(rdf:).freeze,
16
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
17
17
  subClassOf: "rdfs:Container".freeze,
18
18
  type: "rdfs:Class".freeze
19
19
  term :Bag,
20
20
  comment: %(The class of unordered containers.).freeze,
21
21
  label: "Bag".freeze,
22
- "rdfs:isDefinedBy" => %(rdf:).freeze,
22
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
23
23
  subClassOf: "rdfs:Container".freeze,
24
24
  type: "rdfs:Class".freeze
25
25
  term :List,
26
26
  comment: %(The class of RDF Lists.).freeze,
27
27
  label: "List".freeze,
28
- "rdfs:isDefinedBy" => %(rdf:).freeze,
28
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
29
29
  subClassOf: "rdfs:Resource".freeze,
30
30
  type: "rdfs:Class".freeze
31
31
  term :Property,
32
32
  comment: %(The class of RDF properties.).freeze,
33
33
  label: "Property".freeze,
34
- "rdfs:isDefinedBy" => %(rdf:).freeze,
34
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
35
35
  subClassOf: "rdfs:Resource".freeze,
36
36
  type: "rdfs:Class".freeze
37
37
  term :Seq,
38
38
  comment: %(The class of ordered containers.).freeze,
39
39
  label: "Seq".freeze,
40
- "rdfs:isDefinedBy" => %(rdf:).freeze,
40
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
41
41
  subClassOf: "rdfs:Container".freeze,
42
42
  type: "rdfs:Class".freeze
43
43
  term :Statement,
44
44
  comment: %(The class of RDF statements.).freeze,
45
45
  label: "Statement".freeze,
46
- "rdfs:isDefinedBy" => %(rdf:).freeze,
46
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
47
47
  subClassOf: "rdfs:Resource".freeze,
48
48
  type: "rdfs:Class".freeze
49
49
 
@@ -53,84 +53,84 @@ module RDF
53
53
  domain: "rdf:List".freeze,
54
54
  label: "first".freeze,
55
55
  range: "rdfs:Resource".freeze,
56
- "rdfs:isDefinedBy" => %(rdf:).freeze,
56
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
57
57
  type: "rdf:Property".freeze
58
58
  property :object,
59
59
  comment: %(The object of the subject RDF statement.).freeze,
60
60
  domain: "rdf:Statement".freeze,
61
61
  label: "object".freeze,
62
62
  range: "rdfs:Resource".freeze,
63
- "rdfs:isDefinedBy" => %(rdf:).freeze,
63
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
64
64
  type: "rdf:Property".freeze
65
65
  property :predicate,
66
66
  comment: %(The predicate of the subject RDF statement.).freeze,
67
67
  domain: "rdf:Statement".freeze,
68
68
  label: "predicate".freeze,
69
69
  range: "rdfs:Resource".freeze,
70
- "rdfs:isDefinedBy" => %(rdf:).freeze,
70
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
71
71
  type: "rdf:Property".freeze
72
72
  property :rest,
73
73
  comment: %(The rest of the subject RDF list after the first item.).freeze,
74
74
  domain: "rdf:List".freeze,
75
75
  label: "rest".freeze,
76
76
  range: "rdf:List".freeze,
77
- "rdfs:isDefinedBy" => %(rdf:).freeze,
77
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
78
78
  type: "rdf:Property".freeze
79
79
  property :subject,
80
80
  comment: %(The subject of the subject RDF statement.).freeze,
81
81
  domain: "rdf:Statement".freeze,
82
82
  label: "subject".freeze,
83
83
  range: "rdfs:Resource".freeze,
84
- "rdfs:isDefinedBy" => %(rdf:).freeze,
84
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
85
85
  type: "rdf:Property".freeze
86
86
  property :type,
87
87
  comment: %(The subject is an instance of a class.).freeze,
88
88
  domain: "rdfs:Resource".freeze,
89
89
  label: "type".freeze,
90
90
  range: "rdfs:Class".freeze,
91
- "rdfs:isDefinedBy" => %(rdf:).freeze,
91
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
92
92
  type: "rdf:Property".freeze
93
93
  property :value,
94
94
  comment: %(Idiomatic property used for structured values.).freeze,
95
95
  domain: "rdfs:Resource".freeze,
96
96
  label: "value".freeze,
97
97
  range: "rdfs:Resource".freeze,
98
- "rdfs:isDefinedBy" => %(rdf:).freeze,
98
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
99
99
  type: "rdf:Property".freeze
100
100
 
101
101
  # Datatype definitions
102
102
  term :HTML,
103
103
  comment: %(The datatype of RDF literals storing fragments of HTML content).freeze,
104
104
  label: "HTML".freeze,
105
- "rdfs:isDefinedBy" => %(rdf:).freeze,
106
- "rdfs:seeAlso" => %(http://www.w3.org/TR/rdf11-concepts/#section-html).freeze,
105
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
106
+ :"rdfs:seeAlso" => %(http://www.w3.org/TR/rdf11-concepts/#section-html).freeze,
107
107
  subClassOf: "rdfs:Literal".freeze,
108
108
  type: "rdfs:Datatype".freeze
109
109
  term :PlainLiteral,
110
110
  comment: %(The class of plain \(i.e. untyped\) literal values, as used in RIF and OWL 2).freeze,
111
111
  label: "PlainLiteral".freeze,
112
- "rdfs:isDefinedBy" => %(rdf:).freeze,
113
- "rdfs:seeAlso" => %(http://www.w3.org/TR/rdf-plain-literal/).freeze,
112
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
113
+ :"rdfs:seeAlso" => %(http://www.w3.org/TR/rdf-plain-literal/).freeze,
114
114
  subClassOf: "rdfs:Literal".freeze,
115
115
  type: "rdfs:Datatype".freeze
116
116
  term :XMLLiteral,
117
117
  comment: %(The datatype of XML literal values.).freeze,
118
118
  label: "XMLLiteral".freeze,
119
- "rdfs:isDefinedBy" => %(rdf:).freeze,
119
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
120
120
  subClassOf: "rdfs:Literal".freeze,
121
121
  type: "rdfs:Datatype".freeze
122
122
  term :langString,
123
123
  comment: %(The datatype of language-tagged string values).freeze,
124
124
  label: "langString".freeze,
125
- "rdfs:isDefinedBy" => %(rdf:).freeze,
126
- "rdfs:seeAlso" => %(http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal).freeze,
125
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
126
+ :"rdfs:seeAlso" => %(http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal).freeze,
127
127
  subClassOf: "rdfs:Literal".freeze,
128
128
  type: "rdfs:Datatype".freeze
129
129
 
130
130
  # Extra definitions
131
131
  term :"",
132
- "dc11:description" => %(This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts.).freeze,
133
- "dc11:title" => %(The RDF Concepts Vocabulary \(RDF\)).freeze,
132
+ :"dc11:description" => %(This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts.).freeze,
133
+ :"dc11:title" => %(The RDF Concepts Vocabulary \(RDF\)).freeze,
134
134
  type: "owl:Ontology".freeze
135
135
  term :Description,
136
136
  comment: %(RDF/XML node element).freeze,
@@ -150,7 +150,7 @@ module RDF
150
150
  term :nil,
151
151
  comment: %(The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it.).freeze,
152
152
  label: "nil".freeze,
153
- "rdfs:isDefinedBy" => %(rdf:).freeze,
153
+ :"rdfs:isDefinedBy" => %(rdf:).freeze,
154
154
  type: "rdf:List".freeze
155
155
  term :nodeID,
156
156
  comment: %(RDF/XML Blank Node identifier).freeze,
@@ -262,39 +262,6 @@ module RDF
262
262
  @@uris.has_key?(self) ? @@uris[self].to_s : super
263
263
  end
264
264
 
265
- ##
266
- # Load an RDFS vocabulary, optionally from a separate location.
267
- #
268
- # @param [URI, #to_s] url
269
- # @param [String] class_name
270
- # The class_name associated with the vocabulary, used for creating the class name of the vocabulary. This will create a new class named with a top-level constant based on `class_name`.
271
- # @param [RDF::Queryable, URI, #to_s] location
272
- # Location from which to load the vocabulary, or Queryable containing already loaded vocabulary triples, if not from `uri`.
273
- # @param [Array<Symbol>, Hash{Symbol => Hash}] extra
274
- # Extra terms to add to the vocabulary. In the first form, it is an array of symbols, for which terms are created. In the second, it is a Hash mapping symbols to property attributes, as described in {RDF::Vocabulary.property}.
275
- # @param [String] patch
276
- # A patch to run on the graph after loading. Requires the `ld-patch` gem to be available.
277
- # @return [RDF::Vocabulary] the loaded vocabulary
278
- # @deprecated Use Vocabulary.from_graph
279
- def load(url, class_name: nil, location: nil, extra: nil, patch: nil)
280
- warn "[DEPRECATION] Vocabulary.load is deprecated, use Vocabulary.from_graph instead. Called from #{Gem.location_of_caller.join(':')}"
281
- source = location || url
282
-
283
- graph = source.is_a?(RDF::Queryable) ? source : RDF::Repository.load(source)
284
-
285
- if patch
286
- begin
287
- require 'ld/patch'
288
- operator = LD::Patch.parse(patch)
289
- graph.query(operator)
290
- rescue LoadError
291
- raise ArgumentError, "patching vocabulary requires the ld-patch gem"
292
- end
293
- end
294
-
295
- from_graph(graph, url: url, class_name: nil, extra: extra)
296
- end
297
-
298
265
  ##
299
266
  # Create a vocabulary from a graph or enumerable
300
267
  #
@@ -560,7 +527,13 @@ module RDF
560
527
  # Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
561
528
  def initialize(*args, **options)
562
529
  @attributes = options.fetch(:attributes)
563
- super
530
+ if RUBY_ENGINE == "rbx"
531
+ # FIXME: Somehow, this gets messed up in Rubinius
532
+ args << options
533
+ super(*args)
534
+ else
535
+ super
536
+ end
564
537
  end
565
538
 
566
539
  ##
@@ -652,14 +625,30 @@ module RDF
652
625
  prop = RDF::URI("http://schema.org/rangeIncludes")
653
626
  value = RDF::Vocabulary.expand_pname(value)
654
627
  when :label
655
- prop = RDFS.label
628
+ prop = RDF::RDFS.label
656
629
  when :comment
657
- prop = RDFS.comment
630
+ prop = RDF::RDFS.comment
658
631
  else
659
632
  prop = RDF::Vocabulary.expand_pname(prop.to_s)
660
633
  next unless prop
661
- v = RDF::Vocabulary.expand_pname(value.to_s)
662
- value = v.valid? ? v : RDF::Literal(value.to_s)
634
+
635
+ v = value.to_s
636
+ value = RDF::Vocabulary.expand_pname(v)
637
+ unless value && value.valid?
638
+ # Use as most appropriate literal
639
+ value = [
640
+ RDF::Literal::Date,
641
+ RDF::Literal::DateTime,
642
+ RDF::Literal::Integer,
643
+ RDF::Literal::Decimal,
644
+ RDF::Literal::Double,
645
+ RDF::Literal::Boolean,
646
+ RDF::Literal
647
+ ].inject(nil) do |memo, klass|
648
+ l = klass.new(v)
649
+ memo || (l if l.valid?)
650
+ end
651
+ end
663
652
  end
664
653
  yield RDF::Statement(self, prop, value)
665
654
  rescue KeyError
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: 2.0.0
4
+ version: 2.0.1
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: 2016-04-10 00:00:00.000000000 Z
13
+ date: 2016-04-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  version: '0'
285
285
  requirements: []
286
286
  rubyforge_project: rdf
287
- rubygems_version: 2.4.8
287
+ rubygems_version: 2.5.1
288
288
  signing_key:
289
289
  specification_version: 4
290
290
  summary: A Ruby library for working with Resource Description Framework (RDF) data.