occurences_grammar.sh 7.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/bash

xslt=`grep 'xslt' benchmarks-all-full.xml | sed -e 's/.*href="\([^"]*\).*/\1/'`
xquery=`grep 'xquery' benchmarks-all-full.xml | sed -e 's/.*href="\([^"]*\).*/\1/'`

# XSLT queries (total)
total_xslt=0
for file in $xslt
do
  count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath)" $file`
  total_xslt=$(($total_xslt+$count))
done

# Xquery queries (total)
total_xquery=0
for file in $xquery
do
  count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath)" $file`
  total_xquery=$(($total_xquery+$count))
done

# Total queries
total=$(($total_xslt+$total_xquery))

Sylvain Schmitz's avatar
Sylvain Schmitz committed
25
printf '\\begin{tabular}{lr@{\\hspace{1pt}}rr@{\\hspace{1pt}}rr@{\\hspace{1pt}}r}\n'
26
printf '\\toprule\n'
Sylvain Schmitz's avatar
bla  
Sylvain Schmitz committed
27
printf 'Syntactic construct & \\multicolumn{2}{c}{XSLT} & \\multicolumn{2}{c}{XQuery} & \\multicolumn{2}{c}{Total} \\\\\n'
28 29 30
printf '\\midrule\n'

list=(xpathAxis rootExpr stepExpr predicates unionOp functionCallExpr varRef letExpr forExpr orOp isOp data datap)
Sylvain Schmitz's avatar
bla  
Sylvain Schmitz committed
31
legend=('$\\alpha\\dd$' '$/\\pi$' '$\\pi/\\pi$' '$\\pi[\\varphi]$' '$\\pi\\mathrel\\texttt{union}\\pi$' '$f(\\pi_1,\\dots,\\pi_n)$' '$\\mathtt{\\$x}$' '$\\texttt{let}\\:\\mathtt{\\$x}:=\\pi\\mathbin\\texttt{return}\\pi\\!\\!$' '$\\texttt{for}\\:\\mathtt{\\$x}\\mathrel\\texttt{in}\\pi\\mathrel\\texttt{return}\\pi\\!\\!$' '$\\varphi\\mathrel\\texttt{or}\\varphi,~\\varphi\\mathrel\\texttt{and}\\varphi$' '$\\pi\\mathrel\\texttt{is}\\pi$' '$\\pi\\mathbin\\triangle\\pi$' '$\\pi\\mathbin{\\trianglep}d$')
32 33 34 35 36 37 38 39 40 41 42

n=`echo ${#list[@]}`
for (( i=0; i<$n; i++))
do
  name=`echo ${list[$i]}`
  printf ${legend[$i]}
  printf ' & '
  # XSLT files
  count_xslt=0
  for file in $xslt
  do
Anthony Lick's avatar
Anthony Lick committed
43 44 45
    if [ $name = "rootExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[local-name()='functionName' and .='root']] | /benchmark/xpath[ast/descendant::*[local-name()='rootExpr']])" $file`
    elif [ $name = "stepExpr" ]; then
46
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:stepExpr/following-sibling::*[1 and self::xqx:stepExpr]])" $file`
Anthony Lick's avatar
Anthony Lick committed
47 48
    elif [ $name = "varRef" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[local-name()='varRef' and not(*[local-name()='name'] = ancestor::*[local-name()='flworExpr']/*/*/*/*[local-name()='varName'])]])" $file`
49 50 51 52 53
    elif [ $name = "forExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:forExpr or .//xqx:quantifiedExpr]])" $file`
    elif [ $name = "orOp" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:orOp or .//xqx:andOp]])" $file`
    elif [ $name = "data" ]; then
Anthony Lick's avatar
Anthony Lick committed
54
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp') and child::*[local-name()='firstOperand']/child::*[local-name()='pathExpr' or local-name()='contextItemExpr'] and child::*[local-name()='secondOperand']/child::*[local-name()='pathExpr' or local-name()='contextItemExpr']] or ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp') and not(child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr'])]])" $file`
55
    elif [ $name = "datap" ]; then
Anthony LICK's avatar
Anthony LICK committed
56
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp' or local-name()='ltOp' or local-name()='leOp' or local-name()='gtOp' or local-name()='geOp' or local-name()='lessThanOp' or local-name='lessThanOrEqualOp' or local-name()='greaterThanOp' or local-name()='greaterThanOrEqualOp') and child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr']]])" $file`
57 58 59 60 61 62
    else
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:$name])" $file`
    fi
    count_xslt=$(($count_xslt+$count))
  done
  percent=`echo "scale=1; 100*$count_xslt/$total_xslt" | bc`
Sylvain Schmitz's avatar
Sylvain Schmitz committed
63
  printf "%'.0f & (%.1f\\%%)" $count_xslt $percent
64 65 66 67 68
  printf ' & '
  # XQuery files
  count_xquery=0
  for file in $xquery
  do
Anthony Lick's avatar
Anthony Lick committed
69 70 71
    if [ $name = "rootExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[local-name()='functionName' and .='root']] | /benchmark/xpath[ast/descendant::*[local-name()='rootExpr']])" $file`
    elif [ $name = "stepExpr" ]; then
Anthony LICK's avatar
Anthony LICK committed
72
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:stepExpr/following-sibling::*[1 and self::xqx:stepExpr]])" $file`
Anthony Lick's avatar
Anthony Lick committed
73 74
    elif [ $name = "varRef" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[local-name()='varRef' and not(*[local-name()='name'] = ancestor::*[local-name()='flworExpr']/*/*/*/*[local-name()='varName'])]])" $file`
Anthony LICK's avatar
Anthony LICK committed
75
    elif [ $name = "forExpr" ]; then
76
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:forExpr or .//xqx:quantifiedExpr]])" $file`
Anthony LICK's avatar
Anthony LICK committed
77 78 79
    elif [ $name = "orOp" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:orOp or .//xqx:andOp]])" $file`
    elif [ $name = "data" ]; then
Anthony Lick's avatar
Anthony Lick committed
80
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp') and child::*[local-name()='firstOperand']/child::*[local-name()='pathExpr' or local-name()='contextItemExpr'] and child::*[local-name()='secondOperand']/child::*[local-name()='pathExpr' or local-name()='contextItemExpr']] or ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp') and not(child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr'])]])" $file`
Anthony LICK's avatar
Anthony LICK committed
81 82
    elif [ $name = "datap" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp' or local-name()='ltOp' or local-name()='leOp' or local-name()='gtOp' or local-name()='geOp' or local-name()='lessThanOp' or local-name='lessThanOrEqualOp' or local-name()='greaterThanOp' or local-name()='greaterThanOrEqualOp') and child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr']]])" $file`
83 84 85 86 87 88
    else
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:$name])" $file`
    fi
    count_xquery=$(($count_xquery+$count))
  done
  percent=`echo "scale=1; 100*$count_xquery/$total_xquery" | bc`
Sylvain Schmitz's avatar
Sylvain Schmitz committed
89
  printf "%'.0f & (%.1f\\%%)" $count_xquery $percent
90 91 92
  printf ' & '
  count_total=$(($count_xslt+$count_xquery))
  percent=`echo "scale=1; 100*$count_total/$total" | bc`
Sylvain Schmitz's avatar
Sylvain Schmitz committed
93
  printf "%'.0f & (%.1f\\%%)" $count_total $percent
94 95 96 97
  printf ' \\\\\n'
done
printf '\\bottomrule\n'
printf '\\end{tabular}\n'