490 likes | 657 Views
Conditional XPath, the first order complete XPath dialect. Maarten Marx Presented by: Einav Bar-Ner. Introduction. XPath 1.0 is a variable free language used for selecting nodes from XML documents. What is missing?
E N D
Conditional XPath, the first order complete XPath dialect Maarten Marx Presented by: Einav Bar-Ner
Introduction XPath 1.0 is a variable free language used for selecting nodes from XML documents. What is missing? Core XPath (xpath query which interpreted on XML document tree models) cannot express queries with conditional paths as exemplified by “do a child step, while test is true at the resulting node.”
Introduction – Cont. Solution: We add conditional axis relations to Core XPath and show that the resulting language, called conditional XPath, is equally expressive as first-order logic when interpreted on ordered trees. Specifically, conditional XPath extends Core XPath with the until operator. This paper introduces and motivates this addition.
XPath 1.0 VS. XPath 2.0 XPath 2.0 contains variables which are used in if–then–else, for, and quantified expressions. The available axis relations are the same in both versions.
XPath 1.0 VS. XPath 2.0 As XPath 2.0 adds variables and first order quantifiers it is natural to ask whether XPath 1.0 is already expressively complete with respect to first order logic.
XPath VS. First Order Logic More precisely, is every first order query Φ(x) which selects a set of nodes from an XML document model equivalent to an XPath expression? As we will see, it is not, but a simple and natural addition is sufficient.
Lecture’s Topics • Introduction + motivation • A brief introduction to XPath, CXPath • Proving the expressively completeness of CXPath
“Until–like” query The answer set of “until-like” query consists of all nodes n’ satisfying the statement: “n’ is a descendant of n, the label of n’ is A, and for all z, if z is a descendant of n and n’ is a descendant of z, then the label of z is A.” This query can be expressed by (child :: A)+, which we call a conditional axis.
Conditional XPath (CXPath) vs. Core XPath While CXPath is more expressive than Core XPath, in all other aspects it is very conservative. CXPath has the same syntax as XPath 1.0 and Core XPath and the same (standard W3C) semantics.
A Brief Introduction to XPath – Cont. The primitive axis of XPath are and those of CXPath are
A Brief Introduction to XPath Definition 1. The syntax of the XPath languages XCore and CXPath is defined by the grammar Locpath ::= axis ‘::’ntst | axis ‘::’ ntst ‘[’fexpr‘]’ | ‘/’locpath | locpath ‘/’ locpath | locpath ‘ | ’ locpath fexpr ::= locpath | not fexpr | fexpr and fexpr | fexpr or fexpr axis ::= self | primitive_axis | primitive_axis+ | primitive_axis*.
A Brief Introduction to XPath – Cont. • “locpath” is the start production • “axis”– denotes axis relations e.g. descendant, ancestor. • “ntst” denotes tags labeling document nodes or the star ‘*’ that matches all tags (these are called node tests). • “fexpr” will be called filter expressions after their use as filters in location paths. With an XPath expression we always mean a “locpath”.
A Brief Introduction to XPath – Cont. • Interpretation of the axis relations: - Assigns a boolean value: “true” if the node n satisfies fexpr, else false. • Given a tree T and an expression A, the meaning of A in T is written as [[A]]T.
Example Consider the following information need: give elements whose next element in document order has tag A. This can be expressed in first order logic by in which << abbreviates descendant or ancestor_or_self/following_sibling/desc-endant_or_self.
Example – Cont. In the following case, answer ser will not contain x. x y A z
Example – Cont. To “program” this information in navigational XPath we seem to need to express the “next in document order” relation. To do this we use a few macros: first, last and leaf abbreviate , and We also use the converses of the conditional axis, written as Its meaning is the transitive closure of the relation Now we can write the “next in document order” relation in conditional XPath by the following case distinction:
What kind of queries does XPath express? The answer set of locpath evaluated on a tree R (notation: answerR(locpath)) is the set {n ЄR| there exists an m, (m,n) Є[locpath]R} Thus for each expression A, answerR(A) equals
Motivation We will show that for every first order query Φ(x) there exists an absolute CXPath expression A which is equivalent in the following strong sense: for each tree R, for each node n, R|=Φ(n) if and only if n Є answerR(A).
Conditional XPath and First order logic Let be the first order language with two binary relation symbols < and and countably many unary predicates P, Q, . . . L is interpreted on node labeled sibling ordered trees in the obvious manner: < is interpreted as the descendant relation , as the strict total order on the siblings, and the unary predicates P as the sets of nodes labeled with P.
Conditional XPath and First order logic – Cont. Theorem 4. Every formula in one free variable is, on ordered trees, equivalent to an CXPath filter expression. Meaning: For each filter expression fexpr εR(n, fexpr) is true if and only if n Є Note that we do not make a restriction to finite trees. The result holds for the class of all trees.
Defining Xuntil Define Xuntil as the propositional modal language with four binary until–like modal operators The syntax is given by the grammar The pi are propositional variables and
Defining Xuntil – Cont. Formally, a model R is a structure (T, h), with T a tree and h an assignment function from the set of propositional variables to the powerset of the set of tree nodes. Truth of a formula is defined relative to a model R and a node n in that model via the following recursive definition:
n2’’ n3’’ n’ n1’’ n p p q p Example h(p) = {n1’’, n2’’, n3’’}, h(q) = {n’} Φ = q, ψ = p, n |= (q, p)
Xuntil and CXPath Proposition 6. Every Xuntil formula is, on ordered trees, equivalent to an CXPath filter expression.
proof of Theorem 4 Instead of proving that Theorem directly we show expressive completeness of Xuntil , which is sufficient by Proposition 6. We say that Xuntil is expressively complete if for every formula Φ(x) there exists an Xunti formula σsuch that for every tree model R, for all nodes n in R, R|=Φ(n) if and only if R,n |= Φ. Thekey idea of the proof is the brilliant notion of separation.
Separation Let T be a tree and a node t є T. Define the followingpartition onT: Now let h, h’ be two assignments. We say that h, h’ agree on the future of t iff for any atom q and any s є future(t), s є h(q) iff s є h’(q). We similarly define this notion for the present, past, left and right.
t t s2 s2 s1 s1 Example h and h’ agree on the future of t: h: h’: q2 q1 q2 q2 q3 q3
t t s2 s2 s1 s1 Example – Cont. h and h’ do not agree on the future of t: h: h’: q2 q1 q2 q2 q3, q4 q3
Separation – Cont. We say that a wff A is a pure future wff iff for each tree T, for all t є T, for all assignments h, h’, if h, h’ agree on the future of t, then t, h |= A iff t, h’ |= A. Similarly, we define pure present, past, left and right wffs. We say that a wff A is separable iff there exists a wff which is a boolean combination of pure present, future, past, left and right wffs and is equivalent to A everywhere on any tree.
q5 s4 q4 s3 t s2 Example – Not a Pure Future wff (q4, q5) h’: h: q6 s4 q4 s3 t q1 q1 q3 q3 s1 q2 s1 s1 s2 s2 q2 q4 q4 s5 s5
q5 s4 q4 s3 t s2 Example –Pure Future wff (q2, q4) h’: h: q6 s4 q4 s3 t q1 q1 q3 q3 s1 q2 s1 s1 s2 s2 q2 q4 q4 s5 s5
Separation – Cont. Theorem 7. If every Xuntil wff is separable over trees, then Xuntil is expressively complete. Theorem 8. Each Xuntil wff is, over trees, separable. Corollary: Xuntil is expressively complete.
Separation – Cont. Expressively Complete CXPath Xuntil Separable
Separation – Cont. The next lemma describes a syntactic criterion for pure wffs. Theorem 8 is shown by rewriting each wff into a boolean combination of wffs satisfying these syntactic criteria.
Separation – Cont. Lemma 9. 1. Each boolean combination of atoms is a pure present wff. 2. Each boolean combination of wffs in whose scope occur only atoms, , and wffs is a pure future wff. 3. Each boolean combination of wffs in whose scope occur only atoms, wffs and pure future wffs is a pure right wff. 4. Each boolean combination of wffs in whose scope occur only atoms, wffs and pure future wffs is a pure left wff. 5. Each boolean combination of wffs in whose scope occur only atoms, wffs and pure left and right wffs is a pure past wff.
Separating Formulas We shall describe a syntactic procedure for separating each wff into a boolean combination of wffs of the form described in Lemma 9. Then that Lemma yields the theorem.
Separating Formulas – Cont. what do we need to do? 1. pull out wffs from under the scope of wffs, and conversely; 2. pull out wffs from under the scope of , and wffs; 3. pull out wffs from under the scope of wffs.
Separating Formulas – Cont. Lemma 10. The following are valid on all structures, for any of the four orientations
Creating Macros for the Unary Connectives. For one of the four arrows: • abbreviates • abbreviates T) • abbreviates • corresponds to the “next” operator. • corresponds to its transitive closure. • expresses that everywhere below A holds.
Separating Formulas – Cont. Call a wff horizontal if it does not contain and wffs. Theorem 12 (Gabbay). Each horizontal wff is equivalent to a wff in which no wff occurs in the scope of a wff and conversely. The next lemma allows us to bring wffs out of the scope of horizontal wffs.
Separating Formulas – Cont. Lemma 13. Let a, q, A, B be arbitrary wffs. The following are valid over trees. They are also valid if is replaced everywhere by
Separating Formulas – Cont. Proof of Lemma 13. The equivalences follow from the observation that if then for any if and only if
Separating Formulas – Cont. The only cases left are wffs in the scope of wffs and conversely. Lemma 14. Let a, q, A and B be atoms. Consider the followings wffs:
Separating Formulas – Cont. Each of the above wffs is equivalent, over ordered trees, to another wff in which the only appearances of the connective are as + (A, B) and if an appearance of that wff is in the scope of , then (A, B) is in the scope of a or a wff (which itself is in the scope of the ).
The final step. We now know the basic steps of the separation proof. We simply keep pulling out ’s from under the scope of ’s etcetera until there are no more. Given a wff A, this process will eventually lead to a syntactically separated wff.
COMPLEXITY Query evaluation for Core XPath can be done in time O( |D| · |Q| ), with |D| the size of the data and |Q| the size of the query. CXPath is more expressive, but the upper bound remains.
CONCLUSION We defined an easy to use, variable free XPath dialect which is expressively complete with respect to first order logic when interpreted on ordered trees. According to Marx, the lack of variables is one of the reasons for the success of XPath, so it is nice to know that they are not needed for expressivity reasons. Besides that, query evaluation for CXPath can still be done in linear time.