# November 2021, copyleft || Funix || Zine Camp, Worm, Rotterdam # NLTK (Natural Language ToolKit) is a library for Natural Language Process. # We will use it to get the Part Of Speech (POS) of the speech-to-text results. # # What does it mean? # # It works as grammar tagging: for instance, the sentence "Around the clouds" # would have this output: # # [('Around', 'IN'), ('the', 'DT'), ('clouds', 'NN')] # # 'IN' means 'preposition' - 'DT' means 'determiner' - 'NN' means 'noun, common, singular or mass' import nltk # to use NLTK from urllib.request import urlopen # to request urls usage url = 'https://pad.xpub.nl/p/grammar/export/txt' response = urlopen(url) text = response.read().decode('UTF-8') tokens = nltk.word_tokenize(text) # Tokenize the words :: split each word # Elaborate the Part of Speech! It will create an array, a list pos = nltk.pos_tag(tokens) # print(pos) # print the array! # time.sleep(2) # check it in the console! # To see all the POS tags, open the terminal and copy: # # python3 # import nltk # nltk.help.upenn_tagset() # see also: # https://cheatography.com/deacondesperado/cheat-sheets/nltk-part-of-speech-tags/ # start the layouting :: html + css + paged.js >> # # declare html :: we will fill it in the process with loops # declare the first part of the text for two html files with different CSS html = '' html = ''' 📡 💻📘

Title!

Authors!

''' # Process each element of the list for e in pos: # e is the current element, pos is the array to process print(e) if e[0] == '.': # if e is a dot, its class will be 'dot' html += " .
\n" else: # fill the html with each word and assign it as class its POS html += " "+e[0]+" \n" # Close the html text html += '''
''' # to tidy wrong " . " and " ' " position html = html.replace(' .', '.').replace(" '", "'") # Save the files! with open('./index.html', 'w', encoding='utf-8') as index: index.write(html) index.close()