]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_core.tex
updating the introduction
[helm.git] / helm / mathql / doc / mathql_introduction_core.tex
1 \subsection{The core language} 
2
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:
8
9 \begin{itemize}
10
11 \item 
12 Explicit sets of attributed values.
13
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"}]+.
19 \newline
20 In the second form, the contents of an attribute can be the result of a query,
21 like
22 \verb+["head" attr {"attribute-name" = property /"metadata" of "resource"}]+.
23 \newline
24 In this case the contents of the attribute are the head strings of the query
25 result, whose attributes (if any) are discarded. 
26
27 \item 
28 Variable assignment.
29
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
33 allowed.  
34 \newline
35 The assignment has the form: 
36 \TT{let \$}\EM{variable} \TT{=} \EM{av-set} \TT{in} \EM{av-set}
37 so we can write:
38 \newline
39 \verb+let $var = "contents" in ["head" attr {"attribute-name" = $var}]+.
40
41 The scope rules of {\MathQL} variables are tipical for an imperative
42 programming language and any case of assignment propagation will be indicated.
43
44 \item 
45 Sequential composition.
46
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.  
51
52 \item 
53 Unbounded iteration.
54 \newline
55 This construction comes in two forms:
56
57 \TT{while} \EM{av-set} \TT{sup} \EM{av-set}:
58 \newline
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}.
62
63 \TT{while} \EM{av-set} \TT{inf} \EM{av-set}:
64 \newline
65 like the former but set-theoretic intersection is used instead of
66 set-theoretic union.
67
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. 
72
73 \item 
74 Bounded iteration.
75 \newline
76 Also this construction comes in two forms:
77
78 \TT{for @}\EM{variable} \TT{in} \EM{av-set} \TT{sup} \EM{av-set}:
79 \newline
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.
83
84 \TT{for @}\EM{variable} \TT{in} \EM{av-set} \TT{inf} \EM{av-set}:
85 \newline
86 like the former but set-theoretic intersection is used instead of
87 set-theoretic union.
88
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. 
92 \newline
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
95 abiguity).
96
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. 
101
102 \item
103 Addition of groups.
104
105 \TT{add} \EM{optional-flag} \EM{attribute-groups} \TT{in} \EM{av-set}
106 \newline
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
114 considered.
115
116 \figref{Add} shows how to build a one-element {\av} set using \TT{add}.
117
118 \begin{figure}[ht]
119 \begin{footnotesize} \begin{verbatim}
120 The set of attributed values given explicitly:
121 ["head" attr {"attribute-name" = property /"metadata" of "resource"}]
122
123 The same set built with the add operator
124 add {"attribute-name" = property /"metadata" of "resource"} in "head"
125 \end{verbatim} \end{footnotesize}
126 \vskip-1pc
127 \caption{A simple use of the add operator}
128 \label{Add}
129 \end{figure}
130
131 \item 
132 Existential test.
133
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).
146
147 \item
148 Function invocation:
149
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:
155
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+}+
159 \newline
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.
163
164 \TT{gen} \EM{function-name} \verb+{+
165 \EM{av-set} \TT{,} $\cdots$ \TT{,} \EM{av-set} \verb+}+
166 \newline
167 invokes the specified function of the second kind on the given arguments and
168 replaces the function invocation with its result.
169
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.
173
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.
177
178 \end{itemize}