Selecting and Joining Using FLWORs-Bioinformatics Using Semantic Computing-Lecture Slides, Slides of Semantics of Programming Languages

This lecture was delivered by Bhavesh Verma for Bioinformatics Using Semantic Computing course at Bhagwant University Rajasthan. It includes: Selecting, Joining, FLWOR, Expressions, Queries, Evaluating, Function, Intermediate, Values, Keywords

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dharuna
dharuna 🇮🇳

4.7

(6)

85 documents

1 / 82

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Selecting and Joining Using FLWORs
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52

Partial preview of the text

Download Selecting and Joining Using FLWORs-Bioinformatics Using Semantic Computing-Lecture Slides and more Slides Semantics of Programming Languages in PDF only on Docsity!

Selecting and Joining Using FLWORs

FLWOR Expressions

 FLWOR expressions, also known simply as FLWORs, are used for queries that are more complex.

 In addition to allowing more readable and structured selections, they allow functionality such as joining data from multiple sources, constructing new elements and attributes, evaluating functions on intermediate values, and sorting results.

 For:This clause sets up an iteration through the product elements returned by the path expression.

 Let:This clause binds the $prodDept variable to the value of the dept attribute.

 Where:This clause selects elements whose dept attribute is equal to ACC or WMN.

 Return:This clause returns the name child of each of the three product elements that pass the where clause.

  • There can be multiple for and let clauses, in any order, followed by an optional where clause, followed by an optional order by clause, followed by the required return clause. A FLWOR must have at least one for or let clause.

For Clause

 It sets up an iteration that allows the rest of the FLWOR to be evaluated multiple times, once for each item in the sequence returned by the expression after the in keyword.

 This sequence, also known as the binding sequence, can evaluate to any sequence of zero, one or more items

For Clause

 The FLWOR expression with its for clause is similar to loops in procedural languages such as C. However, one key difference is that in XQuery, because it is a functional language, the iterations are considered to be in no particular order. They do not necessarily occur sequentially, one after the other.

 One manifestation of this is that you cannot keep variable counters that are incremented with each iteration, or continuously append to the end of a string variable with each iteration.

Example ,Using a range expression

Query

for $i in 1 to 3

return {$i}

Result

1

2

3

 You can use the reverse function if you want to descend in value, as in:

for $i in reverse(1 to 3)

 You can also increment by some value other than 1 using an expression like: for $i in (1 to 100)[. mod 2 = 0]

which gives you every other number (2, 4, 6, etc.) up to 100.

 Multiple variables can be bound in a single for clause, separated by commas. This has the same effect as using multiple for clauses.

for $i in (1, 2), $j in ("a", "b")

return i is {$i} and j is {$j}

This syntax is shorter but can be less clear in the case of complex expressions.

Let Clause

 A let clause is a convenient way to bind a variable to a value. Unlike a for clause, a let clause does not result in iteration;  it binds the whole sequence to the variable rather than binding each item in turn.  The let clause serves as a programmatic convenience that avoids repeating the same expression multiple times.  Using some implementations, it can also improve performance, because the expression is evaluated only once instead of each time it is needed.

 The FLWOR with the let clause returns only a single oneEval element, because no iteration takes place and the return clause is evaluated only once.

 One or more let clauses can be intermingled with one or more for clauses. Each of the let and for clauses may reference a variable bound in any previous clause.

 The only requirement is that they all appear before any where, order by, or return clauses of that FLWOR.

Intermingled for and let clauses

let $doc := doc("catalog.xml")

for $prod in $doc//product

let $prodDept := $prod/@dept

let $prodName := $prod/name

where $prodDept = "ACC" or $prodDept = "WMN"

return $prodName

Example

for $prod in doc("catalog.xml")//product

let $prodDept := $prod/@dept

where $prod/number > 100

and starts-with($prod/name, "F")

and exists($prod/colorChoices)

and ($prodDept = "ACC" or $prodDept = "WMN")

return $prod

Return Clause

 The return clause consists of the return keyword followed by the single expression that is to be returned.

 It is evaluated once for each iteration, assuming the where expression evaluated to true.

 The result value of the entire FLWOR is a sequence of items returned by each evaluation of the return clause.

for $i in (1 to 3) return {$i}