1. Creating web applications
with LODSPeaKr
Alvaro Graves
Tetherless World Constellation
Rensselaer Polytechnic Institute
gravea3@rpi.edu
@alvarograves
1
2. Agenda
• What is Linked Data?
• Why LODSPeaKr?
• Installation and setting up
• Building an app
• Features of LODSPeaKr
• Future work and Conclusions
2
4. What is Linked Data?
• Set of best practices (based on Semantic Web
technologies) to publish structured data on the Web
• Use of Web technologies (RDF, HTTP, URIs)
• Connect my data to other people’s data by links
4
5. What is Linked Data? (2)
• Use (HTTP) URIs to identify things
• When somebody lookup those URIs, provide useful
information
• HTML for humans
• RDF for machines
• Link to other relevant URIs so people can discover more
data
5
6. Why do we need a XXX
framework?
• Lack of tools for using Linked Data
• Exploring data
• Publishing data
• Create applications
• High quality data is available
• Lots of cases where computational complexity is low
• Data management complexity is high
6
10. Installation
(the easy way)
cd /var/www/myapp
bash < <(curl -s http://lodspeakr.org/install)
•Where is LODSPK located? (e.g., http://localhost/myapp/)
•What is the default namespace? (e.g., http://tw.rpi.edu/)
•Where is your endpoint? (http://logd.tw.rpi.edu/sparql)
10
11. Permissions
• Let apache write in
• cache/
• meta/
• meta/db.sqlite
chown -R www-data cache meta
11
12. Exploring data
• By default LODSPeaKr allow users to
• Find named graphs in sparql endpoint
• Classes available
• Instances available for each class
• All predicates from/to a URI
12
15. Content negotiation
Provides a mechanism for serving documents
according to what the client accepts
GET http://example.org/resource
HTTP Accept: application/rdf+xml
HTTP Status: 303 See Other
Location: http://example.org/resource.rdf Server
GET http://example.org/resource.rdf
HTTP Accept: application/rdf+xml
User
http://example.org/resource.rdf
Content-type: application/rdf+xml
17. Data: TWC People
• Information about
• People
• Meetings
• Publications
• Projects
• etc.
17
18. URI Mirroring
• http://theirdomain/data => http://mydomain/data
• Provides dereferenceable URIs in own domain
• Can reuse data structure in a different domain
• When serving RDF, LODSPeaKr provides
• Data in original form
• owl:sameAs and con:preferredUri that links
original and new URI
18
19. Modules in LODSPeaKr
StaticModule css, js files
URIModule matches particular URIs
Execution
order
TypeModule matches URIs of a certain type
ServiceModule creates new services
19
21. Model queries
LODSPeaKr uses sp.query
Haanga, a Django-style SELECT ?s ?p
{
WHERE {
template engine that GRAPH ?g{
?s ?p <{{uri}}> .
allow developers to }
}UNION{
include values in specific ?s ?p <{{uri}}> .
}
parts of a document. }
21
22. View templates
Templates also uses Haanga for filling results. Results
are accessed via
models.[query]+.variable.[value|curie]
<table>
{% for row in models.main %}
<tr>
<td><a href='{{row.p1.value}}'>{{row.p1.curie}}</a></td>
<td><a href='{{row.s1.value}}'>{{row.s1.curie}}</a></td>
</tr>
{% endfor %}
</table>
<table>
<tr>
<td><a href='http://www.w3.org/1999/02/22-rdf-syntax-ns#type'>rdf:type</a></td>
<td><a rel='rdf:type' href='http://www.w3.org/2000/01/rdf-schema#Resource'>rdfs:Resource</a></td>
</tr>
<tr>
<td><a href='http://www.w3.org/1999/02/22-rdf-syntax-ns#type'>rdf:type</a></td>
<td><a rel='rdf:type' href='http://xmlns.com/foaf/0.1/Person'>foaf:Person</a></td>
</tr>
</table>
22
23. View templates (2)
When you know there is only one row of results (or
you will only use the first) you can access it via
first.[query]+.variable.[value|curie]
<h1>{{first.main.name.value}}</h1>
<h1>Foo Bar</h1>
23
24. Templating types
In LODSPeaKr we can define special templates for URIs
of a certain rdf:type (if multiple types you can define
priorities)
$ utils/lodspk.sh create type foaf:Person
will produce
compponents/types/foaf:Person/
|-> html.template
|-> queries/
|-> main.query
For specific URIs
$ utils/lodspk.sh create uri local:AlvaroGraves
24
25. Customizing types
• You can add all the
queries you want
• You can specify new
endpoints where data
can be fetched from
• Adding a lower level
(subdir) can use
previously fetched
results in their queries
26. Workflow creation
LODSPeaKr allow users to execute queries to multiple
endpoints using previously retrieved values. It can be
multiple queries at each step
LOCAL 3
1
2
2
DBPEDIA
LOGD
26
28. $ curl http://alia/twcpeople/instances/AlvaroGraves.ttl
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ns0: <http://dbpedia.org/ontology/> .
@prefix ns1: <http://xmlns.com/foaf/0.1/> .
@prefix ns2: <http://purl.org/dc/terms/> .
@prefix ns3: <http://tw.rpi.edu/schema/> .
@prefix ns4: <http://www.w3.org/2002/07/owl#> .
@prefix ns5: <http://www.w3.org/2000/10/swap/pim/contact#> .
<http://tw.rpi.edu/instances/AlvaroGraves>
ns0:birthPlace <http://dbpedia.org/resource/Santiago> ;
ns1:name "Alvaro Graves"@en ;
ns1:depiction <http://tw.rpi.edu/wiki.tw/images/2/21/Alvaro.jpg> ;
ns2:description "PhD student in Cognitive Science. My interests are
Semantic Web, Web Science and cognitive and behavioral aspects of the Web.
Also interested in application of semantic technologies in
eGovernment."@en .
<http://tw.rpi.edu/instances/VIVOHackathon2011>
ns3:hasAttendee <http://tw.rpi.edu/instances/AlvaroGraves> ,
<http://tw.rpi.edu/instances/TimLebo> ;
ns1:name "VIVO Hackathon 2011"^^<http://www.w3.org/2001/
XMLSchema#string> .
<http://tw.rpi.edu/instances/TWCSpring2011BBQ>
ns3:hasAttendee <http://tw.rpi.edu/instances/AlvaroGraves> ,
<http://tw.rpi.edu/instances/DominicDiFranzo> ,
<http://tw.rpi.edu/instances/CameronHelm> ,
<http://tw.rpi.edu/instances/PeterFox> ,
<http://tw.rpi.edu/instances/ScottYaninas> ,
<http://tw.rpi.edu/instances/DanielSouza> ,
<http://tw.rpi.edu/instances/PatrickWest> ,
28
29. Serving multiple
representations
• LODSPeaKr will convert SELECT DISTINCT ?person ?email ?name
WHERE {
your SELECT query(*) in GRAPH ?g {
?person a foaf:Person ;
HTML to a CONSTRUCT foaf:name ?name ;
foaf:mbox ?email .
query for serving RDF }
FILTER(regex(?name, "^y", "i" ))
}order by ?name
• You shouldn’t have to worry
about it, unless you explicitly
want something different in CONSTRUCT {
other representations ?person a foaf:Person .
?person foaf:name ?name .
?person foaf:mbox ?email .
} WHERE ...
30. Services
• Allow developers to provide aggregated content
• Similar structure to types
• class, instance and namedGraph are services
$ utils/lodspk.sh create service people
will produce
components/services/people/
|-> html.template
|-> queries/
|-> main.query
31. Same features as in
typeModule
• Multiple representations, based on Accept
HTTP header
• Workflow with multiple queries and
SPARQL endpoints
32. http://alia/twcpeople/people
main.query
SELECT DISTINCT ?person ?email ?name
WHERE {
GRAPH ?g {
?person a foaf:Person ;
foaf:name ?name ;
foaf:mbox ?email .
}
}order by ?name
html.template
<ul>
{% for row in models.main %}
<li>
<a href="{{row.people.value}}">{{row.name.value}}
- {{row.email.value}}</a>
</li>
{% endfor %}
</ul>
33. Arguments in services
Arguments can be passed to a service after its name,
separated by slashes
http://example.org/myService/arg0/arg1/....
main.query
SELECT DISTINCT ?person ?email ?name WHERE {
GRAPH ?g {
?person a foaf:Person ;
foaf:name ?name ;
foaf:mbox ?email .
FILTER(regex(?name, "^{{lodspk.args.arg0}}", "i" ))
}
}order by ?name
http://alia/twcpeople/peopleByName/c
34. Creating APIs based on
services
We can reuse the service to provide a
JSON-friendly version of the document
json.template
{
"people": [
{% for row in models.main %}
{
"uri": "{{row.person.value}}",
"name": "{{row.name.value}}",
"email": "{{row.email.value}}"
}{%if ! forloop.last%},{%endif%}
{% endfor %}
]
}
35. Use of filters
• Haanga provides lots of useful filters
• Capitalize, urlescape, etc.
• LODSPeaKr includes some handy filters
• Right now: Google maps, Google table, D3 graphs,
gRaphael
• Not all are working 100% yet
37. Applications
• Farmers Market data
• http://graves.cl/
farmersmarket
• ESSI mobile webapp
• http://essi-lod.org/
• DataFAQs
• http://bit.ly/datafaqs
38. Conclusions
• LODSPeaKr allows developers build Linked Data-
based applications in a rapid, simple way
• It also provides useful features as Content-
negotiation, workflow execution, filters, etc.
• You can create Open Data portals, APIs, mobile
webapps, etc.
38
39. Future work
• Improve crawling (single URIs, flow control)
• Add controller for more control over data
management and flow
• Improve documentation!
• Comments, suggestions and bug reports
are welcome
39