rdf 3.2.10 → 3.3.0
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.
- checksums.yaml +4 -4
- data/README.md +37 -35
- data/VERSION +1 -1
- data/lib/rdf/cli.rb +1 -1
- data/lib/rdf/mixin/enumerable.rb +23 -2
- data/lib/rdf/mixin/queryable.rb +1 -1
- data/lib/rdf/mixin/writable.rb +5 -2
- data/lib/rdf/model/dataset.rb +1 -1
- data/lib/rdf/model/graph.rb +5 -2
- data/lib/rdf/model/list.rb +0 -13
- data/lib/rdf/model/literal/decimal.rb +1 -1
- data/lib/rdf/model/literal.rb +83 -31
- data/lib/rdf/model/statement.rb +14 -1
- data/lib/rdf/model/uri.rb +60 -43
- data/lib/rdf/nquads.rb +0 -1
- data/lib/rdf/ntriples/format.rb +0 -1
- data/lib/rdf/ntriples/reader.rb +15 -14
- data/lib/rdf/ntriples/writer.rb +2 -1
- data/lib/rdf/ntriples.rb +2 -2
- data/lib/rdf/query/solution.rb +1 -1
- data/lib/rdf/reader.rb +7 -5
- data/lib/rdf/repository.rb +4 -2
- data/lib/rdf/util/cache.rb +2 -2
- data/lib/rdf/util/uuid.rb +2 -2
- data/lib/rdf/vocab/rdfv.rb +11 -0
- data/lib/rdf/writer.rb +3 -1
- data/lib/rdf.rb +0 -1
- metadata +28 -21
- data/lib/rdf/extensions.rb +0 -22
data/lib/rdf/model/uri.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'cgi'
|
3
4
|
|
4
5
|
module RDF
|
@@ -28,27 +29,27 @@ module RDF
|
|
28
29
|
include RDF::Resource
|
29
30
|
|
30
31
|
# IRI components
|
31
|
-
UCSCHAR =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
IPRIVATE = Regexp.compile("[\\uE000-\\uF8FF
|
32
|
+
UCSCHAR = %(
|
33
|
+
\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF
|
34
|
+
\\u{10000}-\\u{1FFFD}\\u{20000}-\\u{2FFFD}\\u{30000}-\\u{3FFFD}
|
35
|
+
\\u{40000}-\\u{4FFFD}\\u{50000}-\\u{5FFFD}\\u{60000}-\\u{6FFFD}
|
36
|
+
\\u{70000}-\\u{7FFFD}\\u{80000}-\\u{8FFFD}\\u{90000}-\\u{9FFFD}
|
37
|
+
\\u{A0000}-\\u{AFFFD}\\u{B0000}-\\u{BFFFD}\\u{C0000}-\\u{CFFFD}
|
38
|
+
\\u{D0000}-\\u{DFFFD}\\u{E1000}-\\u{EFFFD}
|
39
|
+
).gsub(/\s+/, '')
|
40
|
+
IPRIVATE = Regexp.compile("[\\uE000-\\uF8FF\\u{F0000}-\\u{FFFFD}\\u{100000}-\\u{10FFFD}]").freeze
|
40
41
|
SCHEME = Regexp.compile("[A-Za-z](?:[A-Za-z0-9+-\.])*").freeze
|
41
42
|
PORT = Regexp.compile("[0-9]*").freeze
|
42
43
|
IP_literal = Regexp.compile("\\[[0-9A-Fa-f:\\.]*\\]").freeze # Simplified, no IPvFuture
|
43
44
|
PCT_ENCODED = Regexp.compile("%[0-9A-Fa-f][0-9A-Fa-f]").freeze
|
44
|
-
GEN_DELIMS = Regexp.compile(
|
45
|
-
SUB_DELIMS = Regexp.compile(
|
46
|
-
RESERVED = Regexp.
|
45
|
+
GEN_DELIMS = Regexp.compile(%q{[:/\?\#\[\]@]}).freeze
|
46
|
+
SUB_DELIMS = Regexp.compile(%q{[!\$&'\(\)\*\+,;=]}).freeze
|
47
|
+
RESERVED = Regexp.union(GEN_DELIMS, SUB_DELIMS).freeze
|
47
48
|
UNRESERVED = Regexp.compile("[A-Za-z0-9\._~-]").freeze
|
48
49
|
|
49
|
-
IUNRESERVED = Regexp.compile("[
|
50
|
+
IUNRESERVED = Regexp.union(UNRESERVED, Regexp.compile("[#{UCSCHAR}]")).freeze
|
50
51
|
|
51
|
-
IPCHAR = Regexp.
|
52
|
+
IPCHAR = Regexp.union(IUNRESERVED, PCT_ENCODED, SUB_DELIMS, /[:|@]/).freeze
|
52
53
|
|
53
54
|
IQUERY = Regexp.compile("(?:#{IPCHAR}|#{IPRIVATE}|/|\\?)*").freeze
|
54
55
|
|
@@ -65,7 +66,7 @@ module RDF
|
|
65
66
|
IPATH_EMPTY = Regexp.compile("").freeze
|
66
67
|
|
67
68
|
IREG_NAME = Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS}))*").freeze
|
68
|
-
IHOST = Regexp.
|
69
|
+
IHOST = Regexp.union(IP_literal, IREG_NAME).freeze
|
69
70
|
IUSERINFO = Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS})|:)*").freeze
|
70
71
|
IAUTHORITY = Regexp.compile("(?:#{IUSERINFO}@)?#{IHOST}(?::#{PORT})?").freeze
|
71
72
|
|
@@ -116,7 +117,21 @@ module RDF
|
|
116
117
|
# Note: not all reserved characters need to be escaped in SPARQL/Turtle, but they must be unescaped when encountered
|
117
118
|
PN_ESCAPE_CHARS = /[~\.!\$&'\(\)\*\+,;=\/\?\#@%]/.freeze
|
118
119
|
PN_ESCAPES = /\\#{Regexp.union(PN_ESCAPE_CHARS, /[\-_]/)}/.freeze
|
119
|
-
|
120
|
+
|
121
|
+
# For URI encoding
|
122
|
+
# iuserinfo = *( iunreserved / pct-encoded / sub-delims / ":" )
|
123
|
+
ENCODE_USER =
|
124
|
+
ENCODE_PASSWORD = Regexp.compile("[^A-Za-z0-9\._~#{UCSCHAR}!$&'\(\)\*\+,;=:-]").freeze
|
125
|
+
# isegment = *ipchar
|
126
|
+
# ipchar = iunreserved / pct-encoded / sub-delims / ":" / "@"
|
127
|
+
ENCODE_ISEGMENT = Regexp.compile("[^A-Za-z0-9\._~#{UCSCHAR}!$&'\(\)\*\+,;=:-]").freeze
|
128
|
+
# isegment-nz-nc = 1*( iunreserved / pct-encoded / sub-delims / "@" )
|
129
|
+
ENCODE_ISEGMENT_NC = Regexp.compile("[^A-Za-z0-9\._~#{UCSCHAR}!$&'\(\)\*\+,;=-]").freeze
|
130
|
+
# iquery = *( ipchar / iprivate / "/" / "?" )
|
131
|
+
ENCODE_IQUERY = Regexp.compile("[^A-Za-z0-9\._~#{UCSCHAR}\\uE000-\\uF8FF\\u{F0000}-\\u{FFFFD}\\u{100000}-\\u{10FFFD}/?=]").freeze
|
132
|
+
# ifragment = *( ipchar / "/" / "?" )
|
133
|
+
ENCODE_IFRAGMENT = Regexp.compile("[^A-Za-z0-9\._~#{UCSCHAR}/?]").freeze
|
134
|
+
|
120
135
|
##
|
121
136
|
# Cache size may be set through {RDF.config} using `uri_cache_size`.
|
122
137
|
#
|
@@ -170,7 +185,7 @@ module RDF
|
|
170
185
|
# @return [String] normalized path
|
171
186
|
# @see http://tools.ietf.org/html/rfc3986#section-5.2.4
|
172
187
|
def self.normalize_path(path)
|
173
|
-
output, input =
|
188
|
+
output, input = String.new, path.to_s
|
174
189
|
if input.encoding != Encoding::ASCII_8BIT
|
175
190
|
input = input.dup.force_encoding(Encoding::ASCII_8BIT)
|
176
191
|
end
|
@@ -353,7 +368,7 @@ module RDF
|
|
353
368
|
# @return [Boolean] `true` or `false`
|
354
369
|
# @since 0.3.9
|
355
370
|
def valid?
|
356
|
-
RDF::URI::IRI.match(to_s) || false
|
371
|
+
RDF::URI::IRI.match?(to_s) || false
|
357
372
|
end
|
358
373
|
|
359
374
|
##
|
@@ -920,7 +935,7 @@ module RDF
|
|
920
935
|
# Return normalized version of scheme, if any
|
921
936
|
# @return [String]
|
922
937
|
def normalized_scheme
|
923
|
-
|
938
|
+
scheme.strip.downcase if scheme
|
924
939
|
end
|
925
940
|
|
926
941
|
##
|
@@ -946,7 +961,7 @@ module RDF
|
|
946
961
|
# Normalized version of user
|
947
962
|
# @return [String]
|
948
963
|
def normalized_user
|
949
|
-
URI.encode(CGI.unescape(user),
|
964
|
+
URI.encode(CGI.unescape(user), ENCODE_USER).force_encoding(Encoding::UTF_8) if user
|
950
965
|
end
|
951
966
|
|
952
967
|
##
|
@@ -972,7 +987,7 @@ module RDF
|
|
972
987
|
# Normalized version of password
|
973
988
|
# @return [String]
|
974
989
|
def normalized_password
|
975
|
-
URI.encode(CGI.unescape(password),
|
990
|
+
URI.encode(CGI.unescape(password), ENCODE_PASSWORD).force_encoding(Encoding::UTF_8) if password
|
976
991
|
end
|
977
992
|
|
978
993
|
HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
|
@@ -1000,7 +1015,7 @@ module RDF
|
|
1000
1015
|
# @return [String]
|
1001
1016
|
def normalized_host
|
1002
1017
|
# Remove trailing '.' characters
|
1003
|
-
|
1018
|
+
host.sub(/\.*$/, '').downcase if host
|
1004
1019
|
end
|
1005
1020
|
|
1006
1021
|
PORT_FROM_AUTHORITY_RE = /:(\d+)$/.freeze
|
@@ -1028,12 +1043,8 @@ module RDF
|
|
1028
1043
|
# @return [String]
|
1029
1044
|
def normalized_port
|
1030
1045
|
if port
|
1031
|
-
np =
|
1032
|
-
|
1033
|
-
nil
|
1034
|
-
else
|
1035
|
-
np.to_i
|
1036
|
-
end
|
1046
|
+
np = port.to_i
|
1047
|
+
PORT_MAPPING[normalized_scheme] != np ? np : nil
|
1037
1048
|
end
|
1038
1049
|
end
|
1039
1050
|
|
@@ -1064,30 +1075,36 @@ module RDF
|
|
1064
1075
|
# Normalized version of path
|
1065
1076
|
# @return [String]
|
1066
1077
|
def normalized_path
|
1078
|
+
if normalized_scheme == "urn"
|
1079
|
+
# Special-case URI. Normalize the NID component only
|
1080
|
+
nid, p = path.to_s.split(':', 2)
|
1081
|
+
return "#{nid.downcase}:#{p}"
|
1082
|
+
end
|
1083
|
+
|
1067
1084
|
segments = path.to_s.split('/', -1) # preserve null segments
|
1068
1085
|
|
1069
1086
|
norm_segs = case
|
1070
1087
|
when authority
|
1071
1088
|
# ipath-abempty
|
1072
|
-
segments.map {|s| normalize_segment(s,
|
1089
|
+
segments.map {|s| normalize_segment(s, ENCODE_ISEGMENT)}
|
1073
1090
|
when segments[0].nil?
|
1074
1091
|
# ipath-absolute
|
1075
1092
|
res = [nil]
|
1076
|
-
res << normalize_segment(segments[1],
|
1077
|
-
res += segments[2..-1].map {|s| normalize_segment(s,
|
1093
|
+
res << normalize_segment(segments[1], ENCODE_ISEGMENT) if segments.length > 1
|
1094
|
+
res += segments[2..-1].map {|s| normalize_segment(s, ENCODE_ISEGMENT)} if segments.length > 2
|
1078
1095
|
res
|
1079
1096
|
when segments[0].to_s.index(':')
|
1080
1097
|
# ipath-noscheme
|
1081
1098
|
res = []
|
1082
|
-
res << normalize_segment(segments[0],
|
1083
|
-
res += segments[1..-1].map {|s| normalize_segment(s,
|
1099
|
+
res << normalize_segment(segments[0], ENCODE_ISEGMENT_NC)
|
1100
|
+
res += segments[1..-1].map {|s| normalize_segment(s, ENCODE_ISEGMENT)} if segments.length > 1
|
1084
1101
|
res
|
1085
1102
|
when segments[0]
|
1086
1103
|
# ipath-rootless
|
1087
1104
|
# ipath-noscheme
|
1088
1105
|
res = []
|
1089
|
-
res << normalize_segment(segments[0],
|
1090
|
-
res += segments[1..-1].map {|s| normalize_segment(s,
|
1106
|
+
res << normalize_segment(segments[0], ENCODE_ISEGMENT)
|
1107
|
+
res += segments[1..-1].map {|s| normalize_segment(s, ENCODE_ISEGMENT)} if segments.length > 1
|
1091
1108
|
res
|
1092
1109
|
else
|
1093
1110
|
# Should be empty
|
@@ -1096,7 +1113,7 @@ module RDF
|
|
1096
1113
|
|
1097
1114
|
res = self.class.normalize_path(norm_segs.join("/"))
|
1098
1115
|
# Special rules for specific protocols having empty paths
|
1099
|
-
|
1116
|
+
(res.empty? && %w(http https ftp tftp).include?(normalized_scheme)) ? '/' : res
|
1100
1117
|
end
|
1101
1118
|
|
1102
1119
|
##
|
@@ -1120,7 +1137,7 @@ module RDF
|
|
1120
1137
|
# Normalized version of query
|
1121
1138
|
# @return [String]
|
1122
1139
|
def normalized_query
|
1123
|
-
normalize_segment(query,
|
1140
|
+
normalize_segment(query, ENCODE_IQUERY) if query
|
1124
1141
|
end
|
1125
1142
|
|
1126
1143
|
##
|
@@ -1144,7 +1161,7 @@ module RDF
|
|
1144
1161
|
# Normalized version of fragment
|
1145
1162
|
# @return [String]
|
1146
1163
|
def normalized_fragment
|
1147
|
-
normalize_segment(fragment,
|
1164
|
+
normalize_segment(fragment, ENCODE_IFRAGMENT) if fragment
|
1148
1165
|
end
|
1149
1166
|
|
1150
1167
|
##
|
@@ -1274,7 +1291,7 @@ module RDF
|
|
1274
1291
|
self.query = case value
|
1275
1292
|
when Array, Hash
|
1276
1293
|
value.map do |(k,v)|
|
1277
|
-
k = normalize_segment(k.to_s,
|
1294
|
+
k = normalize_segment(k.to_s, /[^A-Za-z0-9\._~-]/)
|
1278
1295
|
if v.nil?
|
1279
1296
|
k
|
1280
1297
|
else
|
@@ -1282,7 +1299,7 @@ module RDF
|
|
1282
1299
|
if vv === TrueClass
|
1283
1300
|
k
|
1284
1301
|
else
|
1285
|
-
"#{k}=#{normalize_segment(vv.to_s,
|
1302
|
+
"#{k}=#{normalize_segment(vv.to_s, /[^A-Za-z0-9\._~-]/)}"
|
1286
1303
|
end
|
1287
1304
|
end.join("&")
|
1288
1305
|
end
|
@@ -1331,7 +1348,7 @@ module RDF
|
|
1331
1348
|
# Normalize a segment using a character range
|
1332
1349
|
#
|
1333
1350
|
# @param [String] value
|
1334
|
-
# @param [Regexp] expr
|
1351
|
+
# @param [Regexp] expr matches characters to be encoded
|
1335
1352
|
# @param [Boolean] downcase
|
1336
1353
|
# @return [String]
|
1337
1354
|
def normalize_segment(value, expr, downcase = false)
|
@@ -1339,7 +1356,7 @@ module RDF
|
|
1339
1356
|
value = value.dup.force_encoding(Encoding::UTF_8)
|
1340
1357
|
decoded = CGI.unescape(value)
|
1341
1358
|
decoded.downcase! if downcase
|
1342
|
-
URI.encode(decoded,
|
1359
|
+
URI.encode(decoded, expr).force_encoding(Encoding::UTF_8)
|
1343
1360
|
end
|
1344
1361
|
end
|
1345
1362
|
|
@@ -1364,7 +1381,7 @@ module RDF
|
|
1364
1381
|
def self.encode(str, expr)
|
1365
1382
|
str.gsub(expr) do
|
1366
1383
|
us = $&
|
1367
|
-
tmp =
|
1384
|
+
tmp = String.new
|
1368
1385
|
us.each_byte do |uc|
|
1369
1386
|
tmp << sprintf('%%%02X', uc)
|
1370
1387
|
end
|
data/lib/rdf/nquads.rb
CHANGED
data/lib/rdf/ntriples/format.rb
CHANGED
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -28,7 +28,7 @@ module RDF::NTriples
|
|
28
28
|
# end
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
# **
|
31
|
+
# ** RDF=star
|
32
32
|
#
|
33
33
|
# Supports statements as resources using `<<s p o>>`.
|
34
34
|
#
|
@@ -60,24 +60,16 @@ module RDF::NTriples
|
|
60
60
|
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
|
61
61
|
IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze
|
62
62
|
|
63
|
-
# 163s
|
64
63
|
PN_CHARS_BASE = /[A-Z]|[a-z]|#{U_CHARS1}/.freeze
|
65
|
-
# 164s
|
66
64
|
PN_CHARS_U = /_|#{PN_CHARS_BASE}/.freeze
|
67
|
-
# 166s
|
68
65
|
PN_CHARS = /-|[0-9]|#{PN_CHARS_U}|#{U_CHARS2}/.freeze
|
69
|
-
# 159s
|
70
66
|
ECHAR = /\\[tbnrf"'\\]/.freeze
|
71
|
-
|
67
|
+
|
72
68
|
IRIREF = /<((?:#{IRI_RANGE}|#{UCHAR})*)>/.freeze
|
73
|
-
# 141s
|
74
69
|
BLANK_NODE_LABEL = /_:((?:[0-9]|#{PN_CHARS_U})(?:(?:#{PN_CHARS}|\.)*#{PN_CHARS})?)/.freeze
|
75
|
-
|
76
|
-
LANGTAG = /@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)/.freeze
|
77
|
-
# 22
|
70
|
+
LANG_DIR = /@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*(?:--[a-zA-Z]+)?)/.freeze
|
78
71
|
STRING_LITERAL_QUOTE = /"((?:[^\"\\\n\r]|#{ECHAR}|#{UCHAR})*)"/.freeze
|
79
72
|
|
80
|
-
# RDF*
|
81
73
|
ST_START = /^<</.freeze
|
82
74
|
ST_END = /^\s*>>/.freeze
|
83
75
|
|
@@ -86,7 +78,7 @@ module RDF::NTriples
|
|
86
78
|
NODEID = /^#{BLANK_NODE_LABEL}/.freeze
|
87
79
|
URIREF = /^#{IRIREF}/.freeze
|
88
80
|
LITERAL_PLAIN = /^#{STRING_LITERAL_QUOTE}/.freeze
|
89
|
-
LITERAL_WITH_LANGUAGE = /^#{STRING_LITERAL_QUOTE}#{
|
81
|
+
LITERAL_WITH_LANGUAGE = /^#{STRING_LITERAL_QUOTE}#{LANG_DIR}/.freeze
|
90
82
|
LITERAL_WITH_DATATYPE = /^#{STRING_LITERAL_QUOTE}\^\^#{IRIREF}/.freeze
|
91
83
|
DATATYPE_URI = /^\^\^#{IRIREF}/.freeze
|
92
84
|
LITERAL = Regexp.union(LITERAL_WITH_LANGUAGE, LITERAL_WITH_DATATYPE, LITERAL_PLAIN).freeze
|
@@ -95,6 +87,9 @@ module RDF::NTriples
|
|
95
87
|
OBJECT = Regexp.union(URIREF, NODEID, LITERAL).freeze
|
96
88
|
END_OF_STATEMENT = /^\s*\.\s*(?:#.*)?$/.freeze
|
97
89
|
|
90
|
+
# LANGTAG is deprecated
|
91
|
+
LANGTAG = LANG_DIR
|
92
|
+
|
98
93
|
##
|
99
94
|
# Reconstructs an RDF value from its serialized N-Triples
|
100
95
|
# representation.
|
@@ -299,8 +294,10 @@ module RDF::NTriples
|
|
299
294
|
if literal_str = match(LITERAL_PLAIN)
|
300
295
|
literal_str = self.class.unescape(literal_str)
|
301
296
|
literal = case
|
302
|
-
when
|
303
|
-
|
297
|
+
when lang_dir = match(LANG_DIR)
|
298
|
+
language, direction = lang_dir.split('--')
|
299
|
+
raise ArgumentError if direction && !@options[:rdfstar]
|
300
|
+
RDF::Literal.new(literal_str, language: language, direction: direction)
|
304
301
|
when datatype = match(/^(\^\^)/) # FIXME
|
305
302
|
RDF::Literal.new(literal_str, datatype: read_uriref || fail_object)
|
306
303
|
else
|
@@ -310,6 +307,10 @@ module RDF::NTriples
|
|
310
307
|
literal.canonicalize! if canonicalize?
|
311
308
|
literal
|
312
309
|
end
|
310
|
+
rescue ArgumentError
|
311
|
+
v = literal_str
|
312
|
+
v += "@#{lang_dir}" if lang_dir
|
313
|
+
log_error("Invalid Literal (found: \"#{v}\")", lineno: lineno, token: "#v", exception: RDF::ReaderError)
|
313
314
|
end
|
314
315
|
|
315
316
|
##
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -224,7 +224,7 @@ module RDF::NTriples
|
|
224
224
|
end
|
225
225
|
|
226
226
|
##
|
227
|
-
# Returns the N-Triples representation of an RDF
|
227
|
+
# Returns the N-Triples representation of an RDF-star quoted triple.
|
228
228
|
#
|
229
229
|
# @param [RDF::Statement] statement
|
230
230
|
# @param [Hash{Symbol => Object}] options ({})
|
@@ -312,6 +312,7 @@ module RDF::NTriples
|
|
312
312
|
# Note, escaping here is more robust than in Term
|
313
313
|
text = quoted(escaped(literal.value))
|
314
314
|
text << "@#{literal.language}" if literal.language?
|
315
|
+
text << "--#{literal.direction}" if literal.direction?
|
315
316
|
text << "^^<#{uri_for(literal.datatype)}>" if literal.datatype?
|
316
317
|
text
|
317
318
|
else
|
data/lib/rdf/ntriples.rb
CHANGED
@@ -8,14 +8,14 @@ module RDF
|
|
8
8
|
# [Turtle](http://www.w3.org/TeamSubmission/turtle/) and
|
9
9
|
# [Notation3](http://www.w3.org/TeamSubmission/n3/) (N3).
|
10
10
|
#
|
11
|
-
# The MIME content type for N-Triples files is `
|
11
|
+
# The MIME content type for N-Triples files is `application/n-triples` and the
|
12
12
|
# recommended file extension is `.nt`.
|
13
13
|
#
|
14
14
|
# An example of an RDF statement in N-Triples format:
|
15
15
|
#
|
16
16
|
# <https://rubygems.org/gems/rdf> <http://purl.org/dc/terms/title> "rdf" .
|
17
17
|
#
|
18
|
-
# ##
|
18
|
+
# ## Quoted Triples
|
19
19
|
#
|
20
20
|
# Supports statements as resources using `<<s p o>>`.
|
21
21
|
#
|
data/lib/rdf/query/solution.rb
CHANGED
@@ -209,7 +209,7 @@ class RDF::Query
|
|
209
209
|
# Merges the bindings from the given `other` query solution into this
|
210
210
|
# one, overwriting any existing ones having the same name.
|
211
211
|
#
|
212
|
-
# ##
|
212
|
+
# ## RDF-star
|
213
213
|
#
|
214
214
|
# If merging a binding for a statement to a pattern,
|
215
215
|
# merge their embedded solutions.
|
data/lib/rdf/reader.rb
CHANGED
@@ -133,7 +133,7 @@ module RDF
|
|
133
133
|
on: ["--canonicalize"],
|
134
134
|
control: :checkbox,
|
135
135
|
default: false,
|
136
|
-
description: "Canonicalize
|
136
|
+
description: "Canonicalize URI/literal forms") {true},
|
137
137
|
RDF::CLI::Option.new(
|
138
138
|
symbol: :encoding,
|
139
139
|
datatype: Encoding,
|
@@ -163,7 +163,7 @@ module RDF
|
|
163
163
|
datatype: TrueClass,
|
164
164
|
control: :checkbox,
|
165
165
|
on: ["--rdfstar"],
|
166
|
-
description: "Parse RDF
|
166
|
+
description: "Parse RDF-star for preliminary RDF 1.2 support."),
|
167
167
|
RDF::CLI::Option.new(
|
168
168
|
symbol: :validate,
|
169
169
|
datatype: TrueClass,
|
@@ -271,13 +271,13 @@ module RDF
|
|
271
271
|
# the base URI to use when resolving relative URIs (not supported by
|
272
272
|
# all readers)
|
273
273
|
# @param [Boolean] canonicalize (false)
|
274
|
-
# whether to canonicalize parsed
|
274
|
+
# whether to canonicalize parsed URIs and Literals.
|
275
275
|
# @param [Encoding] encoding (Encoding::UTF_8)
|
276
276
|
# the encoding of the input stream
|
277
277
|
# @param [Boolean] intern (true)
|
278
278
|
# whether to intern all parsed URIs
|
279
279
|
# @param [Boolean] rdfstar (false)
|
280
|
-
# support
|
280
|
+
# Preliminary support for RDF 1.2.
|
281
281
|
# @param [Hash] prefixes (Hash.new)
|
282
282
|
# the prefix mappings to use (not supported by all readers)
|
283
283
|
# @param [Hash{Symbol => Object}] options
|
@@ -608,7 +608,9 @@ module RDF
|
|
608
608
|
end
|
609
609
|
|
610
610
|
##
|
611
|
-
# Returns `true` if parsed values should be
|
611
|
+
# Returns `true` if parsed values should be in canonical form.
|
612
|
+
#
|
613
|
+
# @note This is for term canonicalization, for graph/dataset canonicalization use `RDF::Normalize`.
|
612
614
|
#
|
613
615
|
# @return [Boolean] `true` or `false`
|
614
616
|
# @since 0.3.0
|
data/lib/rdf/repository.rb
CHANGED
@@ -182,7 +182,8 @@ module RDF
|
|
182
182
|
when :validity then @options.fetch(:with_validity, true)
|
183
183
|
when :literal_equality then true
|
184
184
|
when :atomic_write then false
|
185
|
-
when :
|
185
|
+
when :quoted_triples then false
|
186
|
+
when :base_direction then false
|
186
187
|
when :snapshots then false
|
187
188
|
else false
|
188
189
|
end
|
@@ -269,7 +270,8 @@ module RDF
|
|
269
270
|
when :validity then @options.fetch(:with_validity, true)
|
270
271
|
when :literal_equality then true
|
271
272
|
when :atomic_write then true
|
272
|
-
when :
|
273
|
+
when :quoted_triples then true
|
274
|
+
when :base_direction then true
|
273
275
|
when :snapshots then true
|
274
276
|
else false
|
275
277
|
end
|
data/lib/rdf/util/cache.rb
CHANGED
@@ -110,7 +110,7 @@ module RDF; module Util
|
|
110
110
|
|
111
111
|
##
|
112
112
|
# This implementation uses the `WeakRef` class from Ruby's standard
|
113
|
-
# library, and provides adequate performance on JRuby and on Ruby
|
113
|
+
# library, and provides adequate performance on JRuby and on Ruby 3.x.
|
114
114
|
#
|
115
115
|
# @see http://ruby-doc.org/stdlib-2.2.0/libdoc/weakref/rdoc/WeakRef.html
|
116
116
|
class WeakRefCache < Cache
|
@@ -127,7 +127,7 @@ module RDF; module Util
|
|
127
127
|
def [](key)
|
128
128
|
if (ref = @cache[key])
|
129
129
|
if ref.weakref_alive?
|
130
|
-
|
130
|
+
ref.__getobj__ rescue nil
|
131
131
|
else
|
132
132
|
@cache.delete(key)
|
133
133
|
nil
|
data/lib/rdf/util/uuid.rb
CHANGED
@@ -22,11 +22,11 @@ module RDF; module Util
|
|
22
22
|
begin
|
23
23
|
require 'uuid'
|
24
24
|
::UUID.generate(format)
|
25
|
-
rescue LoadError
|
25
|
+
rescue LoadError
|
26
26
|
begin
|
27
27
|
require 'uuidtools'
|
28
28
|
::UUIDTools::UUID.random_create.hexdigest
|
29
|
-
rescue LoadError
|
29
|
+
rescue LoadError
|
30
30
|
raise LoadError.new("no such file to load -- uuid or uuidtools")
|
31
31
|
end
|
32
32
|
end
|
data/lib/rdf/vocab/rdfv.rb
CHANGED
@@ -92,6 +92,10 @@ module RDF
|
|
92
92
|
# # @return [RDF::Vocabulary::Term]
|
93
93
|
# # @attr_reader :langString
|
94
94
|
#
|
95
|
+
# # The datatype of directional language-tagged string values.
|
96
|
+
# # @return [RDF::Vocabulary::Term]
|
97
|
+
# # @attr_reader :dirLangString
|
98
|
+
#
|
95
99
|
# # RDF/XML node element.
|
96
100
|
# # @return [RDF::Vocabulary::Term]
|
97
101
|
# # @attr_reader :Description
|
@@ -283,6 +287,13 @@ module RDF
|
|
283
287
|
"http://www.w3.org/2000/01/rdf-schema#seeAlso": %(http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal).freeze,
|
284
288
|
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Literal".freeze,
|
285
289
|
type: "http://www.w3.org/2000/01/rdf-schema#Datatype".freeze
|
290
|
+
term :dirLangString,
|
291
|
+
comment: %(The datatype of directional language-tagged string values).freeze,
|
292
|
+
label: "dirLangString".freeze,
|
293
|
+
isDefinedBy: %(http://www.w3.org/1999/02/22-rdf-syntax-ns#).freeze,
|
294
|
+
"http://www.w3.org/2000/01/rdf-schema#seeAlso": %(http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal).freeze,
|
295
|
+
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Literal".freeze,
|
296
|
+
type: "http://www.w3.org/2000/01/rdf-schema#Datatype".freeze
|
286
297
|
|
287
298
|
# Extra definitions
|
288
299
|
term :Description,
|
data/lib/rdf/writer.rb
CHANGED
@@ -392,7 +392,9 @@ module RDF
|
|
392
392
|
end
|
393
393
|
|
394
394
|
##
|
395
|
-
# Returns `true` if terms should be
|
395
|
+
# Returns `true` if terms should be in canonical form.
|
396
|
+
#
|
397
|
+
# @note This is for term canonicalization, for graph/dataset canonicalization use `RDF::Normalize`.
|
396
398
|
#
|
397
399
|
# @return [Boolean] `true` or `false`
|
398
400
|
# @since 1.0.8
|