Beispiel #1
0
 public double score(Candidate[] path, CandidateSet[] candidates) throws IOException {
   double score = 0.0d;
   for (int i = 0; i < candidates.length; i++) {
     score += scorer.score(path, candidates, i, gramSize);
   }
   return Math.exp(score);
 }
Beispiel #2
0
 public void findCandidates(
     CandidateSet[] candidates,
     Candidate[] path,
     int ord,
     int numMissspellingsLeft,
     PriorityQueue<Correction> corrections,
     double cutoffScore,
     final double pathScore)
     throws IOException {
   CandidateSet current = candidates[ord];
   if (ord == candidates.length - 1) {
     path[ord] = current.originalTerm;
     updateTop(
         candidates,
         path,
         corrections,
         cutoffScore,
         pathScore + scorer.score(path, candidates, ord, gramSize));
     if (numMissspellingsLeft > 0) {
       for (int i = 0; i < current.candidates.length; i++) {
         path[ord] = current.candidates[i];
         updateTop(
             candidates,
             path,
             corrections,
             cutoffScore,
             pathScore + scorer.score(path, candidates, ord, gramSize));
       }
     }
   } else {
     if (numMissspellingsLeft > 0) {
       path[ord] = current.originalTerm;
       findCandidates(
           candidates,
           path,
           ord + 1,
           numMissspellingsLeft,
           corrections,
           cutoffScore,
           pathScore + scorer.score(path, candidates, ord, gramSize));
       for (int i = 0; i < current.candidates.length; i++) {
         path[ord] = current.candidates[i];
         findCandidates(
             candidates,
             path,
             ord + 1,
             numMissspellingsLeft - 1,
             corrections,
             cutoffScore,
             pathScore + scorer.score(path, candidates, ord, gramSize));
       }
     } else {
       path[ord] = current.originalTerm;
       findCandidates(
           candidates,
           path,
           ord + 1,
           0,
           corrections,
           cutoffScore,
           pathScore + scorer.score(path, candidates, ord, gramSize));
     }
   }
 }