SPARQLing cocktails

Timea Turdean
Timea TurdeanTechnical Consultant at Semantic Web Company GmbH (SWC)
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
1 of 23

Recommended

Tomcat连接池配置方法V2.1 by
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Zianed Hou
660 views8 slides
Unify Earth Observation products access with OpenSearch by
Unify Earth Observation products access with OpenSearchUnify Earth Observation products access with OpenSearch
Unify Earth Observation products access with OpenSearchGasperi Jerome
2.7K views27 slides
Amazon Cognito使って認証したい?それならSpring Security使いましょう! by
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Amazon Cognito使って認証したい?それならSpring Security使いましょう!
Amazon Cognito使って認証したい?それならSpring Security使いましょう!Ryosuke Uchitate
17K views102 slides
Wicket Security Presentation by
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentationmrmean
2.3K views42 slides
Java Libraries You Can’t Afford to Miss by
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Andres Almiray
3K views64 slides
Distrubuted database connection with oracle by
Distrubuted database connection with oracleDistrubuted database connection with oracle
Distrubuted database connection with oracleashrafulais
102 views8 slides

More Related Content

What's hot

Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ... by
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 ...Red Hat Developers
2.9K views43 slides
Making the most of your gradle build - Gr8Conf 2017 by
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 2017Andres Almiray
413 views49 slides
Making the most of your gradle build - Greach 2017 by
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 2017Andres Almiray
992 views47 slides
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바... by
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...탑크리에듀(구로디지털단지역3번출구 2분거리)
1.1K views7 slides
VRaptor 4 - JavaOne by
VRaptor 4 - JavaOneVRaptor 4 - JavaOne
VRaptor 4 - JavaOneRodrigo Turini
2.7K views109 slides
AssertJ quick introduction by
AssertJ quick introductionAssertJ quick introduction
AssertJ quick introductionThiago Schoppen Veronese
740 views12 slides

What's hot(20)

Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ... by Red Hat Developers
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 ...
Red Hat Developers2.9K views
Making the most of your gradle build - Gr8Conf 2017 by Andres Almiray
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
Andres Almiray413 views
Making the most of your gradle build - Greach 2017 by Andres Almiray
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
Andres Almiray992 views
FluentLeniumで困った話 by Yuuki Ooguro
FluentLeniumで困った話FluentLeniumで困った話
FluentLeniumで困った話
Yuuki Ooguro106 views
Overview of Google spreadsheet API for Java by Nazar Kostiv by IT Booze
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 Booze6K views
Rest API using Flask & SqlAlchemy by Alessandro Cucci
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
Alessandro Cucci2.7K views
How to cheat jb detector and detect cheating by Hokila Jan
How to cheat jb detector and detect cheatingHow to cheat jb detector and detect cheating
How to cheat jb detector and detect cheating
Hokila Jan2.9K views
Test Driven Documentation with Spring Rest Docs by Roman Tsypuk
Test Driven Documentation with Spring Rest DocsTest Driven Documentation with Spring Rest Docs
Test Driven Documentation with Spring Rest Docs
Roman Tsypuk997 views
Functional tests with TYPO3 by cpsitgmbh
Functional tests with TYPO3Functional tests with TYPO3
Functional tests with TYPO3
cpsitgmbh3.5K views
Hypermedia-driven Web Services with Spring Data REST by Sofiia Vynnytska
Hypermedia-driven Web Services with Spring Data RESTHypermedia-driven Web Services with Spring Data REST
Hypermedia-driven Web Services with Spring Data REST
Sofiia Vynnytska1.3K views
10 sharing files and data in windows phone 8 by WindowsPhoneRocks
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
WindowsPhoneRocks1.7K views
SQLite in Adobe AIR by Peter Elst
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
Peter Elst3.1K views
Multi Client Development with Spring - Josh Long by jaxconf
Multi Client Development with Spring - Josh Long Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
jaxconf2.5K views
Taking advantage of Prometheus relabeling by Julien Pivotto
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabeling
Julien Pivotto21.6K views
[xp2013] Narrow Down What to Test by Zsolt Fabok
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
Zsolt Fabok831 views

Viewers also liked

Intro to Semantic Web by
Intro to Semantic WebIntro to Semantic Web
Intro to Semantic WebTimea Turdean
2.1K views24 slides
Intro to AngularJS by
Intro to AngularJSIntro to AngularJS
Intro to AngularJSTimea Turdean
1.8K views19 slides
Overcoming impostor syndrome by
Overcoming impostor syndromeOvercoming impostor syndrome
Overcoming impostor syndromeTimea Turdean
1.7K views32 slides
RDF Analytics... SPARQL and Beyond by
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondFadi Maali
3.1K views27 slides
Self-service Linked Government Data by
Self-service Linked Government DataSelf-service Linked Government Data
Self-service Linked Government DataFadi Maali
5.1K views34 slides
Estimating value through the lens of cost of delay by
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 delayagilebydesign
672 views40 slides

