1 \subsection{The core language}
3 {\MathQL}.4 consists of a core language and of a basic library. Other
4 user-defined libraries can be added at will. The core language includes the
5 \TT{property} operator mentioned in \subsecref{HighAccess} that queries the
6 underlying {\RDF} database and the infrastructure to post-process the
7 query results. The components of this infrastructure are listed below:
12 Explicit sets of attributed values.
14 An explicit {\av} set can be placed in a query in two forms:
15 as a single quoted string, like \verb+"this is a query result"+, that
16 evaluates in a single {\av} with that value and no attributes, or as a full
17 {\av} set in the syntax shown in the previous sections but sorrounded by
18 square brackets, like \verb+["head" attr {"attribute-name" = "contents"}]+.
20 In the second form, the contents of an attribute can be the result of a query,
22 \verb+["head" attr {"attribute-name" = property /"metadata" of "resource"}]+.
24 In this case the contents of the attribute are the head strings of the query
25 result, whose attributes (if any) are discarded.
30 Variables for {\av} sets (preceded by a \TT{\$} sign and called
31 \emph{set variables}) can be assigned using a standard \emph{let-in}
32 construction and may appear wherever an {\av} set ({\ie} a query result) is
35 The assignment has the form:
36 \TT{let \$}\EM{variable} \TT{=} \EM{av-set} \TT{in} \EM{av-set}
39 \verb+let $var = "contents" in ["head" attr {"attribute-name" = $var}]+.
41 The scope rules of {\MathQL} variables are tipical for an imperative
42 programming language and any case of assignment propagation will be indicated.
45 Sequential composition.
47 This construction has the form: \EM{av-set} \TT{;;} \EM{av-set} and works as
48 follows: the two {\av} sets are evaluated one after the other and the first
49 one is discarded but the variables assigned in the first {\av} set are
50 available to the second one.
55 This construction comes in two forms:
57 \TT{while} \EM{av-set} \TT{sup} \EM{av-set}:
59 iterates the evaluation of the second {\av} set until the first {\av set} is
60 empty and returns the {\MathQL} set-theoretic union of all the evaluiations
61 of the second {\av set}.
63 \TT{while} \EM{av-set} \TT{inf} \EM{av-set}:
65 like the former but set-theoretic intersection is used instead of
68 In order for \TT{while} to work as expected, both {\av} sets are evaluaed in
69 a common context during the iteration ({\ie} the variables defined in both
70 are alailable to both) and this context is also propagated outside the
71 \TT{while} for convenience.
76 Also this construction comes in two forms:
78 \TT{for @}\EM{variable} \TT{in} \EM{av-set} \TT{sup} \EM{av-set}:
80 iterates the evaluation of the second \EM{av-set} assigning the \EM{variable}
81 to each element in the first \EM{av-set} and builds the {\MathQL}
82 set-theoretic union of the obtained results.
84 \TT{for @}\EM{variable} \TT{in} \EM{av-set} \TT{inf} \EM{av-set}:
86 like the former but set-theoretic intersection is used instead of
89 The variables for attributed values (preceded by a \TT{@} sign and called
90 \emph{element variables}) may appear wherever an {\av} set is allowed and
91 and in some additional places.
93 The element variables are kept distinct from the set variables (therefore
94 \TT{\$variable} and \TT{@variable} may appear in the same query without
97 Concerning the scope rules used in these constructions, the variables
98 assigned by the first {\av} set are available to the second {\av} set during
99 the iteration and the variables assigned by both {\av} sets are available
100 outside the \TT{for} as in the previous case.
105 \TT{add} \EM{optional-flag} \EM{attribute-groups} \TT{in} \EM{av-set}
107 builds an {\av} set adding the specified \EM{attribute-groups} to each element
108 of the given {\av} set.
109 If no \EM{flag} is specified the addition is set-theoretic, whereas with the
110 \TT{distr} flag the addition is distributive.
111 The \EM{attribute-groups} can be given explicitly (in the same syntax used for
112 explicit {\av} sets) or they can be replaced by an element variable. In the
113 latter case the attribute groups of the {\av} stored in the variable are
116 \figref{Add} shows how to build a one-element {\av} set using \TT{add}.
119 \begin{footnotesize} \begin{verbatim}
120 The set of attributed values given explicitly:
121 ["head" attr {"attribute-name" = property /"metadata" of "resource"}]
123 The same set built with the add operator
124 add {"attribute-name" = property /"metadata" of "resource"} in "head"
125 \end{verbatim} \end{footnotesize}
127 \caption{A simple use of the add operator}
134 The existential test has the form \TT{ex} \EM{av-set} where the
135 specification of the {\av} set contains some instances of the construction
136 \TT{@}\EM{variable}\TT{.}\EM{attribute-name}, and runs as follows:
137 the given {\av} set is evaluated replacing each
138 \TT{@}\EM{variable}\TT{.}\EM{attribute-name}
139 with the contents of \EM{attribute-name} in an attribute group of the {\av}
140 stored in \TT{@}\EM{variable} and the evaluation is repeated for every
141 possible choice of the groups (recall that different groups are allowed to
142 contain attributes with the same name). If one evaluation gives a non empty
143 result, the defaut representation of \emph{true} is returned (the test
144 succeded) in the other case the empty {\av} set, {\ie} \emph{false}, is
145 returned (the test failed).
150 The core language allows to invoke two kinds of external functions (with
151 which a language extension may be provided): the functions of the first kind
152 return an {\av} set, the functions of the second kind return a piece of
153 {\MathQL} code representing an {\av} set ({\ie} they interface a {\MathQL}
154 code generator). In particular:
156 \EM{function-name} \verb+{+
157 \EM{name} \TT{,} $\cdots$ \TT{,} \EM{name} \verb+} {+
158 \EM{av-set} \TT{,} $\cdots$ \TT{,} \EM{av-set} \verb+}+
160 invokes the specified function of the firs kind on the given arguments and
161 returns it result. The \EM{name} argument are {\MathQL} paths and usually
162 represent attribute names.
164 \TT{gen} \EM{function-name} \verb+{+
165 \EM{av-set} \TT{,} $\cdots$ \TT{,} \EM{av-set} \verb+}+
167 invokes the specified function of the second kind on the given arguments and
168 replaces the function invocation with its result.
170 The function names are {\MathQL} paths exactly as the attribute nanes and the
171 graph paths used by the \TT{property} operator. The names of the two kinds of
172 functions are kept in distinct environments so they do not clash.
174 {\MathQL}.4 comes with a basic library of functions of the first kind
175 (see \subsecref{IBasic}) that integrate the core language providing several
176 facilities to the user.