rdf-normalize 0.5.0 → 0.5.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
  SHA256:
3
- metadata.gz: 60932e4daabb349e76fb838c46aeea30ea39ff2406d7fd2f08b4df20b22975e4
4
- data.tar.gz: d1f1b87ac1a46ad18c7a1e848c8e7306b20cedbdb374cc1a197f8a2235875b27
3
+ metadata.gz: 75218bd6e68ada2e64c27fb691f0ff8b92cfd8b9fe9747f02d862bcbcdd8a5dd
4
+ data.tar.gz: fbe6c3579b66435b0b2620178a3ebf46e1bd56f17180a7a64f081aab65a3c447
5
5
  SHA512:
6
- metadata.gz: 263602b7c6861bf74745600e5828f5095cb9a3a3f08974621d050982a78bc6d4d6e1c6e421cc69e5bc9fa0146cfd0521b0f4817989b8644b4d25fa02c13015dd
7
- data.tar.gz: 98a1391dd232a2db5ea8353a51268fcfe9def16dc7a8f309bb305c7feeb9df85f8e96c8cc5dbcf4b3486e34d0133b33bdb353d2aa567bb948d412bb36be5e202
6
+ metadata.gz: 1363fb834466a6a643245a12776ab6c49cff62436af19ecd5d6dfe58feb83b49971868838dc1d9f687a997ee93af2b12b98a51eedc2f6846e1e0e74810eb4285
7
+ data.tar.gz: 62fb2457433083c9b4181353bfa0ec8740a871f3f58b6ac83233a0dd6385b3556a7540c62b1041bab5ba2aee17a55234c70a323fedfc41db09912bf7d3675215
data/README.md CHANGED
@@ -7,7 +7,7 @@ RDF Graph normalizer for [RDF.rb][RDF.rb].
7
7
  [![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
8
8
 
9
9
  ## Description
10
- This is a [Ruby][] implementation of a [RDF Normalize][] for [RDF.rb][].
10
+ This is a [Ruby][] implementation of a [RDF Dataset Canonicalization][] for [RDF.rb][].
11
11
 
12
12
  ## Features
13
13
  RDF::Normalize generates normalized [N-Quads][] output for an RDF Dataset using the algorithm
@@ -16,8 +16,8 @@ to serialize normalized statements.
16
16
 
17
17
  Algorithms implemented:
18
18
 
19
- * [URGNA2012](https://json-ld.github.io/normalization/spec/index.html#dfn-urgna2012)
20
- * [URDNA2015](https://json-ld.github.io/normalization/spec/index.html#dfn-urdna2015)
19
+ * [URGNA2012](https://www.w3.org/TR/rdf-canon/#dfn-urgna2012)
20
+ * [URDNA2015](https://www.w3.org/TR/rdf-canon/#dfn-urdna2015)
21
21
 
22
22
  Install with `gem install rdf-normalize`
23
23
 
@@ -27,7 +27,17 @@ Install with `gem install rdf-normalize`
27
27
  ## Usage
28
28
 
29
29
  ## Documentation
30
- Full documentation available on [Rubydoc.info][Normalize doc]
30
+
31
+ Full documentation available on [GitHub][Normalize doc]
32
+
33
+ ## Examples
34
+
35
+ ### Returning normalized N-Quads
36
+
37
+ require 'rdf/normalize'
38
+ require 'rdf/turtle'
39
+ g = RDF::Graph.load("etc/doap.ttl")
40
+ puts g.dump(:normalize)
31
41
 
32
42
  ### Principle Classes
33
43
  * {RDF::Normalize}
@@ -37,7 +47,6 @@ Full documentation available on [Rubydoc.info][Normalize doc]
37
47
  * {RDF::Normalize::URGNA2012}
38
48
  * {RDF::Normalize::URDNA2015}
39
49
 
40
-
41
50
  ## Dependencies
42
51
 
43
52
  * [Ruby](https://ruby-lang.org/) (>= 2.6)
@@ -80,7 +89,7 @@ see <https://unlicense.org/> or the accompanying {file:LICENSE} file.
80
89
  [YARD]: https://yardoc.org/
81
90
  [YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
82
91
  [PDD]: https://unlicense.org/#unlicensing-contributions
83
- [RDF.rb]: https://rubydoc.info/github/ruby-rdf/rdf-normalize
92
+ [RDF.rb]: https://ruby-rdf.github.io/rdf-normalize
84
93
  [N-Triples]: https://www.w3.org/TR/rdf-testcases/#ntriples
85
- [RDF Normalize]:https://json-ld.github.io/normalization/spec/
86
- [Normalize doc]:https://rubydoc.info/github/ruby-rdf/rdf-normalize/master
94
+ [RDF Dataset Canonicalization]: https://www.w3.org/TR/rdf-canon/
95
+ [Normalize doc]: https://ruby-rdf.github.io/rdf-normalize/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -27,30 +27,23 @@ module RDF::Normalize
27
27
  end
28
28
  end
29
29
 
30
- non_normalized_identifiers, simple = ns.bnode_to_statements.keys, true
30
+ ns.hash_to_bnodes = {}
31
31
 
32
- while simple
33
- simple = false
34
- ns.hash_to_bnodes = {}
35
-
36
- # Calculate hashes for first degree nodes
37
- non_normalized_identifiers.each do |node|
38
- hash = log_depth {ns.hash_first_degree_quads(node)}
39
- log_debug("1deg") {"hash: #{hash}"}
40
- ns.add_bnode_hash(node, hash)
41
- end
32
+ # Calculate hashes for first degree nodes
33
+ ns.bnode_to_statements.each_key do |node|
34
+ hash = log_depth {ns.hash_first_degree_quads(node)}
35
+ log_debug("1deg") {"hash: #{hash}"}
36
+ ns.add_bnode_hash(node, hash)
37
+ end
42
38
 
43
- # Create canonical replacements for hashes mapping to a single node
44
- ns.hash_to_bnodes.keys.sort.each do |hash|
45
- identifier_list = ns.hash_to_bnodes[hash]
46
- next if identifier_list.length > 1
47
- node = identifier_list.first
48
- id = ns.canonical_issuer.issue_identifier(node)
49
- log_debug("single node") {"node: #{node.to_ntriples}, hash: #{hash}, id: #{id}"}
50
- non_normalized_identifiers -= identifier_list
51
- ns.hash_to_bnodes.delete(hash)
52
- simple = true
53
- end
39
+ # Create canonical replacements for hashes mapping to a single node
40
+ ns.hash_to_bnodes.keys.sort.each do |hash|
41
+ identifier_list = ns.hash_to_bnodes[hash]
42
+ next if identifier_list.length > 1
43
+ node = identifier_list.first
44
+ id = ns.canonical_issuer.issue_identifier(node)
45
+ log_debug("single node") {"node: #{node.to_ntriples}, hash: #{hash}, id: #{id}"}
46
+ ns.hash_to_bnodes.delete(hash)
54
47
  end
55
48
 
56
49
  # Iterate over hashs having more than one node
@@ -107,12 +100,13 @@ module RDF::Normalize
107
100
 
108
101
  def add_statement(node, statement)
109
102
  bnode_to_statements[node] ||= []
110
- bnode_to_statements[node] << statement unless bnode_to_statements[node].include?(statement)
103
+ bnode_to_statements[node] << statement unless bnode_to_statements[node].any? {|st| st.eql?(statement)}
111
104
  end
112
105
 
113
106
  def add_bnode_hash(node, hash)
114
107
  hash_to_bnodes[hash] ||= []
115
- hash_to_bnodes[hash] << node unless hash_to_bnodes[hash].include?(node)
108
+ # Match on object IDs of nodes, rather than simple node equality
109
+ hash_to_bnodes[hash] << node unless hash_to_bnodes[hash].any? {|n| n.eql?(node)}
116
110
  end
117
111
 
118
112
  # @param [RDF::Node] node
@@ -143,7 +137,7 @@ module RDF::Normalize
143
137
  identifier = canonical_issuer.identifier(related) ||
144
138
  issuer.identifier(related) ||
145
139
  hash_first_degree_quads(related)
146
- input = position.to_s
140
+ input = "#{position}"
147
141
  input << statement.predicate.to_ntriples unless position == :g
148
142
  input << identifier
149
143
  log_debug("hrel") {"input: #{input.inspect}, hash: #{hexdigest(input)}"}
@@ -225,7 +219,7 @@ module RDF::Normalize
225
219
 
226
220
  hash = log_depth {hash_related_node(term, statement, issuer, pos)}
227
221
  map[hash] ||= []
228
- map[hash] << term unless map[hash].include?(term)
222
+ map[hash] << term unless map[hash].any? {|n| n.eql?(term)}
229
223
  end
230
224
  end
231
225
  end
@@ -23,9 +23,7 @@ module RDF::Normalize
23
23
  identifier = canonical_issuer.identifier(related) ||
24
24
  issuer.identifier(related) ||
25
25
  hash_first_degree_quads(related)
26
- input = position.to_s
27
- input << statement.predicate.to_s
28
- input << identifier
26
+ input = "#{position}#{statement.predicate}#{identifier}"
29
27
  log_debug("hrel") {"input: #{input.inspect}, hash: #{hexdigest(input)}"}
30
28
  hexdigest(input)
31
29
  end
@@ -35,11 +33,11 @@ module RDF::Normalize
35
33
  if statement.subject.node? && statement.subject != identifier
36
34
  hash = log_depth {hash_related_node(statement.subject, statement, issuer, :p)}
37
35
  map[hash] ||= []
38
- map[hash] << statement.subject unless map[hash].include?(statement.subject)
36
+ map[hash] << statement.subject unless map[hash].any? {|n| n.eql?(statement.subject)}
39
37
  elsif statement.object.node? && statement.object != identifier
40
38
  hash = log_depth {hash_related_node(statement.object, statement, issuer, :r)}
41
39
  map[hash] ||= []
42
- map[hash] << statement.object unless map[hash].include?(statement.object)
40
+ map[hash] << statement.object unless map[hash].any? {|n| n.eql?(statement.object)}
43
41
  end
44
42
  end
45
43
  end
@@ -1,5 +1,5 @@
1
1
  module RDF::Normalize::VERSION
2
- VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "VERSION")
2
+ VERSION_FILE = File.expand_path("../../../../VERSION", __FILE__)
3
3
  MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chop.split(".")
4
4
 
5
5
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
@@ -4,7 +4,7 @@ module RDF::Normalize
4
4
  #
5
5
  # Normalizes the enumerated statements into normal form in the form of N-Quads.
6
6
  #
7
- # @author [Gregg Kellogg](http://greggkellogg.net/)
7
+ # @author [Gregg Kellogg](https://greggkellogg.net/)
8
8
  class Writer < RDF::NQuads::Writer
9
9
  format RDF::Normalize::Format
10
10
 
data/lib/rdf/normalize.rb CHANGED
@@ -25,7 +25,7 @@ module RDF
25
25
  # writer << RDF::Repository.load("etc/doap.ttl")
26
26
  # end
27
27
  #
28
- # @author [Gregg Kellogg](http://greggkellogg.net/)
28
+ # @author [Gregg Kellogg](https://greggkellogg.net/)
29
29
  module Normalize
30
30
  require 'rdf/normalize/format'
31
31
  autoload :Base, 'rdf/normalize/base'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-normalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-07 00:00:00.000000000 Z
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.10'
55
- - !ruby/object:Gem::Dependency
56
- name: webmock
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.11'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.11'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: json-ld
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +80,7 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0.9'
97
- description: RDF::Normalize is a Graph normalizer for the RDF.rb library suite.
83
+ description: RDF::Normalize performs Dataset Canonicalization for RDF.rb.
98
84
  email: public-rdf-ruby@w3.org
99
85
  executables: []
100
86
  extensions: []
@@ -115,7 +101,12 @@ files:
115
101
  homepage: https://github.com/ruby-rdf/rdf-normalize
116
102
  licenses:
117
103
  - Unlicense
118
- metadata: {}
104
+ metadata:
105
+ documentation_uri: https://ruby-rdf.github.io/rdf-normalize
106
+ bug_tracker_uri: https://github.com/ruby-rdf/rdf-normalize/issues
107
+ homepage_uri: https://github.com/ruby-rdf/rdf-normalize
108
+ mailing_list_uri: https://lists.w3.org/Archives/Public/public-rdf-ruby/
109
+ source_code_uri: https://github.com/ruby-rdf/rdf-normalize
119
110
  post_install_message:
120
111
  rdoc_options: []
121
112
  require_paths:
@@ -131,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
122
  - !ruby/object:Gem::Version
132
123
  version: '0'
133
124
  requirements: []
134
- rubygems_version: 3.3.3
125
+ rubygems_version: 3.3.7
135
126
  signing_key:
136
127
  specification_version: 4
137
128
  summary: RDF Graph normalizer for Ruby.