-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise 4.3.txt
More file actions
82 lines (68 loc) · 1.92 KB
/
Exercise 4.3.txt
File metadata and controls
82 lines (68 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
declare default element namespace "http://www.parlamento.pt";
let $doc := doc("https://fenix.tecnico.ulisboa.pt/downloadFile/566729524645336/parliamentUdata.xml")
let $sessions := (
for $session in $doc//session
return
copy $s := $session
modify (
insert node ( attribute most-frequent {}) into $s)
return $s
)
let $politicians := (
for $politician in $doc//politician
return
copy $p := $politician
modify (
insert node ( attribute num-interventions {}) into $p,
insert node ( attribute num-sessions {}) into $p)
return $p
)
let $num-interv := (
for $politician in $politicians
let $count := count($doc//speech[@politician eq $politician/@code])
return
copy $p := $politician
modify (
replace value of node $p/@num-interventions with $count)
return $p
)
let $num-sess := (
for $politician in $num-interv
let $interv := (
for $session in $doc//session
let $p := distinct-values($session/speech/@politician)
return $p
)
let $code := $politician/@code
let $count := count(index-of($interv, $code))
return copy $p := $politician
modify (
replace value of node $p/@num-sessions with $count)
return $p
)
let $m-f := (
for $session in $sessions
let $politician := $doc//politician
let $p := (
for $pol in $politician
let $count := count($session/speech[@politician eq $pol/@code])
return <p order= "{$pol/@code}" num= "{$count}" > </p>
)
let $max := max(
for $i in $p
return $i/@num
)
let $politic := $p[@num = $max]
let $party := $politician[@code = $politic/@order]/@party
return
copy $s := $session
modify (
replace value of node $s/@most-frequent with $party)
return $s)
return
copy $d := $doc
modify (
replace node $d//politicians with <politicians> {$num-sess} </politicians>,
replace node $d//parliament-interventions with <parliament-interventions> {$m-f} </parliament-interventions>
)
return $d