From 6b74a90bd476e44f03bdc0b5c9b896bdf136c23d Mon Sep 17 00:00:00 2001 From: hallgren Date: Thu, 10 Dec 2015 14:27:15 +0000 Subject: [PATCH] Wide Coveage Translation Demo: sort parse results by probability Because of the "heurisitc factor", the results returned by the parser might not be in strict probability order. To compensate, a sorting pass has been added to find and show the translation with the highest probability among the 10 first translations. However, this means that the translation demo now immediately has to ask for 10 translations of every segment. Before, it initially asked for only one translation of every segment, and then 9 more translations for a segment when/if the user clicked on it. This change can slow down translation noticeably (e.g. from 15s 30s to load an example with fiction in English). --- src/www/js/wc.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/www/js/wc.js b/src/www/js/wc.js index 2cd19e289..c32d0f2e8 100644 --- a/src/www/js/wc.js +++ b/src/www/js/wc.js @@ -178,7 +178,8 @@ wc.translate=function() { //if(f.speak.checked) wc.speak(t.text,f.to.value) if(!so.got_more) { so.got_more=true - trans(so.input,1,9) + if(so.rs.length<10) + trans(so.input,so.rs.length,10-so.rs.length) } } so.target.onclick=show_more @@ -233,6 +234,8 @@ wc.translate=function() { } } else { + function cmp(a,b) { return a.prob-b.prob; } + tra=tra.sort(cmp) for(var ti=0;ti