forked from friendica/friendica-addons
Merge pull request 'CLD: Keep the original detected language array' (#1428) from heluecht/friendica-addons:cld into 2023.09-rc
Reviewed-on: friendica/friendica-addons#1428
This commit is contained in:
commit
b11538d195
20
cld/cld.php
20
cld/cld.php
|
@ -69,10 +69,9 @@ function cld_detect_languages(array &$data)
|
||||||
|
|
||||||
if (!$result['is_reliable']) {
|
if (!$result['is_reliable']) {
|
||||||
Logger::debug('Unreliable detection', ['uri-id' => $data['uri-id'], 'original' => $original, 'detected' => $detected, 'name' => $result['language_name'], 'probability' => $result['language_probability'], 'text' => $data['text']]);
|
Logger::debug('Unreliable detection', ['uri-id' => $data['uri-id'], 'original' => $original, 'detected' => $detected, 'name' => $result['language_name'], 'probability' => $result['language_probability'], 'text' => $data['text']]);
|
||||||
return;
|
if (($original == $detected) && ($data['detected'][$original] < $result['language_probability'] / 100)) {
|
||||||
}
|
$data['detected'][$original] = $result['language_probability'] / 100;
|
||||||
|
}
|
||||||
if ($original == $detected) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +82,15 @@ function cld_detect_languages(array &$data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::debug('Detected different language', ['uri-id' => $data['uri-id'], 'original' => $original, 'detected' => $detected, 'name' => $result['language_name'], 'probability' => $result['language_probability'], 'text' => $data['text']]);
|
if ($original != $detected) {
|
||||||
$data['detected'] = [$detected => $result['language_probability'] / 100];
|
Logger::debug('Detected different language', ['uri-id' => $data['uri-id'], 'original' => $original, 'detected' => $detected, 'name' => $result['language_name'], 'probability' => $result['language_probability'], 'text' => $data['text']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$length = count($data['detected']);
|
||||||
|
if ($length > 0) {
|
||||||
|
unset($data['detected'][$detected]);
|
||||||
|
$data['detected'] = array_merge([$detected => $result['language_probability'] / 100], array_slice($data['detected'], 0, $length - 1));
|
||||||
|
} else {
|
||||||
|
$data['detected'] = [$detected => $result['language_probability'] / 100];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue