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

7.7 KiB

In [7]:
from pattern.search import STRICT, search
from pattern.en import parsetree
In [8]:
text = open("RESURGENCE.txt").read()
In [9]:
tree = parsetree(text)
In [10]:
text[:100]
Out[10]:
'RESURGENCE | Isabelle Stengers \n\n“We are the grandchildren of the witches you were not able to burn”'
In [11]:
n = 0

for s in tree:
    f = open(f"page{n}.html","w")
    print("""<meta charset='utf-8'><link type="text/css" rel="stylesheet" href="body.css">""","choose your fate:"/n,file = f)
    print(s, file = f)
    f.close()
    n = n + 1
    
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-2a9ed203686d> in <module>
      3 for s in tree:
      4     f = open(f"page{n}.html","w")
----> 5     print("""<meta charset='utf-8'><link type="text/css" rel="stylesheet" href="body.css">""","choose your fate:"/n,file = f)
      6     print(s, file = f)
      7     f.close()

TypeError: unsupported operand type(s) for /: 'str' and 'int'
In [12]:
search('VB DT NN', tree)
Out[12]:
[Match(words=[Word('take/VB'), Word('this/DT'), Word('motto/NN')]),
 Match(words=[Word('disqualify/VB'), Word('the/DT'), Word('resurgence/NN')]),
 Match(words=[Word('be/VB'), Word('the/DT'), Word('way/NN')]),
 Match(words=[Word('inherit/VB'), Word('the/DT'), Word('struggle/NN')]),
 Match(words=[Word('resist/VB'), Word('the/DT'), Word('idea/NN')]),
 Match(words=[Word('have/VB'), Word('the/DT'), Word('courage/NN')]),
 Match(words=[Word('accept/VB'), Word('this/DT'), Word('loss/NN')]),
 Match(words=[Word('be/VB'), Word('a/DT'), Word('question/NN')]),
 Match(words=[Word('have/VB'), Word('no/DT'), Word('power/NN')]),
 Match(words=[Word('signal/VB'), Word('an/DT'), Word('advance/NN')]),
 Match(words=[Word('generate/VB'), Word('the/DT'), Word('capacity/NN')]),
 Match(words=[Word('suspect/VB'), Word('some/DT'), Word('kind/NN')]),
 Match(words=[Word('suppress/VB'), Word('any/DT'), Word('temptation/NN')]),
 Match(words=[Word('doubt/VB'), Word('the/DT'), Word('kind/NN')]),
 Match(words=[Word('make/VB'), Word('a/DT'), Word('living/NN')]),
 Match(words=[Word('become/VB'), Word('an/DT'), Word('ally/NN')]),
 Match(words=[Word('weather/VB'), Word('the/DT'), Word('storm/NN')]),
 Match(words=[Word('recover/VB'), Word('the/DT'), Word('capacity/NN')])]
In [14]:
f = open("adventure.html","w")
n = 0
for m in search ("VB DT NN", tree):
    print(f"<a href='page{n}.html'>{m.string}</a>","choose your fate:"/n,file = f)
    n = n + 1
f.close()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-a6c794b09339> in <module>
      2 n = 0
      3 for m in search ("VB DT NN", tree):
----> 4     print(f"<a href='page{n}.html'>{m.string}</a>","choose your fate:"/n,file = f)
      5     n = n + 1
      6 f.close()

TypeError: unsupported operand type(s) for /: 'str' and 'int'
In [ ]: