Scholarly article on topic 'Algorithmic Design Using Object-Z for Twig XML Queries Evaluation'

Algorithmic Design Using Object-Z for Twig XML Queries Evaluation Academic research paper on "Computer and information sciences"

CC BY-NC-ND
0
0
Share paper
Keywords
{XML / "Twig Query Evaluation" / Object-Z / Specification}

Abstract of research paper on Computer and information sciences, author of scientific article — Yang Liu, Jun Sun

Abstract Web technologies based on XML, e.g. Semantic Web and Web Services, facilitate Web automation and universally accessible content. One of the key factors for the success of XML-based technologies is of finding an efficient query evaluation algorithm for XML-based data models. An XML twig query is a complex selection predicate on both structure and content of a labelled XML document. Several novel twig query evaluation algorithms have been proposed recently. However, these algorithms are difficult to understand and hence implement due to high complexity. In this work, we present an algorithmic design for XML queries evaluation system using Object-Z. An Object-Z specification is developed to give a concise and logical description of the XML data model and the twig queries. It makes the twig query evaluation straight-forward, and allows different evaluation algorithms to be constructed easily and independently.

Academic research paper on topic "Algorithmic Design Using Object-Z for Twig XML Queries Evaluation"

Available online at www.sciencedirect.com

SCIENCE

DIRECT

Electronic Notes in Theoretical Computer Science

ELSEVIER Electronic Notes in Theoretical Computer Science 151 (2006) 107-124

www.elsevier.com/locate/entcs

Algorithmic Design Using Object-Z for Twig XML Queries Evaluation

Web technologies based on XML, e.g. Semantic Web and Web Services, facilitate Web automation and universally accessible content. One of the key factors for the success of XML-based technologies is of finding an efficient query evaluation algorithm for XML-based data models. An XML twig query is a complex selection predicate on both structure and content of a labelled XML document. Several novel twig query evaluation algorithms have been proposed recently. However, these algorithms are difficult to understand and hence implement due to high complexity. In this work, we present an algorithmic design for XML queries evaluation system using Object-Z. An Object-Z specification is developed to give a concise and logical description of the XML data model and the twig queries. It makes the twig query evaluation straight-forward, and allows different evaluation algorithms to be constructed easily and independently.

Key words: XML, Twig Query Evaluation, Object-Z, Specification

1 Introduction

XML is currently emerging as a de facto standard for information exchange over the Internet. XML-based ontology languages like RDF, DMAL+OIL/OWL [3] are the building blocks of Semantic Web [23] as they provide basic vocabularies for data markups: the ontologies. Therefore, the capability of processing XML documents efficiently is vital to the success of

1 Email: liuyang@comp.nus .edu. sg

2 Email: sunj@comp.nus.edu.sg

1571-0661/$ - see front matter © 2006 Elsevier B.V. All rights reserved. doi:10.1016/j.entcs.2005.07.039

Yang Liu1 and Jun Sun2

School of Computing National University of Singapore Singapore

Abstract

SW-aware applications because software agents are to perform autonomous discovery, querying, processing of data marked-up by XML documents.

Although XML documents could have rather complex internal structures, they can generally be modelled as ordered trees. Queries in XML query languages typically specify patterns of selection predicates on multiple elements which have some specified structural relationships (see, e.g., [4,5]). For example, to retrieve all paragraphs that are nested inside sections and have at least one figure and one table can be expressed as:

Q1 = //section//paragraph[figure AND table]

Such a query can be represented as a node-labelled twig pattern (or a small tree) with elements and string values as node labels [6]. Finding all occurrences of a twig pattern is a core operation in XML query processing [14,21,19,22]. Currently, one of the most efficient algorithms is holistic twig join algorithm TSGeneric [16]. It makes use of stacks to cache XML elements and a cursor interface that provides standard methods to return elements with possible matches. With different implementations of the cursor interface [15], efficient algorithms [16] have been developed to process twig joins based on available access methods.

