Commit b22d8458 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-01-23 12:45:12 by cmiachon] Empty log message

Original author: cmiachon
Date: 2004-01-23 12:45:12+00:00
parent 0ea892e2
(*
List the number of items auctioned each month in 1999 for which data is available, ordered by month.
*)
(* functions *)
let fun count(x : [Any*]) : Int =
let tr_count((Int,[Any*]) -> Int)
| (n,[]) -> n
| (n,[_;t]) -> tr_count(n+1,t)
in tr_count(0,x);;
let fun member ((Any,Any) -> Bool)
|(s,[h;t]) -> if (s=h) then `true else member (s,t)
|(_,_) -> `false;;
let fun distinct_values ([Any*] -> [Any*])
| l -> let fun aux (([Any*],[Any*])->[Any*])
| ([h;t],l2) ->if member(h,t) then aux(t,l2)
else aux(t,l2@[h])
| ([],l2) -> l2
in aux(l,[]);;
(* tri a bulle *)
let fun passe ([Any*] -> [Any*])
[]->[]
| [a] -> [a]
| [a b;c] -> if a << b then [a] @ passe ( [b] @ c)
else [b] @ passe ( [a] @ c) ;;
let fun order ([Any*] -> [Any*])
l -> let l2=passe(l) in
if l = l2 then l
else order(l2);;
(**********************)
type Year = ['1'--'9' '0'--'9' '0'--'9' '0'--'9'];;
type Month = [('0' '1'--'9'| '1' '0'--'2')] ;;
type Day = [('0' '1'--'9'| '1'--'2' '0'--'9'|'30'|'31')];;
type Date = ['1'--'9' '0'--'9' '0'--'9' '0'--'9' '-' ('0' '1'--'9'| '1' '0'--'2') '-' ('0' '1'--'9'| '1'--'2' '0'--'9'|'30'|'31')];;
let fun get-day-from-date(Date -> Day)
|[_* '-' d::(_ _)] ->d
;;
let fun get-month-from-date(Date -> Month)
|[_* '-' m::(_ _) '-'_*] ->m
;;
let fun get-year-from-date(Date -> Year)
|[y::(_ _ _ _) _*] -> y
;;
let end_dates = [items]/Item_tuple/End_date
in <result>
select <monthly_result>[<month>m <item_count>counting]
from m in order(distinct_values(
select get-month-from-date([e]/Char & Date)
from e in end_dates )),
counting in let x=count(
select x
from x in end_dates
where get-year-from-date([x]/Char & Date) ="1999"
and get-month-from-date([x]/Char & Date)= m
)in [x]
;;
(* in XQUERY
<result>
{
let $end_dates := doc("items.xml")//item_tuple/end_date
for $m in distinct-values(for $e in $end_dates
return get-month-from-date($e))
let $item := doc("items.xml")
//item_tuple[get-year-from-date(end_date) = 1999
and get-month-from-date(end_date) = $m]
order by $m
return
<monthly_result>
<month>{ $m }</month>
<item_count>{ count($item) }</item_count>
</monthly_result>
}
</result>
*)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment