Smart.Framework Logo

final class \SmartLangIdClient
{ } ->

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.


class Methods

public function __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.
public function getLanguageConfidence ( STRING $the_text ) {} -> ARRAY
@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


Smart.Framework © 2009-2023 unix-world.org