├── composer.json ├── examples.php ├── composer.lock ├── README.md └── src └── Sozluk.php /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "emrebakkal/sozlukphp", 3 | "description": "Türk Dil Kurumunun hazırladığı Türkçe sözlük API'ı için hazırlanmış, basitleştirilmiş bir PHP kutuphanesi.", 4 | "type": "library", 5 | "autoload": { 6 | "psr-4": { 7 | "SozlukPHP\\": "./src/" 8 | } 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Emre BAKKAL", 13 | "homepage": "https://github.com/emrebakkal" 14 | } 15 | ], 16 | "require": {} 17 | } 18 | -------------------------------------------------------------------------------- /examples.php: -------------------------------------------------------------------------------- 1 | word("programlama"); 11 | echo $word->getMeaning(); // Kelimenin anlamını yazdırır. 12 | 13 | // 2. Yöntem 14 | echo $sozluk->word("programlama")->getMeaning(); // Kelimenin anlamını yazdırır. 15 | 16 | 17 | // Bu dosya basit kullanım örnegidir. Daha fazla örnek için lütfen repodaki readme'yi okuyun. -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "a9df57323317211835c38a913792bc47", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": [], 16 | "platform-dev": [], 17 | "plugin-api-version": "2.3.0" 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SozlukPHP 2 | Türkçe sözlük API'ı için hazırlanmış bir PHP kütüphanesi. 3 | 4 | ## 📦 Kurulum 5 | ```sh 6 | composer require emrebakkal/sozlukphp 7 | ``` 8 | 9 | ## 👨‍💻 Kullanım 10 | Kütüphaneyi dosyaya dahil etmek 11 | ```php 12 | checkWord("programlama"); 21 | // Bool (True veya False) dondurur 22 | ``` 23 | Kelimenin anlamını çekmek 24 | ```php 25 | echo $sozluk->word("programlama")->getMeaning(); 26 | // Ekrana, verilen kelimenin ilk anlamini (0 index'ini) yazdirir. Dilerseniz parametre olarak istediginiz anlamin index degerini girebilirsiniz. 27 | ``` 28 | Kelimenin tüm anlamlarını çekmek (Array) 29 | ```php 30 | print_r($sozluk->word("programlama")->getMeanings()); 31 | // Ekrana, verilen kelimenin butun anlamlarini array tipinden yazdiracaktir. 32 | ``` 33 | Kelimenin tüm anlamlarının index sayısını çekmek 34 | ```php 35 | echo $sozluk->word("programlama")->countMeanings(); 36 | ``` 37 | Kelimenin Türkçe sözlükteki ilk örnek cümlesini çekmek 38 | ```php 39 | echo $sozluk->word("programlama")->getExample(); 40 | // Ekrana, verilen kelimenin ilk ornegini (0 index'ini) yazdirir. Dilerseniz parametre olarak istediginiz ornegin index degerini girebilirsiniz. 41 | ``` 42 | Kelimenin ilk atasözünü çekmek 43 | ```php 44 | echo $sozluk->word("zafer")->getProverb(); 45 | // Ekrana, verilen kelimenin ilk atasozunu (0 index'ini) yazdirir. Dilerseniz parametre olarak istediginiz atasozunun index degerini girebilirsiniz. 46 | ``` 47 | Kelimenin bütün atasözlerini çekmek (Array) 48 | ```php 49 | print_r($sozluk->word("fatih")->getProverbs()); 50 | ``` 51 | Kelimenin atasözlerinin index sayısını çekmek 52 | ```php 53 | echo $sozluk->word("ocak")->countProverbs(); 54 | ``` 55 | 56 | Kelimenin Türkçe Sözlük veritabanındaki numarasını çekmek 57 | ```php 58 | echo $sozluk->word("programlama")->getWordNo(); 59 | ``` 60 | Kelimeninin takısını çekmek (varsa) 61 | ```php 62 | echo $sozluk->word("kadir")->getAffix(); 63 | ``` 64 | Kelimenin çoğul olup olmadığını çekmek 65 | ```php 66 | echo $sozluk->word("programlama)->isPlural(); 67 | ``` 68 | Kelimenin birleşiklerini çekmek 69 | ```php 70 | echo $sozluk->word("araba")->getCompound(); 71 | ``` 72 | Kelimenin telaffuzunu çekmek 73 | ```php 74 | echo $sozluk->word("ordu")->getPronunciation(); 75 | ``` 76 | 77 | --- 78 | ## [Telegram](https://t.me/bpercent)'dan benimle iletişime geçebilirsiniz. 79 | - Görüşlerinizi ve isteklerinizi paylaşmayı unutmayın. Eksik gördüğünüz vs. kısımlar için pull request atmayı ve repoyu yıldızlamayı unutmayın! 80 | -------------------------------------------------------------------------------- /src/Sozluk.php: -------------------------------------------------------------------------------- 1 | url = "https://sozluk.gov.tr/gts?ara="; 15 | $this->data = json_decode(file_get_contents($this->url . @$this->word), true); 16 | } 17 | 18 | public function __construct() { 19 | $this->fgc(); 20 | } 21 | 22 | // Kelimenin Türkçe sözlükte var olup olmadığını kontrol eder ve sonuç olarak boolean döndürür. 23 | public function checkWord($word) { 24 | $this->word = $word; 25 | $this->data = json_decode(file_get_contents($this->url . $this->word), true); 26 | if (@$this->data['error']) { 27 | return false; 28 | } else { 29 | return true; 30 | } 31 | } 32 | 33 | public function word($word) { 34 | $this->word = strtolower($word); 35 | return $this; 36 | } 37 | 38 | // Kelimenin Sözlükteki No'sunu döndürür. 39 | public function getWordNo() { 40 | $this->fgc(); 41 | return $this->checkWord($this->word) ? $this->data[0]['kelime_no'] : "Kelime bulunamadı."; 42 | } 43 | 44 | // Kelimenin takısını döndürür. 45 | public function getAffix() { 46 | $this->fgc(); 47 | $affix = @$this->data[0]['taki']; 48 | return $this->checkWord($this->word) ? $affix ? $affix : "Kelimenin takısı yok." : "Kelime bulunamadı."; 49 | } 50 | 51 | // Kelimenin çoğul olup olmadığını boolean olarak döndürür. 52 | public function isPlural() { 53 | $this->fgc(); 54 | $plural = $this->data[0]['cogul_mu']; 55 | return $this->checkWord($this->word) ? $plural ? true : false : "Kelime bulunamadı."; 56 | } 57 | 58 | // Kelimenin birleşiklerini döndürür. 59 | public function getCompound() { 60 | $this->fgc(); 61 | $compound = @$this->data[0]['birlesikler']; 62 | return $this->checkWord($this->word) ? $compound ? $compound : "Kelimenin birleşikleri yok." : "Kelime bulunamadı."; 63 | } 64 | 65 | // Kelimenin telaffuzunu döndürür. 66 | public function getPronunciation() { 67 | $this->fgc(); 68 | $telaffuz = $this->data[0]['telaffuz']; 69 | return $this->checkWord($this->word) ? $telaffuz ? $telaffuz : "Kelimenin telaffuzu bulunamadı." : "Kelime bulunamadı."; 70 | } 71 | 72 | // Kelimenin Türkçe sözlükteki anlamını verilen index'e göre döndürür. Varsayılan index 0'dır. 73 | public function getMeaning($index = 0) { 74 | $this->fgc(); 75 | if ($this->checkWord($this->word)) { 76 | $data = (object) $this->data[0]; 77 | $meaning = @$data->anlamlarListe[$index]['anlam']; 78 | if ($meaning) { 79 | return $meaning; 80 | } else { 81 | return "Anlam bulunamadı."; 82 | } 83 | } else { 84 | return "Kelime bulunamadı."; 85 | } 86 | } 87 | 88 | // Kelimenin Türkçe sözlükteki bütün anlamlarını döndürür. 89 | 90 | public function getMeanings() { 91 | $this->fgc(); 92 | if ($this->checkWord($this->word)) { 93 | $data = $this->data[0]; 94 | for ($i = 1; $i < count($data['anlamlarListe']); $i++) { 95 | $meanings[] = @$data['anlamlarListe'][$i]['anlam']; 96 | } 97 | if ($meanings) { 98 | return array_unique($meanings); 99 | } else { 100 | return "Anlamlar bulunamadı."; 101 | } 102 | } else { 103 | return "Kelime bulunamadı."; 104 | } 105 | } 106 | 107 | // Kelimenin kaç adet anlamı olduğunu integer olarak döndürür. 108 | public function countMeanings() { 109 | $this->fgc(); 110 | return count(@$this->data[0]['anlamlarListe']); 111 | } 112 | 113 | // Kelimenin Türkçe sözlükteki ilk örnek cümlesini döndürür. (Varsayılan index 0'dır. Sonradan deger değiştirilebilir.) 114 | public function getExample($index = 0) { 115 | $this->fgc(); 116 | if ($this->checkWord($this->word)) { 117 | $data = (object) $this->data[0]; 118 | $example = @$data->anlamlarListe[0]['orneklerListe'][$index]['ornek']; 119 | $this->exampleId = $index; 120 | if ($example) { 121 | return $example; 122 | } else { 123 | return "Örnek bulunamadı."; 124 | } 125 | } else { 126 | return "Kelime bulunamadı."; 127 | } 128 | } 129 | 130 | // Kelimenin Türkçe sözlükte bulunan ilk atasözünü döndürür. (Varsayılan index 0'dır. Sonradan deger değiştirilebilir.) 131 | public function getProverb($index = 0) { 132 | $this->fgc(); 133 | if ($this->checkWord($this->word)) { 134 | $data = $this->data[0]; 135 | $proverb = @$data['atasozu']; 136 | if ($proverb) { 137 | return $proverb[$index]['madde']; 138 | } else { 139 | return "Atasözü bulunamadı."; 140 | } 141 | } else { 142 | return "Kelime bulunamadı."; 143 | } 144 | } 145 | 146 | // Kelimenin Türkçe sözlükte bulunan atasözlerini döndürür. 147 | public function getProverbs() { 148 | $this->fgc(); 149 | if ($this->checkWord($this->word)) { 150 | $data = $this->data[0]; 151 | $proverb = @$data['atasozu']; 152 | for ($i = 0; $i < count($proverb); $i++) { 153 | $proverbs[] = @$proverb[$i]['madde']; 154 | } 155 | if ($proverbs) { 156 | return array_unique($proverbs); 157 | } else { 158 | return "Atasözü bulunamadı."; 159 | } 160 | } 161 | } 162 | 163 | // Kelimenin kaç adet atasözü olduğunu integer olarak döndürür. 164 | public function countProverbs() { 165 | $this->fgc(); 166 | for ($i = 0; $i < count(@$this->data[0]['atasozu']); $i++) { 167 | $proverbs[] = @$this->data[0]['atasozu'][$i]['madde']; 168 | } 169 | return $proverbs ? count($proverbs) : 0; 170 | } 171 | } --------------------------------------------------------------------------------