Commit 4b3e434a authored by Arnaud Bey's avatar Arnaud Bey
Browse files

fix palindromic bigram weight

parent 9ecc4170
...@@ -18,24 +18,24 @@ class BigramManager ...@@ -18,24 +18,24 @@ class BigramManager
public function generateBigrams($bigrams, $pathLexiconDir) public function generateBigrams($bigrams, $pathLexiconDir)
{ {
//hash enregistrant les bigrams déjà écrit à dans $string2print //hash enregistrant les bigrams déjà écrit à dans $string2print
$grambigrams = []; $grambigrams = [];
//Impression des keys //Impression des keys
$string2print="Bigrammes\tFreq\tPoids\tArrondi\n"; $string2print = "Bigrammes\tFreq\tPoids\tArrondi\n";
arsort($bigrams); arsort($bigrams);
$max = max($bigrams); $max = max($bigrams);
$nbTranches = 100;#nombre de tranches pour les poids de bigram (on divise $max par $nbtranches et le résultat vaut poids) $nbTranches = 100;#nombre de tranches pour les poids de bigram (on divise $max par $nbtranches et le résultat vaut poids)
$factorBigram=$max/$nbTranches; $factorBigram = $max/$nbTranches;
foreach ($bigrams as $key => $value) { foreach ($bigrams as $key => $value) {
$yek = $this->mb_strrev($key); $yek = $this->mb_strrev($key);
if (!in_array($key, $grambigrams)) { if (!in_array($key, $grambigrams)) {
$freqInverse=0; $freqInverse = 0;
if (isset($bigrams[$yek])) { if ($yek != $key && isset($bigrams[$yek])) {
$freqInverse=$bigrams[$yek]; $freqInverse = $bigrams[$yek];
} }
$poids = ($value+$freqInverse)/$factorBigram; $poids = ($value + $freqInverse) / $factorBigram;
$poidsRound = 1; $poidsRound = 1;
if ($poids>1) { if ($poids > 1) {
$poidsRound=round($poids); $poidsRound = round($poids);
} }
$string2print .= $key."\t".$value."\t".$poids."\t".$poidsRound."\n"; $string2print .= $key."\t".$value."\t".$poids."\t".$poidsRound."\n";
$grambigrams[] = $key; $grambigrams[] = $key;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment