Skip to content

Examples how to use haanga in lodspeakr

alangrafu edited this page Sep 1, 2012 · 4 revisions

Obtaining basic personal data

Query: personalDetails.query

SELECT ?name ?desc ?pic WHERE {
  GRAPH <http://tw.rpi.edu:2020/books>{
     <{{uri}}> foaf:name ?name ;
     		   foaf:depiction ?pic ;
               dcterms:description ?desc.
  }
}LIMIT 1

Template

 <img style='float:right;width:200px' src='{{first.personalDetails.pic.mirroredUri}}'/>
 <h1>{{first.personalDetails.name.value}}</h1>
 <p>{{first.personalDetails.desc.value}}</p>

People with whom a person attended to meetings

Query: attendees.query

SELECT DISTINCT ?attendee ?attendeeName  WHERE {
  GRAPH <http://tw.rpi.edu:2020/books>{
    ?event twc:hasAttendee <{{uri}}> .
    ?event twc:hasAttendee ?attendee .    
    OPTIONAL{ 
      ?attendee foaf:name ?attendeeName .
    }
    FILTER(str(?attendee) != "{{uri}}")
  }
}

Template

    <ul>
    {% for row in models.attendees %}
      <li><a href="{{row.attendee.value}}">{%if row.attendeeName.value%}{{row.attendeeName.value}}{%else%}{{row.attendee.curie}}{%endif%}</a></li>
    {%endfor%}
    </ul>

Using previously fetched results to feed new queries

Query 1: birthplace.query

SELECT distinct ?bplace  WHERE {
  GRAPH <http://tw.rpi.edu:2020/books>{
  	<{{uri}}> dbp:birthPlace ?bplace
  }
}

Query 2 location.query

SELECT distinct ?name ?abstract  WHERE {
<{{first.birthplace.bplace.value}}> dbp:abstract ?abstract;
rdfs:label ?name .
FILTER(lang(?abstract) = "en")
}limit 1

Template

<h3>Born in: {{first.dbpedia.location.name.value}}</h3>
<p style="float:left">{{first.dbpedia.location.abstract.value}}</p>

Using filters, like GoogleMaps

Query: endpoint.dbpedia/geo.query

SELECT distinct ?lat ?lon ?name WHERE {
<{{first.birthplace.bplace.value}}> rdfs:label ?name ;
				    geo:lat  ?lat;
                                    geo:long ?lon.
}limit 1

Template

<div>
  {{models.dbpedia.geo|googlemaps:"lat,lon,name"}}
</div>
Clone this wiki locally