class RoadForest::SourceRigor::GraphStore
Attributes
current_impulse[R]
debug_io[RW]
local_context_node[R]
repository[R]
Public Class Methods
new(repo = nil) { |self| ... }
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 24 def initialize(repo = nil) @repository = repo || RDF::Repository.new @local_context_node = RDF::Node.new(:local) @debug_io = nil force_impulse yield self if block_given? end
Public Instance Methods
add_statement(*args)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 104 def add_statement(*args) case args.length when 1 subject, predicate, object, context = *args.first when 2 triple, context = *args subject, predicate, object = *triple when 3 subject, predicate, object = *args context = nil when 4 subject, predicate, object, context = *args else raise ArgumentError, "insert_statement needs some variation of subject, predicate, object, [context]" end context ||= local_context_node record_statement(normalize_statement(subject, predicate, object, context)) end
context_variable()
click to toggle source
XXX Needed, maybe, if we need to handle constant patterns def include?(statement) end
# File lib/roadforest/source-rigor/graph-store.rb, line 177 def context_variable @context_variable ||= RDF::Query::Variable.new(:context) end
create_list(values = nil)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 77 def create_list(values = nil) named_list(local_context_node, values) end
debug(message)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 54 def debug(message) io = @debug_io || RoadForest.debug_io return if io.nil? io.puts(message) end
delete_statement(statement)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 132 def delete_statement(statement) repository.query(statement) do |statement| next if statement.context.nil? repository.delete(statement) end end
delete_statements(pattern)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 65 def delete_statements(pattern) repository.delete(pattern) end
durable?()
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 158 def durable? @repository.durable? end
each(&block)
click to toggle source
XXX Credence? Default context?
# File lib/roadforest/source-rigor/graph-store.rb, line 163 def each(&block) if @repository.respond_to?(:query) @repository.query(:context => false, &block) elsif @repository.respond_to?(:each) @repository.each(&block) else @repository.to_a.each(&block) end end
each_statement(context=nil) { |statement| ... }
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 146 def each_statement(context=nil, &block) query = {} unless context.nil? query[:context] = context end @repository.query(query) do |statement| next if statement.context.nil? yield statement end end
force_impulse()
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 32 def force_impulse @current_impulse = RDF::Node.new repository.insert(normalize_statement(@current_impulse, [:rdf, 'type'], [:rf, 'Impulse'], nil)) repository.insert(normalize_statement(@current_impulse, [:rf, 'begunAt'], Time.now, nil)) end
insert_document(document)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 81 def insert_document(document) #puts; puts "#{__FILE__}:#{__LINE__} => #{(document).inspect}" #puts document.body_string reader = RDF::Reader.for(:content_type => document.content_type) do sample = document.body.read(1000) document.body.rewind sample end.new(document.body, :base_uri => document.root_url) #consider :processor_graph insert_reader(document.source, reader) end
insert_reader(context, reader)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 92 def insert_reader(context, reader) #puts; puts "#{__FILE__}:#{__LINE__} => #{(context).inspect}" context = normalize_context(context) delete_statements(:context => context) reader.each_statement do |statement| statement.context = context record_statement(statement) end #puts; puts "#{__FILE__}:#{__LINE__} => \n#{(graph_dump(:nquads))}" end
Also aliased as: insert_graph
insert_statement(statement)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 124 def insert_statement(statement) repository.insert(statement) repository.delete([statement.context, expand_curie([:rf, "impulse"]), nil]) repository.insert(normalize_statement(statement.context, [:rf, "impulse"], current_impulse, nil)) end
Also aliased as: record_statement
named_graph(context)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 69 def named_graph(context) ::RDF::Graph.new(context, :data => repository) end
named_list(context, values = nil)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 73 def named_list(context, values = nil) ::RDF::List.new(nil, named_graph(context), values) end
next_impulse()
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 38 def next_impulse return if quiet_impulse? force_impulse #mark ended? #chain impulses? end
query_execute(query, &block)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 181 def query_execute(query, &block) #XXX Weird edge case of GM getting queried with a vanilla RDF::Query... #needs tests, thought query = RoadForest::SourceRigor::ResourceQuery.from(query) query.execute(self).filter do |solution| solution.respond_to?(:context) and not solution.context.nil? end.each(&block) end
query_pattern(pattern) { |statement| ... }
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 190 def query_pattern(pattern, &block) case pattern when RoadForest::SourceRigor::ResourcePattern pattern.execute(@repository, {}, :context_roles => {:local => local_context_node}) do |statement| next if statement.context.nil? yield statement if block_given? end else pattern.execute(@repository, {}) do |statement| next if statement.context.nil? yield statement if block_given? end end end
quiet_impulse?()
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 45 def quiet_impulse? repository.query([nil, nil, @current_impulse, false]).to_a.empty? end
Also aliased as: raw_quiet_impulse?
reader_for(content_type, repository)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 50 def reader_for(content_type, repository) RDF::Reader.for(content_type) end
replace(original, statement)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 139 def replace(original, statement) unless original == statement repository.delete(original) repository.insert(statement) end end
repository_dump(format = :turtle)
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 60 def repository_dump(format = :turtle) repository.dump(format) end
Also aliased as: graph_dump
unnamed_graph()
click to toggle source
# File lib/roadforest/source-rigor/graph-store.rb, line 205 def unnamed_graph ::RDF::Graph.new(nil, :data => @repository) end