Class: PubliSci::Store
- Inherits:
-
Object
show all
- Includes:
- Query
- Defined in:
- lib/publisci/store.rb
Overview
handles connection and messaging to/from the triple store
Instance Method Summary
collapse
Methods included from Query
#execute, #execute_from_file, #property_names, #property_values, #row_names, #vocabulary
Constructor Details
#initialize(options = {}) ⇒ Store
Returns a new instance of Store.
39
40
41
|
# File 'lib/publisci/store.rb', line 39
def initialize(options={})
@options = defaults.merge(options)
end
|
Instance Method Details
#add(file, graph) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# 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) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# 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 ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/publisci/store.rb', line 6
def defaults
{
type: :fourstore,
url: "http://localhost:8080", replace: false
}
end
|
#query(string) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/publisci/store.rb', line 43
def query(string)
if @options[:type] == :graph
execute(string, @store, :graph)
elsif @options[:type] == :fourstore
execute(string, @options[:url], :fourstore)
end
end
|
#url ⇒ Object
52
53
54
|
# File 'lib/publisci/store.rb', line 52
def url
@options[:url]
end
|