Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: case studies #2520

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions Python/Python_Count_characters_from_text.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "88c104cc-bf08-4242-821b-b3a40908152a",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"8%\" alt=\"Naas.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Naas.png\" style=\"border-radius: 15%\">"
]
},
{
"cell_type": "markdown",
"id": "compressed-wilson",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Python - Count characters from text\n",
"\n",
"<a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=Bubble+-+Send+data:+Error+short+description\">Bug report</a>"
]
},
{
"cell_type": "markdown",
"id": "religious-programmer",
"metadata": {},
"source": [
"**Tags:** #letters #words #count #text"
]
},
{
"cell_type": "markdown",
"id": "1fe9f56e-561c-4f52-aef8-b861c9462107",
"metadata": {},
"source": [
"**Author:** [Varsha Kumar](https://www.linkedin.com/in/varsha-kumar-590466305/)"
]
},
{
"cell_type": "markdown",
"id": "0de144be-594d-463e-9849-696fb2f6d1a8",
"metadata": {},
"source": [
"**Last update:** 2024-05-11 (Created: 2024-05-11)"
]
},
{
"cell_type": "markdown",
"id": "31ea7cdb-e10d-43fc-b026-f69249a59736",
"metadata": {},
"source": [
"**Description:** This notebook counts the appearance of a chosen word/letter or phrase in the text."
]
},
{
"cell_type": "markdown",
"id": "d4b89388-5cd5-409a-8169-c53cc8dfab96",
"metadata": {},
"source": [
"**References:**\n",
"- [Naas Documentation](https://site.naas.ai/)"
]
},
{
"cell_type": "markdown",
"id": "distinguished-truth",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "numeric-mediterranean",
"metadata": {},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "potential-surfing",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# No imports being used for this code"
]
},
{
"cell_type": "markdown",
"id": "aggressive-trustee",
"metadata": {},
"source": [
"### Setup variables\n",
"\n",
"- `text`: Inputed sentence\n",
"- `characters`: Chosen letter/word/phrase to count for"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "continuous-melbourne",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"text = \"This is an example text. This text contains the phrase 'example text' multiple times.\"\n",
"characters = \"e\""
]
},
{
"cell_type": "markdown",
"id": "registered-showcase",
"metadata": {},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "tested-astrology",
"metadata": {},
"source": [
"### Count the appearances of the chosen text in a sentence"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "crude-louisville",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"def count_phrase_occurrences(text, chosenText):\n",
" count = 0\n",
" phrases = text.split(chosenText)\n",
" count = len(phrases) - 1\n",
" return count\n",
"\n",
"occurrences = count_phrase_occurrences(text, characters)"
]
},
{
"cell_type": "markdown",
"id": "lonely-pacific",
"metadata": {
"execution": {
"iopub.execute_input": "2021-07-02T23:32:10.789097Z",
"iopub.status.busy": "2021-07-02T23:32:10.788829Z",
"iopub.status.idle": "2021-07-02T23:32:10.796900Z",
"shell.execute_reply": "2021-07-02T23:32:10.796358Z",
"shell.execute_reply.started": "2021-07-02T23:32:10.789033Z"
}
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "890f7c86-b7bb-4f5d-9a1b-e492dd9580fd",
"metadata": {},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c4e3b7b-6440-4844-8054-265f1aec65eb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"print(f\"'{characters}' appears {occurrences} times in the text.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8c7aeb8-d588-4ad2-9726-19fb88d9fdc8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"papermill": {
"default_parameters": {},
"environment_variables": {},
"parameters": {},
"version": "2.3.3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading