class PubliSci::Store
handles connection and messaging to/from the triple store
Public Class Methods
new(options={})
click to toggle source
# File lib/publisci/store.rb, line 39 def initialize(options={}) @options = defaults.merge(options) end
Public Instance Methods
add(file,graph)
click to toggle source
# File lib/publisci/store.rb, line 14 def add(file,graph) if @options[:type] == :graph throw "please provide an RDF::Repository" unless graph.is_a? RDF::Repository graph.load(file) @store = graph @store elsif @options[:type] == :fourstore if @options[:replace] `curl -T #{file} -H 'Content-Type: application/x-turtle' #{@options[:url]}/data/http%3A%2F%2Frqtl.org%2F#{graph}` else `curl --data-urlencode data@#{file} -d 'graph=http%3A%2F%2Frqtl.org%2F#{graph}' -d 'mime-type=application/x-turtle' #{@options[:url]}/data/` end end end
add_all(dir, graph, pattern=nil)
click to toggle source
# File lib/publisci/store.rb, line 29 def add_all(dir, graph, pattern=nil) pattern = /.+\.ttl/ if pattern == :turtle || pattern == :ttl files = Dir.entries(dir) - %w(. ..) files = files.grep(pattern) if pattern.is_a? Regexp nfiles = files.size n = 0 files.each{|file| puts file + " #{n+=1}/#{nfiles} files"; puts add(file,graph)} end
defaults()
click to toggle source
# File lib/publisci/store.rb, line 6 def defaults { type: :fourstore, url: "http://localhost:8080", #TODO port etc should eventually be extracted from URI if given replace: false } end
query(string)
click to toggle source
# File lib/publisci/store.rb, line 43 def query(string) # execute(string, ) if @options[:type] == :graph execute(string, @store, :graph) elsif @options[:type] == :fourstore execute(string, @options[:url], :fourstore) end end
url()
click to toggle source
# File lib/publisci/store.rb, line 52 def url @options[:url] end