Parsing RDF coming from a URL


#1

Hello,

i’m writing an application that needs geocoding information for
locations
outside of the US.
I’m using the brainoff.com geocoding service

mappoint = Net::HTTP.new(‘brainoff.com’, 80)
response = mappoint.get(’/geocoder/rest/?city=Gent,BE’)
logger.debug response.body

and the body of the response is in the following form :

<rdf:RDF xmlns:geo=“http://www.w3.org/2003/01/geo/wgs84_pos#
xmlns:rdf="
http://www.w3.org/1999/02/22-rdf-syntax-ns#">
geo:Point
geo:long3.7166667</geo:long>
geo:lat51.05</geo:lat>
</geo:Point>
</rdf:RDF>

Now my question is : how do i parse this RDF to get to the long and lat
values ?
Is there a library available or am i on my own to get to the long and
lat
values ?

thanks for your help

Werner

ir. Werner Ramaekers

Read my Blog at http://www.werner.be
“May the source be with you.”


#2

Technically that’s RDF/XML, and you should be able to parse it with any
of
Ruby’s XML libraries - REXML, XMLParser, libxml, etc. REXML is part of
the
standard Ruby distribution.


#3

You could also take a look at Ruby integration with Redland if you want
to
do any Sparql related stuff with your RDF:
http://librdf.org/docs/ruby.html

Here is a good article if you are new to Sparql/Semantic Web with RDF as
the
underpinnings:
http://www.xml.com/pub/a/2005/11/16/introducing-sparql-querying-semantic-web-tutorial.html


#4

There is also Rena[1] and Semitar[2]

[1] http://raa.ruby-lang.org/project/rena/
[2] http://semitar.projects.semwebcentral.org/

I don’t recommend using just an XML parser for ingesting RDF. That’s
sorta like using regex to parse HTML. It’s really better to deal
with it as the graph model it is. Sure, it could be done solely with
an XML parser in this simplistic case, and maybe that is
pragmatically a fine way to go. I’ve often parsed HTML with regex
too :slight_smile:

Erik