Skip to main content

Transform casual text into a leetspeak version.

Project description

LeetTransformer :one::three::three::seven::robot:

Under development! Only Basic Leet is available which consists of substituting every vowel for a number.

https://user-images.githubusercontent.com/56938752/147962824-c347e184-14b6-41fe-8b05-ef670ac0a5f9.mp4

Installation

pip install pyleetspeak

Examples of How To Use

The only required argument that the user has to provide is the text_in argument which represent the casual text to transform to leetspeak. Nonetheless, there are other optional arguments that control the behaviour of the transformation:`

  • change_prb determines the probability of a transformation to take place (i.e, if it is equal 1 all the possible transformation will be applied).
  • change_frq is affects how frequently a transformation will occur (i.e, if it is equal 1 all the letters of this transformation type will be changed)
  • mode controls the level of leetspeak transformation. Currently only basic mode is available. We are working on more modes. Stay tuned.
  • seed controls the reproducibility of the results. By default no seed is applied.
  • verbose controls the verbosity of the proccess.

Basic Use

Let's see a simple working example:

from pyleetspeak import LeetSpeaker
text_in = "I speak leetspeak"
leeter = LeetSpeaker(text_in, change_prb=0.8,  change_frq=0.6, mode = "basic", seed = None, verbose=False)
leet_result = leeter.text2leet()
print(leet_result)
# "1 spe4k l33tsp34k"

For the sake of reproducibility you can set a random seed:

from pyleetspeak import LeetSpeaker
leeter = LeetSpeaker(text_in, change_prb=0.8,  change_frq=0.5, mode = "basic", seed = 42, verbose=False)
leet_result = leeter.text2leet()
print(leet_result)
# "1 sp34k l3etspeak"

Minor concerns about the package behaviour: accents are deleted using Unidecode. This is important for languages like Spanish, where the word "melocotón" is preprocessed as "melocoton" and finally transformed to leetspeak.

Get all changes

You can also obtain all the possible versions of a leetspeak text using the get_all_combs parameter like this:

from pyleetspeak import LeetSpeaker
text_in = "leetspeak"
leeter = LeetSpeaker(text_in, mode = "basic", get_all_combs = True)
leet_result = leeter.text2leet()
assert len(leet_result) == 32 # all possible combinations
print(leet_result)

Define your own changes

pyleetspeak is prepared to apply substitutions defined by the user. It is essential to highlight that these new user-defined changes have to follow two possible formats, dictionary or List of tuples. Here we show a toy example to add two new target characters from the original text to be replaced by two different characters and one, respectively:

  • Dictionary type: {"target_chr_1": ["sub_chr_1", "sub_chr_1"], "target_chr_2": ["sub_chr_1"]}
  • List[Tuple] type: [("target_chr_1", ["sub_chr_1", "sub_chr_1"]), (("target_chr_2", ["sub_chr_1"])]

You can add new user-defined substitutions:

from pyleetspeak import LeetSpeaker
text_in = "New changes Leetspeak"
obj = LeetSpeaker(
    text_in,
    change_prb=1,
    change_frq=0.8,
    mode="basic",
    seed=21,
    verbose=False,
    get_all_combs=False,
    user_changes = [("a", "#"), ("s", "$")], # user-defined changes
)
print(obj.text2leet())
# N3w ch@ng3$ L33t$pe4k

Moreover, you can use only the user-defined substitutions:

from pyleetspeak import LeetSpeaker
# Only user changes
text_in = "Only user changes: Leetspeak"
obj = LeetSpeaker(
    text_in,
    change_prb=1,
    change_frq=0.8,
    mode=None, # None pre-defined changes will be applied
    seed=21,
    verbose=False,
    get_all_combs=False,
    user_changes = [("a", "#"), ("s", "$")], # user-defined changes
)
print(obj.text2leet())
# Only u$er ch#nge$: Leet$pe#k

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyleetspeak-0.0.14.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyleetspeak-0.0.14-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pyleetspeak-0.0.14.tar.gz.

File metadata

  • Download URL: pyleetspeak-0.0.14.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pyleetspeak-0.0.14.tar.gz
Algorithm Hash digest
SHA256 c29627fe95f5824f3dddc9724c251d07a30c1685635863bf2ffd78a2437286fa
MD5 5a731204b1b3f18c85da6a60cdd214f4
BLAKE2b-256 e0c768c0e953341e3f8752123ecab25af957c01fd432c44bfa4854f3fc493e17

See more details on using hashes here.

File details

Details for the file pyleetspeak-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: pyleetspeak-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pyleetspeak-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 428623805c58adf42164af8d5e2d7b016e3824276f500d25c8643b1e68c03289
MD5 4e33978bcf440f2615a5d68978d97327
BLAKE2b-256 951b6e43fda87df1b3d829c7d5299acf4c555cb4151c4dbbd94dd9ca3279a0d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page