Beispiel #1
0
double jaro_dist::score(std::string str1,std::string str2)
{
	int halflen = halfLengthOfShorter(str1, str2);
	std::string common1 = commonChars(str1, str2, halflen);
	std::string common2 = commonChars(str1, str2, halflen);
	if (common1.length()!=common2.length()) return 0;
	if (common1.length()==0 || common2.length()==0) return 0;
	int transpos = transpositions(common1, common2);
	double dist = (common1.length()/(double)str1.length() +
			common2.length()/(double)str2.length() +
			(common1.length()-transpos)/((double)common1.length())) /3.0;
	return dist;
}
float
jaro(char *s,  char *t, size_t ss, size_t st) {
  int halflen, transpos;
  char *common1, *common2;
  float retval, sc1, sc2;

  halflen = (ss > st) ? ss / 2 + 1 : st / 2 + 1;

  common1 = common_chars(s, t, ss, st, halflen, &sc1);
  common2 = common_chars(t, s, st, ss, halflen, &sc2);
  retval = 0.0F;

  if(sc1 == sc2 && sc1 != 0){
    transpos = transpositions(common1, common2, sc1);
    retval = (sc1 / ss + sc2 / st + (sc1 - transpos) / sc1) / 3.0F;
  }
  free(common1);
  free(common2);
  return retval;
}
Beispiel #3
0
static char *find_corrections(char *word)
{
  char **possibles = allocate_possibles(strlen(word));
  char *result;
  int index = 0;

  if (possibles == NULL) {
    fprintf(stderr, "cannot allocate the array of possibles");
    exit(EXIT_FAILURE);
  }

  /* construires une liste de mots possibles */
  index = deletions(word, possibles, index);
  index = transpositions(word, possibles, index);
  index = alterations(word, possibles, index);
  index = inserts(word, possibles, index);

  /*choisir le meilleur candidat entre word et les mots possibles */
  result = better_candidate(word, possibles, index);

  /* un peu de ménage avant de renvoyer le meilleur candidat */
  destroy_possibles(possibles, index);
  return result;
}