Türkçe Soundex

phpdeki Soundex() fonksiyonunu turkce içinde çalışabilir yaptık.  siz de sistemlerinizde   “bunu mu demek istediniz ?” diyebileceğiniz bir veritabanı hazırlayabilirsiniz bununla. hemen sınıfı veriyorum .

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
 
  /**
 * @name        D3Soundex | Turkish Soundex
 * @version     1.0.1
 * @author      Tufan Barış YILDIRIM
 * @link        htpp://www.tufyta.com
 * @since       20.10.2009
 * v1.0
 * ======
 * - İlk Soundex Denemem.
 */
 
 class D3Soundex{
 
     const  AEIO    ='AEIİOÖUÜYıü ',
            BPDT    ='BPDT',
            GKH     ='GKĞğH',
            SZ      ='SZŞş',
            CJ      ='CJÇç',
            FV      ='FV',
            LR      ='LR',
            MN      ='MN';
 
      private   $_hassasiyet=50,
                $_ilkharf,
                $_kalan,
                $_deger,
                $_mixdeger,
                $_maxdeger,
                $_metin,
                $_elemanlar,
                $_zip,
                $_sade,
                $_grep;
 
      public function D3Soundex($hassasiyet){
          if($hassasiyet<0 || $hassasiyet>100){
              $this->Hata('Hassasiyet Değeri 0 ile 100 arasında Bir Değer Alabilir.');
          }
          $this->_hassasiyet=$hassasiyet;
          $this->ElemanOlustur();
 
      } 
 
      public function Metin($metin){
            $this->_metin=$metin;
            $this->_ilkharf=$metin[0];
            $this->_kalan=substr($metin,1,strlen($metin));
 
            $this->Sadelestir();
            $this->AdamEt($this->Tart($metin));
            return $this;
      }
 
      private  function Sadelestir(){
            $this->_sade=preg_replace('/.+/i','\1',$this->_metin);
      }
 
      private function Zip($Metin){
          $Metin=preg_replace('/[^'.$this->_grep.']/i','',$Metin);
              return $this->_zip=preg_replace('/['.self::AEIO.']+/i',$this->_elemanlar[self::AEIO],$Metin);
      }
 
      private function Tart($Metin){
             foreach ($this->_elemanlar as $goruntu=>$kilo){
                   $Metin=preg_replace('/['.$goruntu.']+/i',$kilo,$Metin);
             }
             return $Metin;
      }
 
      private function AdamEt($TartilmisMetin){
          $Basamak=min(10,max(4,floor(strlen($this->Zip($Metin))*$this->_hassasiyet/100)));
          $this->_deger=substr($TartilmisMetin,0,$Basamak);
          return strtoupper($this->_ilkharf).$this->_deger;
      }
 
      public function Deger(){
          return $this->_deger;
      }
 
      public function Soundex(){
          return strtoupper($this->_ilkharf).$this->Deger();
      }
 
      private function ElemanOlustur(){
         $this->_elemanlar=array(
             self::AEIO=>'',
             self::BPDT=>5,
             self::SZ=>3,
             self::MN=>4,
             self::GKH=>8,
             self::CJ=>6,
             self::FV=>2,
             self::LR=>7,
             self::MN=>1,
         );
         $this->_grep=str_replace(' ','',implode(' ',array_keys($this->_elemanlar)));
 
      }
 
      private function Hata($hatametni){
          echo '<b>Hata</b> :  '.$hatametni;
      } 
 
 }
 /**
 * Examlpe
 *
 * @var D3Soundex
 */
 $s=new D3Soundex(100);
 $s->Metin('Bunu mu demek istediniz ?');
 echo "Bunu mu demek istediniz ? =>Soundex Degeri : ".$s->Soundex()." Ağırlık : ".$s->Deger()."<br>";
 $s->Metin('Bunu demek mi istediniz ?');
 echo "Bunu demek mi istediniz ?=>Soundex Degeri : ".$s->Soundex()." Ağırlık : ".$s->Deger()."<br>";
?>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top


Yorum Yapılmamış »

Henüz yorum yapılmamış.

Bu yazıya yapılan yorumlar için RSS beslemeleri. TrackBack URL

Yorum yapın