However, due to the high complexity of the holistic approach, it is very difficult to understand and hence implement the evaluation process. Formal specification languages like Object-Z are precise and highly reusable, which offer a non-ambiguous specification of the problems and hence allow efficient algorithmic design. In this paper, Object-Z [13] is used to give an object-oriented specification of the tree-structured XML data model and twig query structure. In particular, generic classes are combined with class inheritance to structure the specifications, which leads to a specification that is highly extensible and a clear structure that is useful for efficient algorithmic designs for XML query evaluation. We show that various evaluation algorithms can be formalized straightforwardly using our structure. In general, we believe that our approach is applicable to other situations where intensive algorithmic design based on complicated data structure is required, e.g. task scheduling, security protocols and etc.

Our work is related to studies on applying Formal Methods to XML-related aspects of the Web domain. In [25], a formal object-oriented semantic model of XSLT in Object-Z is presented, which provides a formal understanding of the language and helps the standardization effort for XSLT. In [26], Object-Z specification is used to model common semantic constructs of XSLT2.0, XPath2.0 and XQuery1.0. The purpose is to reuse these semantic constructs to specify the semantics of XML family languages and to understand the commonality and difference between them. Our work focuses on algorithmic

design using Object-Z for XML queries evaluation. We show that our Object-Z specification eases the design of the complicated algorithms for the twig query evaluation problem. We believe that our approach is applicable to systems where complicated algorithmic design based on complex data structures are required. Our work is also related to works on applying Formal Methods to other Web technologies, some of which are evidenced in [20,12,28,17,7,11]. Another remotely related work is the work on connections between Z schemas and relational database by Martin and Simpson [18].

The rest of the paper is organized as follows: Section 2 briefly introduces the Object-Z specification language. Section 3 describes positional representation of XML data model and its Object-Z specification. Section 4 describes the XML twig query and related data structures. Section 5 presents the whole system of XML twig query evaluation. Section 6 shows how the specification facilitates the design of different evaluation algorithms. Section 7 concludes the paper.

2 Object-Z

Z [24] is a state-based formal specification language based on the established mathematics of set theory and first-order logic. It has been used to specify a wide range of systems including transaction processing systems and communication protocols. A specification in Z typically consists of a number of state and operation schemas. A state schema groups together variables and defines the relationship that holds between their values. An operation schema defines the relationship between the 'before' and 'after' valuations of one or more state schemas. Object-Z [13] is an object-oriented extension of the Z language. It improves the clarity of large Z specifications through enhanced structuring. The main Object-Z construct is class definitions, which captures the object-oriented notion of a class by encapsulating a single state schema with all the operations which may affect its variables.

An Object-Z class is represented syntactically as a named box with zero or more generic parameters. There may be local types and constant definitions, at most one state schema and one associated initial state schema and zero or more operations. The declarations of the state schema are referred to as the state variables and the predicate as the class invariant. The class invariant restricts the possible valuations of the state variables. The initial schema identifies the possible initial valuations of the state schema. An operation is either an operation schema or a schema expression involving existing class operations and schema operators.

To indicate that an object is (physically) contained by another class, rather

level 0

[c(20,35) ] [a(36,45) ]

[a(47,90) ]

