Answer the question
In order to leave comments, you need to log in
What algorithm/library to convert a word entered in the wrong layout?
Basically, do what Punto Switcher does. It is necessary to constantly convert such errors made in different languages that do not use the Latin alphabet. It is desirable - in Python, it is possible in PHP.
Answer the question
In order to leave comments, you need to log in
Here is an outline of what I suggested:
<?php
$layouts['en'] = preg_split('!!u', 'qwertyuiop[]asdfghjkl;\'\zxcvbnm,./', null, PREG_SPLIT_NO_EMPTY);
$layouts['ru'] = preg_split('!!u', 'йцукенгшщзхъфывапролджэ\ячсмитьбю.', null, PREG_SPLIT_NO_EMPTY);
$phrase = "тестовая cnhjrf с неверной раскладкой\n";
echo $phrase;
$phrase_chunks = explode(' ', $phrase);
$ch = array();
foreach ($phrase_chunks as $phrase_chunk) $curl_handles[] = curl_init();
foreach ($curl_handles as $index => $curl_handle) {
curl_setopt($curl_handle, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=".urlencode($phrase_chunks[$index]));
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
}
$mh = curl_multi_init();
foreach ($curl_handles as $index => $curl_handle) {
curl_multi_add_handle($mh, $curl_handle);
}
$active = null;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
foreach ($curl_handles as $index => $curl_handle) {
$responses[] = json_decode(curl_multi_getcontent($curl_handle));
}
foreach ($curl_handles as $index => $curl_handle) {
curl_multi_remove_handle($mh, $curl_handle);
}
curl_multi_close($mh);
foreach ($responses as $index => $response) {
if ($response->responseData->confidence <= 0.005 && $response->responseData->language != 'ru') {
$phrase_chunks[$index] = str_replace($layouts['en'], $layouts['ru'], $phrase_chunks[$index]);
}
}
echo implode(' ', $phrase_chunks)."\n";
?>
Break it into words and send it to Google for search, if the answer is “maybe you were looking for ...” - use it :)
In fact, if there are several languages at once, and even without English ... it's just a trickier task. Perhaps it’s really worth looking in the direction of learning systems, it will be difficult to find a ready-made solution IMHO
sorry "$response->responseData->language != 'ru'" I'm wrong, I'll try to finish it when I get home, don't judge strictly - just a sketch
You can find it in any operating system :) there should be tables of correspondence between scan codes and symbols.
list for Windows , however, after rummaging, I could not properly pull out the layouts, in principle, part of the file is understandable, but ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question