xquery version "3.0"; module namespace display="http://divvun.no/iskkan/display"; import module namespace templates="http://exist-db.org/xquery/templates" ; import module namespace config="http://divvun.no/iskkan/config" at "config.xqm"; declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; declare function display:edit-dist-table($tp as xs:int*, $el as element()) { let $AllEdit1Place := sum($el/sugg1/@editdist1 + $el/sugg1/@editdist2 + $el/sugg1/@editdist3plus), $AllEdit1PlacePerc := round-half-to-even((($AllEdit1Place div $tp) * 100), 2), $OneEdit1PlacePerc := round-half-to-even((($el/sugg1/@editdist1 div $tp) * 100), 2), $TwoEdit1PlacePerc := round-half-to-even((($el/sugg1/@editdist2 div $tp) * 100), 2), $ThrEdit1PlacePerc := round-half-to-even((($el/sugg1/@editdist3plus div $tp) * 100), 2), $AllEdit2Place := sum($el/sugg2/@editdist1 + $el/sugg2/@editdist2 + $el/sugg2/@editdist3plus), $AllEdit2PlacePerc := round-half-to-even((($AllEdit2Place div $tp) * 100), 2), $OneEdit2PlacePerc := round-half-to-even((($el/sugg2/@editdist1 div $tp) * 100), 2), $TwoEdit2PlacePerc := round-half-to-even((($el/sugg2/@editdist2 div $tp) * 100), 2), $ThrEdit2PlacePerc := round-half-to-even((($el/sugg2/@editdist3plus div $tp) * 100), 2), $AllEdit3Place := sum($el/sugg3/@editdist1 + $el/sugg3/@editdist2 + $el/sugg3/@editdist3plus), $AllEdit3PlacePerc := round-half-to-even((($AllEdit3Place div $tp) * 100), 2), $OneEdit3PlacePerc := round-half-to-even((($el/sugg3/@editdist1 div $tp) * 100), 2), $TwoEdit3PlacePerc := round-half-to-even((($el/sugg3/@editdist2 div $tp) * 100), 2), $ThrEdit3PlacePerc := round-half-to-even((($el/sugg3/@editdist3plus div $tp) * 100), 2), $AllEdit4Place := sum($el/sugg4/@editdist1 + $el/sugg4/@editdist2 + $el/sugg4/@editdist3plus), $AllEdit4PlacePerc := round-half-to-even((($AllEdit4Place div $tp) * 100), 2), $OneEdit4PlacePerc := round-half-to-even((($el/sugg4/@editdist1 div $tp) * 100), 2), $TwoEdit4PlacePerc := round-half-to-even((($el/sugg4/@editdist2 div $tp) * 100), 2), $ThrEdit4PlacePerc := round-half-to-even((($el/sugg4/@editdist3plus div $tp) * 100), 2), $AllEdit5Place := sum($el/sugg5/@editdist1 + $el/sugg5/@editdist2 + $el/sugg5/@editdist3plus), $AllEdit5PlacePerc := round-half-to-even((($AllEdit5Place div $tp) * 100), 2), $OneEdit5PlacePerc := round-half-to-even((($el/sugg5/@editdist1 div $tp) * 100), 2), $TwoEdit5PlacePerc := round-half-to-even((($el/sugg5/@editdist2 div $tp) * 100), 2), $ThrEdit5PlacePerc := round-half-to-even((($el/sugg5/@editdist3plus div $tp) * 100), 2), $AllEdit6Place := sum($el/suggbelow5/@editdist1 + $el/suggbelow5/@editdist2 + $el/suggbelow5/@editdist3plus), $AllEdit6PlacePerc := round-half-to-even((($AllEdit6Place div $tp) * 100), 2), $OneEdit6PlacePerc := round-half-to-even((($el/suggbelow5/@editdist1 div $tp) * 100), 2), $TwoEdit6PlacePerc := round-half-to-even((($el/suggbelow5/@editdist2 div $tp) * 100), 2), $ThrEdit6PlacePerc := round-half-to-even((($el/suggbelow5/@editdist3plus div $tp) * 100), 2), $AllEdit0Place := sum($el/nosugg/@editdist1 + $el/nosugg/@editdist2 + $el/nosugg/@editdist3plus), $AllEdit0PlacePerc := round-half-to-even((($AllEdit0Place div $tp) * 100), 2), $OneEdit0PlacePerc := round-half-to-even((($el/nosugg/@editdist1 div $tp) * 100), 2), $TwoEdit0PlacePerc := round-half-to-even((($el/nosugg/@editdist2 div $tp) * 100), 2), $ThrEdit0PlacePerc := round-half-to-even((($el/nosugg/@editdist3plus div $tp) * 100), 2), $AllEditXPlace := sum($el/badsuggs/@editdist1 + $el/badsuggs/@editdist2 + $el/badsuggs/@editdist3plus), $AllEditXPlacePerc := round-half-to-even((($AllEditXPlace div $tp) * 100), 2), $OneEditXPlacePerc := round-half-to-even((($el/badsuggs/@editdist1 div $tp) * 100), 2), $TwoEditXPlacePerc := round-half-to-even((($el/badsuggs/@editdist2 div $tp) * 100), 2), $ThrEditXPlacePerc := round-half-to-even((($el/badsuggs/@editdist3plus div $tp) * 100), 2) return (

Suggestion summary

Correct suggestion position for true positives, %: All edit
dists
Edit
dist=1
Edit
dist=2
Edit
dist≥3
First place: {$AllEdit1PlacePerc} {$OneEdit1PlacePerc} {$TwoEdit1PlacePerc} {$ThrEdit1PlacePerc}
Second place: {$AllEdit2PlacePerc} {$OneEdit2PlacePerc} {$TwoEdit2PlacePerc} {$ThrEdit2PlacePerc}
Third place: {$AllEdit3PlacePerc} {$OneEdit3PlacePerc} {$TwoEdit3PlacePerc} {$ThrEdit3PlacePerc}
Fourth place: {$AllEdit4PlacePerc} {$OneEdit4PlacePerc} {$TwoEdit4PlacePerc} {$ThrEdit4PlacePerc}
Fifth place: {$AllEdit5PlacePerc} {$OneEdit5PlacePerc} {$TwoEdit5PlacePerc} {$ThrEdit5PlacePerc}
Sum: spelling errors with correct suggestion in top 5: {round-half-to-even((sum( $AllEdit1PlacePerc + $AllEdit2PlacePerc + $AllEdit3PlacePerc + $AllEdit4PlacePerc + $AllEdit5PlacePerc) * 100), 2) div 100} {round-half-to-even((sum( $OneEdit1PlacePerc + $OneEdit2PlacePerc + $OneEdit3PlacePerc + $OneEdit4PlacePerc + $OneEdit5PlacePerc) * 100), 2) div 100} {round-half-to-even((sum( $TwoEdit1PlacePerc + $TwoEdit2PlacePerc + $TwoEdit3PlacePerc + $TwoEdit4PlacePerc + $TwoEdit5PlacePerc) * 100), 2) div 100} {round-half-to-even((sum( $ThrEdit1PlacePerc + $ThrEdit2PlacePerc + $ThrEdit3PlacePerc + $ThrEdit4PlacePerc + $ThrEdit5PlacePerc) * 100), 2) div 100}
Below top 5: {$AllEdit6PlacePerc} {$OneEdit6PlacePerc} {$TwoEdit6PlacePerc} {$ThrEdit6PlacePerc}
No suggestions: {$AllEdit0PlacePerc} {$OneEdit0PlacePerc} {$TwoEdit0PlacePerc} {$ThrEdit0PlacePerc}
Only wrong suggestions: {$AllEditXPlacePerc} {$OneEditXPlacePerc} {$TwoEditXPlacePerc} {$ThrEditXPlacePerc}
) }; declare function display:table($invocation as map) {
Precision and recall
Reality Real no Positive Negative
}; declare function display:quality($el as element()) {

Suggestion summary

{ for $p in 1 to 6 return { for $dist in 1 to 3 return } }
Suggestion
Position
Edit dist=1 Edit dist=2 Edit dist>=3
{$p}{$el/words[@position=$p][@edit_dist=$dist]}
{ transform:transform($el, doc("/db/apps/iskkan/resources/xslt/bar-chart-svg.xsl"), ()) }
}; declare function display:summary($invocation as map) {

Precision and Recall

Precision (tp/(tp+fp)) {$invocation('precision')}% Recall (tp/(tp+fn)) {$invocation('recall')}% Accuracy ((tp+tn)/words) {$invocation('accuracy')}%

Data for precision and recall

Nº of input words: {$invocation('words')}

Speller view
Speller Positive
(Nº of flagged words):
{$invocation('speller')('error')}
Speller Negative
(Nº of accepted words):
{$invocation('speller')('correct')}
Reality Nº of real errors:
{$invocation('original')('error')}
Nº of true positives
(detected real errors):
{$invocation('positives')('true')}
Nº of false negatives
(unflagged spelling errors):
{$invocation('negatives')('false')}
Nº of real correct words:
{$invocation('original')('correct')}
Nº of false positives
(incorrectly flagged words):
{$invocation('positives')('false')}
Nº of true negatives
(unflagged correct words):
{$invocation('negatives')('true')}
};