{ "cells": [ { "cell_type": "markdown", "id": "af317257-97a8-46db-ac92-e06bdef22ed3", "metadata": {}, "source": [ "# Stitch\n", "Stitch receives as input a text as a string type, and replaces all the occurrences of a target word, with a character or a word that is repeated as many times as the length of the target. " ] }, { "cell_type": "code", "execution_count": 1, "id": "8c280e90-22dc-4e59-90fe-3bdf97da06b2", "metadata": {}, "outputs": [], "source": [ "from nltk.tokenize import word_tokenize" ] }, { "cell_type": "code", "execution_count": 2, "id": "f26e528c-1d61-4796-a42a-a3d5d0edc574", "metadata": {}, "outputs": [], "source": [ "# text, target, and replacement are string types\n", "def stich(text, target, replacement):\n", " target = target.lower()\n", " txt = word_tokenize(text)\n", " new = []\n", " \n", " for w in txt:\n", " if w == target:\n", " w = len(w)*replacement\n", " new = new + [w]\n", " elif w == target[0].upper() + target[1:]:\n", " w = len(w)*replacement\n", " new = new + [w]\n", " elif w== target.upper():\n", " w = len(w)*replacement \n", " new = new + [w]\n", " else:\n", " new = new + [w]\n", " text = ' '.join(new)\n", " final= text.replace(' .','.').replace(' ,',',').replace(' :',':').replace(' ;',';').replace('< ','<').replace(' >','>').replace(' / ','/').replace('& ','&')\n", " return final" ] }, { "cell_type": "markdown", "id": "7e5443c5-e6d3-4dca-b196-7f8c0204814f", "metadata": {}, "source": [ "This function in itself could be understood as a filter to process and alter texts. By targeting specific words and stitching them, with a character or a word that is repeated as many times as the length of the target , the user of the tool can intervene inside a text. One could break down the meaning of a text or create new narrative meanings by exposing its structure, taking out or highlighting specific and meaningful words and detaching such text from its original context. \n", "This tool offers a broad spectrum of possibilities in which it can be used, from a very political and subversive use, to a more playful and poetic one." ] }, { "cell_type": "markdown", "id": "e054e805-9abb-4751-af1f-0039975520d6", "metadata": {}, "source": [ "# Examples" ] }, { "cell_type": "code", "execution_count": 3, "id": "32c73229-7914-4b16-8054-a74a6869ede8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "' is '" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stich(\"life is life\",\"life\",\" \")" ] }, { "cell_type": "code", "execution_count": 5, "id": "9d273092-5cda-4d75-ad1c-9473bf65e69a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'**** is ****'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stich(\"life is life\",\"life\",\"*\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b0805582-fa73-43b5-b6f9-01cfedd4003d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }