ruby co-depiction client / progress

Dan Brickley danbri at w...
Thu Jun 27 04:14:20 UTC 2002


Now the Ruby code is harvesting RDFWeb/FOAF data again, it's worth doing
things like this, as there's data to play with. The script below shows
a rough cut of Libby's Java 'who is depicted with ...' page,
http://swordfish.rdfweb.org/discovery/2001/08/codepict/codepict.jsp?mbox=mailto%3Alibby.miller%40bristol.ac.uk
...recoded in Ruby.

There's not much by way of error trapping, good HTML or UI design, but
basics should be obvious. The code below talks direct to the PostgreSQL
database using the query rewriter. One could put SOAP, XML, HTTP in the
middle, trading a little database-independence for some performance hit.

Idea is the Ruby code comes out of the box ready to index RDFWeb into a
store that can usefully answer queries such as those below. Since it is
now Debian-packaged (er, packageable) this potentially means 100s of
indexing nodes, each offering SOAP query services and/or HTML generate by
scripts such as this.

Which makes the next interesting problem that of characterising the rules
the harvester uses to traverse the Web, and making sure our RDF files
contain suitable hints and fwd pointers to help it...

Dan

---------- Forwarded message ----------
Date: Thu, 27 Jun 2002 04:25:32 GMT

#!/usr/bin/env ruby
#
# RDFWeb CoDepiction index generator
#
# Look up photos do-depicting some person, via their mailbox.
# Generate HTML.
# Assumes data has been drafragmented / smushed.
#
# danbri $Id$

require 'squish'
require 'dbi'

mbox='mailto:libby.miller at b...'
query=<<EOQ;

SELECT ?thumb, ?name, ?dd, ?mbox, ?uri,
WHERE (foaf::depiction ?x ?uri)
(foaf::depiction ?z ?uri)
(foaf::mbox ?x #{mbox})
(foaf::mbox ?z ?mbox)
(foaf::name ?z ?name)
(foaf::thumbnail ?uri ?thumb)
(dc::description ?uri ?dd)
USING
foaf for http://xmlns.com/foaf/0.1/
dc for http://purl.org/dc/elements/1.1/
EOQ


DBI_DRIVER = 'DBI:Pg:test1'
DBI_USER = 'danbri'
DBI_PASS=''

q = SquishQuery.new.parseFromText query

by_img={}
DBI.connect( DBI_DRIVER, DBI_USER, DBI_PASS) do | dbh |
dbh.select_all( q.toSQLQuery ) do | row |
if by_img[row['uri']] == nil
by_img[row['uri']] = []
end
by_img[row['uri']].push ResultRow.new(row.clone)
end
end

puts "<html><head><title>RDFWeb: Co-depiction directory</title</head>\n\n<body>\n"
puts "<h1>Codepictionary...</h1>\n\n"

by_img.each_value do |images|
i=images[0]
puts "<p>" + i.dd + "<a href=\"#{i.uri}\"><img src=\"#{i.thumb}\" /></a></p>\n\n"
images.each do |who|
puts "#{who.name} #{who.mbox} <br /> \n"
end
puts "\n\n"
end

puts "\n\n</body>\n</html>\n\n"




More information about the foaf-dev mailing list