SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Tutorial: Querying DBpedia
Web Technology
2ID60
14 November 2013
Dr. Katrien Verbert
Dr. ir. Natasha Stash
Dr. George Fletcher
Overview
• 
• 
• 
• 
• 

Introduction to Jena
Setting up the environment
Querying DBpedia
Other APIs
PHP example
Jena
•  Jena is a Java framework for the creation of applications
for the Semantic Web
•  Provides interfaces and classes for the creation and
manipulation of RDF repositories
RDF concepts
Capabilities of Jena
• 
• 
• 
• 

RDF API
Reading and writing in RDF/XML, N-Triples
In-memory and persistent storage
SPARQL query engine
RDF concepts
•  The Jena RDF API contains classes and interfaces for every
important aspect of the RDF specification
•  They can be used in order to construct RDF graphs from
scratch, or edit existent graphs
•  These classes/interfaces reside in the
com.hp.hpl.jena.rdf.model package
•  In Jena, the Model interface is used to represent RDF
graphs
•  Through Model, statements can be obtained/ created/
removed etc
RDF concepts
// Create an empty model
Model model = ModelFactory.createDefaultModel();
String ns = new String("http://www.example.com/example#");
// Create two Resources
Resource john = model.createResource(ns + "John");
Resource jane = model.createResource(ns + "Jane");
// Create the 'hasBrother' Property declaration
Property hasBrother = model.createProperty(ns, "hasBrother");
// Associate jane to john through 'hasBrother'
jane.addProperty(hasBrother, john);
// Create the 'hasSister' Property declaration
Property hasSister = model.createProperty(ns, "hasSister");
// Associate john and jane through 'hasSister' with a Statement
Statement sisterStmt = model.createStatement(john, hasSister, jane);
model.add(sisterStmt);
SPARQL query processing
•  Jena uses the ARQ engine for the processing of
SPARQL queries
•  The ARQ API classes are found in com.hp.hpl.jena.query

•  Basic classes in ARQ:
•  Query: Represents a single SPARQL query.
•  Dataset: The knowledge base on which queries are executed
(Equivalent to RDF Models)
•  QueryFactory: Can be used to generate Query objects from
SPARQL strings
•  QueryExecution: Provides methods for the execution of queries
•  ResultSet: Contains the results obtained from an executed query
•  QuerySolution: Represents a row of query results.
•  If there are many answers to a query, a ResultSet is returned after
the query is executed. The ResultSet contains many QuerySolutions
SPARQL query processing
// Prepare query string
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>n" +
"PREFIX : <http://www.example.com/onto1#>n" +
"SELECT ?married ?spouse WHERE {" +
"?married rdf:type :MarriedPerson.n" +
"?married :hasSpouse ?spouse." +
"}";
// Use the ontology model to create a Dataset object
// Note: If no reasoner has been attached to the model, no results
// will be returned (MarriedPerson has no asserted instances)
Dataset dataset = DatasetFactory.create(ontModel);
// Parse query string and create Query object
Query q = QueryFactory.create(queryString);
// Execute query and obtain result set
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet resultSet = qexec.execSelect();
SPARQL query processing

// Print results
while(resultSet.hasNext()) {
// Each row contains two fields: ‘married’ and ‘spouse’,
// as defined in the query string
QuerySolution row = (QuerySolution)resultSet.next();
RDFNode nextMarried = row.get("married");
System.out.print(nextMarried.toString());
System.out.print(" is married to ");
RDFNode nextSpouse = row.get("spouse");
System.out.println(nextSpouse.toString());
}
ARQ Application API
http://jena.apache.org/documentation/query/app_api.html
Overview
• 
• 
• 
• 

Introduction to Jena
Setting up the environment
Querying Dbpedia
Other APIs
Setting up the environment
Download Netbeans Java EE version:
https://netbeans.org/downloads/
Downloading Jena

http://jena.apache.org
Download binary distribution
http://www.apache.org/dist/jena/
Getting started with Jena in Netbeans
Create a new Java project
Create a Java project
Add Jena libraries to class path
Add Jena libraries to class path
Add all jars in lib folder of Jena distribution
Add all jars in lib folder
Using Jena with Eclipse
•  http://www.iandickinson.me.uk/articles/jena-eclipsehelloworld/
Tutorials

