Download presentation
Presentation is loading. Please wait.
1
SPARQL for Querying PML Data Jitin Arora
2
Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts SELECT Query Solution Sequence Modifiers CONSTRUCT Query
3
Basic Concepts IRI: Internationalized Resource Identifier (RFC 3987). Generalization of URI – can contain characters from ISO 10646. Basic Graph Pattern: A triple like in RDF, except that each of the subject, predicate or object may be a variable.
4
Common Namespaces and Prefixes
5
SELECT Query - Concept SELECT WHERE is a list of the form ?x ?y is a graph pattern Result is a solution sequence There may be zero, one, or more solutions Each solution provides a set of bindings of variables to RDF terms In a basic graph pattern, all variables must have a binding in every solution A variable may be bound to a blank node. The scope of the blank node is the result set.
6
Specifying Literals - General Literals may be used in a basic graph pattern to match literals in data Language tags must be specified when matching a literal with a specific language, such as “literal”@en For typed literals, datatype must be specified using datatype IRI appended to the literal, introduced with the characters ^^ May be enclosed in either single or double quotes, or three single or double quotes
7
Specifying Literals – Numbers and Booleans Numbers can be specified without quotes and datatype and are interpreted as follows: Numbers without decimal points are interpreted as xsd:integer Numbers with decimal point are interpreted as xsd:decimal Numbers with exponents are interpreted as xsd:double Boolean values can also be written simply as true and false
8
Specifying Variables Variables are prefixed with either ? or $ Variable names start with a non-numeric character and can be a combination of numbers and alphabets Variables have global scope
9
Specifying Blank Nodes Blank nodes can be specified using the _:abc notation Blank nodes may also be specified using [] The [] may be used in triple pattern as [ :predicate :object] The above blank node may itself be the subject or object of a triple pattern Abbreviated blank node syntax can be combined with other abbreviations
10
Triple Patterns - Concept Subject, predicate, and object separated by whitespace Common subject for several statements can be indicated by ending the statements with ; instead of. Triples with common subject and predicate can list the objects as comma separated values
11
Specifying RDF Collections RDF collections can be specified using “(element1 element2...)” A collection specified in this way can be the subject or object of a statement Collections can be nested () is shorthand for rdf:nil
12
Other Constructs The word 'a' can be used as shorthand for rdf:type It must be in lower case for this notation
13
SELECT Query - Filters FILTER expressions may be used to restrict which terms are bound to variables Operators used in filter expressions are based on XPATH/XQUERY operators
14
Filter Expressions - Operators SPARQL Specific: bound, isIRI, isBlank, isLiteral, str, lang, datatype, RDFterm-equal (=), sameTerm, langMatches, regex Logical Connectives: OR (||), AND (&&) XPATH Tests: =, !=,, = XPATH Arithmetic: *, /, +, - XPATH Constructor Functions: xsd:boolean, xsd:double, xsd:float, xsd:decimal, xsd:integer, xsd:dateTime, xsd:string
15
Graph Patterns Basic Graph Patterns: set of triple patterns Group Graph Patterns: set of graph patterns Optional Graph Patterns: variables may not be bound Alternative Graph Patters: similar to logical OR Patterns on Named Graphs
16
Basic Graph Patterns A set of triple patterns All triple patterns must be satisfied (implicit AND)
17
Group Graph Patterns Basic graph pattern delimited with {} All triple patterns in all groups must be satisfied (implicit AND) Filters apply to the group in which they are specified
18
Optional Graph Patterns Adds solutions when matched, otherwise variable remains unbound
19
Alternative Graph Patterns Specified using the UNION keyword Triple is considered a solution if any of the alternative patterns match (OR)
20
Solution Sequence Modifiers ORDER BY clause to sort in ascending (ASC) or descending (DESC) order DISTINCT and REDUCED to select only unique solutions OFFSET to skip a specified number of solutions LIMIT to limit the number of solutions
21
Example: List All the NodeSets
22
Example: List All the Types of Conclusions
23
Example: List All the Sources for a NodeSet
24
Example: List All Assertions by CHIP
25
Example: List the Antecedents of a NodeSet
26
CONSTRUCT Query CONSTRUCT is a form of projection (like projection in the relational algebra) CONSTRUCT query returns an RDF graph Graph is built based on the template specified in the query
27
Acknowledgment Based on http://www.w3.org/TR/2008/REC-rdf- sparql-query-20080115/ Background image adapted from http://dragonartz.wordpress.com/2009/04/10/light -rays-with-sparkles-background-vector/
28
Jitin Arora jarora@miners.utep.edu http://trust.utep.edu/members/jarora/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.