PHP Classes

File: examples/spellcheck.php

Recommend this page to a friend!
  Classes of Sergey Karavay   PHPolyglot   examples/spellcheck.php   Download  
File: examples/spellcheck.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHPolyglot
Translate, correct spelling and speak a given text
Author: By
Last change: Updates:
- fixed some minor issues.
Date: 6 years ago
Size: 825 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
GinoPane\PHPolyglot\PHPolyglot;

try {
   
$phpolyglot = new PHPolyglot();

   
$textsToCheck = ['Helo werld', 'Thanxs for ussing thas API'];

   
$languageFrom = 'en';

   
$corrections = $phpolyglot->spellCheckBulk($textsToCheck, $languageFrom)->getCorrections();

   
$correctionsCount = count($corrections);

    for (
$i = 0; $i < count($corrections); $i++) {
       
printf("Errors in \"%s\":\n", $textsToCheck[$i]);

        foreach (
$corrections[$i] as $invalidWord => $correctedWords) {
           
printf("\t%s - %s;\n", $invalidWord, implode(',', $correctedWords));
        }

        echo
"\n";
    }
} catch (
Exception $exception) {
   
$errorMessage = $exception->getMessage();

    echo
sprintf("Error happened: %s", $errorMessage);
}

echo
PHP_EOL;