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/RESURGENCE/textadventuretry.ipynb

173 lines
7.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from pattern.search import STRICT, search\n",
"from pattern.en import parsetree"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"text = open(\"RESURGENCE.txt\").read()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"tree = parsetree(text)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'RESURGENCE | Isabelle Stengers \\n\\n“We are the grandchildren of the witches you were not able to burn”'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"text[:100]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for /: 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-11-2a9ed203686d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtree\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"page{n}.html\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"w\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"\"\"<meta charset='utf-8'><link type=\"text/css\" rel=\"stylesheet\" href=\"body.css\">\"\"\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"choose your fate:\"\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'int'"
]
}
],
"source": [
"n = 0\n",
"\n",
"for s in tree:\n",
" f = open(f\"page{n}.html\",\"w\")\n",
" print(\"\"\"<meta charset='utf-8'><link type=\"text/css\" rel=\"stylesheet\" href=\"body.css\">\"\"\",\"choose your fate:\"/n,file = f)\n",
" print(s, file = f)\n",
" f.close()\n",
" n = n + 1\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Match(words=[Word('take/VB'), Word('this/DT'), Word('motto/NN')]),\n",
" Match(words=[Word('disqualify/VB'), Word('the/DT'), Word('resurgence/NN')]),\n",
" Match(words=[Word('be/VB'), Word('the/DT'), Word('way/NN')]),\n",
" Match(words=[Word('inherit/VB'), Word('the/DT'), Word('struggle/NN')]),\n",
" Match(words=[Word('resist/VB'), Word('the/DT'), Word('idea/NN')]),\n",
" Match(words=[Word('have/VB'), Word('the/DT'), Word('courage/NN')]),\n",
" Match(words=[Word('accept/VB'), Word('this/DT'), Word('loss/NN')]),\n",
" Match(words=[Word('be/VB'), Word('a/DT'), Word('question/NN')]),\n",
" Match(words=[Word('have/VB'), Word('no/DT'), Word('power/NN')]),\n",
" Match(words=[Word('signal/VB'), Word('an/DT'), Word('advance/NN')]),\n",
" Match(words=[Word('generate/VB'), Word('the/DT'), Word('capacity/NN')]),\n",
" Match(words=[Word('suspect/VB'), Word('some/DT'), Word('kind/NN')]),\n",
" Match(words=[Word('suppress/VB'), Word('any/DT'), Word('temptation/NN')]),\n",
" Match(words=[Word('doubt/VB'), Word('the/DT'), Word('kind/NN')]),\n",
" Match(words=[Word('make/VB'), Word('a/DT'), Word('living/NN')]),\n",
" Match(words=[Word('become/VB'), Word('an/DT'), Word('ally/NN')]),\n",
" Match(words=[Word('weather/VB'), Word('the/DT'), Word('storm/NN')]),\n",
" Match(words=[Word('recover/VB'), Word('the/DT'), Word('capacity/NN')])]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"search('VB DT NN', tree)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for /: 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-a6c794b09339>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mm\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msearch\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"VB DT NN\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtree\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"<a href='page{n}.html'>{m.string}</a>\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"choose your fate:\"\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'int'"
]
}
],
"source": [
"f = open(\"adventure.html\",\"w\")\n",
"n = 0\n",
"for m in search (\"VB DT NN\", tree):\n",
" print(f\"<a href='page{n}.html'>{m.string}</a>\",\"choose your fate:\"/n,file = f)\n",
" n = n + 1\n",
"f.close()"
]
},
{
"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
}