-
Notifications
You must be signed in to change notification settings - Fork 0
WQuery
WQuery embeds WPath expressions in imperative constructs such as loops, conditional statements and sequential execution blocks. Below we describe briefly its syntax.
emit expr
An emission simply returns the result of evaluating the WPath expression passed as its argument.
emit {car}
{ car:1:n auto:1:n automobile:1:n machine:6:n motorcar:1:n }
{ car:2:n railcar:1:n railway car:1:n railroad car:1:n }
{ car:3:n gondola:3:n }
{ car:4:n elevator car:1:n }
{ cable car:1:n car:5:n }
do
expr_1
expr_2
...
expr_n
end
A block of code executes sequentially the enclosed WQuery expressions. The result of evaluating a block is a concatenation of the results of the expressions enclosed by do
and end
.
do
emit {car:3:n}
emit {car:1:n}
emit {person:1:n}
end
{ car:3:n gondola:3:n }
{ car:1:n auto:1:n automobile:1:n machine:6:n motorcar:1:n }
{ person:1:n individual:1:n someone:1:n somebody:1:n mortal:1:n soul:2:n }
%var := expr
An assignment binds the result of evaluating a WPath expression to a variable. WQuery variables start with %
sign. As in the case of WPath variables, the %
-prefixed variables may be referenced in WPath expressions.
do
%a := {car:1:n}
emit %a.hypernym
end
{ car:1:n auto:1:n automobile:1:n machine:6:n motorcar:1:n } hypernym { motor vehicle:1:n automotive vehicle:1:n }
if [condition]
i_expr
else
e_expr
The result of a conditional expression consists of the result of i_expr
if the condition enclosed in [
and ]
holds. Otherwise, the result of e_expr
is returned.
The else
block is optional. If there is no else
block and the condition does not hold the result is empty.
The syntax of the condition to be evaluated is the same as in the case of WPath filters.
All the WPath conditional operators can be used.
if [count({}) < 10000]
emit `This is a small wordnet.`
else
emit `This is a big one.`
'This is a small wordnet.'
from wpath_expr
wquery_expr
A from
loop executes the WQuery expression defined in its body for every set of bindings associated with the dataset returned by the WPath expression specified in its head.
The variables bound by the WPath expression in the head can be referenced in the body.
The result of a from
loop execution is a concatenation of the results obtained by executing its body for every set of bindings returned by its head.
from {}$a.hypernym$b do
if [$a.pos != $b.pos]
emit $a,$b
end
(no result)
while [condition]
wquery_expr
A while
loop executes the WQuery expression in its body as long as the condition enclosed in [
and ]
holds true.
The result of a while
loop execution is a concatenation of the results obtained by subsequent executions of its body.
do
%i := 0
%f := 1
while [%i < 10] do
emit %i,%f
%i := %i + 1
%f := %f * %i
end
end
0 1
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880