semvec/pypi-packages huggingface dataset:
word-shortener 0.0.3
A simple library to shorten words in text
License: 0BSD

# Word Shortener

A simple library to shorten words in text.

## Example

### input
```
The utilization of this library can significantly enhance the accessibility of written content by abbreviating lengthy words. By reducing the number of characters in words such as internationalization, the overall readability and understandability of the text improves. Furthermore, it can also aid in reducing the amount of space required to display the text, which can be beneficial in digital contexts such as on websites or mobile devices.
```

### output
```
The u9n of this library can s11y enhance the a11y of written content by a10g lengthy words. By reducing the number of c8s in words such as i18n, the overall r9y and u15y of the text improves. F9e, it can also aid in reducing the amount of space required to display the text, which can be b8l in digital contexts such as on websites or mobile devices.
```

## Installation
```bash
pip install word-shortener
```

## Usage
```python
from word_shortener import shorten_words

text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."

shortened_text = shorten_words(text)
print(shortened_text)
# "Lorem ipsum dolor sit amet, c9r a8g elit, sed do eiusmod tempor i8t ut labore et dolore magna aliqua."

shortened_text = shorten_words(text, n=5)
print(shortened_text)
# "L3m i3m d3r sit amet, c9r a8g elit, sed do e5d t4r i8t ut l4e et d3re m3a a4a."
```

For example, you can use the following code to read a text file named `my_text.txt`, and replace its text. Additionally, you can also save the shortened text to another text file of your choice.

```python
from word_shortener import shorten_words

with open("my_text.txt", "r", encoding='utf-8') as file:
    text = file.read()

shortened_text = shorten_words(text, n=10)
print(shortened_text)

with open("shortened.txt", "w", encoding='utf-8') as file:
    file.write(shortened_text)
```

## Function

```python
shorten_words(text:str, n:int=10)->str:
    """
    Shorten the words in text.
    :param text: input text.
    :param n: the number of characters (default value is 10).
    :return: replaced text.
    """
```
The function takes two arguments, the text you want to shorten and the number of characters, and returns the replaced text. The default number of characters is 10.

## License

This project is licensed under the 0BSD License.