Giter Site home page Giter Site logo

go-lang-correct's Introduction

go-lang-correct

Tckb ds xfcnj dcnhtxftnt gjlj,ysq ntrcn nj 'nj inerf lkz dfc!

Пакет пытается определить, не ошибся ли автор текста раскладкой. Если да - можно исправить.

Usage:

go get github.com/fordarian/go-lang-correct

package main

import (
    "fmt"

    "github.com/fordarian/go-lang-correct"
)

func main() {
    str := "'nj zdyj cnhfiyfz jib,rf!"
    // просто меняем раскладку
    fmt.Println(lang.Correct(str)) // это явно страшная ошибка!

    // попробуем определить, насколько вероятно что текст испорчен:
    // если == 0 - неясно
    // если > 0 - скорее всего раскладка не та
    // если < 0 - скорее всего раскладка правильная

    score := lang.ScoreText(str)
    fmt.Println(score) // 4
}

Как это работает:

На оценку строки функцией ScoreText влияют:

  1. Явное совпадение слов с некоторыми шаблонами
  2. Наличие\отсутствие типичных окончаний, которые "странно" смотрятся в другой раскладке
  3. Количество идущих подряд гласных\согласных букв и знаков препинания (не всех, только тех что на англ. раскладке под русскими символами, вроде Ю, Б и т.д.).
  4. Начинаются ли слова "нетипичных" букв, например "ъ"
  5. Содержит ли строка ссылки (http*)

Наиболее явные признаки дают +-10 к счету, это почти полная гарантия что определено корректно. Средние признаки +-5 и незначительные +-3 балла. Строка разбивается на отдельные слова (разделитель - пробел), возвращается средний рейтинг из всех слов.

Перед обработкой из строки удаляются все повторения символов более двух раз подряд. Для определения это не сильно важно, но зато убирает ложные срабатывания на фразах вроде "даааа нууууу" или "ааааааааа!!".

Лицензия

MIT

go-lang-correct's People

Contributors

fordarian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.