<?php /** * example usage (CLI) * * @package Text_LanguageDetect * @version CVS: $Id: example_clui.php 322305 2012-01-15 00:04:17Z clockwerx $ */ require_once 'Text/LanguageDetect.php'; $l = new Text_LanguageDetect(); $stdin = fopen('php://stdin', 'r'); echo "Supported languages:\n"; $langs = $l->getLanguages(); sort($langs); echo join(', ', $langs); echo "\ntotal ", count($langs), "\n\n"; while ($line = fgets($stdin)) { $result = $l->detect($line, 4); print_r($result); $blocks = $l->detectUnicodeBlocks($line, true); print_r($blocks); } fclose($stdin); unset($l); /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
function test_omit_error() { $str = 'On January 29, 1737, Thomas Paine was born in Thetford, England. His father, a corseter, had grand visions for his son, but by the age of 12, Thomas had failed out of school. The young Paine began apprenticing for his father, but again, he failed.'; $myobj = new Text_LanguageDetect(); $result = $myobj->detectSimple($str); $this->assertEquals('english', $result); // omit all languages and you should get an error $myobj->omitLanguages($myobj->getLanguages()); $result = $myobj->detectSimple($str); $this->assertNull($result, gettype($result)); }