|
| 1 | +******************* |
| 2 | +Text_LanguageDetect |
| 3 | +******************* |
| 4 | +PHP library to identify human languages from text samples. |
| 5 | +Returns confidence scores for each. |
| 6 | + |
| 7 | + |
| 8 | +Installation |
| 9 | +============ |
| 10 | + |
| 11 | +PEAR |
| 12 | +---- |
| 13 | +:: |
| 14 | + |
| 15 | + $ pear install Text_LanguageDetect |
| 16 | + |
| 17 | +Composer |
| 18 | +-------- |
| 19 | +:: |
| 20 | + |
| 21 | + $ composer require pear/text_languagedetect |
| 22 | + |
| 23 | + |
| 24 | +Usage |
| 25 | +===== |
| 26 | +Also see the examples in the ``docs/`` directory and |
| 27 | +the `official documentation`__. |
| 28 | + |
| 29 | +__ http://pear.php.net/package/Text_LanguageDetect/docs |
| 30 | + |
| 31 | +Language detection |
| 32 | +------------------ |
| 33 | +Simple language detection:: |
| 34 | + |
| 35 | + <?php |
| 36 | + require_once 'Text/LanguageDetect.php'; |
| 37 | + |
| 38 | + $text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?'; |
| 39 | + |
| 40 | + $ld = new Text_LanguageDetect(); |
| 41 | + $language = $ld->detectSimple($text); |
| 42 | + |
| 43 | + echo $language; |
| 44 | + //output: german |
| 45 | + |
| 46 | +Show the three most probable languages with their confidence score:: |
| 47 | + |
| 48 | + <?php |
| 49 | + require_once 'Text/LanguageDetect.php'; |
| 50 | + |
| 51 | + $text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?'; |
| 52 | + |
| 53 | + $ld = new Text_LanguageDetect(); |
| 54 | + //3 most probable languages |
| 55 | + $results = $ld->detect($text, 3); |
| 56 | + |
| 57 | + foreach ($results as $language => $confidence) { |
| 58 | + echo $language . ': ' . number_format($confidence, 2) . "\n"; |
| 59 | + } |
| 60 | + |
| 61 | + //output: |
| 62 | + //german: 0.35 |
| 63 | + //dutch: 0.25 |
| 64 | + //swedish: 0.20 |
| 65 | + ?> |
| 66 | + |
| 67 | + |
| 68 | +Language code |
| 69 | +------------- |
| 70 | +Instead of returning the full language name, ISO 639-2 two and three |
| 71 | +letter codes can be returned:: |
| 72 | + |
| 73 | + <?php |
| 74 | + require_once 'Text/LanguageDetect.php'; |
| 75 | + $ld = new Text_LanguageDetect(); |
| 76 | + |
| 77 | + //will output the ISO 639-1 two-letter language code |
| 78 | + // "de" |
| 79 | + $ld->setNameMode(2); |
| 80 | + echo $ld->detectSimple('Das ist ein kleiner Text') . "\n"; |
| 81 | + |
| 82 | + //will output the ISO 639-2 three-letter language code |
| 83 | + // "deu" |
| 84 | + $ld->setNameMode(3); |
| 85 | + echo $ld->detectSimple('Das ist ein kleiner Text') . "\n"; |
| 86 | + ?> |
| 87 | + |
| 88 | + |
| 89 | +Supported languages |
| 90 | +=================== |
| 91 | +- albanian |
| 92 | +- arabic |
| 93 | +- azeri |
| 94 | +- bengali |
| 95 | +- bulgarian |
| 96 | +- cebuano |
| 97 | +- croatian |
| 98 | +- czech |
| 99 | +- danish |
| 100 | +- dutch |
| 101 | +- english |
| 102 | +- estonian |
| 103 | +- farsi |
| 104 | +- finnish |
| 105 | +- french |
| 106 | +- german |
| 107 | +- hausa |
| 108 | +- hawaiian |
| 109 | +- hindi |
| 110 | +- hungarian |
| 111 | +- icelandic |
| 112 | +- indonesian |
| 113 | +- italian |
| 114 | +- kazakh |
| 115 | +- kyrgyz |
| 116 | +- latin |
| 117 | +- latvian |
| 118 | +- lithuanian |
| 119 | +- macedonian |
| 120 | +- mongolian |
| 121 | +- nepali |
| 122 | +- norwegian |
| 123 | +- pashto |
| 124 | +- pidgin |
| 125 | +- polish |
| 126 | +- portuguese |
| 127 | +- romanian |
| 128 | +- russian |
| 129 | +- serbian |
| 130 | +- slovak |
| 131 | +- slovene |
| 132 | +- somali |
| 133 | +- spanish |
| 134 | +- swahili |
| 135 | +- swedish |
| 136 | +- tagalog |
| 137 | +- turkish |
| 138 | +- ukrainian |
| 139 | +- urdu |
| 140 | +- uzbek |
| 141 | +- vietnamese |
| 142 | +- welsh |
| 143 | + |
| 144 | + |
| 145 | +Links |
| 146 | +===== |
| 147 | +Homepage |
| 148 | + http://pear.php.net/package/Text_LanguageDetect |
| 149 | +Bug tracker |
| 150 | + http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Text_LanguageDetect |
| 151 | +Documentation |
| 152 | + http://pear.php.net/package/Text_LanguageDetect/docs |
| 153 | +Unit test status |
| 154 | + https://travis-ci.org/pear/Text_LanguageDetect |
| 155 | + |
| 156 | + .. image:: https://travis-ci.org/pear/Text_LanguageDetect.svg?branch=master |
| 157 | + :target: https://travis-ci.org/pear/Text_LanguageDetect |
0 commit comments