ServBay'in Dahili SCWS Modülünün Etkinleştirilmesi
ServBay, güçlü bir entegre web geliştirme aracı olarak kendi SCWS modülüyle birlikte gelir ve bu modülün etkinleştirilmesi oldukça basittir. SCWS (Simple Chinese Word Segmentation), yüksek verimli bir Çince kelime bölme motorudur ve Çince metinleri hızlı ve doğru bir şekilde segment ederek arama motorları, metin analizi gibi uygulama alanlarına son derece uygundur.
SCWS Modülüne Giriş
SCWS, Çince metinleri işlemek üzere tasarlanmış açık kaynaklı bir kelime bölme motorudur. Sözlük eşleştirme ve istatistiksel modelleri birleştirerek yüksek verimli ve doğru kelime bölme işlevleri sağlar. SCWS, temel kelime bölme işlevlerinin yanı sıra anahtar kelime çıkarma ve kelime türü etiketleme gibi gelişmiş işlevleri de destekler.
Ana Özellikler
- Yüksek Verimlilikte Kelime Bölme: SCWS, büyük ölçekli Çince metinleri hızlı bir şekilde işleyebilen yüksek verimli kelime bölme algoritması kullanır.
- Yüksek Doğruluk: Sözlük eşleştirme ve istatistiksel modelleri birleştirerek, SCWS kelime bölme doğruluğunda belirgin bir avantaja sahiptir.
- Birçok Fonksiyon Desteği: Temel kelime bölme işlevlerinin yanı sıra, SCWS anahtar kelime çıkarma ve kelime türü etiketleme gibi gelişmiş işlevleri destekler.
- Kolay Entegrasyon: SCWS, geliştiricilerin çeşitli uygulamalara kolayca entegre edebileceği zengin bir API sağlar.
- Açık Kaynaklı Yazılım: SCWS açık kaynaklı bir yazılımdır, geliştiriciler ihtiyaçlarına göre özelleştirme ve genişleme yapabilirler.
ServBay'ın Dahili SCWS Modülünün Sürümü
ServBay, çeşitli PHP sürümlerini destekler ve her sürüm için ilgili SCWS modülünü önceden yüklenmiş halde getirir. Özel sürümler:
- PHP 5.6 - 8.4: SCWS 1.2.3
SCWS Modülünün Etkinleştirilmesi
Varsayılan olarak, SCWS modülü devre dışıdır. SCWS modülünü etkinleştirmek için ilgili PHP sürümünün yapılandırma dosyasını değiştirmeniz yeterlidir. Aşağıda ayrıntılı adımlar verilmiştir:
Adım 1: Yapılandırma Dosyasını Bulma
Öncelikle, ilgili PHP sürümünün conf.d
dizinine gidin. Örneğin, PHP 8.3 için SCWS modülünü etkinleştirmek istiyorsanız, aşağıdaki dosyayı düzenlemeniz gerekir:
/Applications/ServBay/etc/php/8.3/conf.d/scws.ini
Adım 2: Yapılandırma Dosyasını Düzenleme
scws.ini
dosyasını açın ve aşağıdaki içeriğin yorum satırından çıkartın:
[scws]
; Uncomment the following line to enable scws
extension = scws.so
scws.default.charset = gbk
scws.default.fpath = /Applications/ServBay/etc/scws
2
3
4
5
Adım 3: PHP Hizmetini Yeniden Başlatma
ServBay'ın hizmet yönetim panelinden ilgili PHP hizmetini yeniden başlatın. Örneğin, PHP 8.3 hizmetini yeniden başlatın. Yeniden başlatma işlemi tamamlandıktan sonra, SCWS modülü başarıyla yüklenecektir.
SCWS Modülünün Başarıyla Yüklenip Yüklenmediğini Doğrulama
SCWS modülünün başarıyla yüklendiğini doğrulamak için basit bir PHP dosyası oluşturabilirsiniz. Web sunucusunun kök dizininde bir phpinfo.php
dosyası oluşturun ve içeriğini aşağıdaki gibi yapın:
<?php
phpinfo();
?>
2
3
https://servbay.host/phpinfo.php
adresine gidin ve çıktıdaki PHP bilgileri arasında SCWS modülüne dair bilgileri arayın. SCWS ile ilgili bilgileri görüyorsanız, modül başarıyla yüklenmiş demektir.
SCWS Sözlüğü Oluşturma
SCWS'yi kullanarak kelime bölme işlemi yapmadan önce, sözlük dosyasını oluşturmanız ve yapılandırmanız gerekir. SCWS tarafından kullanılan sözlük dosyası, normal bir metin dosyası veya ikili formatta bir xdb dosyası olabilir. Aşağıda sözlük oluşturma adımları verilmiştir:
Adım 1: Sözlük Dosyasını Hazırlama
Gerekli kelimeler ve kelime frekanslarını içeren bir metin dosyası oluşturun. Dosya formatı şu şekilde olmalıdır:
Kelimeler1 Frekans1
Kelimeler2 Frekans2
2
Örneğin:
Türkiye 1000
İstanbul 800
Ankara 600
2
3
Bu dosyayı dict.txt
olarak kaydedin.
Adım 2: XDB Formatında Sözlük Dosyası Üretme
SCWS, xdb formatında sözlük dosyası üretmek için bir araç sağlar. Bu araç, ServBay ile birlikte gelir ve aşağıdaki komutla xdb dosyası oluşturabilirsiniz:
scws-gen-dict -i dict.txt -o dict.utf8.xdb
Bu komut dict.txt
dosyasını dict.utf8.xdb
olarak dönüştürecektir.
Adım 3: SCWS'nin Sözlük Dosyasını Kullanacak Şekilde Yapılandırılması
Oluşturulan dict.utf8.xdb
dosyasını /Applications/ServBay/etc/scws
dizinine yerleştirin ve scws.ini
dosyasındaki sözlük yolunu doğru yapılandırdığınızdan emin olun:
[scws]
; Uncomment the following line to enable scws
extension = scws.so
scws.default.charset = utf8
scws.default.fpath = /Applications/ServBay/etc/scws
2
3
4
5
Kullanım Örneği
SCWS modülünü etkinleştirip sözlüğü yapılandırdıktan sonra, PHP kodunda SCWS'yi kullanarak Çince kelime bölme işlemi yapabilirsiniz. Aşağıda basit bir örnek verilmiştir:
Örnek Kod
<?php
// SCWS'yi başlat
$scws = scws_new();
$scws->set_charset('utf8');
$scws->set_dict('/Applications/ServBay/etc/scws/dict.utf8.xdb');
$scws->set_rule('/Applications/ServBay/etc/scws/rules.utf8.ini');
// Bölmek istediğiniz metin
$text = "我是中国人,我爱我的祖国。";
// Kelime bölme
$scws->send_text($text);
// Kelime bölme sonuçlarını alın
while ($result = $scws->get_result()) {
foreach ($result as $word) {
echo $word['word'] . "\n";
}
}
// SCWS kaynaklarını serbest bırak
$scws->close();
?>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Yukarıdaki kodda, öncelikle SCWS başlatılıyor ve karakter seti, sözlük ve kural dosyaları ayarları yapılıyor. Daha sonra, bölünmesi gereken metin SCWS'ye iletiliyor ve bir döngü aracılığıyla kelime bölme sonuçları alınıyor. En sonunda, SCWS kaynakları serbest bırakılıyor.
Sonuç
ServBay, SCWS modülünü yönetme ve etkinleştirme konusunda kolaylık sağlar. Basit yapılandırma ve yeniden başlatma işlemleri ile geliştiriciler, farklı PHP sürümlerinde SCWS modülünü hızlı bir şekilde etkinleştirebilir, böylece yüksek verimli ve doğru kelime bölme işlevlerinden tam anlamıyla yararlanabilir. SCWS'nin yüksek verimli kelime bölme, yüksek doğruluk ve zengin işlevsellik özellikleri, onu Çince metin analizi ve işleme için ideal bir seçenek haline getirir.