1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey.

Slides:



Advertisements
Similar presentations
CH-4 Ontologies, Querying and Data Integration. Introduction to RDF(S) RDF stands for Resource Description Framework. RDF is a standard for describing.
Advertisements

Ontology Engineering Lab #8 October 21, Review - Trial Query Exercises  What are the bones of the foot? (not sure this can be done in a single.
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
RDF Tutorial.
A Visual Approach to Semantic Query Design Using a Web-Based Graphical Query Designer Paul R. Smart, Alistair Russell, Dave Braines, Yannis Kalfoglou,,
Jena Sparql 4/11/2017.
 Copyright 2004 Digital Enterprise Research Institute. All rights reserved. SPARQL Query Language for RDF presented by Cristina Feier.
Chapter 3 Querying RDF stores with SPARQL. TL;DR We will want to query large RDF datasets, e.g. LOD SPARQL is the SQL of RDF SPARQL is a language to query.
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
JOSH FLECK Semantic Web. What is Semantic Web? Movement led by W3C that promotes common formats for data on the web Describes things in a way that computer.
Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.
Semantic Web Bootcamp Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation.
Chapter 3A Semantic Web Primer 1 Chapter 3 Querying the Semantic Web Grigoris Antoniou Paul Groth Frank van Harmelen Rinke Hoekstra.
Logics for Data and Knowledge Representation SPARQL Protocol and RDF Query Language (SPARQL) Feroz Farazi.
RDF: Concepts and Abstract Syntax W3C Recommendation 10 February Michael Felderer Digital Enterprise.
Managing Large RDF Graphs (Infinite Graph) Vaibhav Khadilkar Department of Computer Science, The University of Texas at Dallas FEARLESS engineering.
RDF (Resource Description Framework) Why?. XML XML is a metalanguage that allows users to define markup XML separates content and structure from formatting.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Master Informatique 1 Semantic Technologies Part 5SPARQL Werner Nutt.
Practical RDF Chapter 1. RDF: An Introduction
CIS Computer Programming Logic
Introduction to SPARQL. Acknowledgements This presentation is based on the W3C Candidate Recommendation “SPARQL Query Language for RDF” from
Entity Recognition via Querying DBpedia ElShaimaa Ali.
RDF Query language The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer” Dean Allemang, Jim Hendler, “Semantic Web.
SPARQL Semantic Web - Spring 2008 Computer Engineering Department Sharif University of Technology.
Logics for Data and Knowledge Representation
The Semantic Web Web Science Systems Development Spring 2015.
Chapter 3 Querying RDF stores with SPARQL. Why an RDF Query Language? Why not use an XML query language? XML at a lower level of abstraction than RDF.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
The Jena RDF Framework Konstantinos Tzonas. Contents What is Jena Capabilities of Jena Basic notions RDF concepts in Jena Persistence Ontology management.
SPARQL W3C Simple Protocol And RDF Query Language
Ontology Query. What is an Ontology Ontologies resemble faceted taxonomies but use richer semantic relationships among terms and attributes, as well as.
SPARQL AN RDF Query Language. SPARQL SPARQL is a recursive acronym for SPARQL Protocol And Rdf Query Language SPARQL is the SQL for RDF Example: PREFIX.
SPARQL All slides are adapted from the W3C Recommendation SPARQL Query Language for RDF Web link:
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
Coastal Atlas Interoperability - Ontologies (Advanced topics that we did not get to in detail) Luis Bermudez Stephanie Watson Marine Metadata Interoperability.
JSON Java Script Object Notation Copyright © 2013 Curt Hill.
RQL: RDF Query language Jianguo Lu University of Windsor The following slides are from Grigoris Antoniou, Frank van Harmelen, “A Semantic Web Primer”
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
Semantically Processing The Semantic Web Presented by: Kunal Patel Dr. Gopal Gupta UNIVERSITY OF TEXAS AT DALLAS.
1 Artificial Intelligence Applications Institute Centre for Intelligent Systems and their Applications Stuart Aitken Artificial Intelligence Applications.
Practical RDF Chapter 10. Querying RDF: RDF as Data Shelley Powers, O’Reilly SNU IDB Lab. Hyewon Lim.
Organization of the Lab Three meetings:  today: general introduction, first steps in Protégé OWL  November 19: second part of tutorial  December 3:
User Profiling using Semantic Web Group members: Ashwin Somaiah Asha Stephen Charlie Sudharshan Reddy.
Of 33 lecture 1: introduction. of 33 the semantic web vision today’s web (1) web content – for human consumption (no structural information) people search.
Practical RDF Ch.10 Querying RDF: RDF as Data Taewhi Lee SNU OOPSLA Lab. Shelley Powers, O’Reilly August 27, 2004.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 5 1COMP9321, 15s2, Week.
05/01/2016 SPARQL SPARQL Protocol and RDF Query Language S. Garlatti.
Chapter 3 Querying RDF stores with SPARQL
Alexandra Cristea 1.  pronounced "sparkle“  recursive acronym for: ◦ SPARQL Protocol and RDF Query Language  a semantic query language  a query language.
Of 38 lecture 6: rdf – axiomatic semantics and query.
RDF & SPARQL Introduction Dongfang Xu Ph.D student, School of Information, University of Arizona Sept 10, 2015.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
An Effective SPARQL Support over Relational Database Jing Lu, Feng Cao, Li Ma, Yong Yu, Yue Pan SWDB-ODBIS 2007 SNU IDB Lab. Hyewon Lim July 30 th, 2009.
CC L A W EB DE D ATOS P RIMAVERA 2015 Lecture 7: SPARQL (1.0) Aidan Hogan
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
 CONACT UC:  Magnific training   
