Merge branch 'master' of git.xpub.nl:/var/www/git.xpub.nl/repos/OuNoPo-make

master
ange 7 years ago
commit 660f89544a

BIN
.DS_Store vendored

Binary file not shown.

@ -61,7 +61,7 @@ output/tagged-words.txt: ocr/output.txt ## Analyzes OCR'ed text using a Part of
# >>> import nltk # >>> import nltk
# >>> nltk.download('averaged_perceptron_tagger') # >>> nltk.download('averaged_perceptron_tagger')
output/chatbot.txt: ocr/output.txt ## DESCRIBE WHAT IT DOES. Dependencies: python3's chatterbot output/chatbot.txt: ocr/output.txt ## Comments a text with a simple chatbot. Dependencies: python3's chatterbot
cat $< | python3 src/textbotconversation.py $(@) cat $< | python3 src/textbotconversation.py $(@)

@ -1,26 +1,28 @@
import nltk import nltk
from sys import stdin, stdout from sys import stdin, stdout
# Step 1: define input and set up a list # Define input
input = stdin.read() input = stdin.read()
taggedwordlist = []
string = input # FILTER FUNCTIONS
# This function cuts a string into words. Then runs a POS tagger for each word. Returns a list with tags
def postagger(string):
words = nltk.word_tokenize(string) words = nltk.word_tokenize(string)
taggedwordlist = nltk.pos_tag(words) taggedwordlist = nltk.pos_tag(words)
for word, pos in nltk.pos_tag(words): for word, pos in nltk.pos_tag(words):
taggedwordlist = nltk.pos_tag(words) taggedwordlist = nltk.pos_tag(words)
# print('{0} is a {1}'.format(word,pos)) # Command out to print the analysis step #print('{0} is a {1}'.format(word,pos)) # Comment out to print the analysis step
taglist = [ pos for word,pos in taggedwordlist ] taglist = [ pos for word,pos in taggedwordlist ]
#print(taglist) #print(taglist)
return taglist;
# This function changes the tags to readable equivalents (NNP to noun for example)
def postagger_readable(list):
readabletaglist = [] readabletaglist = []
for tag in taglist: for tag in list:
if tag in {"NNP","NNS","NN","NNPS"}: if tag in {"NNP","NNS","NN","NNPS"}:
readabletag = 'noun' readabletag = 'noun'
elif tag in {'VB','VBD','VBG','VBN','VBP','VBZ'}: elif tag in {'VB','VBD','VBG','VBN','VBP','VBZ'}:
@ -67,5 +69,14 @@ for tag in taglist:
readabletag = tag readabletag = tag
readabletaglist.append(readabletag) readabletaglist.append(readabletag)
return readabletaglist;
# This function creates the output
def main():
taglist = postagger(input)
readabletaglist = postagger_readable(taglist)
stdout.write(' '.join(readabletaglist)) stdout.write(' '.join(readabletaglist))
stdout.write('\n')
main()

Loading…
Cancel
Save