Giter Club home page Giter Club logo

php-cld's Introduction

PHP Bindings for Chromium Compact Language Detector (CLD)

Build Status

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. Chcek out cld2 (Compact Language Detector 2) with svn checkout http://cld2.googlecode.com/svn/trunk/ cld2
  2. cd cld2/internal
  3. run chmod +x ./compile_libs.sh followed by ./compile_libs.sh
  4. cd ../../
  5. Checkout Chromium Language Detector with hg clone https://code.google.com/p/chromium-compact-language-detector
  6. cd chromium-compact-language-detector
  7. Edit both setup.py and setup_full.py: edit CLD2_PATH to point to where you checked out the CLD2 sources.
  8. Run ./build.sh
  9. Checkout this project
  10. Run phpize && ./configure --with-libcld-dir=... && make && sudo make install
  11. 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->detectLanguage('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->detectLanguage("日[の]本([の]国", 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,
  ),
)

php-cld's People

Contributors

lstrojny avatar weltling avatar arnaud-lb avatar pierrejoye avatar timgws avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.