|
require 'rdf' |
|
require 'rdf/do' |
|
require 'rdf/turtle' |
|
require 'do_sqlite3' |
|
require 'sparql' |
|
require 'benchmark' |
|
|
|
sqlite_repo = RDF::DataObjects::Repository.new 'sqlite3::memory:' |
|
mem_graph = RDF::Graph.new |
|
|
|
sse = SPARQL.parse %q{ |
|
SELECT ?time |
|
WHERE { |
|
?obs1 a <http://example.com/sometype> . |
|
?obs2 a <http://example.com/sometype> . |
|
?obs1 <http://example.com/end> ?time . |
|
?obs2 <http://example.com/start> ?time . |
|
?obs1 <http://example.com/someprop> ?fromProp . |
|
?obs2 <http://example.com/someprop> ?toProp . |
|
?obs2 <http://example.com/someprop> "interesting" . |
|
FILTER ( ?fromProp != ?toProp ) |
|
} |
|
} |
|
|
|
## |
|
#repo << RDF::Turtle::Reader.new(<<-TURTLE) |
|
#PREFIX ex: <http://example.com/> |
|
# |
|
# _:b1 a ex:sometype . |
|
# _:b1 ex:start 0 . |
|
# _:b1 ex:end 10 . |
|
# _:b1 ex:someprop "boring" |
|
# _:b2 a ex:sometype . |
|
# _:b2 ex:start 10 . |
|
# _:b2 ex:end 20 . |
|
# _:b3 ex:someprop "interesting" |
|
# _:b3 a ex:sometype . |
|
# _:b3 ex:start 20 . |
|
# _:b3 ex:end 30 . |
|
# _:b4 ex:someprop "boring" |
|
# _:b4 a ex:sometype . |
|
# _:b4 ex:start 30 . |
|
# _:b4 ex:end 40 . |
|
# |
|
def populate_with_statements(desired_subjects, repo) |
|
ex = RDF::Vocabulary.new('http://example.com/') |
|
(1..desired_subjects).each do |i| |
|
subject = ex["observation#{i}"] |
|
|
|
repo << RDF::Statement.new(subject, RDF::type, ex.sometype) |
|
repo << RDF::Statement.new(subject, ex.start, RDF::Literal.new(i * 10)) |
|
repo << RDF::Statement.new(subject, ex.end, RDF::Literal.new((i * 10)+10)) |
|
repo << RDF::Statement.new(subject, ex.someprop, RDF::Literal.new(i % 3 == 0 ? 'interesting' : 'boring')) |
|
end |
|
end |
|
|
|
|
|
puts "" |
|
puts "RDF::Graph query times" |
|
puts "" |
|
puts "subjects statements time " |
|
puts "----------------------------------------" |
|
[5, 8, 10, 12, 15, 30, 60, 100, 200, 300, 400, 500, 600, 700, 800, 1600].each do |number_of_subjects| |
|
populate_with_statements(number_of_subjects, mem_graph) |
|
printf "%10d %10d ", number_of_subjects, mem_graph.count |
|
time = Benchmark.realtime { sse.execute(mem_graph) } |
|
printf "%18.5f\n", time |
|
break if time > 30 |
|
end |
|
puts "========================================" |
|
puts "" |
|
|
|
# to see the SQL statements being executed: |
|
# ::DataObjects.logger.set_log(STDERR, :debug) |
|
puts "" |
|
puts "DO+SQLite query times" |
|
puts "" |
|
puts "subjects statements time " |
|
puts "----------------------------------------" |
|
[5, 8, 10, 12, 15, 30, 60, 100, 200, 300, 400, 500, 600, 700, 800, 1600].each do |number_of_subjects| |
|
populate_with_statements(number_of_subjects, sqlite_repo) |
|
printf "%10d %10d ", number_of_subjects, sqlite_repo.count |
|
time = Benchmark.realtime { sse.execute(sqlite_repo) } |
|
printf "%18.5f\n", time |
|
break if time > 30 |
|
end |
|
puts "========================================" |
|
puts "" |