/**
  *  @dataProvider langProvider
  */
 public function testGetLanguages($format)
 {
     $detect = LanguageDetector\Detect::initByPath(__DIR__ . "/../example/datafile." . $format);
     $langs = $detect->getLanguages();
     $this->assertTrue(is_array($langs));
     $this->assertTrue(count($langs) > 10);
 }
Exemple #2
0
require 'vendor/autoload.php';
try {
    $results = new \StdClass();
    $html = '';
    while ($line = fgets(STDIN)) {
        $html .= $line;
    }
    if ($html) {
        $doc = new \DOMDocument();
        libxml_use_internal_errors(true);
        $doc->loadHTML($html);
        libxml_clear_errors();
        $xpath = new \DOMXpath($doc);
        $textNodes = $xpath->query('//text()');
        $text = '';
        foreach ($textNodes as $textNode) {
            $text .= $textNode->textContent . "\n";
        }
        $detect = LanguageDetector\Detect::initByPath('vendor/crodas/languagedetector/example/datafile.php');
        $language = $detect->detect($text);
        if (gettype($language) != 'string') {
            $language = null;
        }
        $results->languages = [$language];
    }
    echo json_encode($results) . "\n";
} catch (\Exception $e) {
    echo $e->getMessage() . "\n";
    exit(1);
}
exit(0);
Exemple #3
0
<?php

require __DIR__ . '/../lib/LanguageDetector/autoload.php';
$detect = LanguageDetector\Detect::initByPath('datafile.php');
var_dump($detect->detect("Agricultura (-ae, f.), sensu latissimo, est summa omnium artium et scientiarum et technologiarum quae de terris colendis et animalibus creandis curant, ut poma, frumenta, charas, carnes, textilia, et aliae res e terra bene producantur. Specialius, agronomia est ars et scientia quae terris colendis student, agricultio autem animalibus creandis."));
var_dump($detect->detect("El llatí és una llengua indoeuropea de la branca itàlica, parlada antigament pels romans. A partir de l'evolució de la seva versió vulgar en sorgiren les llengües romàniques que sobreviuen avui dia.\n            "));
var_dump($detect->detect("hola"));
var_dump($detect->detect("Hi there, this is a tiny text"));
var_dump($detect->detect("* This file implements in memory hash tables with insert/del/replace/find/\n             * get-random-element operations. Hash tables will auto resize if needed\n              * tables of power of two in size are used, collisions are handled by\n               * chaining. See the source code for more information... :)"));
var_dump($detect->detect("House of Cards is an American political drama series developed and produced by Beau Willimon. It is an adaptation of a previous BBC miniseries of the same name which is based on the novel by Michael Dobbs. The entire first season premiered on February 1, 2013, on the streaming service Netflix.[1] A second season of 13 episodes is currently in production.[1][2]\n            "));