http://jena.apache.org/getting_started/
Overview
• 
• 
• 
• 

Introduction to Jena
Setting up the environment
Querying Dbpedia
Other APIs
QueryFactory
•  has various create() methods to read a textual query
•  these create() methods
•  return a Query object,
•  which encapsulates a parsed query.
QueryExecutionFactory
Create a QueryExecution that will access a SPARQL
service over HTTP
QueryExecutionFactory.sparqlService(String service,
Query query)
Querying Dbpedia
SPARQL endpoint
http://dbpedia.org/sparql
Example
String service = "http://dbpedia.org/sparql";
String query = "ASK { }";
QueryExecution qe = QueryExecutionFactory.sparqlService(service,
query);
Test connection
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP;
public class QueryTest {
public static void main(String[] args) {
String service = "http://dbpedia.org/sparql";
String query = "ASK { }";
QueryExecution qe = QueryExecutionFactory.sparqlService(service, query);
try {
if (qe.execAsk()) {
System.out.println(service + " is UP");
} // end if
} catch (QueryExceptionHTTP e) {
System.out.println(service + " is DOWN");
} finally {
qe.close();
}
}
}
Example queries
http://wiki.dbpedia.org/OnlineAccess#h28-5
Example query: people who were born in Eindhoven
String service="http://dbpedia.org/sparql";
String query="PREFIX dbo:<http://dbpedia.org/ontology/>"
+ "PREFIX : <http://dbpedia.org/resource/>"
+ "select ?person where {?person dbo:birthPlace :Eindhoven.}";
QueryExecution qe=QueryExecutionFactory.sparqlService(service, query);
ResultSet rs=qe.execSelect();
while (rs.hasNext()){
QuerySolution s=rs.nextSolution();
System.out.println(s.getResource("?person").toString());
}

03/28/11
Processing results
QuerySolution soln = results.nextSolution() ;
RDFNode x = soln.get("varName") ; // Get a result variable by name.
Resource r = soln.getResource("VarR") ; // Get a result variable - must be a resource
Literal l = soln.getLiteral("VarL") ; // Get a result variable - must be a literal
Example
String service="http://dbpedia.org/sparql";
String query="PREFIX dbo:<http://dbpedia.org/ontology/>"
+ "PREFIX : <http://dbpedia.org/resource/>"
+ "PREFIX foaf:<http://xmlns.com/foaf/0.1/>"
+ "select ?person ?name where {?person dbo:birthPlace :Eindhoven."
+ "?person foaf:name ?name}";
QueryExecution qe=QueryExecutionFactory.sparqlService(service, query);
ResultSet rs=qe.execSelect();
while (rs.hasNext()){
QuerySolution s=rs.nextSolution();
Resource r=s.getResource("?person");
Literal name=s.getLiteral("?name");
System.out.println(s.getResource("?person").toString());
System.out.println(s.getLiteral("?name").getString());
}
03/28/11
Example query: people who were born in Berlin
before 1900
PREFIX dbo: http://dbpedia.org/ontology/
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : http://dbpedia.org/resource/
SELECT ?name ?birth ?death ?person WHERE {
?person dbo:birthPlace :Berlin .
?person dbo:birthDate ?birth .
?person foaf:name ?name .
?person dbo:deathDate ?death .
FILTER (?birth < "1900-01-01"^^xsd:date) .
}
ORDER BY ?name
Other APIs
PHP:	
  RAP	
  –	
  RDF	
  
h+p://www.seasr.org/wp-­‐content/plugins/meandre/rdfapi-­‐php/doc/	
  
	
  

Python:	
  RDFLib	
  
h+p://www.rdflib.net/	
  
	
  

C:	
  Redland	
  
h+p://librdf.org/	
  
