Module: RoadForest::Graph::Etagging
- Included in:
- Interface::RDF
- Defined in:
- lib/roadforest/graph/etagging.rb
Instance Method Summary collapse
Instance Method Details
#blank_mapped(quads) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/roadforest/graph/etagging.rb', line 18 def blank_mapped(quads) sequence = 0 mapping = Hash.new do |h,k| h[k] = RDF::Node.new(sequence+=1) end quads.map do |quad| quad.map do |term| case term when RDF::Node mapping[term].to_s when nil nil else term.to_s end end end end |
#etag_from(graph) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/roadforest/graph/etagging.rb', line 5 def etag_from(graph) require 'openssl' quads = sorted_quads(graph) mapped = blank_mapped(quads) strings = mapped.map(&:inspect) ripe = OpenSSL::Digest::RIPEMD160.new mapped.each do |quad| ripe << quad.inspect end "W/\"#{ripe.base64digest}\"" end |
#sorted_quads(graph) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/roadforest/graph/etagging.rb', line 38 def sorted_quads(graph) graph.statements.map do |statement| [statement.subject, statement.predicate, statement.object, statement.context] end.sort_by do |quad| quad.map do |term| case term when RDF::Node nil else term end end.join("/") end end |