Created
October 30, 2008 01:58
-
-
Save bct/20877 to your computer and use it in GitHub Desktop.
sparqling soprano via dbus and ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
nepomukserver --nofork | |
And then: | |
kcmshell4 kcm_nepouk | |
to set what files to scan. | |
If the environment variable DBUS_SESSION_BUS_ADDRESS is not set then you | |
need to put this in your .xinitrc: | |
eval `dbus-launch --sh-syntax --exit-with-session` | |
=end | |
require 'dbus' | |
class SopranoClient | |
def initialize | |
@bus = DBus::SessionBus.instance | |
proxy = @bus.introspect("org.kde.NepomukStorage", "/org/soprano/Server") | |
model_s = proxy["org.soprano.Server"].createModel("main")[0] | |
@model = @bus.introspect('org.kde.NepomukStorage', model_s) | |
end | |
def each_result(sparql) | |
xyz_s = @model['org.soprano.Model'].executeQuery(sparql, 'SPARQL')[0] | |
xyz = @bus.introspect('org.kde.NepomukStorage', xyz_s) | |
while xyz['org.soprano.QueryResultIterator'].next[0] | |
line = xyz['org.soprano.QueryResultIterator'].current[0][0] | |
yield line | |
end | |
end | |
end | |
sparql = <<END | |
PREFIX xes: <http://freedesktop.org/standards/xesam/1.0/core#> | |
SELECT ?type ?path ?name ?size | |
WHERE { | |
?x xes:mimeType ?type . | |
?x xes:url ?path . | |
?x xes:name ?name . | |
?x xes:size ?size . | |
FILTER ( regex(?type, 'image/') ) | |
} | |
END | |
cl = SopranoClient.new | |
cl.each_result(sparql) do |line| | |
type = line['type'][1] | |
path = line['path'][1] | |
name = line['name'][1] | |
size = line['size'][1] | |
puts [type, path, name, size].inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment