You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SI13/LIQUID/MANIFESTO/nltk-similar-words-Copy1.ipynb

232 lines
18 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NLTK - Similar Words"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://www.nltk.org/book/ch01.html#searching-text"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import nltk"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"txt = open('manifesto.txt').read()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tokens"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['_MANIFESTO', 'LIQUID', 'LIFE', 'IS', 'AN', 'UNCERTAIN', 'REALM', '.', 'THE', 'CONCEPTS', 'NEEDED', 'TO', 'REALISE', 'ITS', 'POTENTIAL', 'HAVE', 'NOT', 'YET', 'EXISTED', 'UNTIL', 'NOW', '.', 'THE', 'HYPERCOMPLEXITY', 'AND', 'HYPEROBJECT-NESS', 'OF', 'LIQUID', 'TERRAINS', 'EXCEEDS', 'OUR', 'ABILITY', 'TO', 'OBSERVE', 'OR', 'COMPREHEND', 'THEM', 'IN', 'THEIR', 'TOTALITY', '.', 'INDEED', ',', 'WHAT', 'WE', 'TYPICALLY', 'RECOGNISE', 'AS', 'LIVING', 'THINGS', 'ARE', 'BY-PRODUCTS', 'OF', 'LIQUID', 'PROCESSES', '.', 'LIQUID', 'LIFE', 'IS', 'A', 'WORLDVIEW', '.', 'A', 'PHANTASMAGORIA', 'OF', 'EFFECTS', ',', 'DISOBEDIENT', 'SUBSTANCES', ',', 'EVASIVE', 'STRATEGIES', ',', 'DALLIANCES', ',', 'SKIRMISHES', ',', 'FLIRTATIONS', ',', 'ADDICTIONS', ',', 'QUANTUM', 'PHENOMENA', ',', 'UNEXPECTED', 'TWISTS', ',', 'SUDDEN', 'TURNS', ',', 'FURTIVE', 'EXCHANGES', ',', 'SLY', 'MANOEUVRES', ',', 'BLIND', 'ALLEYS', ',', 'AND', 'EXUBERANT', 'DIGRESSIONS', '.', 'IT', 'CAN', 'NOT', 'BE', 'REDUCED', 'INTO', 'SIMPLE', 'CIPHERS', 'OF', 'PROCESS', ',', 'SUBSTANCE', ',', 'METHOD', ',', 'OR', 'TECHNOLOGY', '.', 'IT', 'IS', 'MORE', 'THAN', 'A', 'SET', 'OF', 'PARTICULAR', 'MATERIALS', 'THAT', 'COMPRISE', 'A', 'RECOGNIZABLE', 'BODY', '.', 'IT', 'IS', 'MORE', 'THAN', 'VITAL', 'PROCESSES', 'THAT', 'ARE', 'SHAPED', 'ACCORDING', 'TO', 'SPECIFIC', 'CONTEXTS', 'AND', 'SUBJECTIVE', 'ENCOUNTERS', '.', 'YET', 'WE', 'RECOGNISE', 'ITS', 'COHERENCE', 'THROUGH', 'THE', 'LIVES', 'OF', '', 'BEINGS', '', ',', 'WHICH', 'REMAIN', 'COGENT', 'DESPITE', 'INCALCULABLE', 'PERSISTENT', 'CHANGES', 'SUCH', 'AS', 'FLOWS', ',', 'AMBIGUITIES', ',', 'TRANSITIONAL', 'STATES', 'AND', 'TIPPING', 'POINTS', 'THAT', 'BRING', 'ABOUT', 'RADICAL', 'TRANSFORMATION', 'WITHIN', 'PHYSICAL', 'SYSTEMS', '.', 'LIQUID', 'LIFE', 'IS', 'A', 'KIND', 'OF', '', 'METABOLIC', 'WEATHER', '', '.', 'IT', 'IS', 'A', 'DYNAMIC', 'SUBSTRATE', '-', 'OR', 'HYPERBODY', '-', 'THAT', 'PERMEATES', 'THE', 'ATMOSPHERE', ',', 'LIQUID', 'ENVIRONMENTS', ',', 'SOILS', 'AND', 'EARTH', '', 'S', 'CRUST', '.', '', 'METABOLIC', 'WEATHER', '', 'REFERS', 'TO', 'COMPLEX', 'PHYSICAL', ',', 'CHEMICAL', 'AND', 'EVEN', 'BIOLOGICAL', 'OUTCOMES', 'THAT', 'ARE', 'PROVOKED', 'WHEN', 'FIELDS', 'OF', 'MATTER', 'AT', 'THE', 'EDGE', 'OF', 'CHAOS', 'COLLIDE', '.', 'IT', 'IS', 'A', 'VECTOR', 'OF', 'INFECTION', ',', 'AN', 'EXPRESSION', 'OF', 'RECALCITRANT', 'MATERIALITY', 'AND', 'A', 'PRINCIPLE', 'OF', 'ECOPOIESIS', ',', 'WHICH', 'UNDERPINS', 'THE', 'PROCESS', 'OF', 'LIVING', ',', 'LIFELIKE', 'EVENTS', '', 'AND', 'EVEN', 'LIFE', 'ITSELF', '.', 'THESE', 'LIFE', 'FORMS', 'ARISE', 'FROM', 'ENERGY', 'GRADIENTS', ',', 'DENSITY', 'CURRENTS', ',', 'KATABATIC', 'FLOWS', ',', 'WHIRLWINDS', ',', 'DUST', 'CLOUDS', ',', 'POLLUTION', 'AND', 'THE', 'MYRIAD', 'EXPRESSIONS', 'OF', 'MATTER', 'THAT', 'DETAIL', 'OUR', '(', 'EARTHY', ',', 'LIQUID', ',', 'GASEOUS', ')', 'TERRAINS', '.', 'LIQUID', 'LIFE', 'IS', 'IMMORTAL', '.', 'ARISING', 'FROM', 'OUR', 'UNIQUE', 'PLANETARY', 'CONDITIONS', ',', 'ITS', 'INGREDIENTS', 'ARE', 'CONTINUALLY', 'RE-INCORPORATED', 'INTO', 'ACTIVE', 'METABOLIC', 'WEBS', 'THROUGH', 'CYCLES', 'OF', 'LIFE', 'AND', 'DEATH', '.', 'MOST', 'DECEASED', 'LIQUID', 'MATTER', 'LIES', 'QUIESCENT', ',', 'PATIENTLY', 'WAITING', 'FOR', 'ITS', 'REANIMATION', 'THROUGH', 'THE', 'PERSISTENT', 'METABOLISMS', 'WITHIN', 'OUR', 'SOILS', '.', 'LIQUID', 'LIFE', 'EXCEEDS', 'RHETORIC', '.', 'ITS', 'CONCEPTS', 'CAN', 'BE', 'EMBODIED', 'AND', 'EXPERIMENTALLY', 'TESTED', 'USING', 'A', 'TRANS-DISCIPLINARY', 'APPROACH', ',', 'WHICH', 'DRAWS', 'UPON', 'A', 'RANGE', 'OF', 'CONCEPTUAL', 'LENSES', 'AND', 'TECHNIQUES', 'TO', 'INVOLVE', 'THE', 'LIQUID', 'REALM', 'WITH', 'ITS', 'OWN', '', 'VOICE', '', '.', 'FROM', 'THESE', 'PERSPECTIVES', 'LIQUID', 'TECHNOLOGIES', 'EMERGE', 'THAT', 'ARE', 'CAPABLE', 'OF', 'GENERATING', 'NEW', 'KINDS', 'OF', 'ARTEFACTS', ',', 'LIKE', 'BÜTSCHLI', 'DROPLETS', ',', 'WHICH', 'ARE', 'LIQUID', 'CHEMICAL', 'ASSEMBLAGES', 'CAPABLE', 'OF', 'SURPRISINGLY', 'LIFELIKE', 'BEHAVIOURS', '.', 'THESE', 'AGENTS', 'EXCEED', 'RHETORIC'
]
}
],
"source": [
"tokens = nltk.word_tokenize(txt)\n",
"print(tokens)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## NLTK Text object"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<Text: _MANIFESTO LIQUID LIFE IS AN UNCERTAIN REALM ....>\n"
]
}
],
"source": [
"text = nltk.Text(tokens)\n",
"print(text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## concordance"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Displaying 25 of 25 matches:\n",
"_MANIFESTO LIQUID LIFE IS AN UNCERTAIN REALM . THE CO\n",
"RCOMPLEXITY AND HYPEROBJECT-NESS OF LIQUID TERRAINS EXCEEDS OUR ABILITY TO OBS\n",
"AS LIVING THINGS ARE BY-PRODUCTS OF LIQUID PROCESSES . LIQUID LIFE IS A WORLDV\n",
"E BY-PRODUCTS OF LIQUID PROCESSES . LIQUID LIFE IS A WORLDVIEW . A PHANTASMAGO\n",
"FORMATION WITHIN PHYSICAL SYSTEMS . LIQUID LIFE IS A KIND OF METABOLIC WEATH\n",
"Y - THAT PERMEATES THE ATMOSPHERE , LIQUID ENVIRONMENTS , SOILS AND EARTH S \n",
"F MATTER THAT DETAIL OUR ( EARTHY , LIQUID , GASEOUS ) TERRAINS . LIQUID LIFE \n",
"THY , LIQUID , GASEOUS ) TERRAINS . LIQUID LIFE IS IMMORTAL . ARISING FROM OUR\n",
"S OF LIFE AND DEATH . MOST DECEASED LIQUID MATTER LIES QUIESCENT , PATIENTLY W\n",
"TENT METABOLISMS WITHIN OUR SOILS . LIQUID LIFE EXCEEDS RHETORIC . ITS CONCEPT\n",
"ENSES AND TECHNIQUES TO INVOLVE THE LIQUID REALM WITH ITS OWN VOICE . FROM\n",
" VOICE . FROM THESE PERSPECTIVES LIQUID TECHNOLOGIES EMERGE THAT ARE CAPABL\n",
" LIKE BÜTSCHLI DROPLETS , WHICH ARE LIQUID CHEMICAL ASSEMBLAGES CAPABLE OF SUR\n",
"EN EVOLVING POLY-VOCAL DIALECTICS . LIQUID LIFE PROVOKES AN EXPANDED NOTION OF\n",
"RDINATING CENTRE , LIKE THE BRAIN . LIQUID ARE NON-BODIES . THEY ARE WITHOUT F\n",
"ARIES AND ARE CONSTANTLY CHANGING . LIQUID BODIES ARE PARADOXICAL STRUCTURES T\n",
"APT , SELF-REPAIR , AND EMPATHIZE . LIQUID BODIES ARE PLURI-PONTENT . THEY ARE\n",
"D UPON GENERALIZATIONS AND IDEALS , LIQUID BODIES RESIST THESE TROPES . LIQUID\n",
"LIQUID BODIES RESIST THESE TROPES . LIQUID BODIES DISCUSS A MODE OF EXISTENCE \n",
"IONS OF MAKING AND BEING EMBODIED . LIQUID BODIES INVITE US TO ARTICULATE THE \n",
" BODY TO ANOTHER . INDEED , PROTEAN LIQUID BODIES HELP US UNDERSTAND THAT WHIL\n",
"HE MATERIALITY OF THE ENVIRONMENT . LIQUID BODIES ARE POLITICAL AGENTS . THEY \n",
"ERMEATED BY THEIR NURTURING MEDIA . LIQUID BODIES INVITE US TO UNDERSTAND OUR \n",
" WE RECOGNISE AS BEING ALIVE. “ LIQUID LIFE ARISES FROM OUT OF A SOUP , SM\n",
" PUMP UNIVERSAL SOLVENT THROUGH ITS LIQUID EYES , LENSING ERRANT LIGHT INTO IT\n"
]
}
],
"source": [
"# This is what you did with Michael before the break ...\n",
"concordance = text.concordance(\"liquid\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## similarities"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"living\n"
]
}
],
"source": [
"# With a small next step ...\n",
"similar = text.similar(\"liquid\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"liquid_are liquid_invite participating_creates liquid_resist\n",
"liquid_discuss other_as liquid_help caustic_a\n"
]
}
],
"source": [
"# And searching for contexts ...\n",
"contexts = text.common_contexts([\"bodies\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"----------------"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read on"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://www.nltk.org/book/ch01.html#searching-text (recommended!)"
]
},
{
"cell_type": "code",
"execution_count": null,
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}