bct (owner)

Revisions

gist: 20877 Download_button fork
public
Description:
sparqling soprano via dbus and ruby
Public Clone URL: git://gist.github.com/20877.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
=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