<?php
require_once("SoundRegex.class.php");
$resultado = "";
if(@$_POST['cmdProcurar']){
$string = @$_POST['string'];
$word = @$_POST['word'];
$tolerancia = @$_POST['tolerancia'];
$soundregex = new SoundRegex($word, $string);
$soundregex->setTolerance($tolerancia);
$matches = $soundregex->getMatches();
//$resultado.= "Usando a ER: ".$soundregex->getPattern()."<br/>";
if($matches){
$resultado.= "<pre>";
$string = $soundregex->getString();
$resultado.= "Procurando <b>'$word'</b> no texto:</br>$string <br/>";
$resultado.= "<h2>Textos encontrados (Ordem de Similaridade): </h2>";
$similarity = $soundregex->getMatchesSimilarity();
foreach ($similarity as $perc => $match) {
$resultado.= "<li>".$match." - Similarity: $perc%</li>";
}
$resultado.= "</pre>";
}
else{
$resultado.= "Nenhuma ocorrência parecida com <b>'$word'</b> no texto:<br/> $string";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Algoritmo de Busca Fonética para Textos</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action='' method='post' name='formRegexSoundex'>
<h1>Algoritmo de Busca Fonética para Textos</h1>
<p>
<label>Texto Procurado</label><br/>
<input type='text' name='word' value='<?=@$_POST['word'];?>'/></p>
<p>
<label>Conteúdo</label><br/>
<textarea name='string' rows='6' cols='100'><?=@$_POST['string'];?></textarea>
</p>
<p>
<label>Tolerância</label>
<select name='tolerancia'>
<option value='0' <?=(@$_POST['tolerancia'] == 0)? 'selected' : '';?>>0%</option>
<option value='25' <?=(@$_POST['tolerancia'] == 25)? 'selected' : '';?>>25%</option>
<option value='50' <?=(@$_POST['tolerancia'] == 50)? 'selected' : '';?>>50%</option>
<option value='75' <?=(@$_POST['tolerancia'] == 75)? 'selected' : '';?>>75%</option>
<option value='100' <?=(@$_POST['tolerancia'] == 100)? 'selected' : '';?>>100%</option>
</select>
</p>
<p>
<input type='submit' value='Procurar' name='cmdProcurar'/>
</p>
<p>
<div><?=$resultado;?></div>
</p>
</form>
</body>
</html>