SlideShare a Scribd company logo
1 of 23
Download to read offline
Developing for the
Semantic Web
by Timea Turdean
21.11.2015
#devfest15
Vienna
SEMANTIC WEB
&
LINKED DATA
2 http://dbpedia.org/resource/Sir_Tim_Berners_Lee
Triple
http://example.org/myProject/Triple
the form of
subject–predicate–object
expressions
<?s ?p ?o>
World Wide Web Consortium
(w3.org)
English computer scientists
RDF
http://dbpedia.org/resource/Resource_Description_Framework
http://www.w3.
org/2004/02/skos/core#de
finition
http://www.w3.org/1999/02/22-rdf-
syntax-ns#type http://example.org/Timea-
Custom-
Scheme/contained_in
http://example.org/Timea-
Custom-
Scheme/knows_to_use
3
Place your screenshot here
4Web
Application
http://preview.poolparty.biz/sparqlingCocktails/cocktails
5FEATURES &
FUNCTIONALITY
● Tap into your Linked Data endpoint
● Query Linked Data
● Display your Linked Data
● Display OPEN Linked Data
● The power of Linked Data
● BONUS *An improved search
Tap into your
Linked Data
endpoint
▸ data contains:
6 ▸ data is available
through a
SPARQL
endpoint
Tap into your
Linked Data
endpoint
<http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.
org/2004/02/skos/core#Concept> .
<http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83>
<http://www.w3.org/2004/02/skos/core#prefLabel> "Brandy"@en .
<http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83>
<http://www.w3.org/2004/02/skos/core#altLabel> "Grape spirit"@en .
<http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83>
<http://www.w3.org/2004/02/skos/core#definition> "Brandy (from brandywine, derived from
Dutch brandewijnu2014"burnt wine") is a spirit produced by distilling wine. Brandy
generally contains 35u201360% alcohol by volume and is typically taken as an after-
dinner drink. Some brandies are aged in wooden casks, some are coloured with caramel
colouring to imitate the effect of aging, and some brandies are produced using a
combination of both aging and colouring."@en .
<http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83>
<http://www.w3.org/2004/02/skos/core#narrower> <http://vocabulary.semantic-web.
at/cocktails/16b625c5-3930-4cf8-a75b-b25e72f2bfb6> .
<http://vocabulary.semantic-web.at/cocktails/16b625c5-3930-4cf8-a75b-b25e72f2bfb6>
<http://www.w3.org/2004/02/skos/core#prefLabel> "Calvados"@en .
7
SPARQL
8 SELECT * WHERE
{
?s ?p ?o
}
SELECT * WHERE
{
?s ?p ?o
}
Query
Linked Data
▸ Give me all Alcoholic Beverages:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT ?label WHERE {
<http://vocabulary.semantic-web.
at/cocktails/f3000285-36b0-4ffe-af90-
740c2dd8fff5> skos:narrower ?o .
?o skos:prefLabel ?label .
}
▸ Results:
"Brandy"@en
"Fortified wine"@en
"Gin"@en
"Liqueur"@en
"Rum"@en
"Schnapps"@en
"Tequila"@en
"Vodka"@en
"Whisky"@en
"Wine"@en
9
Tap into your
Linked Data
endpoint
public class SPARQLendpointConnection extends HttpClient {
URL sparqlEndpointURL = null;
NameValuePair queryParam = new NameValuePair( "query", "QUERY");
List<NameValuePair> urlParams = new ArrayList() ;
List<Header> headers = new ArrayList<>() ;
public SPARQLendpointConnection (URL sparqlEndpointURL) {
this.sparqlEndpointURL = sparqlEndpointURL ;
this.addQueryParameter( "query", "QUERY");
this .addQueryParameter( "content-type" , "application/json" );
super .getParams().setParameter( "http.protocol.version" , HttpVersion. HTTP_1_1);
super .getParams().setParameter( "http.protocol.content-charset" , "UTF-8");
}
public void addQueryParameter (String key , String value) {
if (value.equals( "QUERY")) {
this.queryParam = new NameValuePair(key , value);
} else {
this.urlParams.add(new NameValuePair(key , value));
}
} [...]
}
10
Display your
Linked Data
public class SPARQLendpointConnection extends HttpClient {
public TupleQueryResult runAndParseSelectQuery (String query) throws IOException {
InputStream in = null;
TupleQueryResult tqr = null;
try {
in = IOUtils. toInputStream(runSelectQuery(query)) ;
tqr = QueryResultIO. parse(in, TupleQueryResultFormat. JSON);
return tqr;
} catch (QueryResultParseException | TupleQueryResultHandlerException |
UnsupportedQueryResultFormatException ex) {
throw new IOException(ex) ;
} finally {
if (in != null) {
in.close() ;
}
}
}
}
11
Display your
Linked Data
public class SPARQLendpointConnection extends HttpClient {
public String runSelectQuery (String query) throws IOException {
PostMethod post = new PostMethod( this.sparqlEndpointURL .toString()) ;
NameValuePair[] params = this.urlParams.toArray(new NameValuePair[ this.urlParams.
size() + 1]);
params[(params. length - 1)] = new NameValuePair( queryParam .getName() , query);
post.setRequestBody(params) ;
for (Header h : this.headers) { post.addRequestHeader(h) ; }
int statusCode ;
String response ;
try {
statusCode = super.executeMethod(post) ;
response = post.getResponseBodyAsString() ;
if (statusCode != HttpStatus. SC_OK) {
System. out.println(statusCode) ;
}} finally {
post.releaseConnection() ;
}
return response;
}}
12
Tap into your
Linked Data
endpoint
import org.apache.commons.httpclient.* ;
import org.apache.commons.httpclient.methods.PostMethod ;
13
org.apache.commons.httpclient.jar
commons.io.jar
import org.apache.commons.io.IOUtils ;
sesame-query.jar
import org.openrdf.query.TupleQueryResult ;
import org.openrdf.query.TupleQueryResultHandlerException ;
sesame-queryresultio-api.jar; sesame-queryresultio-sparqljson.jar
import org.openrdf.query.resultio.QueryResultIO ;
import org.openrdf.query.resultio.QueryResultParseException ;
import org.openrdf.query.resultio.TupleQueryResultFormat ;
import org.openrdf.query.resultio.UnsupportedQueryResultFormatException ;
Display your
Linked Data
public void test() throws Exception {
String value = "";
SPARQLendpointConnection myConncetion = new SPARQLendpointConnection( new URL("http:
//vocabulary.semantic-web.at/PoolParty/sparql/cocktails" ));
TupleQueryResult tqr = myConnection.runAndParseSelectQuery(
"PREFIX skos:<http://www.w3.org/2004/02/skos/core#> n" +
"SELECT ?label WHERE { n" +
"<http://vocabulary.semantic-web.at/cocktails/f3000285-36b0-4ffe-af90-740c2dd8fff5>
skos:narrower ?p . n" +
"?p skos:prefLabel ?label n" +
"}");
BindingSet bs = null;
try {
while (tqr.hasNext()) {
bs = tqr.next() ;
value = bs.getValue( "label").toString() ;
System.out.println(bs.getValue( "label"));
}} finally {
tqr.close() ;
}}
14
Display your
Linked Data
"Brandy"@en
"Fortified wine"@en
"Gin"@en
"Liqueur"@en
"Rum"@en
"Schnapps"@en
"Tequila"@en
"Vodka"@en
"Whisky"@en
"Wine"@en
15 RESULTS
Display your
Linked Data
private ModelAndView mavChooseIngredients;
mavChooseIngredients = new ModelAndView( "cocktails/index" );
mavChooseIngredients .addObject( "myMenu", this.retrieveMainAlcoholicBeverages()) ;
[..]
public List<BindingSet> retrieveMainAlcoholicBeverages () throws
IOException , QueryEvaluationException {
return QueryResults. asList(myConnection .runAndParseSelectQuery(
"PREFIX skos:<http://www.w3.org/2004/02/skos/core#> n" +
"SELECT ?label WHERE { n" +
"<http://vocabulary.semantic-web.at/cocktails/f3000285-36b0-4ffe-af90-
740c2dd8fff5> skos:narrower ?p . n" +
"?p skos:prefLabel ?label n" +
"}"
));
}
16
Display your
Linked Data
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core " %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions " %>
[...]
<c:forEach items="${myMenu}" var="bindingSet ">
<li class="entity">
${bindingSet.getValue( 'label').stringValue() }
</li>
</c:forEach>
17 index.jsp
Display OPEN
Linked Data
DBpedia SPARQL endpoint:
▸ http://dbpedia.org/sparql
SELECT * WHERE {
<http://dbpedia.org/resource/Negroni>
<http://dbpedia.org/ontology/abstract>
?abstract
}
18
The POWER
of
Linked data
▸ easy change of data
▸ cost efficient
▸ graph algorithms
19
Place your screenshot here
20An improved SEARCH
Faceted search
http://preview.poolparty.biz/sparqlingCocktails/search
Thank you!
21
Connect
Timea Turdean
Technical Consultant, Semantic Web Company
▸ timea.turdean@gmail.com
▸ http://at.linkedin.com/in/timeaturdean
▸ http://timeaturdean.com
22
© Semantic Web Company - http://www.semantic-web.at/ and http://www.poolparty.biz/
▸ LD2014 picture slide3- http://data.dws.informatik.uni-
mannheim.de/lodcloud/2014/
▸ Linked Data principles: http://www.w3.
org/DesignIssues/LinkedData.html
▸ Introduction to Semantic Web: http://timeaturdean.
com/introduction-semantic-web/
23Resources

More Related Content

What's hot

Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv
IT Booze
 
How to cheat jb detector and detect cheating
How to cheat jb detector and detect cheatingHow to cheat jb detector and detect cheating
How to cheat jb detector and detect cheating
Hokila Jan
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
Peter Elst
 

What's hot (20)

Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
 
VRaptor 4 - JavaOne
VRaptor 4 - JavaOneVRaptor 4 - JavaOne
VRaptor 4 - JavaOne
 
AssertJ quick introduction
AssertJ quick introductionAssertJ quick introduction
AssertJ quick introduction
 
FluentLeniumで困った話
FluentLeniumで困った話FluentLeniumで困った話
FluentLeniumで困った話
 
Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv Overview of Google spreadsheet API for Java by Nazar Kostiv
Overview of Google spreadsheet API for Java by Nazar Kostiv
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
 
9.Spring DI_4
9.Spring DI_49.Spring DI_4
9.Spring DI_4
 
#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
How to cheat jb detector and detect cheating
How to cheat jb detector and detect cheatingHow to cheat jb detector and detect cheating
How to cheat jb detector and detect cheating
 
Test Driven Documentation with Spring Rest Docs
Test Driven Documentation with Spring Rest DocsTest Driven Documentation with Spring Rest Docs
Test Driven Documentation with Spring Rest Docs
 
Functional tests with TYPO3
Functional tests with TYPO3Functional tests with TYPO3
Functional tests with TYPO3
 
Hypermedia-driven Web Services with Spring Data REST
Hypermedia-driven Web Services with Spring Data RESTHypermedia-driven Web Services with Spring Data REST
Hypermedia-driven Web Services with Spring Data REST
 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
 
Taking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabeling
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
 

Viewers also liked

RDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and Beyond
Fadi Maali
 

Viewers also liked (7)

Intro to Semantic Web
Intro to Semantic WebIntro to Semantic Web
Intro to Semantic Web
 
Intro to AngularJS
Intro to AngularJSIntro to AngularJS
Intro to AngularJS
 
Overcoming impostor syndrome
Overcoming impostor syndromeOvercoming impostor syndrome
Overcoming impostor syndrome
 
RDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and Beyond
 
Self-service Linked Government Data
Self-service Linked Government DataSelf-service Linked Government Data
Self-service Linked Government Data
 
Estimating value through the lens of cost of delay
Estimating value through the lens of cost of delayEstimating value through the lens of cost of delay
Estimating value through the lens of cost of delay
 
Building a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / SpringBuilding a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / Spring
 

Similar to SPARQLing cocktails

WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
Katrien Verbert
 
03 form-data
03 form-data03 form-data
03 form-data
snopteck
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
Mariano Rodriguez-Muro
 
China Science Challenge
China Science ChallengeChina Science Challenge
China Science Challenge
remko caprio
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 

Similar to SPARQLing cocktails (20)

WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
 
03 form-data
03 form-data03 form-data
03 form-data
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
URLProtocol
URLProtocolURLProtocol
URLProtocol
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
China Science Challenge
China Science ChallengeChina Science Challenge
China Science Challenge
 
SgCodeJam24 Workshop
SgCodeJam24 WorkshopSgCodeJam24 Workshop
SgCodeJam24 Workshop
 
JavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle Database
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
Summer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scala
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 

SPARQLing cocktails

  • 1. Developing for the Semantic Web by Timea Turdean 21.11.2015 #devfest15 Vienna
  • 2. SEMANTIC WEB & LINKED DATA 2 http://dbpedia.org/resource/Sir_Tim_Berners_Lee Triple http://example.org/myProject/Triple the form of subject–predicate–object expressions <?s ?p ?o> World Wide Web Consortium (w3.org) English computer scientists RDF http://dbpedia.org/resource/Resource_Description_Framework http://www.w3. org/2004/02/skos/core#de finition http://www.w3.org/1999/02/22-rdf- syntax-ns#type http://example.org/Timea- Custom- Scheme/contained_in http://example.org/Timea- Custom- Scheme/knows_to_use
  • 3. 3
  • 4. Place your screenshot here 4Web Application http://preview.poolparty.biz/sparqlingCocktails/cocktails
  • 5. 5FEATURES & FUNCTIONALITY ● Tap into your Linked Data endpoint ● Query Linked Data ● Display your Linked Data ● Display OPEN Linked Data ● The power of Linked Data ● BONUS *An improved search
  • 6. Tap into your Linked Data endpoint ▸ data contains: 6 ▸ data is available through a SPARQL endpoint
  • 7. Tap into your Linked Data endpoint <http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3. org/2004/02/skos/core#Concept> . <http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83> <http://www.w3.org/2004/02/skos/core#prefLabel> "Brandy"@en . <http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83> <http://www.w3.org/2004/02/skos/core#altLabel> "Grape spirit"@en . <http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83> <http://www.w3.org/2004/02/skos/core#definition> "Brandy (from brandywine, derived from Dutch brandewijnu2014"burnt wine") is a spirit produced by distilling wine. Brandy generally contains 35u201360% alcohol by volume and is typically taken as an after- dinner drink. Some brandies are aged in wooden casks, some are coloured with caramel colouring to imitate the effect of aging, and some brandies are produced using a combination of both aging and colouring."@en . <http://vocabulary.semantic-web.at/cocktails/8f09ee6f-d5b9-4b8a-aa17-b0665fae4e83> <http://www.w3.org/2004/02/skos/core#narrower> <http://vocabulary.semantic-web. at/cocktails/16b625c5-3930-4cf8-a75b-b25e72f2bfb6> . <http://vocabulary.semantic-web.at/cocktails/16b625c5-3930-4cf8-a75b-b25e72f2bfb6> <http://www.w3.org/2004/02/skos/core#prefLabel> "Calvados"@en . 7
  • 8. SPARQL 8 SELECT * WHERE { ?s ?p ?o } SELECT * WHERE { ?s ?p ?o }
  • 9. Query Linked Data ▸ Give me all Alcoholic Beverages: PREFIX skos:<http://www.w3.org/2004/02/skos/core#> SELECT ?label WHERE { <http://vocabulary.semantic-web. at/cocktails/f3000285-36b0-4ffe-af90- 740c2dd8fff5> skos:narrower ?o . ?o skos:prefLabel ?label . } ▸ Results: "Brandy"@en "Fortified wine"@en "Gin"@en "Liqueur"@en "Rum"@en "Schnapps"@en "Tequila"@en "Vodka"@en "Whisky"@en "Wine"@en 9
  • 10. Tap into your Linked Data endpoint public class SPARQLendpointConnection extends HttpClient { URL sparqlEndpointURL = null; NameValuePair queryParam = new NameValuePair( "query", "QUERY"); List<NameValuePair> urlParams = new ArrayList() ; List<Header> headers = new ArrayList<>() ; public SPARQLendpointConnection (URL sparqlEndpointURL) { this.sparqlEndpointURL = sparqlEndpointURL ; this.addQueryParameter( "query", "QUERY"); this .addQueryParameter( "content-type" , "application/json" ); super .getParams().setParameter( "http.protocol.version" , HttpVersion. HTTP_1_1); super .getParams().setParameter( "http.protocol.content-charset" , "UTF-8"); } public void addQueryParameter (String key , String value) { if (value.equals( "QUERY")) { this.queryParam = new NameValuePair(key , value); } else { this.urlParams.add(new NameValuePair(key , value)); } } [...] } 10
  • 11. Display your Linked Data public class SPARQLendpointConnection extends HttpClient { public TupleQueryResult runAndParseSelectQuery (String query) throws IOException { InputStream in = null; TupleQueryResult tqr = null; try { in = IOUtils. toInputStream(runSelectQuery(query)) ; tqr = QueryResultIO. parse(in, TupleQueryResultFormat. JSON); return tqr; } catch (QueryResultParseException | TupleQueryResultHandlerException | UnsupportedQueryResultFormatException ex) { throw new IOException(ex) ; } finally { if (in != null) { in.close() ; } } } } 11
  • 12. Display your Linked Data public class SPARQLendpointConnection extends HttpClient { public String runSelectQuery (String query) throws IOException { PostMethod post = new PostMethod( this.sparqlEndpointURL .toString()) ; NameValuePair[] params = this.urlParams.toArray(new NameValuePair[ this.urlParams. size() + 1]); params[(params. length - 1)] = new NameValuePair( queryParam .getName() , query); post.setRequestBody(params) ; for (Header h : this.headers) { post.addRequestHeader(h) ; } int statusCode ; String response ; try { statusCode = super.executeMethod(post) ; response = post.getResponseBodyAsString() ; if (statusCode != HttpStatus. SC_OK) { System. out.println(statusCode) ; }} finally { post.releaseConnection() ; } return response; }} 12
  • 13. Tap into your Linked Data endpoint import org.apache.commons.httpclient.* ; import org.apache.commons.httpclient.methods.PostMethod ; 13 org.apache.commons.httpclient.jar commons.io.jar import org.apache.commons.io.IOUtils ; sesame-query.jar import org.openrdf.query.TupleQueryResult ; import org.openrdf.query.TupleQueryResultHandlerException ; sesame-queryresultio-api.jar; sesame-queryresultio-sparqljson.jar import org.openrdf.query.resultio.QueryResultIO ; import org.openrdf.query.resultio.QueryResultParseException ; import org.openrdf.query.resultio.TupleQueryResultFormat ; import org.openrdf.query.resultio.UnsupportedQueryResultFormatException ;
  • 14. Display your Linked Data public void test() throws Exception { String value = ""; SPARQLendpointConnection myConncetion = new SPARQLendpointConnection( new URL("http: //vocabulary.semantic-web.at/PoolParty/sparql/cocktails" )); TupleQueryResult tqr = myConnection.runAndParseSelectQuery( "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> n" + "SELECT ?label WHERE { n" + "<http://vocabulary.semantic-web.at/cocktails/f3000285-36b0-4ffe-af90-740c2dd8fff5> skos:narrower ?p . n" + "?p skos:prefLabel ?label n" + "}"); BindingSet bs = null; try { while (tqr.hasNext()) { bs = tqr.next() ; value = bs.getValue( "label").toString() ; System.out.println(bs.getValue( "label")); }} finally { tqr.close() ; }} 14
  • 15. Display your Linked Data "Brandy"@en "Fortified wine"@en "Gin"@en "Liqueur"@en "Rum"@en "Schnapps"@en "Tequila"@en "Vodka"@en "Whisky"@en "Wine"@en 15 RESULTS
  • 16. Display your Linked Data private ModelAndView mavChooseIngredients; mavChooseIngredients = new ModelAndView( "cocktails/index" ); mavChooseIngredients .addObject( "myMenu", this.retrieveMainAlcoholicBeverages()) ; [..] public List<BindingSet> retrieveMainAlcoholicBeverages () throws IOException , QueryEvaluationException { return QueryResults. asList(myConnection .runAndParseSelectQuery( "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> n" + "SELECT ?label WHERE { n" + "<http://vocabulary.semantic-web.at/cocktails/f3000285-36b0-4ffe-af90- 740c2dd8fff5> skos:narrower ?p . n" + "?p skos:prefLabel ?label n" + "}" )); } 16
  • 17. Display your Linked Data <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core " %> <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions " %> [...] <c:forEach items="${myMenu}" var="bindingSet "> <li class="entity"> ${bindingSet.getValue( 'label').stringValue() } </li> </c:forEach> 17 index.jsp
  • 18. Display OPEN Linked Data DBpedia SPARQL endpoint: ▸ http://dbpedia.org/sparql SELECT * WHERE { <http://dbpedia.org/resource/Negroni> <http://dbpedia.org/ontology/abstract> ?abstract } 18
  • 19. The POWER of Linked data ▸ easy change of data ▸ cost efficient ▸ graph algorithms 19
  • 20. Place your screenshot here 20An improved SEARCH Faceted search http://preview.poolparty.biz/sparqlingCocktails/search
  • 22. Connect Timea Turdean Technical Consultant, Semantic Web Company ▸ timea.turdean@gmail.com ▸ http://at.linkedin.com/in/timeaturdean ▸ http://timeaturdean.com 22 © Semantic Web Company - http://www.semantic-web.at/ and http://www.poolparty.biz/
  • 23. ▸ LD2014 picture slide3- http://data.dws.informatik.uni- mannheim.de/lodcloud/2014/ ▸ Linked Data principles: http://www.w3. org/DesignIssues/LinkedData.html ▸ Introduction to Semantic Web: http://timeaturdean. com/introduction-semantic-web/ 23Resources