Skip to content

Commit 7f114c3

Browse files
committed
Update documentation examples
1 parent c429f2d commit 7f114c3

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Table of contents
1111
=================
1212
- [Features](#features)
1313
- [Install](#install)
14-
- [Examples](#examples)
14+
- [Quick usage](#quick-usage)
1515
- [Detect language](#detect-language)
1616
- [Other methods](#other-methods)
1717
- [API Methods](#api-methods)
@@ -28,6 +28,7 @@ Features
2828
- More than 50 supported languages
2929
- Very fast, no database needed
3030
- Packaged with a 2MB dataset
31+
- Learning steps are already done, library is ready to use
3132
- Small code, small footprint
3233
- N-grams algorithm
3334
- Supports PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3 and HHVM
@@ -42,25 +43,59 @@ composer require landrok/language-detector
4243

4344
________________________________________________________________________
4445

45-
Examples
46-
--------
46+
Quick usage
47+
-----------
4748

4849
### Detect language
4950

50-
If you have a list of texts to detect, a possible way is to instanciate
51-
once and then to evaluate your list.
51+
Instanciate a detector and pass a text.
52+
53+
Then, you can get the detected language.
5254

5355
```php
5456
require_once 'vendor/autoload.php';
5557

56-
$text = 'My sentence is in english';
58+
$text = 'My tailor is rich and Alison is in the kitchen with Bob.';
5759

5860
$detector = new LanguageDetector\LanguageDetector();
5961

6062
$language = $detector->evaluate($text)->getLanguage();
6163

6264
echo $language; // Prints something like 'en'
6365
```
66+
67+
Once it's instanciated, you can check for multiple texts.
68+
69+
```php
70+
require_once 'vendor/autoload.php';
71+
72+
// An array of texts to evaluate
73+
$texts = [
74+
'My tailor is rich and Alison is in the kitchen with Bob.',
75+
'Mon tailleur est riche et Alison est dans la cuisine avec Bob'
76+
];
77+
78+
$detector = new LanguageDetector\LanguageDetector();
79+
80+
foreach ($texts as $key => $text) {
81+
82+
$language = $detector->evaluate($text)->getLanguage();
83+
84+
echo sprintf(
85+
"Text %d, language=%s\n",
86+
$key,
87+
$language
88+
);
89+
}
90+
91+
```
92+
93+
Would output something like:
94+
95+
```sh
96+
Text 0, language=en
97+
Text 1, language=fr
98+
```
6499
________________________________________________________________________
65100

66101
### Other methods
@@ -78,6 +113,8 @@ $scores = $detector->getScores();
78113

79114
```
80115

116+
You can see documentation for these methods below.
117+
81118
________________________________________________________________________
82119

83120
API Methods

0 commit comments

Comments
 (0)