arnaud-lb / php-cld

PHP bindings for the Chrome Language Detector

Home Page:http://code.google.com/p/chromium-compact-language-detector/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Bindings for Chromium Compact Language Detector (CLD)

This small extension provides bindings to use the Chromium Compact Language Detector (http://code.google.com/p/chromium-compact-language-detector/) in PHP.

Installation

  1. Checkout Chromium Language Detector from with hg clone https://code.google.com/p/chromium-compact-language-detector
  2. Run ./build.sh
  3. Checkout this project
  4. Run phpize && ./configure --with-libcld-dir=... && make && sudo make install
  5. Add extension=cld.so to your php.ini

Usage

Procedural API

<?php
var_export(CLD\detect("Drüben hinterm Dorfe wohnt ein Leiermann. Und mit starren Fingern spielt er was er kann"));
var_export(CLD\detect("日[の]本([の]国", false, true, null, CLD\Language::JAPANESE, CLD\Encoding::JAPANESE_EUC_JP));

Object-oriented API

<?php
$detector = new CLD\Detector();
var_export($detector->detect('Drüben hinterm Dorfe wohnt ein Leiermann. Und mit starren Fingern spielt er was er kann'));

$detector->setLanguageHint(CLD\Language::JAPANESE);
$detector->setEncodingHint(CLD\Encoding::JAPANESE_EUC_JP);
$detector->detect("日[の]本([の]国", false);

will return

array (
  0 =>
  array (
    'name' => 'GERMAN',
    'code' => 'de',
    'reliable' => true,
    'bytes' => 90,
  ),
)
array (
  0 =>
  array (
    'name' => 'JAPANESE',
    'code' => 'ja',
    'reliable' => true,
    'bytes' => 22,
  ),
  1 =>
  array (
    'name' => 'CHINESE',
    'code' => 'zh',
    'reliable' => true,
    'bytes' => 22,
  ),
)

About

PHP bindings for the Chrome Language Detector

http://code.google.com/p/chromium-compact-language-detector/


Languages

Language:PHP 62.0%Language:C++ 31.6%Language:C 5.8%Language:Shell 0.6%