Class: SmartLangIdClient - provides a LangId.Py Service Client that can be used to validate Language / GetLanguage Confidence for a text.
This class can be used just with the DEFAULT settings which must be set in etc/config.php: $configs['langid'] or can be used with CUSTOM settings.
Language: PHP
Located at: modules/smart-extra-libs/lib_langid_cli.php
Package: extralibs:LanguageDetection
Namespace: \
Class Name: SmartLangIdClient
Version: v.20221220
Depends: classes: Smart, SmartHttpClient
Hints: If the DEFAULT settings are not available will simply fallback for not using any service.
Usage: dynamic object: (new Class())->method() - This class provides only DYNAMIC methods
class Methods
publicfunction__construct (
ARRAY$cfg = []
) {} @
@param: {ARRAY} $cfg: *OPTIONAL* The Array of Configuration parameters - if not provided will use the DEFAULT config from config.php: $configs['langid'].
Class Constructor - will initiate also the LangId.Py Client with the DEFAULT or CUSTOM connection.
@return: {ARRAY} The LangId.Py detection result: [ service-available, lang-id, confidence-score, error-message ]
@param: {STRING} $the_text: The text to be checked
Checks and Get the Language Confidence information for the best detected Language (from the available list) for a given text using the LangId.Py Service.
If LangId.Py is not set in configuration as it may not be available will return a negative confidence score and the default language: en.
class Properties
class Constants
Sample code: PHP
<?php
$check_with_default_service = (array) (new SmartLangIdClient())->getLanguageConfidence('Your text to check goes here ...'); $check_with_custom_service = (array) (new SmartLangIdClient([ 'url' => 'http://langid.host:9008/detect', 'ssl' => '', 'auth-user' => '', 'auth-pass' => '' ]))->getLanguageConfidence('Your text to check goes here ...');
// #end php code
documentation generated on: 2023-10-19 23:15:58 +0000
This class can be used just with the DEFAULT settings which must be set in etc/config.php: $configs['langid'] or can be used with CUSTOM settings.