NEDA ALIPANAH, MARIA ADELA GRANDO DBMI 11/19/2012.
OWL (Ontology Web Language and Applications) Maw-Sheng Horng Department of Mathematics and Information Education National Taipei University of Education.
Vincenzo Maltese, Fausto Giunchiglia University of Trento
CC La Web de Datos Primavera 2017 Lecture 7: SPARQL [i]
SPARQL.
Introduction to SPARQL
SPARQL SPARQL Protocol and RDF Query Language
SPARQL: A query language for RDF
Logics for Data and Knowledge Representation
Built in Fairfield County: Front End Developers Meetup
CC La Web de Datos Primavera 2016 Lecture 7: SPARQL (1.0)
Logics for Data and Knowledge Representation
Presentation transcript:

1 Ontology Query and Reasoning Payam Barnaghi Institute for Communication Systems (ICS) Faculty of Engineering and Physical Sciences University of Surrey Spring 2015 Lecture 8: Mobile Applications and Web Services module

2 Query Languages −We have discussed data models and semantics for XML/RDF and OWL. −This week: query languages for the semantic metadata and Ontologies. −There have been several proposed languages for querying RDF data such as RQL, SeRQL, RDQL, etc. −SPARQL is a W3C Recommendation that contains: −A query language −a data access protocol to define simple HTTP and SOAP protocols for querying remote data repositories −XML, JSON, CSV, TSV formats in which query results will be returned

3 SPARQL Query Language −SPARQL consists of the following components: −Graph Patterns −Consist of combinations of triple patterns (one or more subject, predicate and objects, replaced by variables) −Variables are denoted as: ? −Identify a subset of the RDF graph which need to be retrieved. −RDF dataset −Several RDF data stores can hold multiple RDF graphs; −RDF queries could involve information from more than one graph. −Solution modifiers −The query patterns generate an unordered collection of the results. −Solution modifiers are applied to create other sequences (order the results). −Query form −Query form such as SELECT, CONSTRUCT, ASK

4 Querying RDF data −RDF is a directed, labeled graph data format for representing information in the Web. −Most forms of the query languages contain a set of triple patterns. −Triple patterns are like RDF triples except that each of the subject, predicate and object may be a variable.

5 Graph Patterns −SPARQL queries can be used to formulate queries ranging from simple graph pattern matching to complex queries. −Graph Patterns are a subset of the main RDF graph. −A Graph Pattern is a set of triple patterns which are constructed by using variables instead of subjects, predicates or objects in an RDF graph.

6 Writing a Simple Query Data: "SPARQL Tutorial". Query: SELECT ?title WHERE { ?title. } Query Result: title "SPARQL Tutorial"

7 Graph Patterns - The (subject, p, o) is a pattern for what we are looking for; - with p and o as “unknowns” Source: Ivan Herman, W3C, Tutorial on Semantic Web Technologies, Trento, Italy, on the 14th December, 2005

