Skip to content

Commit 1a2adb4

Browse files
committed
Improve readme
1 parent 93ce7a4 commit 1a2adb4

File tree

6 files changed

+204
-8
lines changed

6 files changed

+204
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
composer.lock
33
composer.phar
44
vendor
5+
/README.html
6+
/dist

README.rst

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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

docs/confidence.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
require_once 'Text/LanguageDetect.php';
3+
4+
$text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?';
5+
6+
$ld = new Text_LanguageDetect();
7+
//3 most probable languages
8+
$results = $ld->detect($text, 3);
9+
10+
foreach ($results as $language => $confidence) {
11+
echo $language . ': ' . number_format($confidence, 2) . "\n";
12+
}
13+
14+
//output:
15+
//german: 0.35
16+
//dutch: 0.25
17+
//swedish: 0.20
18+
?>

docs/iso.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
* The "name mode" changes the way languages are accepted and returned.
66
*/
77
require_once 'Text/LanguageDetect.php';
8-
$l = new Text_LanguageDetect();
9-
8+
$ld = new Text_LanguageDetect();
109

1110
//will output the ISO 639-1 two-letter language code
1211
// "de"
13-
$l->setNameMode(2);
14-
echo $l->detectSimple('Das ist ein kleiner Text') . "\n";
12+
$ld->setNameMode(2);
13+
echo $ld->detectSimple('Das ist ein kleiner Text') . "\n";
1514

1615
//will output the ISO 639-2 three-letter language code
1716
// "deu"
18-
$l->setNameMode(3);
19-
echo $l->detectSimple('Das ist ein kleiner Text') . "\n";
20-
21-
?>
17+
$ld->setNameMode(3);
18+
echo $ld->detectSimple('Das ist ein kleiner Text') . "\n";
19+
?>

docs/languages.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* List all supported languages
4+
*/
5+
require_once 'Text/LanguageDetect.php';
6+
$ld = new Text_LanguageDetect();
7+
8+
foreach ($ld->getLanguages() as $lang) {
9+
echo $lang . "\n";
10+
}
11+
?>

docs/simple.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
require_once 'Text/LanguageDetect.php';
3+
4+
$text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?';
5+
6+
$ld = new Text_LanguageDetect();
7+
$result = $ld->detectSimple($text);
8+
var_dump($result);
9+
//output: german
10+
?>

0 commit comments

Comments
 (0)