From 807b6cc095b69f92ed84d5af504157c5ad099a3b Mon Sep 17 00:00:00 2001 From: RA Date: Tue, 3 Nov 2015 10:18:09 +0200 Subject: [PATCH] fix genderAutoDetect --- Library/NCL/NCLNameCaseCore.php | 29 +++++++++++++++++++++++++++-- Library/NCL/NCLNameCaseWord.php | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Library/NCL/NCLNameCaseCore.php b/Library/NCL/NCLNameCaseCore.php index 3580548..43af4f3 100644 --- a/Library/NCL/NCLNameCaseCore.php +++ b/Library/NCL/NCLNameCaseCore.php @@ -88,6 +88,8 @@ class NCLNameCaseCore extends NCL */ private $index = array(); + public $gender_koef=0;//вероятность автоопредления пола [0..10]. Достаточно точно при 0.1 + /** * Метод очищает результаты последнего склонения слова. Нужен при склонении нескольких слов. */ @@ -516,9 +518,32 @@ class NCLNameCaseCore extends NCL public function genderAutoDetect() { $this->prepareEverything(); - if (isset($this->words[0])) + + if (!empty($this->words)){ + $n=-1; + $max_koef=-1; + foreach ($this->words as $k=>$word){ + $genders=$word->getGender(); + $min=min( $genders ); + $max=max( $genders ); + $koef=$max-$min; + if ($koef>$max_koef) { + $max_koef=$koef; + $n=$k; + } + } + + if ($n>=0){ + if (isset($this->words[$n])) { - return $this->words[0]->gender(); + $genders=$this->words[$n]->getGender(); + $min=min( $genders ); + $max=max( $genders ); + $this->gender_koef=$max-$min; + + return $this->words[$n]->gender(); + } + } } return false; } diff --git a/Library/NCL/NCLNameCaseWord.php b/Library/NCL/NCLNameCaseWord.php index c004a23..ed81e95 100644 --- a/Library/NCL/NCLNameCaseWord.php +++ b/Library/NCL/NCLNameCaseWord.php @@ -200,7 +200,7 @@ class NCLNameCaseWord { if (!$this->genderSolved) { - if ($this->genderMan > $this->genderWoman) + if ($this->genderMan >= $this->genderWoman) { $this->genderSolved = NCL::$MAN; }