8 Graph Patterns −The fundamental idea: generalise the approach of graph patterns: −the pattern contains unbound symbols −by binding the symbols (if possible), sub-graphs of the RDF graph are selected −if there is such a selection, the query returns the bound resources −SPARQL −is a programming language-independent query language; Source: Ivan Herman, W3C, Tutorial on Semantic Web Technologies, Trento, Italy, on the 14th December, 2005

9 Group Patterns SELECT ?p ?o WHERE {subject ?p ?o} The triplets in WHERE define the graph pattern, with ?p and ?o “unbound” symbols The query returns a list of matching p, o pairs Source: Ivan Herman, W3C, Tutorial on Semantic Web Technologies, Trento, Italy, on the 14th December, 2005

10 Group Graph Patterns −A group graph patter is a set of patterns in which all the patterns match using the same substitution. −Example: SELECT ?person, ?name,? friend WHERE { ?person foaf:name ?name. ?person foaf:knows ?friend. }

11 Group Graph Patterns – Multiple matches

12 SPARQL Example Returns: [["Total Members",100],["Total Members",200],…,["Full Members",10],…] Source: Ivan Herman, W3C, Tutorial on Semantic Web Technologies, Trento, Italy, on the 14th December, 2005 SELECT ?cat ?val WHERE { ?x rdf:value ?val. ?x category ?cat. }

13 Basic Queries −The example provided in SPARQL. −Using select-from-where −SELECT specifies the number and order of retrieved data. −WHERE is used to navigate through the data model. −FILTER imposes constraints on possible solutions

14 Value Constraints −Graph matching creates binding of variables. −It is possible to filter the results by constraining the allowable bindings of variables to RDF terms. −The restriction of results can be based on direct matching or, −Value constraints are defined in the form of boolean valued expressions.

15 Example: Value Constraints SELECT ?cat ?val WHERE { ?x rdf:value ?val. ?x category ?cat. FILTER(?val>=200). } Returns: [["Total Members",200],…,] Source: Ivan Herman, W3C, Tutorial on Semantic Web Technologies, Trento, Italy, on the 14th December, 2005

16 Example: Value Constraints Select ?name ?age WHERE { ?student unis:hasAge ?age. Filter (?age > 18). ?student unis:hasName ?name. } − Exercise 1: Show an ontology graph for the above example and also show two instances.

17 Restricting the Values of Strings −SPARQL FILTER functions like regex can test RDF literals. − regex matches only plain literals with no language tag. − regex can be used to match the lexical forms of other literals by using the str function.

18 Restricting the Values of Strings SPARQL 1.1 Overview, W3C Recommendation 21 March 2013,

19 Optional Graph Patterns −In normal graph pattern queries entire query pattern much match the solution sub- graph/triples. −It is however useful to be able to have queries that allow variables to be added to the query matching solutions when the information is available; −But not to have the matching rejected if some parts of the query does not match. −Optional matching provide this form of queries.

20 Example: Optional Graph Patterns Select ?name ?age WHERE { ?student hasName ?name. OPTIONAL {?student hasAge ?age. Filter (?age > 18)} }

21 Union Graph Patterns −The graph patterns can be combined in a SPARQL query. −A combination of patterns can contain several alternative graph patterns that may match to the query. −The keyword to create combination of alternative patterns in SPARQL is UNION.

