<?xml version="1.0" encoding="UTF-8"?>
<TEI xml:space="preserve" xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 https://raw.githubusercontent.com/kermitt2/grobid/master/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
	<teiHeader xml:lang="en">
		<fileDesc>
			<titleStmt>
				<title level="a" type="main">Nested Constructs vs. Sub-Selects in SPARQL</title>
			</titleStmt>
			<publicationStmt>
				<publisher/>
				<availability status="unknown"><licence/></availability>
			</publicationStmt>
			<sourceDesc>
				<biblStruct>
					<analytic>
						<author>
							<persName><forename type="first">Axel</forename><surname>Polleres</surname></persName>
							<affiliation key="aff0">
								<orgName type="institution">Vienna University of Economics</orgName>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Juan</forename><surname>Reutter</surname></persName>
							<affiliation key="aff1">
								<orgName type="institution">Pontificia Universidad Católica de Chile and Center for Semantic Web research</orgName>
								<address>
									<country>CL</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Egor</forename><forename type="middle">V</forename><surname>Kostylev</surname></persName>
							<affiliation key="aff2">
								<orgName type="institution">University of Oxford</orgName>
								<address>
									<country key="GB">UK</country>
								</address>
							</affiliation>
						</author>
						<title level="a" type="main">Nested Constructs vs. Sub-Selects in SPARQL</title>
					</analytic>
					<monogr>
						<imprint>
							<date/>
						</imprint>
					</monogr>
					<idno type="MD5">F773BABE19D2AF511D04B1C7569B81E7</idno>
				</biblStruct>
			</sourceDesc>
		</fileDesc>
		<encodingDesc>
			<appInfo>
				<application version="0.7.2" ident="GROBID" when="2023-03-24T04:48+0000">
					<desc>GROBID - A machine learning software for extracting information from scholarly documents</desc>
					<ref target="https://github.com/kermitt2/grobid"/>
				</application>
			</appInfo>
		</encodingDesc>
		<profileDesc>
			<abstract>
<div xmlns="http://www.tei-c.org/ns/1.0"><p>The issue of subqueries in SPARQL has appeared in different papers as an extension point to the original SPARQL query language. Particularly, nested CONSTRUCT in FROM clauses are a feature that has been discussed as a potential input for SPARQL 1.1 which was resolved to be left out in favour of select subqueries under the-unproven-conjecture that such subqueries can express nested construct queries. In this paper, we show that it is indeed possible to unfold nested SPARQL construct queries into subqueries in SPARQL 1.1; our transformation, however, requires an exponential blowup in the nesting depth. This suggests that nested construct queries are indeed a useful syntactic feature in SPARQL that cannot compactly be replaced by subqueries.</p></div>
			</abstract>
		</profileDesc>
	</teiHeader>
	<text xml:lang="en">
		<body>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Introduction</head><p>SPARQL as a standard query language for the Semantic Web data has been the subject of many theoretical and practical works in over the last years. Upon version 1.0 of its standardisation, works have been published on its expressivity <ref type="bibr" target="#b1">[2,</ref><ref type="bibr" target="#b7">8,</ref><ref type="bibr" target="#b9">10,</ref><ref type="bibr" target="#b10">11]</ref> and on adding features, among others value creation and subqueries <ref type="bibr" target="#b1">[2,</ref><ref type="bibr" target="#b8">9]</ref>.</p><p>These features have been taken on board in version 1.1 of the SPARQL specification. The first feature corresponds to an extension of SPARQL select queries, allowing SELECT clauses to assign values (i.e., blank nodes, literals or IRIs) to particular variables, by means of a new keyword AS. But more importantly, SPARQL 1.1 now permits the use of subqueries, that is, select queries can be arbitrarily nested within WHERE clauses <ref type="bibr" target="#b3">[4,</ref><ref type="bibr">Section 12]</ref>.</p><p>To showcase these operators, let us start from the following simple SPARQL 1.0 query that essentially replaces all object values in a given graph with blank nodes: While nested select queries are allowed in SPARQL 1.1, other forms of subqueries such as nested CONSTRUCT queries in FROM clauses, as proposed in <ref type="bibr" target="#b1">[2,</ref><ref type="bibr" target="#b8">9]</ref>, were not included to the new specification under the-unproven-conjecture that select subqueries can express nested construct queries. <ref type="foot" target="#foot_0">5</ref>For instance, consider the following query Q that uses nested constructs:</p><p>CONSTRUCT { ?X ex:goodFriend ?Y } FROM { CONSTRUCT { ?U ex:friends ?V } WHERE { ?U foaf:knows ?V . ?U ex:worksWith ?V } } WHERE { ?X ex:friends ?Y . ?X ex:friends ?Z . ?Y ex:friends ?Z }.</p><p>The intention of this query is to construct first an RDF document where a person U is a friend of V if U knows V and U works together with V. This is done by means of the inner construct subquery of Q. In essence, we have replaced and rewritten each of the triples in the outer WHERE clause for the conditions in the inner construct query that give rise to these triples, as it is for instance commonly done in query rewriting using views <ref type="bibr" target="#b0">[1]</ref>.</p><p>But can this idea be generalised for all nested construct queries? That is, is it true that given any SPARQL query Q that uses nested CONSTRUCT one can find a query in SPARQL 1.1 (without nested CONSTRUCT) that is equivalent to Q? This question was considered in <ref type="bibr" target="#b6">[7]</ref>, with a positive answer for a restricted case of SPARQL queries where one disallows blank nodes in templates and only uses the functionalities in SPARQL 1.0. On the other hand, it was shown that there are some queries with nested CONSTRUCT that cannot be expressed as a SPARQL 1.0 query (this follows from the close connection between construct queries and data exchange <ref type="bibr" target="#b2">[3]</ref>). However, the results in <ref type="bibr" target="#b6">[7]</ref> consider a much weaker language, because they do not consider any of the SPARQL 1.1 operators, and in particular the binding of variables in SELECT subqueries.</p><p>In this paper we show that by allowing full SPARQL 1.1 one can indeed express nested construct queries, that is, in other words, the language of SPARQL 1.1 construct queries is composable. However, our result, just as <ref type="bibr" target="#b6">[7]</ref>, assumes set semantics, contrary to bag semantics in the specification. Also, our rewriting, even if polynomial when just one construct query is nested in another, is exponential in the depth of nesting. Moreover, it is quite cumbersome and unintuitive. Nevertheless, this is the first step in proving the conjecture that nested SELECT queries are indeed the right notion for subqueries in SPARQL. We do believe that looking at set semantics is a natural and important first step in the direction of this work.</p><p>The plan of this paper is as follows: after formalisation of SPARQL 1.1 in Section 2, we define the notion of composability in Section 3, present our rewriting in Section 4, and conclude in Section 5.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">SPARQL Algebra</head><p>We next recapitulate the SPARQL algebra as well as basic notions on RDF.</p><p>RDF Graphs Let I, L, and B be countably infinite pairwise disjoint sets of IRIs, literals, and blank nodes, respectively, where literals include numbers, strings, and Boolean values true and false. The set of (RDF) terms T is I ∪ L ∪ B. An (RDF) triple is an element (s, p, o) of (I ∪ B) × I × T where s is called the subject, p the predicate, and o the object. An (RDF) graph is a finite set of RDF triples.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>SPARQL Algebra Syntax</head><p>We concentrate on the core of SPARQL 1.1 and build upon the formalisation by <ref type="bibr" target="#b7">[8]</ref>. We distinguish three types of syntactic building blocksfilter expressions, patterns, and queries, built over terms T and an infinite set V = {?x, ?y, . . .} of variables, disjoint from T as defined next.</p><p>(Filter) expressions are defined inductively as follows: -all variables in V and all terms in I ∪ L are expressions, -bNode() and IRINode(b), for b ∈ B, are expressions, -if ?x is a variable in V then bound(?x) is an expression, -if R 1 is an expression then so are isBlank(R 1 ), isIRI(R 1 ) and isLiteral(R 1 ), -if also R 2 is an expression then so are (R</p><formula xml:id="formula_0">1 = R 2 ), (R 1 &lt; R 2 ), (¬R 1 ), (R 1 ∧ R 2 ), -if also R 3 is an expression, then so is if(R 1 , R 2 , R 3 ). We use expressions R 1 ∨ R 2 , R 1 → R 2 and R 1 ↔ R 2 as abbreviations for ¬(¬R 1 ∧ ¬R 2 ), ¬R 1 ∨ R 2 and (R 1 ∧ R 2 ) ∨ (¬R 1 ∧ ¬R 2 ), respectively. A triple pattern is a triple in (I ∪ L ∪ V) × (I ∪ V) × (I ∪ L ∪ V).</formula><p>Then, (graph) patterns are inductively defined as follows:</p><p>-a BGP, that is a possibly empty set of triple patterns, is a pattern; -if P 1 and P 2 are patterns, then so are P 1 AND P 2 and P 1 UNION P 2 ; -if also R is an expression, then P 1 FILTER R and P 1 OPT R P 2 are patterns; -if also ?x is a variable not appearing in P 1 , then</p><formula xml:id="formula_1">P 1 BIND R AS ?x is a pattern; -if also X is a set of variables, then SELECT X WHERE R is a pattern.</formula><p>If a pattern is of the form SELECT X WHERE R then the set of its free variables is X; otherwise, it is the union of the free variables of all its immediate subpatterns and, in case of P 1 BIND R AS ?x, of the singleton set {?x}.</p><p>Finally, there are several types of queries in SPARQL. Most commonly used and studied are select queries, which are just patterns in our formalisation. In this paper, however, we concentrate on construct queries of the form</p><formula xml:id="formula_2">CONSTRUCT H WHERE P,</formula><p>where H is a set of triples from (T ∪ V) × (I ∪ V) × (T ∪ V), called template, and P is a pattern. For S a pattern, condition, template, etc., let IRI(S), blank(S) and var(S) denote all the IRIs, blank nodes and variables, respectively, that appear in S.</p><p>The standard includes several other constructs besides the ones defined above. Some of them, such as subqueries in expressions (i.e., Exists in filters), VALUES and MINUS are easily (and polynomially) expressible, under set semantics, adopted here (see below), via the core operators <ref type="bibr" target="#b4">[5,</ref><ref type="bibr" target="#b5">6]</ref>. Others, such as the named graph operator GRAPH and property paths, are immaterial to our research and omitted for brevity. Finally, note that filter expression IRINode(b), whose intention is to create a fresh IRI for each blank node b, does not appear in SPARQL 1.1. However, this operator can be expressed in our formalisation, provided it additionally include the string concatenation operator as well as casting operators from strings to IRIs and back, which are present in the specification.</p><p>To distinguish SPARQL 1.1 as in the standard and our formalisation we denote S C the language of construct queries as in the latter.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>SPARQL Algebra Semantics</head><p>The semantics of patterns in S C is defined in terms of (solution) mappings, that is, partial functions µ from variables V to terms T. The domain of µ, denoted dom(µ), is the set of variables over which µ is defined. Mappings µ 1 and µ 2 are compatible, written µ 1 ∼ µ 2 , if µ 1 (?x) = µ 2 (?x) for each ?x in dom(µ 1 ) ∩ dom(µ 2 ). If µ 1 ∼ µ 2 , then µ 1 ∪ µ 2 is the mapping obtained by extending µ 1 according to µ 2 on all the variables in dom(µ 2 ) \ dom(µ 1 ).</p><p>The evaluation [[R]] µ of an expression R in S C with respect to a mapping µ is a value in T ∪ {error}, where error is a special symbol not in T, defined as follows:</p><p>- </p><formula xml:id="formula_3">[[?x]] µ is µ(?x) if ?x ∈ dom(µ)</formula><formula xml:id="formula_4">-[[isBlank(R 1 )]] µ , [[isIRI(R 1 )]] µ , and [[isLiteral(R 1 )]] µ are true if [[R 1 ]] µ ∈ B, [[R 1 ]] µ ∈ I, and [[R 1 ]] µ ∈ L, respectively, and false otherwise; -[[R 1 • R 2 ]] µ , for a comparison operator •, is [[R 1 ]] µ • [[R 2 ]] µ if [[R 1 ]] µ and [[R 2 ]] µ</formula><p>are both not error and of suitable types, or error otherwise; -</p><formula xml:id="formula_5">[[¬R 1 ]] µ is true if [[R 1 ]] µ = false, it is false if [[R 1 ]] µ = true, and it is error otherwise, while [[R 1 ∧ R 2 ]] µ is true if [[R 1 ]] µ = [[R 2 ]] µ = true, it is false if [[R 1 ]] µ or [[R 2 ]] µ is false, and it is error otherwise; -[[if(R 1 , R 2 , R 3 )]] µ = [[R 2 ]] µ if [[R 1 ]] µ = true, it is [[R 3 ]] µ if [[R 1 ]] µ = false,</formula><p>and error otherwise. The semantics of patterns over a graph G is defined as follows, where µ(P ) is the pattern obtained from P by replacing its variables according to µ:</p><p>-</p><formula xml:id="formula_6">[[P ]] G = µ : var(P ) → T | µ(P ) ⊆ G for a BGP P ; -[[P 1 AND P 2 ]] G = µ | µ 1 ∈ [[P 1 ]] G , µ 2 ∈ [[P 2 ]] G , µ = µ 1 ∪ µ 2 ; -[[P 1 UNION P 2 ]] G = [[P 1 ]] G ∪ [[P 2 ]] G ; -[[P 1 FILTER R]] G = µ | µ ∈ [[P 1 ]] G , [[R]] µ = true ; -[[P 1 OPT R P 2 ]] G = [[P 1 AND P 2 ]] G ∪ µ | µ ∈ [[P 1 ]] G , ∀µ 2 ∈ [[P 2 ]] G . µ ∼ µ 2 or [[R]] µ∪µ2 = false ; -[[P BIND R AS ?x]] G = µ | µ ∈ [[P ]] G , µ = µ ∪ {?x → [[R]] µ }, [[R]] µ = error ∪ µ | µ ∈ [[P ]] G , [[R]] µ = error ; -[[SELECT X FROM P 1 ]] G = µ | µ = µ | X , µ ∈ [[P 1 ]] G }, where µ | X is a restriction of µ to X.</formula><p>To define the semantics of construct queries in S C fix, for every template H and graph G, a family F (H, G) of renaming functions. This family contains, for every mapping µ from var(H) to T, an injective function f µ : blank(H) → B \ blank(G). These functions must have pairwise disjoint ranges (i.e., there are no b and b such that</p><formula xml:id="formula_7">f µ1 (b) = f µ2 (b ) for different µ 1 and µ 2 ). Then, [[CONSTRUCT H WHERE P ]] G = {µ(f µ (t)) | µ ∈ [[G]] P , t is a triple in H and µ(f µ (t)) is well-formed},</formula><p>where f µ is the corresponding renaming function for µ in F (H, G). Here, a triple is well-formed if it is indeed an RDF triple, that is, does not have a blank node as predicate, literal as subject, etc. <ref type="foot" target="#foot_1">6</ref>Note that we adopt set semantics, contrary to bag (multi-set) semantics in the specification. We leave the consideration of bag semantics for future work.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">Definitions and Problem Statement</head><p>In this paper we address the question of composability of SPARQL. Definition 1. A query language L with the same input and output domains D is composable if for any queries q 1 , q 2 ∈ L there is a query q ∈ L such that q 2 (q 1 (D)) = q(D) for any D ∈ D, where q (D ) is the output of a query q on an input D .</p><p>The language of SPARQL select queries does not satisfy the requirements in this definition, because its input domain is RDF graphs and its output domain is sets of mappings. However, the language of SPARQL construct queries does satisfy the requirements, because its inputs, the set of RDF graphs, are its outputs as well; therefore, this is the subject of inquiry of this paper.</p><p>Note, however, that whether</p><formula xml:id="formula_8">[[Q 2 ]] [[Q1]] G = [[Q]] G holds, for construct queries Q 1 , Q 2 and</formula><p>Q, depends on the particular blank-node generating functions in the definitions of the semantics of bNode() and construct templates. Since the intuitive meaning of blank nodes is to represent existentially quantified named nulls whose exact names are immaterial, we silently consider RDF graphs and sets of mappings up to isomorphism, that is, up to bijective renaming of blank nodes. In this way checking whether</p><formula xml:id="formula_9">[[Q 2 ]] [[Q1]] G is equivalent to [[Q]</formula><p>] G under such renaming does not depend on the particular choice of the generating functions.</p><p>As it is mentioned in the introduction, the question of composability of construct queries was considered in <ref type="bibr" target="#b6">[7]</ref>, and it was shown, using techniques from data exchange <ref type="bibr" target="#b2">[3]</ref>, that these queries are not composable. However, the language considered in this previous work is different from ours, because it includes neither the BIND operator nor the bNode() and IRINode(b) functions. The main result of this paper is the following theorem, which shows that the negative result does not extend to S C . Theorem 1. The language S C of construct queries is composable.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">Composability of Construct Queries</head><p>Consider the following queries in language S C described in Section 2.</p><formula xml:id="formula_10">Q 1 = CONSTRUCT H 1 WHERE P 1 , Q 2 = CONSTRUCT H 2 WHERE P 2 .</formula><p>In the rest of the paper we explain how to rewrite these queries to just one query</p><formula xml:id="formula_11">Q = CONSTRUCT H 2 WHERE P, also in S C , such that [[Q 2 ]] [[Q1]] G = [[Q]]</formula><p>G for any graph G. Since we apply Q 2 to the result of Q 1 , we call these queries the outer and the inner, respectively.</p><p>Note that the template of the rewriting Q is the template of the outer query Q 2 . The pattern P of Q is defined as P unif (P blank , P rew ) for patterns P unif , P blank , and P rew , with the former taking the latter two as parameters (i.e., subpatterns). Next we define these patterns and study their properties. It is important to mention that rewriting Q is always of polynomial size in the size of Q 1 and Q 2 (but the rewriting is exponential in the number of queries we nest in this fashion). Without loss of generality we assume that all local (not free) variables in different SELECT subpatterns of P 1 and P 2 have different names; and that var(P 1 )∩var(P 2 ) = ∅ (we can always achieve this by renaming). In what follows we denote the variables in var(P 1 ) and in var(P 2 ) by ?x and ?y, respectively (both possibly with subscripts). We also assume that P 2 does not use any BIND sub-patterns; it is possible to cover the general case by a construction similar to the one described below, but the notation becomes more elaborated.</p><p>We start with P blank . The idea of this pattern is to produce the same set of mappings as P 1 except that each of them is extended to new variables bound to fresh blank nodes, one variable for each blank node in H 1 . To this end, let ?b 1 , . . . , ?b l be fresh variables, for l the size of blank(H 1 ). Then</p><formula xml:id="formula_12">P blank = P 1 BIND bNode() AS ?b 1 . . . BIND bNode() AS ?b l .</formula><p>The following property of P blank follows from the definition of the BIND operator (recall that we consider sets of mappings up to renaming of blank nodes).</p><p>Lemma 1. For each mapping µ, let λ µ map each ?b i , 1 ≤ i ≤ l, to a fresh blank node. Then, for any graph G, we have that</p><formula xml:id="formula_13">[[P blank ]] G = {µ 1 | µ 1 = µ ∪ λ µ , µ ∈ [[P 1 ]] G }.</formula><p>For space reasons we cannot give a complete example of our construction, but we have uploaded one at http://web.ing.puc.cl/˜jreutter/construct/.</p><p>Our results confirm the fact that nested CONSTRUCT queries are, in theory, an unnecessary feature of SPARQL, at least concerning set semantics. However, our construction introduces a blowup when translating from nested CONSTRUCT to SPARQL 1.1, which can be exponential in the depth of nesting. We conjecture that this blowup is unavoidable in the worst case. But even if this blowup was not important, the rewriting appears to be a very deep and technical translation, and unfortunately it is not easy to discover the intentions of nested CONSTRUCT queries simply by looking at their translation. For this reason we believe that nested CONSTRUCT queries are actually a desired feature of SPARQL. As a future work we would like to investigate update queries in SPARQL. Since we conjecture that update queries can be expressed as nested construct queries, it would be conceivable that the former are also a replaceable (but welcome) addition of SPARQL 1.1.</p></div><figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_0"><head></head><label></label><figDesc>and error otherwise, while [[ ]] µ is for ∈ I∪L; -[[bNode()]] µ is a fresh blank node that does not appear in the queried graph G, while [[IRINode(b)]] µ = g(b), where g is an injective function from B to I\IRI(G); -[[bound(?x)]] µ is true if ?x ∈ dom(µ) and false otherwise;</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_0"><head></head><label></label><figDesc>The resulting graph is then queried by the WHERE clause of the outer query, which creates a graph of good friends: X is a good friend of Y if X and Y are friends and have another friend in common. With a little work one can see that query Q is indeed equivalent to the following SPARQL 1.1 query:</figDesc><table /><note>CONSTRUCT { ?X ex:goodFriend ?Y } WHERE { { SELECT ?X ex:friends AS ?W1 ?Y WHERE { ?X foaf:knows ?Y . ?X ex:worksWith ?Y } } . { SELECT ?X ex:friends AS ?W2 ?Z WHERE { ?X foaf:knows ?Z . ?X ex:worksWith ?Z } } . { SELECT ?Y ex:friends AS ?W3 ?Z WHERE { ?Y foaf:knows ?Z . ?Y ex:worksWith ?Z } } }.</note></figure>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="5" xml:id="foot_0">https://www.w3.org/2009/sparql/track/issues/7</note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="6" xml:id="foot_1">Note that this can be achieved by extending P with the respective FILTER expressions.</note>
		</body>
		<back>
			<div type="annex">
<div xmlns="http://www.tei-c.org/ns/1.0"><p>Having P blank at hand we define pattern P rew . Its intention is to be a rewriting of P 2 such that it works not over the result of Q 1 , but over the original input graph. For any input graph, its answer, that is, its output set of mappings, coincides with the answer of P 2 , except that, first, the mappings are extended to some additional variables (e.g., all projections are discarded), and, second, instead of blank nodes constructed by Q 1 the answer to P rew has the corresponding IRIs IRINode(b) in the ranges of its mappings. Note, however, that blank nodes b here are from template H 1 and not the blank nodes f µ (b) in the result of Q 1 , so it could be several f µ (b) for each IRINode(b) (more precisely, one for each µ in the evaluation of P ). Replacing IRINode(b) with f µ (b) is done by the third part P unif of P , which takes into account both patterns P blank and P rew .</p><p>Consider any occurrence p of a triple pattern (s 1 , s 2 , s 3 ) in pattern P 2 . Note that we consider each occurrence, not just each triple pattern: for example the two occurrences in (?x, ?y, ?z) AND (?x, ?y, ?z) are considered separately. Let ρ p be a renaming function that maps each free variable ?x of P 1 to a fresh variable ?x p and let π p be a renaming function that maps each ?y ∈ var(p) to a fresh variable ?y p . Assuming that ρ p extends to IRIs and literals as identity, let ρ blank p further extend ρ p to each blank node b as IRINode(b). For each triple t = (r 1 , r 2 , r 3 ) in template H 1 let P sub (t, p) = P 3 , with patterns P i , i = 1, 2, 3, defined as follows, taking P 0 as ρ p (P 1 ):</p><p>-if s i is a variable in V that is different from all s 1 , . . . , s i−1 then</p><p>-if s i is a variable that is equal to some s j for 1 ≤ j &lt; i then</p><p>For example, if p = (?y 1 , ?y 2 , ?y 3 ) and t = (?x 1 , ?x 2 , b) then P sub (t, p) is ρ p (P 1 ) BIND ?x 1 p AS ?y 1 p BIND ?x 2 p AS ?y 2 p BIND IRINode(b) AS ?y 3 p , while if p = (?y 1 , , ?y 1 ) and t = (?x 1 , ?x 2 , ?x 3 ) then P sub (t, p) is ρ p (P 1 ) BIND ?x 1 p AS ?y 1 p FILTER ?x 2 p = FILTER ?x 3 p = ?y 1 p .</p><p>Let p = (s 1 , s 2 , s 3 ) be an occurrence of triple pattern in P 2 as above, and H 1 = t 1 , . . . , t m . Then let P p be the pattern</p><p>where ?y 1 , . . . , ?y k are all the variables among s 1 , s 2 , and s 3 .</p><p>Patterns P p are rewritings of all particular occurrences p of triple patterns in pattern P 2 . The rewritings of different occurences, however, have no variables in common by construction. Therefore, we introduce a condition R join (p 1 , p 2 , ?y) for any two occurrences of triple patterns p 1 and p 2 in P 2 that share a variable ?y, that is defined as follows, for all the blank nodes b 1 , . . . , b l in blank(H 1 ):</p><p>where ?x 1 , . . . , ?x n are all the free variables of P 1 and ?x 1 ∼ ?x 2 is the condition</p><p>The idea of R join (p 1 , p 2 , ?y) is as follows: if both of ?y p 1 and ?y p 2 are defined and mapped to usual IRIs, literals or blank nodes, then they should be the same; if they are defined and mapped to some IRINode(b i ), then they should be not only the same, but also be associated to exactly the same mapping in the answer to the inner pattern. We now define the rewriting P rew of P 2 by structural induction, and start with conditions. To this end, the rewriting Rew(R ) of a condition R in P 2 is obtained from R by the following two steps, for b 1 , . . . , b l all the blank nodes of H 1 and p 1 , . . . , p k all the occurrences of triple patterns of P 2 that mention ?y:</p><p>1. replace each isBlank(?y) by the expression</p><p>2. replace each variable ?y by the expression if(bound(?y p 1 ), ?y p 1 , if(bound(?y p 2 ), ?y p 2 , . . . , if(bound(?y p k−1 ), ?y p k−1 , ?y p k ) . . .)).</p><p>Finally, the rewriting Rew(P ) for any subpattern P of P 2 (including occurrences of triple patterns) is defined as follows:</p><p>-if P is the empty BGP P ∅ then Rew(P ) = P ∅ , -if P is a singleton BGP {p} then Rew(P ) = P p , -if P is a BGP {p 1 , . . . , p k } for k &gt; 1 then Rew(P ) = Rew({p 1 } AND • • • AND {p k }) (see below), -if P = P 1 ANDP 2 then Rew(P ) = (Rew(P 1 )ANDRew(P 2 )) FILTER R, where R is a conjunction of R join (p 1 , p 2 , ?y) for each triple pattern p 1 in P 1 and each triple pattern p 2 in P 2 such that p 1 and p 2 have a common variable, as well as for each their common variable ?y, -if P = P 1 OPT R P 2 then Rew(P ) = Rew(P 1 ) OPT Rew(R )∧R Rew(P 2 ), where R is as in the case of AND, -if P = P 1 UNION P 2 then Rew(P ) = Rew(P 1 ) UNION Rew(P 2 ),</p><p>The first important property of P rew is given in the following lemma. Let P * 2 be obtained from P 2 by replacing each subpattern SELECT X WHERE P by P , that is, by disregarding all projections (recall that we assume local variables in different subpatterns to have different names).</p><p>Lemma 2. For any graph G, mapping µ ∈ [[P rew ]] G , variable ?y ∈ Vars(P * 2 ) and triple patterns p 1 , p 2 of P 2 that mention ?y, if both ?y p 1 and ?y p 2 are bound by µ then µ(?y p 1 ) = µ(?y p 2 ).</p><p>Let us extend, for technical reasons, the set of terms to all pairs [b, µ 1 ] for all blank nodes b in H 1 and mappings µ 1 . Then, having this definition and Lemma 2 at hand, we can "gather" every mapping µ ∈ [[P rew ]] G to its gathering mapping μ as follows, for every ?y ∈ Vars(P *</p><p>2 ): -?y is bound in μ if and only if one of ?y p 1 , . . . , ?y p k is bound in µ, where p 1 , . . . , p k are all triple patterns of P 2 that mention ?y; -if i is such that ?y p i is bound and ?y p i = IRINode(b) for some b ∈ blank(H 1 ) then μ(?y) = [b, σ(µ|</p><p>, where X p i = x 1 p i , . . . , x n p i is the copy of the free variables x 1 , . . . , x n of P 1 corresponding to p i and σ is the renaming of each x j p i to x j ; -if i is such that ?y p i is bound and ?y p i = IRINode(b) for any b ∈ blank(H 1 ) then μ(?y) = µ(?y p i ).</p><p>The second property of P rew is as follows.</p><p>Lemma  Having this lemma at hand, we can define the pattern P unif (P blank , P rew ). To this end, let Y = ?y 1 , . . . , ?y m be all the free variables of P 2 and let P i , 1 ≤ i ≤ m, be defined as follows, taking P 0 = P blank AND P rew :</p><p>where V ?y i is the following condition, for b 1 , . . . , b l all the blank nodes of H 1 : if(S ?y i = IRINode(b 1 ), ?b 1 , . . . if(S ?y i = IRINode(b l ), ?b l , S ?y i ) . . .), S ?y i is as follows, for p 1 , . . . , p k all the triple patterns in P 2 that uses ?y i : if(bound(?y i p 1 ), ?y i p 1 , . . . if(bound(?y i p k−1 ), ?y i p k−1 , ?y i p k ) . . .), and R ?y i is as follows, for free variables ?x 1 , . . . , ?x n of P 1 (which appear in P blank ): We have the following lemma, whose immediate corollary is Theorem 1. </p></div>			</div>
			<div type="references">

				<listBibl>

<biblStruct xml:id="b0">
	<monogr>
		<author>
			<persName><forename type="first">S</forename><surname>Abiteboul</surname></persName>
		</author>
		<author>
			<persName><forename type="first">R</forename><surname>Hull</surname></persName>
		</author>
		<author>
			<persName><forename type="first">V</forename><surname>Vianu</surname></persName>
		</author>
		<title level="m">Foundations of databases</title>
				<imprint/>
	</monogr>
</biblStruct>

<biblStruct xml:id="b1">
	<analytic>
		<title level="a" type="main">Subqueries in SPARQL</title>
		<author>
			<persName><forename type="first">R</forename><surname>Angles</surname></persName>
		</author>
		<author>
			<persName><forename type="first">C</forename><surname>Gutierrez</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">AMW&apos;</title>
		<imprint>
			<biblScope unit="volume">11</biblScope>
			<date type="published" when="2011">2011</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b2">
	<analytic>
		<title level="a" type="main">Composing schema mappings: Second-order dependencies to the rescue</title>
		<author>
			<persName><forename type="first">R</forename><surname>Fagin</surname></persName>
		</author>
		<author>
			<persName><forename type="first">P</forename><forename type="middle">G</forename><surname>Kolaitis</surname></persName>
		</author>
		<author>
			<persName><forename type="first">L</forename><surname>Popa</surname></persName>
		</author>
		<author>
			<persName><forename type="first">W</forename><forename type="middle">C</forename><surname>Tan</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">ACM Trans. Database Syst</title>
		<imprint>
			<biblScope unit="volume">30</biblScope>
			<biblScope unit="issue">4</biblScope>
			<biblScope unit="page" from="994" to="1055" />
			<date type="published" when="2005">2005</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b3">
	<monogr>
		<title level="m" type="main">SPARQL 1.1 Query Language</title>
		<author>
			<persName><forename type="first">S</forename><surname>Harris</surname></persName>
		</author>
		<author>
			<persName><forename type="first">A</forename><surname>Seaborne</surname></persName>
		</author>
		<imprint>
			<date type="published" when="2013-03">Mar 2013</date>
			<publisher>W3C Rec</publisher>
			<pubPlace>W3C</pubPlace>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b4">
	<analytic>
		<title level="a" type="main">Semantics and Expressive Power of Subqueries and Aggregates in SPARQL 1.1</title>
		<author>
			<persName><forename type="first">M</forename><surname>Kaminski</surname></persName>
		</author>
		<author>
			<persName><forename type="first">E</forename><forename type="middle">V</forename><surname>Kostylev</surname></persName>
		</author>
		<author>
			<persName><forename type="first">B</forename><surname>Cuenca Grau</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">WWW&apos;</title>
		<imprint>
			<biblScope unit="volume">16</biblScope>
			<date type="published" when="2016">2016</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b5">
	<analytic>
		<title level="a" type="main">On expressibility of non-monotone operators in sparql</title>
		<author>
			<persName><forename type="first">R</forename><surname>Kontchakov</surname></persName>
		</author>
		<author>
			<persName><forename type="first">E</forename><forename type="middle">V</forename><surname>Kostylev</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">KR&apos;</title>
		<imprint>
			<biblScope unit="volume">16</biblScope>
			<date type="published" when="2016">2016</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b6">
	<analytic>
		<title level="a" type="main">CONSTRUCT Queries in SPARQL</title>
		<author>
			<persName><forename type="first">E</forename><forename type="middle">V</forename><surname>Kostylev</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><forename type="middle">L</forename><surname>Reutter</surname></persName>
		</author>
		<author>
			<persName><forename type="first">M</forename><surname>Ugarte</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">ICDT&apos;15</title>
				<imprint>
			<date type="published" when="2015">2015</date>
			<biblScope unit="volume">31</biblScope>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b7">
	<analytic>
		<title level="a" type="main">Semantics and Complexity of SPARQL</title>
		<author>
			<persName><forename type="first">J</forename><surname>Pérez</surname></persName>
		</author>
		<author>
			<persName><forename type="first">M</forename><surname>Arenas</surname></persName>
		</author>
		<author>
			<persName><forename type="first">C</forename><surname>Gutierrez</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">ACM Transactions on Database Systems</title>
		<imprint>
			<biblScope unit="volume">34</biblScope>
			<biblScope unit="issue">3</biblScope>
			<date type="published" when="2009">2009</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b8">
	<analytic>
		<title level="a" type="main">SPARQL++ for mapping between RDF vocabularies</title>
		<author>
			<persName><forename type="first">A</forename><surname>Polleres</surname></persName>
		</author>
		<author>
			<persName><forename type="first">F</forename><surname>Scharffe</surname></persName>
		</author>
		<author>
			<persName><forename type="first">R</forename><surname>Schindlauer</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">ODBASE&apos;</title>
		<imprint>
			<biblScope unit="volume">07</biblScope>
			<biblScope unit="page" from="878" to="896" />
			<date type="published" when="2007">2007</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b9">
	<analytic>
		<title level="a" type="main">On the relation between SPARQL1.1 and answer set programming</title>
		<author>
			<persName><forename type="first">A</forename><surname>Polleres</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><forename type="middle">P</forename><surname>Wallner</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">Journal of Applied Non-Classical Logics</title>
		<imprint>
			<biblScope unit="volume">23</biblScope>
			<biblScope unit="issue">1-2</biblScope>
			<biblScope unit="page" from="159" to="212" />
			<date type="published" when="2013">2013</date>
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b10">
	<analytic>
		<title level="a" type="main">On the primitivity of operators in SPARQL</title>
		<author>
			<persName><forename type="first">X</forename><surname>Zhang</surname></persName>
		</author>
		<author>
			<persName><forename type="first">J</forename><surname>Van Den Bussche</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">Inf. Process. Lett</title>
		<imprint>
			<biblScope unit="volume">114</biblScope>
			<biblScope unit="issue">9</biblScope>
			<biblScope unit="page" from="480" to="485" />
			<date type="published" when="2014">2014</date>
		</imprint>
	</monogr>
</biblStruct>

				</listBibl>
			</div>
		</back>
	</text>
</TEI>
