]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction_property.tex
updating all sections
[helm.git] / helm / mathql / doc / mathql_introduction_property.tex
1 \subsection{High level access to metadata} \label{HighAccess}
2
3 {\MathQL} high level access to an {\RDF} database is \emph{graph-oriented} and
4 is delegated to its \TT{property} operator that builds a \emph{result} {\av}
5 set starting from two mandatory arguments: the \emph{source} {\av} set and the
6 \emph{head path}.
7 Other optional arguments may be used to change its default behaviour or to
8 request advanced functionalities. 
9
10 This operator has the following syntax, where a path has the structure of an
11 attribute name ({\ie} a list of strings) and denotes a (possibly empty) finite
12 sequence of contiguous arcs (describing properties in the {\RDF} graph%
13 \footnote
14 {When we say \emph{{\RDF} graph}, we actually mean both the {\RDFM} graph and
15 the {\RDFS} graph.}%
16 ).
17
18 \begin{center}
19 \TT{property} \EM{optional-flags} \EM{head-path} \EM{optional-clauses} \TT{of}
20 \EM{optional-flag} \EM{av-set}
21 \end{center}
22
23 \begin{figure}
24 \begin{footnotesize} \begin{verbatim}
25  These examples refer to the resources "A" and "B" of Figure 2.
26
27 Example 1: reading an unstructured property - simple case:
28  property /"id"/"major" of {"A", "B"} gives "1"
29  property /"id"/"minor" of {"A", "B"} gives "2"; "7"
30
31 Example 2: reading an unstructured property - use of pattern:
32  property /"id"/"minor" of pattern ".*" gives "2"; "7"
33
34 Example 3: reading a structured property without main component:
35  property /"id" attr /"major", /"minor" of {"A", "B"}  
36  generates the following attributed values:
37  "" attr {/"major" = "1"; /"minor" = "2"}; 
38  "" attr {/"major" = "1"; /"minor" = "7"}
39  that are composed with the set-theoretic union giving:
40  "" attr {/"major" = "1"; /"minor" = "2"}, 
41          {/"major" = "1"; /"minor" = "7"} 
42
43 Example 4: reading a structured property specifying a main component:
44  property /"id" main /"major" attr /"minor" of {"A", "B"} gives
45  "1" attr {/"minor" = "2"}, {/"minor" = "7"} 
46
47 Example 5: the renaming mechanism:
48  property /"id" attr /"minor" as /"new-name" of {"A", "B"} gives  
49  "" attr {/"new-name" = "2"}, {/"new-name" = "7"}
50
51 Example 6: imposing constraints on property values:
52  property /"date" istrue /"first" in "2002-01-01" 
53                   attr /"modified" of {"A", "B"} and  
54  property /"date" istrue /"first" match ".*01.*" 
55                   attr /"modified" of {"A", "B"} give
56  "" attr {/"modified" = "2002-03-01"}
57  Only the instance of "date" with "first" set to "2002-01-01" 
58   is considered.
59
60 Example 7: inverse traversal of the head path:
61 property inverse /"date" attr /"first" in "" gives
62 "A" attr {/"first" = "2002-01-01"}; "B" attr {/"first" = "2002-02-01"}
63 \end{verbatim} \end{footnotesize}
64 \vspace{-1pc}
65 \caption{The ``property'' operator}
66 \label{Property}
67 \end{figure}
68
69 In the simplest case \TT{property} is used to read the values of a (possibly
70 compound) property with an unstructured value and does the following:
71
72 \begin{enumerate}
73
74 \item
75 It computes the instances of the given path in the {\RDF} graph available to
76 the query engine, using the resources specified in the head strings of the 
77 source {\av} set (call them source resources) as start-nodes.
78
79 \item
80 The computation gives a set of nodes ({\ie} the end-nodes of the instantiated
81 paths) which are the values of the instances of the (possibly compound)
82 property specified by the path and concerning the source resources.
83
84 \item
85 These values, encoded into {\av}'s as explained above, are composed by means
86 of the {\MathQL} set-theoretic union to form the result {\av} set.
87
88 \end{enumerate}
89
90 \figref{Property} (example 1) shows an instance of this procedure. 
91 Note that the result sets of this example have no attributes and that a path
92 is represented by a slash-separated list of strings denoting the path's arcs.%
93 \footnote{If needed, the empty path is represented by a single slash.}
94
95 Using the \TT{pattern} flag, \TT{property} can be instructed to regard the
96 values of the source {\av} set as POSIX regular expressions rather than as
97 constant strings.
98 In this case \TT{pattern} selects the set of resources matching at least one
99 of the given expressions.
100 See for instance \figref{Property} (example 2).
101
102 If we want to read the value of a structured property we can specify the
103 value's main component in the \TT{main} \EM{optional-clause} (this
104 specification overrides the default setting inferred from the {\RDF} graph
105 through the \emph{rdf:value} property) and the list of the value's secondary
106 components in the \TT{attr} \EM{optional-clause}. 
107
108 Note that if a secondary component is not listed in the \TT{attr} clause, it
109 will not be read.
110 Also recall that, when the result {\av}'s are formed, the main component is
111 is read in the head string, whereas the secondary components are
112 encoded using the attributes of a single group.
113 See for instance \figref{Property} (examples 3 and 4).
114 As a component of a property's value may be a structured property, its
115 specification (appearing in the \TT{main} or \TT{attr} clause) is
116 actually a path in the {\RDF} graph starting from the end-node of the head
117 path.
118
119 Note that the name of an attribute, which by default is its defining path in
120 the \TT{attr} clause, can be changed with an optional \TT{as} clause for the
121 user's convenience. See for instance \figref{Property} (example 5).
122 Note that the assigned name must be a path for typing reasons.
123 The alternative could be to use a simple string but in any case a string can
124 be seen as a one-element path.
125
126 In the default case \TT{property} builds its result considering every
127 component of the {\RDFM} graph ({\ie} every {\RDFM}) but we can constrain
128 some nodes of the inspected components to have (or not to have) a given value,
129 with the aim of improving the performance of the inspection procedure.
130 The constrained nodes are specified in the \TT{istrue} and \TT{istrue}
131 \EM{optional-clauses} and the constraining values are expressed by \TT{in} or
132 \TT{match} constructions depending on their semantics (constant values or
133 POSIX regular expressions respectively).
134 See for instance \figref{Property} (example 6).
135 Again a constrained node may be the value of a compound property, therefore
136 its specification (appearing in the \TT{istrue} or \TT{isfalse} clause) is
137 a path in the {\RDF} graph starting from the end-node of the head path.
138
139 \TT{property} allows to access the {\RDFS} property hierarchy by specifying
140 a flag \TT{sub} or \TT{super}.
141 If the \TT{sub} flag is present, \TT{property} inspects the instances of the
142 default tree (made by the head path and by the \EM{optional-clauses} paths)
143 and every other tree obtained by substituting an arc $ p $ with the arc of a
144 subproperty of $ p $.
145 If the \TT{super} flag is present, super-property arcs are substituted instead.
146
147 \TT{property} also allows the inverse traversal of its head path if the
148 \TT{inverse} flag is specified.
149 In this case the operator works as follows:
150
151 \begin{enumerate}
152
153 \item
154 It instantiates the head path using as end-nodes the values whose main
155 component is specified in head strings of the source {\av} set.
156
157 \item
158 It encodes the resources corresponding to the instances of the start-nodes into
159 {\av}'s assigning the attributes obtained instantiating the attribute paths%
160 \footnote{The paths in the \EM{optional-clauses} are never traversed backward.}
161 and builds the result set composing these {\av}'s with the set-theoretic union.
162
163 \end{enumerate}
164
165 See for instance \figref{Property} (example 7).