Exemplo n.º 1
0
char	*levenshtein(char *str, UNUSED char **env)
{
  char	**dic;
  char	**command;
  int	i;
  int	pos;

  i = 0;
  pos = 0;
  command = cut_command(str);
  if ((dic = gen_data(save_my_env(NULL))) == NULL)
    return (str);
  while (command && command[i] != NULL)
    {
      if (i == 0 || is_separator_ext(command[i - 1][0]) == 0)
	{
	  if (check_command(command[i], save_my_env(NULL)) == -1)
	    {
	      pos = where_is_space(command[i]);
	      command[i] = change_command(command[i],
					  leven(dic, po_s(command[i], pos)));
	    }
	}
      i++;
    }
  free_array_char(dic);
  return (tab_string(command));
}
Exemplo n.º 2
0
Snippet::Snippet(const Text &original, const Text &modified)
{
    if (original.numLines() != modified.numLines()){
        _fromTextToTextSnippets(original, _original);
        _fromTextToTextSnippets(modified, _modified);
    }else{
        LevenshteinDistances leven(original, modified);
        const list_of_ranges_t orig_ranges = leven.getRangesOriginal();
        const list_of_ranges_t modif_ranges = leven.getRangesModified();
        int len = original.numLines();

        _original.resize(len);
        _modified.resize(len);

        for (int i=0; i < len; i++){
            //original:
            if (orig_ranges[i].size() == 0){
                _original[i].push_back(new TextSnippet(original.getLine(i),
                                                       range_t::NOCHANGE));
            }else{
                _splitByRanges(original.getLine(i), orig_ranges[i],
                        _original[i]);
            }

            //modified:
            if (modif_ranges[i].size() == 0){
                _modified[i].push_back(new TextSnippet(modified.getLine(i),
                                                       range_t::NOCHANGE));
            }else{
                _splitByRanges(modified.getLine(i), modif_ranges[i],
                        _modified[i]);
            }
        }
    }
}