Viewers also liked(7)

Intro to Semantic Web by Timea Turdean
Intro to Semantic WebIntro to Semantic Web
Intro to Semantic Web
Timea Turdean2.1K views
Overcoming impostor syndrome by Timea Turdean
Overcoming impostor syndromeOvercoming impostor syndrome
Overcoming impostor syndrome
Timea Turdean1.7K views
RDF Analytics... SPARQL and Beyond by Fadi Maali
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and Beyond
Fadi Maali3.1K views
Self-service Linked Government Data by Fadi Maali
Self-service Linked Government DataSelf-service Linked Government Data
Self-service Linked Government Data
Fadi Maali5.1K views
Estimating value through the lens of cost of delay by agilebydesign
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
agilebydesign672 views
Building a Secure App with Google Polymer and Java / Spring by sdeeg
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
sdeeg14K views

Similar to SPARQLing cocktails

WebTech Tutorial Querying DBPedia by
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaKatrien Verbert
8.2K views41 slides
03 form-data by
03 form-data03 form-data
03 form-datasnopteck
403 views23 slides
4 sw architectures and sparql by
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparqlMariano Rodriguez-Muro
680 views42 slides
Overview of RESTful web services by
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
4.2K views27 slides
Bootstrat REST APIs with Laravel 5 by
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
3.9K views40 slides
URLProtocol by
URLProtocolURLProtocol
URLProtocolKosuke Matsuda
347 views46 slides

Similar to SPARQLing cocktails(20)

WebTech Tutorial Querying DBPedia by Katrien Verbert
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
Katrien Verbert8.2K views
03 form-data by snopteck
03 form-data03 form-data
03 form-data
snopteck403 views
Overview of RESTful web services by nbuddharaju
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
nbuddharaju4.2K views
Bootstrat REST APIs with Laravel 5 by Elena Kolevska
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska3.9K views
比XML更好用的Java Annotation by javatwo2011
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo20111K views
China Science Challenge by remko caprio
China Science ChallengeChina Science Challenge
China Science Challenge
remko caprio737 views
SgCodeJam24 Workshop by remko caprio
SgCodeJam24 WorkshopSgCodeJam24 Workshop
SgCodeJam24 Workshop
remko caprio909 views
JavaScript straight from the Oracle Database by Dimitri Gielis
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle Database
Dimitri Gielis3.4K views
Developing RESTful WebServices using Jersey by b_kathir
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir3.1K views
Тарас Олексин - Sculpt! Your! Tests! by DataArt
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
DataArt260 views
Swift LA Meetup at eHarmony- What's New in Swift 2.0 by Claire Townend Gee
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
Claire Townend Gee983 views
Adding a modern twist to legacy web applications by Jeff Durta
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta354 views
Tutorial on developing a Solr search component plugin by searchbox-com
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
searchbox-com26.2K views
Summer - The HTML5 Library for Java and Scala by rostislav
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scala
rostislav3.1K views
XamarinとAWSをつないでみた話 by Takehito Tanabe
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
Takehito Tanabe1.7K views
ASP.NET Overview - Alvin Lau by Spiffy
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy3.2K views

Recently uploaded

Cencora Executive Symposium by
Cencora Executive SymposiumCencora Executive Symposium
Cencora Executive Symposiummarketingcommunicati21
159 views14 slides
Generative AI: Shifting the AI Landscape by
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI LandscapeDeakin University
53 views55 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
96 views46 slides
Evaluation of Quality of Experience of ABR Schemes in Gaming Stream by
Evaluation of Quality of Experience of ABR Schemes in Gaming StreamEvaluation of Quality of Experience of ABR Schemes in Gaming Stream
Evaluation of Quality of Experience of ABR Schemes in Gaming StreamAlpen-Adria-Universität
38 views34 slides
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
158 views59 slides
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineShapeBlue
221 views19 slides

Recently uploaded(20)

Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash158 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue221 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue138 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue194 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro34 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue147 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays56 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue263 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li85 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri32 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue180 views
Optimizing Communication to Optimize Human Behavior - LCBM by Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE79 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue198 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue161 views

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