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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

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