sparql with qualitative & quantitative preferences marina gueroussova axel polleres* sheila a....
TRANSCRIPT
SPARQL with Qualitative & Quantitative Preferences
Marina Gueroussova Axel Polleres* Sheila A. McIlraithDepartment of Computer Science, University of Toronto* Vienna University of Economics and Business (WU Wien), Contact: @AxelPolleres
OrdRing2013 October 21, 20131
MotivationSPARQL Data:•Massive•Produced, shared, consumed by diversity of stakeholders•Dynamically integrated•Scope of content often unknown:
Queries can lead to the “empty result effect” (no answer) and its opposite “flooding effect” (too many answers), resulting in a time consuming and frustrating manual/iterative search
Consider searching for a car to buy – one might prefer a car with a powerful engine, but only if it’s a hybrid, or failing that an electric car if it’s under a certain price … ideally silver, rear camera, but these are less important …
2Preferences!Preferences!
Challenge: How do we specify and generate preference-based queries in SPARQL
3
Rich LiteraturePreferences have been long studies across many fields including economics, philosophy, and computer science.
Databases (preferences in relational queries & SQL, top-K), e.g. :•Chomicki (2002,2003,2011)•Kießling, Endres &Wenzel (2011) , Kießling&Köstler (2002), Kießling (2002),
AI (decision theory in AI, CP nets, preference-based planning), e.g.:•Domshlak, Hullermeier, Kaci & Prade (2011)•Boutilier, Brafman, Domshlak, Hoos & Poole (2004)
Semantic Web & Linked Data (top-k, qualitative preferences), e.g.:•Siberski, Pan & Thaden (2006)•Wagner, Tran, Ladwig, Harth & Studer (2012)•Magliacane, Bozzon & Della Valle (2011, 2012)
4
Rich LiteraturePreferences have been long studies across many fields including economics, philosophy, and computer science.
Databases (preferences in relational queries & SQL, top-K), e.g. :•Chomicki (2002,2003,2011)•Kießling, Endres &Wenzel (2011) , Kießling&Köstler (2002), Kießling (2002),
AI (decision theory in AI, CP nets, preference-based planning), e.g.:•Domshlak, Hullermeier, Kaci & Prade (2011)•Boutilier, Brafman, Domshlak, Hoos & Poole (2004)
Semantic Web & Linked Data (top-k, qualitative preferences), e.g.:•Siberski, Pan & Thaden (2006)•Wagner, Tran, Ladwig, Harth & Studer (2012)•Magliacane, Bozzon & Della Valle (2011, 2012) 5
Contributions • Extend SPARQL Syntax to handle qualitative and quantitative
preferences queries
• Demonstrate that qualitative and conditional preferences can be natively expressed in SPARQL (both 1.0 and 1.1)
• Illustrate how queries can be rewritten into standard compliant SPARQL queries via filtering. (Contrary to an earlier conjecture predicated on a less expressive SPARQL.)
• Discuss avenues for future work
6
Outline
• Example
• PrefSPARQL Grammar
• Query Rewriting
• Future Work
7
Outline
• Example
• PrefSPARQL Grammar
• Query Rewriting
• Future Work
8
Example *
9
<#mary>
excellent
<#appointmt1>
<#appointmt2>
<#appointmt3>
<#appointmt4>
<#appointmt5>
rated
very-good
<#john>
rated
Tue
1500
1555
Sun
1600
1655
Sun
1600
1655
Mon
1900
1955
Sat
1800
1855
* Modified from [Siberski et al., 2006]
offers
offers
offers
offers
offers
daystartsend
daystartsend
daystartsend
daystartsend
daystartsend
Example (cont.):mary a :therapist ;
:rated :excellent ; :offers :appointmt1, :appointmt2, :appointmt3 .
:john a :therapist ; :rated :very-good ;
:offers :appointmt4, :appointmt5 .
:appointmt1 :day "Tue"; :starts 1500; :ends 1555.:appointmt2 :day "Sun"; :starts 1600; :ends 1655.:appointmt3 :day "Fri"; :starts 1700; :ends 1755.:appointmt4 :day "Sat"; :starts 1800; :ends 1855.:appointmt5 :day "Mon"; :starts 1900; :ends 1955.
10
Example QueriesQUERY 1:Return all therapist appointments with the following preferences:
Prefer excellent therapists.Prefer appointments around lunchtime (between 12:00 and 13:00).Prefer later appointments over earlier ones provided that both are equal with respect to lunchtime.
This is a so-called skyline query that returns an undominated solution.
QUERY 2: Return all appointments with the following preferences:
Prefer appointments before 6pm on weekends (Sat & Sun) and appointments after 6pm on weekdays.
11
How do we specify preference-based queries in SPARQL?
13
PrefSPARQL GrammarFilter ::= 'FILTER' Constraint | 'PREFERRING' '(' MultidimensionalPref ')'MultidimensionalPref ::= PrioritizedPref ('AND' PrioritizedPref)*PrioritizedPref ::= ConditionalOrAtomicPref ('PRIOR TO' ConditionalOrAtomicPref)*ConditionalOrAtomicPref ::= ConditionalPref | AtomicPrefConditionalPref ::= 'IF' Expression 'THEN' ConditionalOrAtomicPref 'ELSE' ConditionalOrAtomicPrefAtomicPref ::= Expression | HighestPref | LowestPref | BetweenPref | AroundPref | MoreThanPref | LessThanPrefHighestPref ::= 'HIGHEST' ExpressionLowestPref ::= 'LOWEST' ExpressionBetweenPref ::= Expression 'BETWEEN' '(' Expression ',' Expression ')'AroundPref ::= Expression 'AROUND' ExpressionMoreThanPref ::= Expression 'MORE THAN' ExpressionLessThanPref ::= Expression 'LESS THAN' Expression
14
PrefSPARQL GrammarFilter ::= 'FILTER' Constraint | 'PREFERRING' '(' MultidimensionalPref ')'MultidimensionalPref ::= PrioritizedPref ('AND' PrioritizedPref)*PrioritizedPref ::= ConditionalOrAtomicPref ('PRIOR TO' ConditionalOrAtomicPref)*ConditionalOrAtomicPref ::= ConditionalPref | AtomicPrefConditionalPref ::= 'IF' Expression 'THEN' ConditionalOrAtomicPref 'ELSE' ConditionalOrAtomicPrefAtomicPref ::= Expression | HighestPref | LowestPref | BetweenPref | AroundPref | MoreThanPref | LessThanPrefHighestPref ::= 'HIGHEST' ExpressionLowestPref ::= 'LOWEST' ExpressionBetweenPref ::= Expression 'BETWEEN' '(' Expression ',' Expression ')'AroundPref ::= Expression 'AROUND' ExpressionMoreThanPref ::= Expression 'MORE THAN' ExpressionLessThanPref ::= Expression 'LESS THAN' Expression
15
PrefSPARQL Grammar (Query 1)…PrioritizedPref ::= ConditionalOrAtomicPref ('PRIOR TO' ConditionalOrAtomicPref)* ConditionalOrAtomicPref ::= ConditionalPref | AtomicPref…AtomicPref ::= Expression | HighestPref | LowestPref | BetweenPref | AroundPref | MoreThanPref | LessThanPref…BetweenPref ::= Expression 'BETWEEN' '(' Expression ',' Expression ')'AroundPref ::= Expression 'AROUND' Expression…
17
SELECT ?A WHERE {?T :rated ?R; offers ?A. ?A starts ?S; :end ?E.PREFFERING { ?R = excellent AND
{ ?S BETWEEN(1200,1300) AND ?E BETWEEN{1200,1300)PRIOR TO HIGHEST ?E } } }
PrefSPARQL Grammar (Query 2)…
ConditionalOrAtomicPref ::= ConditionalPref | AtomicPrefConditionalPref ::= 'IF' Expression 'THEN' ConditionalOrAtomicPref 'ELSE' ConditionalOrAtomicPref…
18
SELECT ?A WHERE { ?A :day ?D; :starts ?S. PREFERRING ( IF (?D = "Sat" || ?D = "Sun") THEN ?S < 1800 ELSE ?S >= 1800 ) }
Outline
• Example
• PrefSPARQL Grammar
• Query Rewriting
• Future Work
19
How do we generate preference-based queries using SPARQL query engines?
20
Approach• [Siberski et al. 2006] realized a subset of qualitative preferences in
SPARQL using solution modifiers. • It’s easy to imagine how to realize at least some of these references using
“stacked optionals”.• Contrary to the conjecture* in [Sibserski et al. 2006], we argue that our
PrefSPARQL queries can be expressed in SPARQL by the following high-level translation schema in SPARQL 1.1 **:
* Made in 2006, prior to the addition of OPTIONAL to SPARQL** There is a corresponding translation schema for SPARQL 1.0
21
P PREFERRING Pref
P FILTER NOT EXISTS {P’ FILTER (tr(P, P’, Pref))}
Rewriting (simplified version of) Query 1
22
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E .
PREFERRING ( (?R = excellent) AND ((?S >= 1800) || ?E <= 1600) PRIOR TO HIGHEST ?S ))}
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E . BIND ( (?R = :excellent) AS ?Pref1 ) BIND ( (?S >= 1800 || ?E <= 1600) AS ?Pref2 ) BIND ( ?S AS ?Pref3 )FILTER NOT EXISTS { ?T_ :rated ?R_; :offers ?A_. ?A_ :starts ?S_; :ends ?E_ . BIND ( (?R_ = :excellent) AS ?Pref1_ ) BIND ( (?S_ >= 1600 || ?E_ <= 1600) AS ?Pref2_ ) BIND ( ?S_ AS ?Pref3_ ) FILTER( ( (?Pref1_ > ?Pref1) && !((?Pref2_ < ?Pref2) || (?Pref3_ < ?Pref3 && ?Pref2 = ?Pref2_ ))) || ( !(?Pref1_ < ?Pref1) && ((?Pref2_ > ?Pref2) || (?Pref3_ > ?Pref3 && ?Pref2 = ?Pref2_ ))))}}
P PREFERRING Pref
P FILTER NOT EXISTS {P’ FILTER (tr(P, P’, Pref))}
Rewriting (simplified version of) Query 1
23
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E .
PREFERRING ( (?R = excellent) AND ((?S >= 1800) || ?E <= 1600) PRIOR TO HIGHEST ?S ))}
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E . BIND ( (?R = :excellent) AS ?Pref1 ) BIND ( (?S >= 1800 || ?E <= 1600) AS ?Pref2 ) BIND ( ?S AS ?Pref3 )FILTER NOT EXISTS { ?T_ :rated ?R_; :offers ?A_. ?A_ :starts ?S_; :ends ?E_ . BIND ( (?R_ = :excellent) AS ?Pref1_ ) BIND ( (?S_ >= 1600 || ?E_ <= 1600) AS ?Pref2_ ) BIND ( ?S_ AS ?Pref3_ ) FILTER( ( (?Pref1_ > ?Pref1) && !((?Pref2_ < ?Pref2) || (?Pref3_ < ?Pref3 && ?Pref2 = ?Pref2_ ))) || ( !(?Pref1_ < ?Pref1) && ((?Pref2_ > ?Pref2) || (?Pref3_ > ?Pref3 && ?Pref2 = ?Pref2_ ))))}}
tr(P,P’,Pref1 AND Pref23)(Pref1’ > Pref1 && Pref23’ < Pref23) || (Pref1’ < Pref1 && Pref23’ > Pref23 )
Rewriting (simplified version of) Query 1
24
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E .
PREFERRING ( (?R = excellent) AND ((?S >= 1800) || ?E <= 1600) PRIOR TO HIGHEST ?S ))}
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E . BIND ( (?R = :excellent) AS ?Pref1 ) BIND ( (?S >= 1800 || ?E <= 1600) AS ?Pref2 ) BIND ( ?S AS ?Pref3 )FILTER NOT EXISTS { ?T_ :rated ?R_; :offers ?A_. ?A_ :starts ?S_; :ends ?E_ . BIND ( (?R_ = :excellent) AS ?Pref1_ ) BIND ( (?S_ >= 1600 || ?E_ <= 1600) AS ?Pref2_ ) BIND ( ?S_ AS ?Pref3_ ) FILTER( ( (?Pref1_ > ?Pref1) && !((?Pref2_ < ?Pref2) || (?Pref3_ < ?Pref3 && ?Pref2 = ?Pref2_ ))) || ( !(?Pref1_ < ?Pref1) && ((?Pref2_ > ?Pref2) || (?Pref3_ > ?Pref3 && ?Pref2 = ?Pref2_ ))))}}
tr(P,P’,Pref2 PRIOR TO Pref3)(Pref2’ > Pref2) || (Pref3’ > Pref3 && Pref2’ = Pref2 )
Rewriting (simplified version of) Query 1
25
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E .
PREFERRING ( (?R = excellent) AND ((?S >= 1800) || ?E <= 1600) PRIOR TO HIGHEST ?S ))}
SELECT ?A WHERE { ?T :rated ?R; :offers ?A. ?A :starts ?S; :ends ?E . BIND ( (?R = :excellent) AS ?Pref1 ) BIND ( (?S >= 1800 || ?E <= 1600) AS ?Pref2 ) BIND ( ?S AS ?Pref3 )FILTER NOT EXISTS { ?T_ :rated ?R_; :offers ?A_. ?A_ :starts ?S_; :ends ?E_ . BIND ( (?R_ = :excellent) AS ?Pref1_ ) BIND ( (?S_ >= 1600 || ?E_ <= 1600) AS ?Pref2_ ) BIND ( ?S_ AS ?Pref3_ ) FILTER( ( (?Pref1_ > ?Pref1) && !((?Pref2_ < ?Pref2) || (?Pref3_ < ?Pref3 && ?Pref2 = ?Pref2_ ))) || ( !(?Pref1_ < ?Pref1) && ((?Pref2_ > ?Pref2) || (?Pref3_ > ?Pref3 && ?Pref2 = ?Pref2_ ))))}}
P PREFERRING Pref
P FILTER NOT EXISTS {P’ FILTER (tr(P, P’, Pref))}
FILTER NOT EXISTS can be emulated in SPARQL1.0 with
OPTIONAL + FILTER( !bound(...) )
expressible in SPARQL1.0!!
FILTER NOT EXISTS can be emulated in SPARQL1.0 with
OPTIONAL + FILTER( !bound(...) )
expressible in SPARQL1.0!!
Rewriting Query 2 (conditional preferences)
26
SELECT ?A WHERE { ?A :day ?D; :starts ?S. PREFERRING ( IF (?D = "Sat" || ?D = "Sun") THEN ?S < 1800 ELSE ?S >= 1800 ) }
SELECT ?A WHERE { ?A :day ?D; :starts ?S. BIND ( IF( (?D = "Sunday" || ?D = "Saturday"), ?S < 1800, ?S >= 1800) AS ?Pref1) FILTER NOT EXISTS { ?T_ :rated ?R_; :offers ?A_. ?A_ :day ?D_; :starts ?S_. BIND ( IF( (?D_ = "Sunday" || ?D_ = "Saturday"), ?S_ < 1800, ?S_ >= 1800) AS ?Pref1_) FILTER (?Pref1_ > ?Pref1)}}
IF E THEN Pref1 ELSE Pref2)IF(E, Pref1, Pref2)
Again: FILTER NOT EXISTS can be emulated in SPARQL1.0 with
OPTIONAL + FILTER( !bound(...) )
expressible in SPARQL1.0!!
Again: FILTER NOT EXISTS can be emulated in SPARQL1.0 with
OPTIONAL + FILTER( !bound(...) )
expressible in SPARQL1.0!!
Observe that these queries (use of NOT EXISTS, i.e. OPTIONAL+!bound()) yield non-well-designed patterns [Perez et al., 2009], [Letelier et al., 2012].
27
Cost of rewriting?
SELECT ?Contact WHERE { me foaf:knows ?X OPTIONAL {?X foaf:mbox ?Contact} OPTIONAL {?X foaf:homepage ?Contact} }
Similar to well-known trick in in SPARQL to express preferences by simply “stacking optionals”…
… which is also non-well-designed
Summary of Contributions • Extend SPARQL Syntax to handle qualitative and quantitative
preferences queries
• Demonstrate that qualitative and conditional preferences can be natively expressed in SPARQL (both 1.0 and 1.1)
• Illustrate how queries can be rewritten into standard compliant SPARQL queries via filtering. (Contrary to an earlier conjecture predicated on a less expressive version of SPARQL.)
28
Ongoing Work• Experimental evaluation of the efficacy of the rewriting approach
proposed here. • Further investigation of relaxation of the well-designedness principle,
which will enable efficient preference query evaluation.• Expanding scope to (better) deal with:
– Top-k queries– Ranking within skyline queries– Preferences over endpoints w/ SPARQL 1.1 Fedration extension– Express SPARQL endpoint preference (SERVICE patterns)– Interactions between preferences and Entailment Regimes [Glimm et
al. 2013]
29
Want to know more?
SPARQL with Qualitative and Quantitative Preferences (Extended Report) . Marina Gueroussova, Axel Polleres, Sheila A. McIlraith. Technical Report CSRG-619, Department of Computer Science, University of Toronto (October 2013).
ftp://ftp.cs.toronto.edu/csrg-technical-reports/619/
30
References• Craig Boutilier, Ronen I. Brafman, Carmel Domshlak, Holger H. Hoos, David Poole: CP-nets: A Tool for Representing and
Reasoning with Conditional Ceteris Paribus Preference StatementsJ. Artif. Intell. Res.(JAIR) 21, 135-191 (2004).• Jan Chomicki: Querying with Intrinsic Preferences. EDBT 2002: 34-51 (2002)• Jan Chomicki: Preference formulas in relational queries. ACM Trans. Database Syst. 28(4): 427-466 (2003)• Jan Chomicki: Logical Foundations of Preference Queries. IEEE Data Eng. Bull. 34(2): 3-10 (2011)• Carmel Domshlak, Eyke Hüllermeier, Souhila Kaci, Henri Prade: Preferences in AI: An overview. Artif. Intell. 175(7-8):
1037-1052 (2011)• Werner Kießling: Foundations of Preferences in Database Systems. VLDB 2002: 311-322 (2002)• Werner Kießling, Markus Endres, Florian Wenzel: The Preference SQL System - An Overview. IEEE Data Eng. Bull. 34(2):
11-18 (2011)• Werner Kießling, Gerhard Köstler: Preference SQL - Design, Implementation, Experiences. VLDB 2002: 990-1001 (2002)• Andrés Letelier, Jorge Pérez, Reinhard Pichler, Sebastian Skritek: Static analysis and optimization of semantic web
queries. PODS 2012: 89-100 (2012)• Sara Magliacane, Alessandro Bozzon, Emanuele Della Valle: Efficient Execution of Top-K SPARQL Queries.
International Semantic Web Conference (1) 2012 : 344-360 (2012)• Jorge Pérez, Marcelo Arenas, Claudio Gutierrez: Semantics and complexity of SPARQL. ACM Trans. Database Syst. 34(3)
(2009)• Wolf Siberski, Jeff Z. Pan, Uwe Thaden: Querying the Semantic Web with Preferences.
International Semantic Web Conference 2006 : 612-624 (2006)• Kostas Stefanidis, Georgia Koutrika, Evaggelia Pitoura: A survey on representation, composition and application of
preferences in database systems. ACM Trans. Database Syst. 36(3): 19 (2011)• Andreas Wagner, Duc Thanh Tran, Günter Ladwig, Andreas Harth, Rudi Studer: Top-k Linked Data Query Processing.
ESWC 2012: 56-71 (2012)31
32
Thank You. Questions?