S
S
samlowry2010-10-22 07:08:40
Keyboard layout
samlowry, 2010-10-22 07:08:40

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

10 answer(s)
O
Oleg Matrozov, 2010-10-22
@Mear

forum.dklab.ru/viewtopic.php?t=30888

D
Daggett, 2010-10-22
@Daggett

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";
  
?>

I
iStyx, 2010-10-23
@iStyx

Break it into words and send it to Google for search, if the answer is “maybe you were looking for ...” - use it :)

A
Alexey Sidorov, 2010-10-22
@Gortauer87

Neural networks, too. They images like nuts are cracking.

I
izmalk, 2010-10-22
@izmalk

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

D
Daggett, 2010-10-22
@Daggett

code.google.com/intl/en-US/apis/ajaxlanguage/

D
Daggett, 2010-10-22
@Daggett

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

W
Wott, 2010-10-22
@Wott

You can find it in any operating system :) there should be tables of correspondence between scan codes and symbols.

D
Daggett, 2010-10-23
@Daggett

list for Windows , however, after rummaging, I could not properly pull out the layouts, in principle, part of the file is understandable, but ...

R
RinNas, 2012-04-11
@RinNas

Text_LangCorrect (PHP)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question