Code Monkey home page Code Monkey logo

typo's Issues

Keeping some characters fixed while applying a typo function

Hello,

I was wondering if there is a way to keep some characters fixed while applying a typo function to it?
For instance: Keeping the first and last characters in a word unchanged irrespective of what typo function you use.

Best,
Shalaka

`KeyError` in `extra_char` function

I noticed that some non-English characters can trigger a KeyError exception:

E.g. the (I think) Eastern Arabic numeral for 6, ٦:

File "/.../python3.8/site-packages/typo/Errer.py", line 69, in extra_char
    char_to_add = en_default.get_random_neighbor(trigger_char)
  File "/.../python3.8/site-packages/typo/keyboardlayouts/en_default.py", line 118, in get_random_neighbor
    return random.choice(NEIGHBORINGNUMPADDIGITS[char])
KeyError: '٦'

I think it is due to the use of str.isdecimal() instead of str.isdigit() in
Edit: str.isdigit() is also True for ٦ apparently, I didn't check properly.

def get_random_neighbor(char, seed=None):
if seed is not None:
random.seed(seed)
if len(char) != 1:
raise Exception("Need exactly one character to find a neighbor")
if char.isdecimal():
numpad = random.choice([True, False])
if numpad:
return random.choice(NEIGHBORINGNUMPADDIGITS[char])

Either using str.isdigit() here or char in NEIGHBORINGNUMPADDIGITS would solve this.

Alternatively, you could use '{:d}'.format(int(char)) to reinterpret the numeral to 0-9 which I think for most arabic numerals, but for say ي it won't work since that doesn't fit with the default base 10 and would raise a ValueError. Edit: You'd change the language of the character, so I'd say this is not a good solution either.

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.