Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jaume-ferrarons/hidetext

A python library to hide fragments of text.
https://github.com/jaume-ferrarons/hidetext

Last synced: 25 days ago
JSON representation

A python library to hide fragments of text.

Awesome Lists containing this project

README

        

{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hidetext\n",
"\n",
"Extensible Python library to hide fragments of text.\n",
"\n",
"[![version](https://img.shields.io/pypi/v/hidetext?logo=pypi&logoColor=white)](https://pypi.org/project/hidetext/)\n",
"[![build](https://github.com/jaume-ferrarons/hidetext/actions/workflows/push-event.yml/badge.svg)](https://github.com/jaume-ferrarons/hidetext/actions/workflows/push-event.yml)\n",
"[![codecov](https://codecov.io/github/jaume-ferrarons/hidetext/branch/main/graph/badge.svg?token=MZQOAFBQ5I)](https://codecov.io/github/jaume-ferrarons/hidetext)\n",
"\n",
"## Installation\n",
"**Requirements**: python >= 3.8\n",
"\n",
"It can be easily installed with:\n",
"```bash\n",
"pip install -U hidetext\n",
"```\n",
"\n",
"## Basic usage"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-08T12:39:09.584891Z",
"iopub.status.busy": "2022-12-08T12:39:09.584529Z",
"iopub.status.idle": "2022-12-08T12:39:09.608086Z",
"shell.execute_reply": "2022-12-08T12:39:09.607412Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Dear Mr Robinson,\n",
"\n",
"I'm contacting you regarding \n",
"My DNI is *********.\n",
"\n",
"Email: ****************\n",
"\n"
]
}
],
"source": [
"from hidetext import Hidetext\n",
"\n",
"hide = Hidetext()\n",
"\n",
"print(hide.character(\"\"\"\n",
"Dear Mr Robinson,\n",
"\n",
"I'm contacting you regarding \n",
"My DNI is 43244328J.\n",
"\n",
"Email: [email protected]\n",
"\"\"\"))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-08T12:39:09.648901Z",
"iopub.status.busy": "2022-12-08T12:39:09.648669Z",
"iopub.status.idle": "2022-12-08T12:39:09.652141Z",
"shell.execute_reply": "2022-12-08T12:39:09.651571Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Dear Mr Robinson,\n",
"\n",
"I'm contacting you regarding \n",
"My DNI is .\n",
"\n",
"Email: \n",
"\n"
]
}
],
"source": [
"print(hide.kind(\"\"\"\n",
"Dear Mr Robinson,\n",
"\n",
"I'm contacting you regarding \n",
"My DNI is 43244328J.\n",
"\n",
"Email: [email protected]\n",
"\"\"\"))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating custom filters\n",
"\n",
"It's easy to create custom filters to remove undesired text using `PatternFilter`:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"The train departs at and arrives at , therefore I'll be at the party at .\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from typing import Dict\n",
"\n",
"from hidetext import Hidetext\n",
"from hidetext.filters import PatternFilter\n",
"\n",
"class HourFilter(PatternFilter):\n",
" name: str = \"HOUR\"\n",
"\n",
" patterns: Dict[str, str] = {\n",
" \"digital_hour\": r\"\\d{2}(:\\d{2}){1,2}\",\n",
" \"hour\": \"\\d{1,2}\\s?(am|pm)\"\n",
" }\n",
"\n",
"hide = Hidetext(filters=[HourFilter()])\n",
"\n",
"hide.kind(\"The train departs at 15:45 and arrives at 19:35, therefore I'll be at the party at 8pm.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 ('.venv': poetry)",
"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.8.10"
},
"vscode": {
"interpreter": {
"hash": "c559b2d52db72af873d1d533ab03f87fe3d7c5a9b4dde5583603b6c59dfb15c0"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}