Installing PHP
Mac OS:
https://netbeans.org/kb/docs/php/configure-phpenvironment-mac-os.html
Windows:
https://netbeans.org/kb/docs/php/configure-phpenvironment-windows.html
Create new PHP project
Install RAP
•  Download at:
http://wifo5-03.informatik.uni-mannheim.de/bizer/rdfapi/
•  Unpack the zip file.
•  Include RDF API into your scripts:
•  define("RDFAPI_INCLUDE_DIR", "C:/Apache/htdocs/rdf_api/
api/");
•  include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");

•  Change the constant RDFAPI_INCLUDE_DIR to the
directory in which you have unpacked the zip file.
PHP RAP: example
k.verbert@tue.nl
n.v.stash@tue.nl
g.l.fletcher@tue.nl

03/28/11
Sources
•  Konstantinos Tzonas. The Jena RDF Framework.

Mais conteúdo relacionado

Mais procurados

Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityApache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityWes McKinney
 
Dublin Core, the DCMI Abstract Model & DC Application Profiles
Dublin Core, the DCMI Abstract Model & DC Application ProfilesDublin Core, the DCMI Abstract Model & DC Application Profiles
Dublin Core, the DCMI Abstract Model & DC Application ProfilesEduserv Foundation
 
Using MongoDB as a high performance graph database
Using MongoDB as a high performance graph databaseUsing MongoDB as a high performance graph database
Using MongoDB as a high performance graph databaseChris Clarke
 
Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0Databricks
 
Implementing Semantic Search
Implementing Semantic SearchImplementing Semantic Search
Implementing Semantic SearchPaul Wlodarczyk
 
Data pipelines observability: OpenLineage & Marquez
Data pipelines observability:  OpenLineage & MarquezData pipelines observability:  OpenLineage & Marquez
Data pipelines observability: OpenLineage & MarquezJulien Le Dem
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
 
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Databricks
 
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...Databricks
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkIke Ellis
 
Vectors are the new JSON in PostgreSQL
Vectors are the new JSON in PostgreSQLVectors are the new JSON in PostgreSQL
Vectors are the new JSON in PostgreSQLJonathan Katz
 
SHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudSHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudRichard Cyganiak
 
Base NoSql et Python
Base NoSql et PythonBase NoSql et Python
Base NoSql et Pythonyboussard
 
02. Information solution outline template
02. Information solution outline template02. Information solution outline template
02. Information solution outline templateAlan D. Duncan
 
Securing SharePoint, OneDrive, & Teams with Sensitivity Labels
Securing SharePoint, OneDrive, & Teams with Sensitivity LabelsSecuring SharePoint, OneDrive, & Teams with Sensitivity Labels
Securing SharePoint, OneDrive, & Teams with Sensitivity LabelsDrew Madelung
 
The Real Cost of Slow Time vs Downtime
The Real Cost of Slow Time vs DowntimeThe Real Cost of Slow Time vs Downtime
The Real Cost of Slow Time vs DowntimeRadware
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In ElasticsearchKnoldus Inc.
 
Découverte du SPARQL endpoint de HAL
Découverte du SPARQL endpoint de HALDécouverte du SPARQL endpoint de HAL
Découverte du SPARQL endpoint de HALGautier Poupeau
 
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...Altinity Ltd
 

Mais procurados (20)

Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise NecessityApache Arrow: Open Source Standard Becomes an Enterprise Necessity
Apache Arrow: Open Source Standard Becomes an Enterprise Necessity
 
Dublin Core, the DCMI Abstract Model & DC Application Profiles
Dublin Core, the DCMI Abstract Model & DC Application ProfilesDublin Core, the DCMI Abstract Model & DC Application Profiles
Dublin Core, the DCMI Abstract Model & DC Application Profiles
 
Using MongoDB as a high performance graph database
Using MongoDB as a high performance graph databaseUsing MongoDB as a high performance graph database
Using MongoDB as a high performance graph database
 
Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0
 
Implementing Semantic Search
Implementing Semantic SearchImplementing Semantic Search
Implementing Semantic Search
 
Data pipelines observability: OpenLineage & Marquez
Data pipelines observability:  OpenLineage & MarquezData pipelines observability:  OpenLineage & Marquez
Data pipelines observability: OpenLineage & Marquez
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
Lessons from the Field: Applying Best Practices to Your Apache Spark Applicat...
 
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...
Presto: Fast SQL-on-Anything (including Delta Lake, Snowflake, Elasticsearch ...
 
Data Lake,beyond the Data Warehouse
Data Lake,beyond the Data WarehouseData Lake,beyond the Data Warehouse
Data Lake,beyond the Data Warehouse
 
Azure Databricks is Easier Than You Think
Azure Databricks is Easier Than You ThinkAzure Databricks is Easier Than You Think
Azure Databricks is Easier Than You Think
 
Vectors are the new JSON in PostgreSQL
Vectors are the new JSON in PostgreSQLVectors are the new JSON in PostgreSQL
Vectors are the new JSON in PostgreSQL
 
SHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data MudSHACL: Shaping the Big Ball of Data Mud
SHACL: Shaping the Big Ball of Data Mud
 
Base NoSql et Python
Base NoSql et PythonBase NoSql et Python
Base NoSql et Python
 
02. Information solution outline template
02. Information solution outline template02. Information solution outline template
02. Information solution outline template
 
Securing SharePoint, OneDrive, & Teams with Sensitivity Labels
Securing SharePoint, OneDrive, & Teams with Sensitivity LabelsSecuring SharePoint, OneDrive, & Teams with Sensitivity Labels
Securing SharePoint, OneDrive, & Teams with Sensitivity Labels
 
The Real Cost of Slow Time vs Downtime
The Real Cost of Slow Time vs DowntimeThe Real Cost of Slow Time vs Downtime
The Real Cost of Slow Time vs Downtime
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In Elasticsearch
 
Découverte du SPARQL endpoint de HAL
Découverte du SPARQL endpoint de HALDécouverte du SPARQL endpoint de HAL
Découverte du SPARQL endpoint de HAL
 
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
 

Semelhante a WebTech Tutorial Querying DBPedia

070517 Jena
070517 Jena070517 Jena
070517 Jenayuhana
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
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 SPARQLMariano Rodriguez-Muro
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLMyungjin Lee
 
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 pluginsearchbox-com
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenchesIsmail Mayat
 
Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Olaf Hartig
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)Jen Wong
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray testkopiczko
 
Web data from R
Web data from RWeb data from R
Web data from Rschamber
 

Semelhante a WebTech Tutorial Querying DBPedia (20)

070517 Jena
070517 Jena070517 Jena
070517 Jena
 
03 form-data
03 form-data03 form-data
03 form-data
 
SPARQLing cocktails
SPARQLing cocktailsSPARQLing cocktails
SPARQLing cocktails
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
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
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Data shapes-test-suite
Data shapes-test-suiteData shapes-test-suite
Data shapes-test-suite
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
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
 
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxeSFScon 2020 - Peter Hopfgartner - Open Data de luxe
SFScon 2020 - Peter Hopfgartner - Open Data de luxe
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
 
Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)Querying Linked Data with SPARQL (2010)
Querying Linked Data with SPARQL (2010)
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray test
 
