<commit_before>module namespace xmark = "http://www.cwi.nl/~boncz/xmark/opt/";

declare function xmark:convert($v as xs:decimal?) as xs:decimal?
{
  2.20371 * $v (: convert Dfl to Euro :)
};

declare function xmark:q01($doc as xs:string, $id as xs:string) as xs:string*
{
  for $b in doc($doc)/descendant::person[@id=$id]
  return $b/name/text()
};

declare function xmark:q02($doc as xs:string) as xs:anyNode*
{
  for $b in doc($doc)/descendant::open_auction
  return <increase> { $b/bidder[1]/increase/text() } </increase>
};

declare function xmark:q03($doc as xs:string) as xs:anyNode* 
{
  for $b in doc($doc)/descendant::open_auction
  where exactly-one($b/bidder[1]/increase/text()) * 2 <= $b/bidder[last()]/increase/text()
  return <increase first="{ $b/bidder[1]/increase/text() }"
                   last="{ $b/bidder[last()]/increase/text() }"/>
};

declare function xmark:q04($doc as xs:string, $person1 as xs:string, $person2 as xs:string) as xs:anyNode*
{
  for $b in doc($doc)/descendant::open_auction
  where some $pr1 in $b/descendant::personref[@person=$person1],
             $pr2 in $b/descendant::personref[@person=$person2] satisfies $pr1 << $pr2
  return <history> { $b/reserve/text() } </history>
};

declare function xmark:q05($doc as xs:string, $min as xs:double) as xs:integer
{
  count(for $i in doc($doc)/descendant::closed_auction
        where  $i/price/text() >= $min
        return $i/price)
};

declare function xmark:q06($doc as xs:string) as xs:integer*
{
  for $b in doc($doc)/descendant::regions
  return count($b//item)
};

declare function xmark:q07($doc as xs:string) as xs:integer*
{
  for $p in doc($doc)/descendant::site
  return count($p/descendant::description) + count($p/descendant::annotation) + count($p/descendant::emailaddress)
};

declare function xmark:q08($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  for $p in $auction/descendant::person
  let $a := for $t in $auction/descendant::closed_auction
            where $t/buyer/@person = $p/@id
            return $t
  return <item person="{ $p/name/text() }"> { count($a) } </item>
};

declare function xmark:q09($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  let $ca := $auction/s/closed_auction
  let $ei := $auction/descendant::item
  for $p in $auction/descendant::person
  let $a :=
    for $t in $ca
    where $p/@id = $t/buyer/@person
    return
      let $n :=
        for $t2 in $ei
        where $t/itemref/@item = $t2/@id
        return $t2
      return <item>{$n/name/text()}</item>
  return <person name="{$p/name/text()}">{$a}</person>
};

declare function xmark:q10($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  for $i in distinct-values($auction/descendant::interest/@category)
  let $p := 
    for $t in $auction/descendant::person
    where $t/profile/interest/@category = $i
    return <personne>
  <statistiques>
    <sexe> { $t/profile/gender/text() } </sexe>
    <age> { $t/profile/age/text() } </age>
    <education> { $t/profile/education/text() } </education>
    <revenu> { fn:data($t/profile/@income) } </revenu><commit_msg>these changes seem to fix bug #1393682 "PF: tests q0{1,4,9} fail in tests/XMark/opt/{MIL,XQ}".<commit_after>module namespace xmark = "http://www.cwi.nl/~boncz/xmark/opt/";

declare function xmark:convert($v as xs:decimal?) as xs:decimal?
{
  2.20371 * $v (: convert Dfl to Euro :)
};

declare function xmark:q01($doc as xs:string, $id as xs:string) as xs:anyNode*
{
  for $b in doc($doc)/descendant::person[@id=$id]
  return $b/name/text()
};

declare function xmark:q02($doc as xs:string) as xs:anyNode*
{
  for $b in doc($doc)/descendant::open_auction
  return <increase> { $b/bidder[1]/increase/text() } </increase>
};

declare function xmark:q03($doc as xs:string) as xs:anyNode* 
{
  for $b in doc($doc)/descendant::open_auction
  where exactly-one($b/bidder[1]/increase/text()) * 2 <= $b/bidder[last()]/increase/text()
  return <increase first="{ $b/bidder[1]/increase/text() }"
                   last="{ $b/bidder[last()]/increase/text() }"/>
};

declare function xmark:q04($doc as xs:string, $person1 as xs:string, $person2 as xs:string) as xs:anyNode*
{
  for $b in doc($doc)/descendant::open_auction
  where some $pr1 in ($b/descendant::personref)[@person=$person1],
             $pr2 in ($b/descendant::personref)[@person=$person2] satisfies $pr1 << $pr2
  return <history> { $b/reserve/text() } </history>
};

declare function xmark:q05($doc as xs:string, $min as xs:double) as xs:integer
{
  count(for $i in doc($doc)/descendant::closed_auction
        where  $i/price/text() >= $min
        return $i/price)
};

declare function xmark:q06($doc as xs:string) as xs:integer*
{
  for $b in doc($doc)/descendant::regions
  return count($b//item)
};

declare function xmark:q07($doc as xs:string) as xs:integer*
{
  for $p in doc($doc)/descendant::site
  return count($p/descendant::description) + count($p/descendant::annotation) + count($p/descendant::emailaddress)
};

declare function xmark:q08($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  for $p in $auction/descendant::person
  let $a := for $t in $auction/descendant::closed_auction
            where $t/buyer/@person = $p/@id
            return $t
  return <item person="{ $p/name/text() }"> { count($a) } </item>
};

declare function xmark:q09($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  let $ca := $auction/descendant::closed_auction
  let $ei := $auction/descendant::europe/item
  for $p in $auction/descendant::person
  let $a :=
    for $t in $ca
    where $p/@id = $t/buyer/@person
    return
      let $n :=
        for $t2 in $ei
        where $t/itemref/@item = $t2/@id
        return $t2
      return <item>{$n/name/text()}</item>
  return <person name="{$p/name/text()}">{$a}</person>
};

declare function xmark:q10($doc as xs:string) as xs:anyNode*
{
  let $auction := doc($doc)
  for $i in distinct-values($auction/descendant::interest/@category)
  let $p := 
    for $t in $auction/descendant::person
    where $t/profile/interest/@category = $i
    return <personne>
  <statistiques>
    <sexe> { $t/profile/gender/text() } </sexe>
    <age> { $t/profile/age/text() } </age>
    <education> { $t/profile/education/text() } </education>
    <revenu> { fn:data($t/profile/@income) } </revenu>
{'fraction_non_alphanumeric': 0.18154526781482067, 'fraction_numerical': 0.014694264496760942, 'mean_word_length': 3.8804934464148033, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5821373', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2316, 'n_words': 537}