GRDDL Guitar->Hotel Primer

I have worked abit on the Guitar Buying Primer to convert it to a
Hotel finding Primer. I have switched Steven to Jane, so it follows
nicely from the first primer. It is not ready to be published, there
are a few new outstanding issues now that we have switched.
Previously, when Steven wanted a guitar, all he needed was a Filter on
Rating. Now with Hotels, we need to filter on Rating AND location.
This is not difficult, but it requires abit more SPAQRL to extract a
location from the hCard in the hReview. The sample data has the
hReviews with hCard, so there is no need to manufacture more data, but
the XSLT that converts the HTML to RDF needs to be updated to extract
both Review data and associated vCard data.

This is the reviewed Text, if anyone is interested in reading through
the changes. (the SPAQRL is NOT correct - it is just a placeholder). I
have added another example and paragraph about the XFN->FoaF,
hopefully this clears up some of the confusions/worries.

Once i sort out the XSLT and the SPAQRL, and clean-up any suggestions
about the primer, i can commit the changes.

-brian

===========

Finding a Hotel

This section is not worked out in as much detail as the sections
above. In particular, the relationship between XFN and FOAF is still
under study. Stay tuned for future drafts, or better yet, send us
suggested improvements.

Jane is a Frequent traveller and needs to find a hotel in (Edinburgh)
when she is there for her next conference. She decides to check
reviews. There are various special interest publications online which
feature hotel and restaurant reviews and there are blogs which contain
reviews by individuals. Among the reviewers there may be friends and
collegues of Jane and people whose opinion Jane values (e.g. other
conference attendees and people whose reviews Jane has found useful in
the past). There may also be reviews planted by hotels which offer
very biased views.

First, Jane needs to get a list of people she considers trusted
sources into some sort of machine readable document. One choice would
be FoaF (Friend of a Friend), a popular RDF vocabulary for describing
social networks of friends and personal data. Other choices include
vCard/RDF. The question is how to get these values? Microformats
define simple formats which can easily convert between HTML and RDF
through the use of GRDDL. To extract vCard/RDF from HTML she uses an
XSLT stylesheet to transform the hCard encoded HTML document.

<address class="vcard" id="smith-jane">
<a href="http://example.org/jsmith" class="fn url">Jane Smith</a>
</address>

This snippet of HTML is converted into RDF with the use of the XSLT:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
  xmlns:rdf  ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#">

 <rdf:Description rdf:about="http://example.org/jsmith">
  <vCard:FN>Jane Smith</vCard:FN>
  <vCard:URL>http://example.org/jsmith</vCard:URL>
 </rdf:Description>
</rdf:RDF>

Another microformat that allows for more information to be gleaned
from the document is XFN. XFN is the XHTML Friends Network. XFN
outlines relationships between individuals using a controlled set of
values in the rel attributes of links. Examples of such relationships
are friends, colleagues, co-workers, etc.

<ul>
  <li><a href="http://peter.example.org/" rel="met friend
collegue">Peter Smith</a></li>
  <li><a href="http://john.example.org/" rel="met">John Doe</a></li>
  <li><a href="http://paul.example.org/" rel="met">Paul Revere</a></li>
</ul>

Since XFN relationships are embedded in anchor (a) elements, they can
be expressed in RDF in a variety of ways. Given a document with XFN
data, a GRDDL transformation can extract RDF data about his friends
from a document marked up with XFN. These descriptions would allow an
RDF spider (a scutter) to follow links to additional RDF content that
may include vCard and FOAF descriptions.

That XFN list could be converted to RDF with the use of another XSLT:

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF
  xmlns:rdf  ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:xfn  ="http://gmpg.org/xfn/11#"
  xmlns:foaf ="http://xmlns.com/foaf/0.1/"
  xmlns:h    ="http://www.w3.org/1999/xhtml"
>

<met namespace="http://gmpg.org/xfn/11#">
	<rdf:Description>
		<foaf:homepage rdf:resource="http://peter.example.org/"/>
	</rdf:Description>
</met>

<friend namespace="http://gmpg.org/xfn/11#">
	<rdf:Description>
		<foaf:homepage rdf:resource="http://peter.example.org/"/>
	</rdf:Description>
</friend>

<collegue namespace="http://gmpg.org/xfn/11#">
	<rdf:Description>
		<foaf:homepage rdf:resource="http://peter.example.org/"/>
	</rdf:Description>
</collegue>

<met namespace="http://gmpg.org/xfn/11#">
	<rdf:Description>
		<foaf:homepage rdf:resource="http://john.example.org/"/>
	</rdf:Description>
</met>

<met namespace="http://gmpg.org/xfn/11#">
	<rdf:Description>
		<foaf:homepage rdf:resource="http://paul.example.org/"/>
	</rdf:Description>
</met>

</rdf:RDF>

With all of these tools we can find Jane's friends and find the hotel
reviews that those friends created. Using GRDDL we can glean
information about the hotel in the form of product specifications
supplied by the manufacturer and reviews from site members. Once we
have this data as RDF we can run queries can be run on it using
SPARQL. SPARQL (The SPARQL Protocol and RDF Query Language) is a query
language for RDF.

If Jane was looking for a hotel with a specific review rating or
higher from a her group of trusted friends, we now have enough data in
RDF to do just that.

This SPAQRL query will return a list of reviewers names and ratings,
only if they rated the hotel with more than 2 out of 5 stars.

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rev: <http:/www.purl.org/stuff/rev#>

SELECT DISTINCT ?name ?rating

FROM <http://example.org/hotel/1234/>

WHERE {
  ?x rev:reviewer ?reviewer ;
     rev:rating ?rating .
  FILTER (?rating > "2") .
  ?reviewer foaf:name ?name .
}

The unfortunately get us all hotels with more than 2 stars, so we need
to further restrict the results to only hotels in (Edinburgh) [NEED to
double check my SPAQRL and RDF output!]

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rev: <http:/www.purl.org/stuff/rev#>
PREFIX vcard: <http:/www.w3.org/2006/vcard/ns#>

SELECT DISTINCT ?name ?rating ?region

FROM <http://example.org/hotel/1234/>

WHERE {
  ?x rev:reviewer ?reviewer ;
     rev:rating ?rating ;
 	 vcard:region ?region .
  FILTER (?rating > "2" and ?region = "Edinburgh") .
  ?reviewer foaf:name ?name .
}

Now the results will be hotels with a rating of 2 stars or higher that
are located in (Edinburgh). The problem with the possible list of
results is that there could be biased reviews. The next step is to
further restrict the results to only reviews by our trusted list of
contacts From the XFN links in Jane's page which identify people Jane
trusts, we can match URIs to other locations where they have been
asserted (the hotel review page for instance).

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rev: <http:/www.purl.org/stuff/rev#>
PREFIX xfn: <http://gmpg.org/xfn/11#>
PREFIX vcard: <http:/www.w3.org/2006/vcard/ns#>


SELECT DISTINCT ?name ?rating ?xfnhomepage ?foafhomepage

FROM <http://example.org/hotel/1234/>
FROM <http://example.org/jsmith/blogroll/xfn/>

WHERE {
  ?x rev:reviewer ?reviewer ;
     rev:rating ?rating .
 	 vcard:region ?region .
  FILTER (?rating > "2" and ?region = "Edinburgh") .

  ?reviewer foaf:name ?name ;
            foaf:homepage ?foafhomepage .

  ?y xfn:friend ?xperson .
  ?xperson foaf:homepage ?xfnhomepage .
  FILTER (?xfnhomepage = ?foafhomepage)
}

SPARQL results can be obtained as XML or JSON and can easily be
consumed by another application. This can display the results on
screen, email them to Jane or it can be pulled into another
application to search the web for the best prices on the short list of
hotels.

-- 
brian suda
http://suda.co.uk

Received on Saturday, 4 November 2006 16:50:17 UTC