-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild.php
More file actions
26 lines (23 loc) · 1.05 KB
/
build.php
File metadata and controls
26 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<pre>
<?php
include 'classifier.php';
$classifier = new NGramProfiles('etc/classifiers/full.dat');
$classifier->train('en', 'etc/data/english.raw');
$classifier->train('nl', 'etc/data/dutch.raw');
$classifier->train('fr', 'etc/data/french.raw');
$classifier->train('de', 'etc/data/german.raw');
$classifier->train('id', 'etc/data/indonesian.raw');
$classifier->train('jp', 'etc/data/japanese.raw');
$classifier->train('pt', 'etc/data/portugese.raw');
$classifier->train('es', 'etc/data/spanish.raw');
$classifier->save();
// simple prediction function that takes a classifier and a text and echo's the most likely language
function predict($classifier, $text, $result) {
$language = $classifier->predict($text);
echo "{$language} = {$result} @ '{$text}'\n";
}
predict($classifier, "Dit is een nederlandse text.", 'nl');
predict($classifier, "This is an english text.", 'en');
predict($classifier, "Ceci n'est pas une pipe.", 'fr');
predict($classifier, "dies ist ein Satz auf Deutsch", 'de');
predict($classifier, "esta es una frase en alemán", 'es');