Sha256: 5c28705bf8b7e2733ac247c1a822e6184baff854cde83ba7399c2f3102e9b462
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
module Grom class Reader attr_reader :data, :statements_by_subject, :subjects_by_type, :edges_by_subject, :objects def initialize(data) @data = data read_data @objects = Grom::Builder.new(self).objects end def read_data # Reset all our hashes just in case @statements_by_subject = {} # TODO: Find a better name for this hash! @edges_by_subject = {} RDF::NTriples::Reader.new(@data) do |reader| reader.each_statement do |statement| subject = statement.subject.to_s # TODO: Use Ruby key value syntax in below method. Grom::Helper.lazy_array_insert(@statements_by_subject, subject, statement) predicate = statement.predicate.to_s if (statement.object =~ URI.regexp) == 0 && predicate != RDF.type.to_s predicate = Grom::Helper.get_id(predicate) @edges_by_subject[subject] ||= {} @edges_by_subject[subject][predicate] ||= [] @edges_by_subject[subject][predicate] << statement.object.to_s end end end self end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
grom-0.3.5 | lib/grom/reader.rb |
grom-0.3.4 | lib/grom/reader.rb |
grom-0.3.2 | lib/grom/reader.rb |