22 Example: Union Graph Patterns SELECT ?name WHERE { { ?student hasName ?name ?student hasAge ?age FILTER (?age > 25) } UNION { ?student hasName ?name ?student hasCourse ?degree FILTER regex (?degree, “^undegraduate”) } What is wrong in this code?

23 Example: Union Graph Patterns SELECT ?name WHERE { { ?student name ?name. ?student age ?age. FILTER (?age > 25) } UNION { ?student name ?name. ?student course ?degree. FILTER regex (?degree, “^undegraduate”) } Correct form

24 Different query results formats supported by SPARQL 1.1

25 Different query results formats supported by SPARQL 1.1

26 Different query results formats supported by SPARQL 1.1

JavaScript Object Notation (JSON) −JSON is a lightweight format for data interchange. −JSON is designed to be easy for humans to read and write and also easy for machines to parse and generate. −JSON is built on two structures: −A collection of name/value pairs. −In different languages, this concept is defined as an object, record, struct, associative array, etc. −An ordered list of values. −In different languages, this is defined as an array, vector, list, etc. 27

JSON Syntax −JSON data is written as pairs of name/value. −A name/value pair includes a name field (written in double quotes), then a colon, and then followed by a value (written in double quotes); “ ” : “ ” -For example: {“moduleName” : “Mobile Apps”, “moduleCode“, “EEEM042”} 28

JSON Values −JSON values can be: −A number (integer or floating point) −A string (in double quotes) −A Boolean (true or false) −An array (in square brackets) −An object (in curly braces) −Null −JSON arrays are written inside square brackets. 29 Source:

JSON Example 30 XML JSON Source:

31 Logic and Inference −Logic is the discipline that studies the principles of reasoning −Formal languages for expressing knowledge −Well-understood formal semantics −Declarative knowledge: we describe what holds without caring about how it can be deduced −Automated reasoners can deduce (infer) conclusions from the given knowledge Source: A Semantic Web Primer, Grigoris Antoniou and Frank van Harmelen, MIT Press

32 An Inference Example prof(X)  faculty(X) faculty(X)  staff(X) prof(michael) We can deduce the following conclusions: faculty(michael) staff(michael) prof(X)  staff(X) Source: A Semantic Web Primer, Grigoris Antoniou and Frank van Harmelen, MIT Press

33 Querying RDF in JAVA −Using Jena API: − −The package com.hp.hpl.jena.query is the main application package. − Query - a class that represents the application query. It is a container for all the details of the query. Objects of class Query are normally created by calling one of the methods of QueryFactory methods which provide access to the various parsers. − QueryExecution - represents one execution of a query. − QueryExecutionFactory - a place to get QueryExecution instances − DatasetFactory - a place to make datasets, including making a DataSource (an updatable Dataset)

34 Jena API −For SELECT queries: − QuerySolution - A single solution to the query − ResultSet - All the QuerySolutions. An iterator. − ResultSetFormatter - turn a ResultSet into various forms; into text, into an RDF graph (Model, in Jena terminology) or as plain XML

35 Jena API Model model = ModelFactory.createDefaultModel();

36 Exercise 2 −Dataset: DBPedia −DBPedia is an RDF version of information from Wikipedia.DBPedia −DBPedia contains data derived from Wikipedia's infoboxes, category hierarchy, article abstracts, and various external links. −The DBpedia Ontology currently contains about 2,350,000 instances. The table below lists the number of instances for several classes within the ontology: −Class Instances −Resource (overall) 2,350,000 −Place 573,000 −Person 764,000 −Work 333,000 −Species 202,000 −Organisation 192,000

37 Exercise 2 −Find me 50 example concepts in the DBPedia dataset. SELECT DISTINCT ?concept WHERE { ?subject a ?concept. } LIMIT 50 −LIMIT limits the number of rows returned from a query. −ORDER BY for to order the results by one or more variables −OFFSET, used in conjunction with LIMIT and ORDER BY −takes a part of a sorted solution set (e.g. for paging) −The SPARQL keyword a is a shortcut for the common predicate rdf:type, giving the class of a resource. −The DISTINCT modifier eliminates duplicate rows within the results.

38 Exercise 2 −You can try dbpedia SPARQL queries at: − −For string matching you can use : −?label 'Guildford'. Instead of: −FILTER regex(str(?label), "^Guildford")

39 Exercise 2 Consider this sample query: PREFIX rdf: PREFIX rdfs: SELECT ?entity ?label WHERE { ?entity rdf:type. ?entity rdfs:label ?label. }

40 Exercise 2 1.Write a query to limit the results of the sample query to 10 instances? 2.Write a query to order the results by Label? 3.Write a query to select concepts that include “Guildford” in their labels? 4.Write a query to select latitude and longitude values for “Guildford” from dbpedia? - for this you need to visit the resource for “Guildford” on dbpedia. - Use this prefix for geo location: PREFIX geo: - The concept for Guildford on dbpedia:

41 Acknowledgments −SPARQL 1.1 Overview, W3C Recommendation 21 March 2013, −SPARQL Query Language for RDF, W3C Recommendation 15 January 2008,

42 Questions?