function testOmitLanguages() { $str = 'This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.'; $myobj = new TextLanguageDetect(); $myobj->_use_unicode_narrowing = false; $count = $myobj->getLanguageCount(); $returnval = $myobj->omitLanguages('english'); $newcount = $myobj->getLanguageCount(); $this->assertEquals(1, $returnval); $this->assertEquals(1, $count - $newcount); $result = strtolower($myobj->detectSimple($str)); $this->assertTrue($result != 'english', $result); $myobj = new TextLanguageDetect(); $count = $myobj->getLanguageCount(); $returnval = $myobj->omitLanguages(array('danish', 'italian'), true); $newcount = $myobj->getLanguageCount(); $this->assertEquals($count - $newcount, $returnval); $this->assertEquals($count - $returnval, $newcount); $result = strtolower($myobj->detectSimple($str)); $this->assertTrue($result == 'danish' || $result == 'italian', $result); $result = $myobj->detect($str); $this->assertEquals(2, count($result)); $this->assertTrue(isset($result['danish'])); $this->assertTrue(isset($result['italian'])); unset($myobj); }
/** * example usage (CLI) * * @package Text_LanguageDetect * @version CVS: $Id: example_clui.php 322305 2012-01-15 00:04:17Z clockwerx $ */ spl_autoload_register(function ($class) { $file = __DIR__ . '/../lib/' . strtr($class, '\\', '/') . '.php'; if (file_exists($file)) { require $file; return true; } }); use TextLanguageDetect; $l = new TextLanguageDetect\TextLanguageDetect(); $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: */