[ a(3,8) ] [ c(9,15) ) (b(21,25) j [b(26,32) ] [a(37,42) ) (c(49,67) ] [c(71,88) j

[ c(4,7) j (c(10,13) ] [c(23,24) ] [b(27,30) ] (c(38,39) ] [b(50,65) ] (b(73,85)

[ a(5,6) j [a(11,12) ] [c(28,29) ] (c(52,54) ] (c(57,60) j [c(76,80) |

Fig. 1. A Sample XML Document

than just referenced by it, its type is annotated with the symbol @ [9]. For example, the declaration a : A@ in class B indicates that an object of class B has a reference a to an object of class A and this object is contained by the object of class B. A single object cannot (directly) be contained by more than one object. Classes may be specified incrementally using inheritance. A class which inherits another may extend its definition with new state variables, new invariant and initial constraints, and new operations. It may also add new constraints to existing operations. In a specification including one or more inheritance hierarchies, variables may be declared polymorphically to have the type of any class within a hierarchy.

3 XML Data Model

In this section, we explore the commonly used representation of XML data in twig query evaluations. This representation gives some interesting relations between the XML elements. The formal definition of XML document using Object-Z class definition is presented in the end of this section.

Most existing XML query processing algorithms rely on a positional representation of XML elements [27,2,8,15], where XML documents are modelled as ordered trees and each tree node (XML element) is represented as a tuple of the form: (docID, start, end, level). docID is the identifier of the XML document in XML database. start (end) refers to the number of elements traversed in pre-order from the root r of the document till the start (end) of the element. level indicates the nesting depth of the element. A sample XML document containing root r and elements a, b and c is shown in Figure 1. Pre-order traverse is performed starting from the root r. Once an element is visited, its start value is set to current counter. When an element is visited in second time, its end value is set to current counter.

In order to represent the XML document elements completely in Object-Z, first we define XML element tag names set TAG using free type Char. Char includes all valid characters for tag names. TAG is the set of all possible XML element node tag names, i.e. a sequence of valid characters starting with a letter or two special characters. This definition strictly follows the definition in the World Wide Web Consortium. Detailed definitions can be found at [1].

[Letter, Digit, CombiningChar, Extender]

Char ::= letter ((Letter)) \ digit ((Digit)) | '.' | '-' | | ':' |

comChar((CombiningChar)) | extender((Extender)) TAG == {t : seq Char | head(t) e Letter V

(,head(t) = V t. head(t) = ':')}

The Object-Z modelling of XML elements is defined as the following Element class, where two simple class invariants are defined:

_Element_

\(docLD, start, end, level, tag)

docID, start, end, level : N tag : TAG

start < end A level < start

With positional representation, the structural relationships between tree nodes can be determined easily as: (1) ancestor-descendant (A-D) relationship: element v is a descendant of element u if and only if u.start < v.start < u.end; (2) parent-child (P-C) relationship: element v is a child of element u iff u.start < v.start < u.end and u.level = v.level — 1. Two relations IsAncestorOf and IsParentOf are defined accordingly:

IsAncestorOf : Element ^ Element IsParentOf : Element ^ Element

V x, y : Element •

x IsAncestorOf y <!=> x.start < y.start A y.start < x.end A x .level < y .level A x .docID = y .docID Vi, y : Element • x IsParentOf y <!=>

x IsAncestorOf y A x.level = y.level — 1

Case 1 Case 2 Case 3 Case 4

Property x.end < y.start x.start < y.start x.end > y.end x.start > y.start x.end < y.end y.end < x.start

Segments e-X-e •— Y X . Y . X Y

Tree • Root A • Root A • Root A • Root A

Fig. 2. Four Possible Relationships of Any Two XML Elements

For any two elements x and y in a XML document, there are four possible positional relationships between them, which are illustrated in Figure 2. Case 2 and case 3 in Figure 2 are captured by the previous relation IsAncestorOf. A new relation is needed to describe the case 1 and case 4: x.end < y.start and x and y have a common ancestor. These two constraints are summarized in the following relation IsLeftKinOf (and it's inverse):

IsLeftKinOf : Element ^ Element

Vi, y : Element • x IsLeftKinOf y <!=> x.end < y.start A

3 z : Element • z IsAncestorOf x A z IsAncestorOf y

Before we give the full Object-Z definition of XML documents, we need to introduce one more concept: stream. A stream contains all the positional representations (tuples) of the XML nodes that have the same tag. The tuples in one stream are sorted by their start values ascend-ingly. For example, a stream of tag a (denoted as Ta) in the XML document shown in Figure 1 is a sequence (assume docID of the XML is 1):

{(1, 2,17,1), (1, 3,8, 2), (1, 5,6,4), (1,11,12,4), (1, 36,45,1), (1,37,42,2), (1,47, 90,1)}.

_Stream,_

\ (elements, INIT)

elements : seq Element@

tag : TAG

V i, j : 1 .. # elements •

elements (i ).tag = elements (j ).tag A elements (i ).tag = tag A elements (i ).docID = elements (j ).docID A i < j ^^ elements (i). start < elements (j). start

elements = {)

_XMLDocument_

\ (docID, root, tags, INIT, GetStream)

docID : N root : Element tags : P TAG elements : P Element@ A

streams : P Stream^,

Vx,y : elements • x IsLeftKlnOf y V y IsLeftKlnOf x V

x IsAncestorOf y V y IsAncestorOf x [One of the four cases]

root £ elements A root .docID = docID A root .level = 0

Ve : elements • root IsAncestorOf e [Single tree with one root]

{e : elements • e.tag} = tags

Vx, y : streams • [No intersection]

x = y ^^ x.tag = y.tag A ran(x.elements) n ran(y.elements) = 0 U{s : streams • ran(s.elements)} = elements [Partition]

elements = 0

_GetStream_

tag? : TAG stream! : Stream,

tag? £ tags A stream! £ streams A stream!.tag = tag?

n1: //section

n2://paragraph

n3:/figure n4:/table

Fig. 3. Tree Representation of Q1

The Object-Z class definitions for Stream and XMLDocument are defined above. Each XML document is a single rooted tree, which can be accessed from the root element. An XML document has a collection of elements with positional representation, which have the same docID as the XML document. The distinct tag names of the elements form the tag set of this XML document. Any two XML elements are in one of the four possible positional relationships. The streams partition all the elements, which is described using a secondary attribute [10]. Operation GetStream retrieves the stream of the given tag name. The use of secondary attribute gives an elegant way of describing the operation.

4 XML Twig Query and Related Data Structure

In this section, we present the XML twig query specification and two related data structures: cursor interface and element stack.

Twig queries are represented as trees. Each node in the tree stands for one query node in the original twig query. A query node has the content /tag or //tag, where '/' denotes a child relationship, '//' denotes a descendant relationship, and ' tag' is the corresponding label in the twig query. For example, query Q1 in Section 1 can be represented using tree in Figure 3 above.

Matching a twig query against an XML database is of finding all occurrences of the pattern in the database. It is a core operation in XML query processing [6]. Formally, given a twig query Q and an XML database D, a match of Q in D is identified with a mapping from nodes in Q to nodes in D, such that query node predicates are satisfied by the corresponding database nodes (the images under the mapping), and the structural (P-C and A-D) relationships between query nodes are satisfied by the corresponding database nodes. The answer to query Q with n nodes is represented as an n-ary relation where each tuple (di, d2, ... ,dn) consists of the database nodes that identify a distinct match of Q in D.

A cursor interface Cq is defined for each query node q as the interface to

access its stream Tq. Each cursor Cq points to some element in the stream. Initially, the stream of the cursor is empty. It is assigned when the stream data is retrieved from the XML document successfully. The cursor can move to the next element (if any) by invoking operation Cq.Advance. The current stream element can be accessed by operation Cq .GetCurrentElement. The class of Cursor is shown below. There is a variable pointer to remember the current cursor position. The pointer can be advanced before reaching the end of the stream.

_Cursor_

\(stream, pointer, endOfStream, INIT, AssignStream,

GetCurrentElement, Advance) Flag ::= ok | error

stream : StreamQ, pointer : N A

endOfStream : B

pointer ^ #(stream.elements)

endOfStream = (pointer = #(stream .elements ))

.INIT.

pointer = 0

AssignStream,_

A(stream, pointer) s ? : Stream,

stream ' = s ? A pointer ' = 1

. GetCurrentElement. e ! : Element

e ! = stream .elements (pointer )

-AdvanceOK . A(pointer ) flag ! : Flag

pointer ' = pointer + 1 flag ! = ok

,_ AdvanceError. flag ! : Flag

pointer = #(stream .elements ) flag ! = error

Advance = AdvanceOK V AdvanceError

We also associate each query node q with a stack Sq. Initially, all stacks are empty. During query execution, each stack Sq may cache some stream elements before current cursor Cq and these elements are strictly nested in the stack from bottom to top, i.e. each element is a descendant of the element below it. Each element e in Sq is associated with a pointer pointing to the lowest ancestor in Sparent(q) so as to efficiently access all e's ancestors in Sparent(q). In

fact, cached elements in stacks represent the partial solutions that could be further extended to full solutions as the evaluation continues. As described above, first we extend the Element class to form StackElement class by adding the ParentStackPointer. The ElementStack is essentially a stack to store stack elements. One extra operation that ElementStack supports is ClearStack, which removes all elements whose end value is smaller than the input value.

_StackElement_

Element

ParentStackPointer : N

. ElementStack.

¡(stack, INIT, Push, Pop, ClearStack)

stack : seq StackElementgg,

Vi, j : stack • stack(i).tag = stack(j).tag

i < j stack(i) IsAncestorOf stack(j)

[Strictly nested relation]

.INIT.

stack =

. ClearStack_

A(stack ) position ? : Ni

,_ Push_

A(stack )

e ? : StackElement

stack ' = stack ^ (e ?)

stack' C stack V e : ran stack • e £ ran stack' ^^ e.end < position?

A(stack ) e ! : StackElement

stack = ( )

stack = stack ' (e !)

Twig queries are tree structures with multiple branches. Therefore, we can use the recursive tree structure to represent the twig queries. Object containment [9] is used to model tree nodes to get rid of cyclic tree structures. Each query node has a tag, which is the same as the tags of elements in its cursor and stack. It has a property ADJoin, which specifies whether the structural relationship is child or descendant. The secondary Boolean variable hasValidMatching tests whether the elements in the stack forms the match (See Section 4) of the query against the database.

QueryNode provides various operations for query evaluation. Child nodes can be added into and retrieved from the children variable. Evaluation algorithms can be applied to the query node to produce matching in the element stacks. Before the evaluation, query's cursor is pointing to the first element in the stream and stack is empty. After the evaluation, the cursor moved to the end of the stream and matched elements are stored in the element stack. In addition, most of the operations in Cursor and ElementStack are promoted in QueryNode class to support the query evaluation. The Object-Z class definition of query node is presented on the next page. Two auxiliary functions IsRoot and IsLeaf are defined below to test whether the given query node is a root node or leaf node respectively.

IsRoot : QueryNode ^ B

V q : QueryNode • IsRoot(q) = ($p : QueryNode • q.parent = p)

IsLeaf : QueryNode ^ B

V q : QueryNode • IsLeaf (q) = (q.children = {})

_QueryNode_

tag : TAG

tags : P TAG

stack : ElementStackQ

cursor : CursorQ

children : seq QueryNodeQ

parent : QueryNode

ADJoin : B

hasValidMatching, endOfStream : B

> V index

[Tags of the whole subtree]

[Location step axis ]

1.. e. ParentStackPoint

V c : children • V e : dom c.stack <

stack(index) IsAncestorOf e

[Stack elements satisfy structural relationships]

tags = U(i : 1 .. #children • children(i).tags} U tag

V i : 1..#stack • stack (i).tag = cursor .stream .tag A stack (i ).tag = tag hasValidMatching = #q.children = 0 V

V qi 6 q.children • qi.hasValidMatching A

V e : dom qi .stack • V index : 1..e.ParentStackPoint • qi. AD Join q.stack(index) IsAncestorOf e A -i qi.ADJoin q.stack(index) IsParentOf e endOfStream = cursor.endOfStream

IN IT_

children = 0

stack.INIT A cursor.INIT -AddChild_

_ OetTag _ i! : TAG

i! = tag

A(children ) child ? : QueryNode

child? 6 dom children children' = children {child?)

-GetGhild_

position? : Ni child! : QueryNode

children = 0 position ^ # children child ! = children (position )

_ EvaluateQuery_

A(cursor, stack)

#(stack .stack) =0 A cursor .pointer = 1 A endOfStream' A hasValidMatching'

GetCursorElement = cursor .GetCurrentElement AdvanceCursor = cursor .Advance AssignStream = cursor. AssignStream PushToStack = stack .Push PopFromStack = stack .Pop ClearStack = stack .ClearStack

5 Query Evaluation System

In this section, the whole system for XML twig query evaluation is presented based on the XML document and query node classes described in section 3 and 4.

XML document and query node are independent classes. The query system is built to evaluate twig queries against XML documents. The Object-Z class describing the query system is defined as the following. The query system consists of an XML database which is a set of XML document, and an input query. XML documents can be added and deleted from the system via AddXML and DeleteXML operations respectively. New query can be input into the system via InputQuery operation. The most important operation QueryEvaluation gives the formal requirement of twig query evaluation, which is promoted from QueryNode class.

_Query System_

database : P XMLDocument

query : QueryNode

3 xml : database • query .tags £ xml .tags

,-INIT

InputQuery_

A(query) q? : QueryNode

database = 0

V xml : database • xml.INIT

query' = q?

AddXML

RemoveXML_

A(database)

db? : XMLDocument

A(database)

db? : XMLDocument

db? £ database

database' = database U {db?}

db? £ database

database' = database — {db?}

The query evaluation process is described like following: first of all, a new query is input into the system. At this stage, all cursors' streams of query

nodes are not assigned and stacks of query nodes are empty. Then operation RetrieveStream is applied to build up the cursors of query by retrieving the stream from the destination XML document to query streams according to the tag name. After that, we can apply a particular query evaluation algorithm [6,16] to evaluate the query by invoking QueryEvaluation operation. After the evaluation, cursor of the query root reaches the end and all valid matchings are stored in the stacks of the query nodes. Finally stack elements are merged and output to form the final solutions. Merging multiple lists of sorted path solutions is a simple practice of a multi-way merge join [27].

6 Query Evaluation Algorithms

The Object-Z specification shown in the last section is well designed with high extensibility and reusability. Different evaluation algorithms can be built based on the general interface and data structures defined in class QueryNode. In this section, we present two evaluation algorithms PathStack [6] and TSGeneric [16], which produce all matchings of a twig query against an XML document. PathStack is a decomposition method, while TSGeneric uses a holistic approach. We show that both of them can be expressed precisely based on the data structures and operations defined in the Object-Z specification.

PathStack is a straightforward way of computing answers to a twig query pattern by decomposing the twig query into multiple path queries. Each path query is evaluated, and then the solutions of the path queries are merged to form the answers of the twig query. For simplicity, we ignore the decomposition and merge of PathStack. The main algorithm that finds solutions of a path query is presented in the following:

Algorithm PathStackMain(root)

1: while (not root.endOfStream)

2: q_min = GetMinSource(root);

3: for each q_i in root.children 4: while (#(q_i.stack) != 0 &&

tail(q_i.stack).start < q_i.cursor.end) 5: q_i.PopFromStack();

6: q_min.PushToStack(q_min.GetCursorElement(), #(q_min.parent.stack));

7: q_min.AdvanceCursor();

8: if (IsLeaf(q_min))

9: OutputPathSolutions(q_min);

10: q_min.PopFromStack();

The key idea of Algorithm PathStack is to repeatedly construct element stack of partial and total answers to the query path pattern, by traversing the stream. Thus, the path query nodes will be matched from the query root down to the query leaf. In line 2, GetMinSource method returns the descendant query node of q along the path query, whose current cursor element has the

minimum start value. The details of GetMinSource function is ignored for the simplicity. Interested readers could construct this function based on the above description. Lines 3-5 remove partial answers from the stacks that cannot be extended to total answers, given knowledge of the next stream node to be processed. Line 6 augments the partial answers encoded in the stacks with the new stream node. Line 7 advances the Cursor to next element. OutputPathSolutions is invoked by Algorithm PathStack (lines 8-10) to output these answers.

PathStack has a significant disadvantage: many intermediate results may not contribute to the final answers. In order to solve this problem, TSGeneric is proposed by [6,16]. TSGeneric operates in two phases. Firstly, it repeatedly calls the GetQNode algorithm to get the next "good" query node for processing. Secondly, selected query node is stored in the element stacks or discarded.

GetQNode is similar to GetMinSource, which returns a subtree node of root who has the minimal start value. Because the twig query is considered as a whole, this gives idea of the holistic approach. The detail of the GetQNode algorithm is shown below:

Algorithm GetQNode(q)

1: if (IsLeaf(q))

2: return q;

3: for each q_i in q.children

4: n_i = GetQNode(q_i);

5: if (n_i != q_i)

6: return n_i;

7: n_min = getMinSource(q);

8: if (q.cursor.start < n_min.cursor.start)

9: return q;

10: else

11: return q_min;

The following is the TSGeneric algorithm. After getting the next good node using GetQNode (line 2), elements are popped from the q's parent stack and stack Sq (lines 4-5), because they do not contribute to new outputs. Cq is then processed if q is either a root node or Cq has ancestor elements in the parent stack Sparent(q), which means it is possible to contribute to the final matches. If q is a leaf output node, all path solutions for element Cq (line 10) are outputted.

Algorithm TSGeneric

while (not root.endOfStream) q = GetQNode(root); if (not IsRoot(q))

q.CleanStack(q.cursor.start); q.CleanStack(q.cursor.start); if (IsRoot(q) or #(q.parent.stack) != 0) if (not IsLeaf(q))

q.PushToStack(q.GetCursorElement(), #(q.parent.stack));

10: OutputPathSolutions(q);

11: q.AdvanceCursor();

With the Object-Z specification of the XML data structure and twig query, the twig query evaluation becomes straightforward by using the operations provided by the Object-Z classes. Different evaluation algorithms can be constructed using different methods to access the data stream. An implementation of a query evaluation algorithm is correct as long as it fulfills the operation QueryNode defined in class QuerySystem. Nevertheless, the design of the algorithm is independent of the implementation of the XML data model and hence focuses only on the algorithmic aspects. For example, Cursor class can be implemented using either simple file cursor, XB-tree cursor [6] or XR-tree cursor [15]. Efficient index access methods can skip the stream quickly, hence significantly improve the evaluation.

7 Conclusion

In this paper, we presented an Object-Z specification of the XML twig query evaluation system. A reusable formal specification of the general XML data model is constructed, based on which the XML twig query evaluation is formalized incrementally. This specification gives a concise and logical description of relationships between XML data and twig queries. Having this specification, the twig query evaluation becomes straightforward. Two highly complicated twig query evaluation algorithms are presented based on the data model.

Our work in this paper serves as an example to show that extensible formal specification languages like Object-Z may help complicated algorithmic designs for systems with complex data structures.

References

[1] Extensible Markup Language XML 1.0 (Third Edition). http://www.w3.org/TR/2004/REC-xml-20040204/.

[2] S. Al-Khalifa, H. V. Jagadish, N. Koudas, J. M. Patel, D. Srivastava, and Y. Wu. Structural Joins: a Primitive for Efficient XML Query Pattern Matching. In Proceedings of the IEEE International Conference on Data Engineering, 2002.

[3] G. Antoniou and F. v. Harmelen. Web Ontology Language: OWL. In Handbook on Ontologies, pages 67-92. 2004.

[4] A. Berglund, S. Boag, D. Chamberlin, M. F. Fernandez, M. Kay, J. Robie, and J. Simeon. XML Path Language XPath 2.0. Technical report, W3C, 2002. http://www.w3.org/TR/2005/WD-xpath20-20050404/.

[5] S. Boag, D. Chamberlin, M. F. Fernandez, D. Florescu, J. Robie, and J. Simeon. XQuery 1.0: An XML Query Language. Technical report, W3C, 2002. http://www.w3.org/TR/2005/WD-xquery-20050404/.

N. Bruno, N. Koudas, and D. Srivastava. Holistic Twig Joins: Optimal XML Pattern Matching. In Proceedings of the 2002 ACM SIGMOD International Conference on Management of Data, pages 310-321, 2002.

0. Caprotti, J. H. Davenport, M. Dewar, and J. A. Padget. Mathematics on the (Semantic) NET. In The Semantic Web: Research and Applications, First European Semantic Web Symposium, ESWS 2004, pages 213-224, 2004.

S. Y. Chien, Z. Vagena, D. Zhang, V. Tsotras, and C. Zaniolo. Efficient Structural Joins on Indexed XML Documents. In Proceedings of International Conference on Very Large Data Bases, pages 263-274, 2002.

J. S. Dong and R. Duke. The Geometry of Object Containment. In Object-Oriented Systems (OOS) journal, volume 2(1), pages 41-63. Chapman Hall, 1995.

J. S. Dong, G. Rose, and R. Duke. The Role of Secondary Attributes in Formal Object Modelling. In Ft. Lauderdale, editor, Proceedings of the First IEEE International Conference on Engineering Complex Computer Systems (ICECCS'95), pages 31-38. IEEE Computer Society Press, November 1995.

J. S. Dong, J. Sun, and H. Wang. Checking and Reasoning about Semantic Web through Alloy. In FME 2003: Formal Methods, International Symposium of Formal Methods Europe, pages 796-813, 2003.

J. S. Dong, J. Sun, H. Wang, C. H. Lee, and H. B. Lee. Analysing Web Ontology in Alloy: A Military Case Study. In SEKE 2003, pages 542-546, 2003.

R. Duke, G. Rose, and G. Smith. Object-Z: a Specification Language Advocated for the Description of Standards. In Computer Standards and Interfaces, volume 17, pages 511-533, 1995.

D. Florescu and D. Kossmann. Storing and Querying XML Data using an RDBMS. In IEEE Data Engineering Bulletin, pages 27-34, 1999.

H. Jiang, H. Lu, W. Wang, and B. C. Ooi. XR-Tree: Indexing XML Data for Efficient Structural Joins. In Proceedings of the 19th International Conference on Data Engineering, pages 253263, 2003.

H. Jiang, W. Wang, H. Lu, and J. X. Yu. Holistic Twig Joins on Indexed XML Documents. In VLDB 2003, Proceedings of 29th International Conference on Very Large Data Bases, pages 273-284, 2003.

M. Marchiori. The Mathematical Semantic Web. In Mathematical Knowledge Management, Second International Conference, MKM 2003, pages 216-224, 2003.

A. Martin and A. Simpson. Generalising the Z Schema Calculus: Database Schemas and Beyond. In 10th Asia-Pacific Software Engineering Conference (APSEC 2003), pages 28-37, 2003.

J. McHugh and J. Widom. Query Optimization for XML. In Proceedings of International Conference on Very Large Data Bases, pages 315-326, 1999.

A. Rezazadeh and M. Butler. Some Guidelines for Formal Development of Web-Based Applications in B-Method. In ZB 2005: Formal Specification and Development in Z and B, pages 472-492, 2005.

J. Shanmugasundaram, K. Tufte, C. Zhang, H. Gang, D. J. DeWitt, and J. F. Naughton. Relational Databases for Querying XML Documents: Limitations and Opportunities. In Proceedings of International Conference on Very Large Data Bases, pages 302-314, 1999.

1. Tatarinov, S. Viglas, K. Beyer, J. Shanmugasundaram, E. Shekita, and C. Zhang. Storing and Querying Ordered XML using a Relational Database System. In Proceedings of the 2002 ACM SIGMOD International Conference on Management of Data, pages 204-215, 2002.

23] F. v. Harmelen. The Semantic Web: What, Why, How, and When. IEEE Distributed Systems Online, 5(3), 2004.

[24] J. Woodcock and J. Davies. Using Z: Specification, Refinement, and Proof. Prentice-Hall International, 1996.

[25] H. L. Yang, J. S. Dong, K. G. Hao, and J. G. Han. Formalizing Semantics of XSLT Using Object-Z. In 5th Asian-Pacific Web Conference, pages 120-131, 2003.

[26] H. L. Yang, J. G. Han, and K. G. Hao. The Common Semantic Constructs of XML Family. In ,5th International Conference on Formal Engineering Methods, pages 416-431, 2003.

[27] C. Zhang, J. F. Naughton, D. J. DeWitt, Q. Luo, , and G. M. Lohman. On Supporting Containment Queries in Relational Database Management Systems. In Proceedings of the 2001 ACM SIGMOD International Conference on Management of Data, pages 425-436, 2001.

[28] H. Zhu, B. Zhou, X. Mao, L. Shan, and D. A. Duce. Agent-Oriented Formal Specification of Web Services. In Grid and Cooperative Computing - GCC 2004 Workshops, pages 633-641, 2004.