I have a text file containing a very long text extracted from a book. I want to iterate over each sentence of the text and then, iterate again over every word of each sentence.
The idea is that if the word falls within category 1, it will be replaced by 'determiner', and if it falls within category 2, it will be replaced by 'non-determiner'. The for loop will then print each sentence (one sentence per line) with all the words replaced accordingly.
This is what I have tried so far:
import my_books
for sentence in my_books.sents("book1"):
for word in my_books.words("book1"):
if word == "the":
print("determiner")
else:
print("non-determiner")
However, my output is a list with one word per line:
determiner
non-determiner
non-determiner
non-determiner
...
This is what I want instead:
determiner non-determiner non-determiner non-determiner
non-determiner non-determiner determiner non-determiner non-determiner
non-determiner non-determiner determiner ...
What can I do to get the output as I want it? I think the problem has to do with the for loop, since there's a print statement after each word is classified into a category.