{ "cells": [ { "cell_type": "markdown", "id": "f0e7e936-865b-4389-b180-e07eaf8f4cfc", "metadata": {}, "source": [ "# Reveal\n", "Reveal takes a text as string input and deletes all its characters except the input list of words." ] }, { "cell_type": "code", "execution_count": 3, "id": "f920735b-ed2a-4dd6-8c28-95b4dafad70a", "metadata": {}, "outputs": [], "source": [ "from nltk.tokenize import word_tokenize" ] }, { "cell_type": "code", "execution_count": 11, "id": "2c72ec84-7f91-4d1e-b9f9-6629ab4fae94", "metadata": {}, "outputs": [], "source": [ "def reveal(text,group):\n", " txt = word_tokenize(text)\n", " \n", " txt_linebr = []\n", " for token in txt:\n", " if token == '<':\n", " continue\n", " elif token == 'br/':\n", " token='
'\n", " txt_linebr.append(token)\n", " elif token == '>':\n", " continue\n", " else:\n", " txt_linebr.append(token) \n", " new = []\n", " for w in txt_linebr:\n", " if w=='
':\n", " new = new + [w]\n", " elif w not in group:\n", " w = len(w) * ' '\n", " new = new + [w]\n", " elif w in group :\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": "cff36759-e377-48d5-93f8-d78f6f9a3050", "metadata": {}, "source": [ "This function in itself could be understood as a filter to process and alter texts. By chosing to keeping specific words of a text and deleting all the others, 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": "code", "execution_count": 12, "id": "a6bce73e-8084-4bd0-b7b8-95cd39069030", "metadata": {}, "outputs": [], "source": [ "text = f\"\"\"\n", "Live\n", "Live is life\n", "Live\n", "Live\n", "\n", "When we all give the power\n", "We all give the best\n", "Every minute of an hour\n", "Don't think about a rest\n", "Then you all get the power\n", "You all get the best\n", "When everyone gives everything\n", "And every song everybody sings\n", "\n", "Then it's live\n", "Live is life\n", "Live is life\n", "Live\n", "\n", "Live is life, when we all feel the power\n", "Live is life, come on stand up and dance\n", "Live is life, when the feeling of the people\n", "Live is life, is the feeling of the band\n", "\n", "When we all give the power\n", "We all give the best\n", "Every minute of an hour\n", "Don't think about a rest\n", "Then you all get the power\n", "You all get the best\n", "When everyone gives everything\n", "And every song everybody sings\n", "\n", "Then it's live\n", "Live is life\n", "Live\n", "Live is life\n", "Live\n", "\n", "Live\n", "Live is life\n", "Live\n", "Live is life\n", "\n", "And you call when it's over\n", "You call it should last\n", "Every minute of the future\n", "Is a memory of the past\n", "'Cause we all gave the power\n", "We all gave the best\n", "And everyone gave everything\n", "And every song everybody sang\n", "Live is life\n", "\"\"\"" ] }, { "cell_type": "markdown", "id": "8d6dfda4-122b-42cc-8d29-5d141d726c47", "metadata": {}, "source": [ "# Examples" ] }, { "cell_type": "code", "execution_count": 16, "id": "89d83728-6e1c-4270-b0bc-6cfb59f4f389", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Live Live is life Live Live live Live is life Live is life Live Live is life Live is life Live is life Live is life is live Live is life Live Live is life Live Live Live is life Live Live is life Live is life'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reveal(text,[\"Live\",\"is\",\"life\",\"live\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "8ec2e799-7e05-42c3-ae4c-84a299b66a2d", "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 }