Giter Club home page Giter Club logo

detectlanguage-php's Introduction

Detect Language API PHP Client

PHP version Build Status

Detects language of the given text. Returns detected language codes and scores.

Installation

There are two ways to install:

Require Library

require_once("/path/to/lib/detectlanguage.php");

Or via Composer:

Create or add the following to composer.json in your project root:

{
    "require": {
        "detectlanguage/detectlanguage": "*"
    }
}

Usage

Configuration

Before using Detect Language API client you have to setup your personal API key. You can get it by signing up at http://detectlanguage.com

use \DetectLanguage\DetectLanguage;

DetectLanguage::setApiKey("YOUR API KEY");

// Enable secure mode if passing sensitive information
// DetectLanguage::setSecure(true);

Language detection

$results = DetectLanguage::detect("Buenos dias señor");

Results

Array
(
    [0] => stdClass Object
        (
            [language] => es
            [isReliable] => 1
            [confidence] => 10.24
        )

)

Simple language detection

If you need just a language code you can use simpleDetect. It returns just the language code.

$languageCode = DetectLanguage::simpleDetect("Buenos dias señor");

Result

"es"

Batch detection

It is possible to detect language of several texts with one request. This method is faster than doing one request per text. To use batch detection just pass array of texts to detect method.

$results = DetectLanguage::detect(array("Buenos dias señor", "Hello world"));

Results

Result is array of detections in the same order as the texts were passed.

Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [language] => es
                    [isReliable] => 1
                    [confidence] => 10.24
                )

        )

    [1] => Array
        (
            [0] => stdClass Object
                (
                    [language] => en
                    [isReliable] => 1
                    [confidence] => 11.94
                )

        )

)

Get your account status

$results = DetectLanguage::getStatus();

Result

stdClass Object
(
    [date] => 2013-10-19
    [requests] => 1680
    [bytes] => 21800
    [plan] => FREE
    [plan_expires] =>
    [daily_requests_limit] => 5000
    [daily_bytes_limit] => 1048576
    [status] => ACTIVE
)

License

Detect Language API Client is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

detectlanguage-php's People

Contributors

laurynas avatar rvanlaak avatar thomascorthals avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

detectlanguage-php's Issues

Obvious cases of misinterpretation

Your engine works very fine, in general. But after testing a little, I found that there are annoying cases of misinterpretation, one of which is found directly in your instructions.

How can it be that a word like "señor" is interpreted as Portuguese at all? In Portuguese, your example sentence would read "Bom dia senhor".

Likewise, a construction like "Fjord- und Familienpferde", which is clearly German, is interpreted as Norwegian, probably due to the word "Fjord" which takes preference here.

The same is true for the sequence "Fjordpferd, Fjord, Pferde, Pferd, Fjordpferde, Fjordgestüt, Gestüt" which has lots of words nonexistent in Norwegian. Google detects it as German and translates into Norwegian with "Fjord hest, fjord, hester, hest, fjordhest, Fjord Stud, Stud".

I think the 2nd test is proof that "Fjord" is the trigger for the characterization as Norwegian. Acknowledging this, how big is the chance that other words would trigger wrong language characterizations as well?

Throws an error with special characters in Laravel

Hi

I've been a longtime (and happy!) user. I'm currently converting my site to Laravel and thus also my languagedetect routine. This however gives me an error:

DetectLanguage::detect("Buenos dias señor"); throws an error while DetectLanguage::detect("Buenos dias senor"); doesn't (same with é, à etc)

The error thrown is
` Invalid server response:

at vendor/detectlanguage/detectlanguage/lib/DetectLanguage/Client.php:45
41▕ $response_body = self::$request_method($url, $params);
42▕ $response = json_decode($response_body);
43▕
44▕ if (!is_object($response))
➜ 45▕ throw new Error("Invalid server response: $response_body");
46▕
47▕ if (isset($response->error))
48▕ throw new Error($response->error->message);
`

In Client.php the params-parameter is

array:1 [
  "q" => b"Buenos dias señor"
]

I'm guessing the 'b' doesn't belong there :) I can't seem to find where it's coming from?! it's already present in $text in the detect() class in DetectLanguage.php.

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.