Skip to main content

A package that alters text in four different ways.

Project description

Python Package Exercise

An exercise to create a Python package, build it, test it, distribute it, and use it. See instructions for details.

Badges

Tests Workflow Status Build Workflow Status

About

Text Alterations is a package that alters text in four different ways.

With this package you can:

  1. Capitalize the first letter of sentences in a text
  2. List words in a text in order of frequency
  3. Find the number of sentences in a text
  4. Remove all the punctuation and capital letters in a text

Link

Find our package on PyPI here

Functions

1. Capitalize Sentences

capitalize_sentences(text: str) -> str:

Returns the input text with the first letter of each sentence capitalized. Sentences are identified by the punctuation marks ., !, and ?.

Parameters: text (str): The input text to be capitalized

Returns: str: The text with first letter of each sentence capitalized

For example:

string = 'i am a student at NYU. i like software engineering. this class is valuable to my education.'

capitalize_sentences(string) returns:

'I am a student at NYU. I like software engineering. This class is valuable to my education.'

2. Most Frequent Words

most_frequent_words(text: str, num_words: int = 0) -> list[str]:

Returns the num_words most frequent words in the text as a list. The list will be sorted from most frequent to least frequent. If num_words = 0, all words will be returned. Words are separated by spaces.

Parameters: text (str): The input text num_words (int): The number of words to be returned

Returns: list[str]: the most frequent words, sorted by frequency

For example:

string = 'i am a student at NYU. i like software engineering. this class is valuable to my education.'

most_frequent_words(string) returns:

['i', 'am', 'a', 'student', 'at', 'NYU.', 'like', 'software', 'engineering.', 'this', 'class', 'is', 'valuable', 'to', 'my', 'education.']

3. Remove Punctuation

removepunctuation(str) -> str:

This function takes an input String and then converts it to lower case and removes all punctuation

We used regular expression to make this process easier

Parameters: text(str): input string Returns: str: the input string without punctuation and converted to lowercase

For example:

string = 'i am a student at NYU. i like software engineering. this class is valuable to my education.'

removepunctuation(string) returns:

'i am a student at nyu i like software engineering this class is valuable to my education'

4. Sentence Count

sentence_count(text: str) -> int:

Returns the number of sentences in the text string. This function identifies sentences and accounts for several common abbreviations but not all abbreviations.

Parameters: text (str): The input text

Returns: int: The number of sentences in the input text.

For example:

string = 'i am a student at NYU. i like software engineering. this class is valuable to my education.'

sentence_count(string) returns:

3

Contribute

Please install a virtual environment of your choice

In this example, we will use pipenv

pip install pipenv

Please clone the repo

git clone https://github.com/software-students-fall2024/3-python-package-subwaysurfers.git

cd 3-python-package-subwaysurfers

Install dev packages and activate the virtual environment

pipenv install --dev

pipenv shell

Build

pip install build

python -m build

Run unit tests

pytest

Installation and Usage

Create and activate a virtual environment of your choice

In this example, we will use pipenv

pip install pipenv

pipenv shell

Install our package!

pipenv install pytextalterations

To run

Run our package

python -m pytextalterations

You will see a screen that looks like this:


Welcome to Text Alterations

With this package you can:

(C) Capitalize the first letter of sentences in a text

(F) List words in a text in order of frequency

(N) Find the number of sentences in a text

(R) Remove all the punctuation and capital letters in a text

Please choose an option (C, F, N, R, or Quit) to continue:


Enjoy!

Group Members

Neha Magesh: link Luca Ignatescu: link James Whitten: link Tahsin Tawhid: link

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

pytextalterations-1.1.0.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

pytextalterations-1.1.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file pytextalterations-1.1.0.tar.gz.

File metadata

  • Download URL: pytextalterations-1.1.0.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pytextalterations-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3b7f5fb1a634ec1c06cb18604e31e8e0809f1de8a51bd3c4926b009ad727b9dc
MD5 68060954d50b88326d514026696c5b69
BLAKE2b-256 a6999260087b50caad00f9fb0e1ff1b851a8e9a35f7dcd05ccef267bd86c1c64

See more details on using hashes here.

File details

Details for the file pytextalterations-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytextalterations-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aab0a414ac099207fd0a129d8f20aeee5d57e73bbfd745b624ce6238cbeeac3f
MD5 0fe1d8bfcf96cfd5cb0764e29c3ec717
BLAKE2b-256 b331b06b935cf73467ea7b87ed5f4ef09904ff7897c9120ff2a4b7aa1d572672

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