• No results found

To explain how simple event queries are matched against incoming events and how events derived by rules are constructed, we have to explain some concepts of the Web query language Xcerpt, whose query and construct terms are used in XChangeEQ. We try too keeps these explanations brief, concentrating on the “interface” to XChangeEQ without providing much details about the inner workings of Xcerpt. This also serves to illustrate that the general concepts of XChangeEQ and its declarative semantics might easily be applied also to using other languages for querying and constructing simple events.

9.2.1

Substitutions and Substitution Sets

Since query terms and construct terms in rules contain free variables that are bound to values in the application of a rule, we need the concepts of substitution and substitution set.

LetV arsdenote the set of all variable names. Asubstitutionσthen is a partial mapping from these variable names to the data terms the variables are bound to, i.e.,σ:V ars→DataT erms. We write substitutions as σ = {X1 7→ v1, . . . , Xn 7→ vn}, meaning that σ(Xi) = vi for i ∈

{1, . . . , n} andσ(Y) =⊥forY 6∈ {X1, . . . , Xn}.

Theapplicationof a substitutionσto a query termqreplaces the occurrences of free variables V inqwith their valuesσ(V). The result is denotedσ(q). Ifσ(q) is a ground query term, that is, a query term that does not contain variables anymore, we callσagrounding substitution. In the application ofσtoqwe always assume thatσis defined on all free variables ofq.

To accommodate for grouping and aggregation in construct terms, our model theory will mostly work withsubstitution setsΣ, which are just sets of substitutions. For convenience, we define the application of a substitution set Σ to a query termqas Σ(q) ={σ(q)|σ∈Σ}. The application of a substitution set to a construct term will be discusses later.

9.2.2

Matching: Simulation

Simple event queries in XChangeEQ are single Xcerpt query terms q that are matched against the data term part e of incoming events et. This matching of simple event queries is based on

simulation between ground terms —that is, terms not containing free variables— as defined for Xcerpt [Sch04].

Simulation is a relation between ground terms denoted . Intuitively, q d means that the nodes and the structure of the graph that the query termq represents can be found in the graph of the data term d. This simulation relationship of Xcerpt is especially designed for the variations and incompleteness in semi-structured data. We will not reproduce the full definition of simulation here and refer to [Sch04]; for the understanding of the semantics of XChangeEQ the intuitive understanding of matching should suffice and we can treat simulation as a “black box.”

Simulation naturally extends to a non-ground query term q0 by asking whether there is a (grounding) substitution such that the ground query terms q =σ(q0) obtained by applying the substitution σ to q0 simulates with the given data termd. Note that for a given (non-ground) query termqand a given data termd, there are often several substitutions that allow a simulation between the two.

The result of matching a query term q against a data term d thus is the set of all possible substitutions so thatqanddsimulation under each substitution. An empty substitution setσ6=∅

means thatqandddo not match. Substitution sets are also the results of complex event queries, which include several query terms as simple event queries.

Example The query term

q=a {{ desc var X, e [ "f", var Y ] }}

matches the data term

d=a [ b {"c"}, "d", e [ "f", "g" ] ] with substitution set Σ ={σ1, σ2, σ3}, where

σ1 = {X 7→b{”c”}, Y 7→”f”}, σ2 = {X 7→”c”, Y 7→”f”}, σ3 = {X 7→”d”, Y 7→”f”}.

9.2.3

Construction: Application of Substitution Sets

Rule heads contain Xcerpt construct terms for constructing new, derived events. This construction uses the set of substitutions obtained from the evaluation of the query in the body to replace variables and grouping constructs with values.

Construction is based on the applicationof a substitution set Σ to a construct term c. The result is denoted Σ(c) and is, provided that all substitutions in Σ are grounding, a set of data terms. Again, we will not reproduce the full definition of this application here and refer to [Sch04]; for the understanding of the semantics of XChangeEQ the intuitive understanding of construction should suffice and we can treat application of a substitution set to a construct term as a “black box.”

Example The application of the substitution set Σ from the previous section to the construct term

q=z[var Y, var X] constructs the three data terms

d1 = z[ "f", b {"c"} ], d2 = z[ "f", "c" ], d3 = z[ "f", "d" ]. Its application to

q0 =z{var Y, all var X}

constructs the single data term

d0 =z{ "f", b {"c"}, "c", "d" }.