Web data from R
Web data from RWeb data from R
Web data from R
 
How to use soap component
How to use soap componentHow to use soap component
How to use soap component
 
Practical OData
Practical ODataPractical OData
Practical OData
 

Mais de Katrien Verbert

Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Katrien Verbert
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveKatrien Verbert
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedKatrien Verbert
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedKatrien Verbert
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Katrien Verbert
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert usersKatrien Verbert
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsKatrien Verbert
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Katrien Verbert
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Katrien Verbert
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scaleKatrien Verbert
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningKatrien Verbert
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Katrien Verbert
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender SystemsKatrien Verbert
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLKatrien Verbert
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principlesKatrien Verbert
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionKatrien Verbert
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: IntroductionKatrien Verbert
 

Mais de Katrien Verbert (20)

Explainability methods
Explainability methodsExplainability methods
Explainability methods
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspective
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learned
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons Learned
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert users
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methods
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scale
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learning
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender Systems
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTML
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principles
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: Introduction
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: Introduction
 

Último

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Último (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

WebTech Tutorial Querying DBPedia

  • 1. Tutorial: Querying DBpedia Web Technology 2ID60 14 November 2013 Dr. Katrien Verbert Dr. ir. Natasha Stash Dr. George Fletcher
  • 2. Overview •  •  •  •  •  Introduction to Jena Setting up the environment Querying DBpedia Other APIs PHP example
  • 3. Jena •  Jena is a Java framework for the creation of applications for the Semantic Web •  Provides interfaces and classes for the creation and manipulation of RDF repositories
  • 5. Capabilities of Jena •  •  •  •  RDF API Reading and writing in RDF/XML, N-Triples In-memory and persistent storage SPARQL query engine
  • 6. RDF concepts •  The Jena RDF API contains classes and interfaces for every important aspect of the RDF specification •  They can be used in order to construct RDF graphs from scratch, or edit existent graphs •  These classes/interfaces reside in the com.hp.hpl.jena.rdf.model package •  In Jena, the Model interface is used to represent RDF graphs •  Through Model, statements can be obtained/ created/ removed etc
  • 7. RDF concepts // Create an empty model Model model = ModelFactory.createDefaultModel(); String ns = new String("http://www.example.com/example#"); // Create two Resources Resource john = model.createResource(ns + "John"); Resource jane = model.createResource(ns + "Jane"); // Create the 'hasBrother' Property declaration Property hasBrother = model.createProperty(ns, "hasBrother"); // Associate jane to john through 'hasBrother' jane.addProperty(hasBrother, john); // Create the 'hasSister' Property declaration Property hasSister = model.createProperty(ns, "hasSister"); // Associate john and jane through 'hasSister' with a Statement Statement sisterStmt = model.createStatement(john, hasSister, jane); model.add(sisterStmt);
  • 8. SPARQL query processing •  Jena uses the ARQ engine for the processing of SPARQL queries •  The ARQ API classes are found in com.hp.hpl.jena.query •  Basic classes in ARQ: •  Query: Represents a single SPARQL query. •  Dataset: The knowledge base on which queries are executed (Equivalent to RDF Models) •  QueryFactory: Can be used to generate Query objects from SPARQL strings •  QueryExecution: Provides methods for the execution of queries •  ResultSet: Contains the results obtained from an executed query •  QuerySolution: Represents a row of query results. •  If there are many answers to a query, a ResultSet is returned after the query is executed. The ResultSet contains many QuerySolutions
  • 9. SPARQL query processing // Prepare query string String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>n" + "PREFIX : <http://www.example.com/onto1#>n" + "SELECT ?married ?spouse WHERE {" + "?married rdf:type :MarriedPerson.n" + "?married :hasSpouse ?spouse." + "}"; // Use the ontology model to create a Dataset object // Note: If no reasoner has been attached to the model, no results // will be returned (MarriedPerson has no asserted instances) Dataset dataset = DatasetFactory.create(ontModel); // Parse query string and create Query object Query q = QueryFactory.create(queryString); // Execute query and obtain result set QueryExecution qexec = QueryExecutionFactory.create(q, dataset); ResultSet resultSet = qexec.execSelect();
  • 10. SPARQL query processing // Print results while(resultSet.hasNext()) { // Each row contains two fields: ‘married’ and ‘spouse’, // as defined in the query string QuerySolution row = (QuerySolution)resultSet.next(); RDFNode nextMarried = row.get("married"); System.out.print(nextMarried.toString()); System.out.print(" is married to "); RDFNode nextSpouse = row.get("spouse"); System.out.println(nextSpouse.toString()); }
  • 12. Overview •  •  •  •  Introduction to Jena Setting up the environment Querying Dbpedia Other APIs
  • 13. Setting up the environment Download Netbeans Java EE version: https://netbeans.org/downloads/
  • 16. Getting started with Jena in Netbeans Create a new Java project
  • 17. Create a Java project
  • 18. Add Jena libraries to class path
  • 19. Add Jena libraries to class path
  • 20. Add all jars in lib folder of Jena distribution
  • 21. Add all jars in lib folder
  • 22. Using Jena with Eclipse •  http://www.iandickinson.me.uk/articles/jena-eclipsehelloworld/
  • 24. Overview •  •  •  •  Introduction to Jena Setting up the environment Querying Dbpedia Other APIs
  • 25. QueryFactory •  has various create() methods to read a textual query •  these create() methods •  return a Query object, •  which encapsulates a parsed query.
  • 26. QueryExecutionFactory Create a QueryExecution that will access a SPARQL service over HTTP QueryExecutionFactory.sparqlService(String service, Query query)
  • 28. Example String service = "http://dbpedia.org/sparql"; String query = "ASK { }"; QueryExecution qe = QueryExecutionFactory.sparqlService(service, query);
  • 29. Test connection import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; public class QueryTest { public static void main(String[] args) { String service = "http://dbpedia.org/sparql"; String query = "ASK { }"; QueryExecution qe = QueryExecutionFactory.sparqlService(service, query); try { if (qe.execAsk()) { System.out.println(service + " is UP"); } // end if } catch (QueryExceptionHTTP e) { System.out.println(service + " is DOWN"); } finally { qe.close(); } } }
  • 31. Example query: people who were born in Eindhoven String service="http://dbpedia.org/sparql"; String query="PREFIX dbo:<http://dbpedia.org/ontology/>" + "PREFIX : <http://dbpedia.org/resource/>" + "select ?person where {?person dbo:birthPlace :Eindhoven.}"; QueryExecution qe=QueryExecutionFactory.sparqlService(service, query); ResultSet rs=qe.execSelect(); while (rs.hasNext()){ QuerySolution s=rs.nextSolution(); System.out.println(s.getResource("?person").toString()); } 03/28/11
  • 32. Processing results QuerySolution soln = results.nextSolution() ; RDFNode x = soln.get("varName") ; // Get a result variable by name. Resource r = soln.getResource("VarR") ; // Get a result variable - must be a resource Literal l = soln.getLiteral("VarL") ; // Get a result variable - must be a literal
  • 33. Example String service="http://dbpedia.org/sparql"; String query="PREFIX dbo:<http://dbpedia.org/ontology/>" + "PREFIX : <http://dbpedia.org/resource/>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "select ?person ?name where {?person dbo:birthPlace :Eindhoven." + "?person foaf:name ?name}"; QueryExecution qe=QueryExecutionFactory.sparqlService(service, query); ResultSet rs=qe.execSelect(); while (rs.hasNext()){ QuerySolution s=rs.nextSolution(); Resource r=s.getResource("?person"); Literal name=s.getLiteral("?name"); System.out.println(s.getResource("?person").toString()); System.out.println(s.getLiteral("?name").getString()); } 03/28/11
  • 34. Example query: people who were born in Berlin before 1900 PREFIX dbo: http://dbpedia.org/ontology/ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX : http://dbpedia.org/resource/ SELECT ?name ?birth ?death ?person WHERE { ?person dbo:birthPlace :Berlin . ?person dbo:birthDate ?birth . ?person foaf:name ?name . ?person dbo:deathDate ?death . FILTER (?birth < "1900-01-01"^^xsd:date) . } ORDER BY ?name
  • 35. Other APIs PHP:  RAP  –  RDF   h+p://www.seasr.org/wp-­‐content/plugins/meandre/rdfapi-­‐php/doc/     Python:  RDFLib   h+p://www.rdflib.net/     C:  Redland   h+p://librdf.org/  
  • 37. Create new PHP project
  • 38. Install RAP •  Download at: http://wifo5-03.informatik.uni-mannheim.de/bizer/rdfapi/ •  Unpack the zip file. •  Include RDF API into your scripts: •  define("RDFAPI_INCLUDE_DIR", "C:/Apache/htdocs/rdf_api/ api/"); •  include(RDFAPI_INCLUDE_DIR . "RDFAPI.php"); •  Change the constant RDFAPI_INCLUDE_DIR to the directory in which you have unpacked the zip file.
  • 41. Sources •  Konstantinos Tzonas. The Jena RDF Framework.