Dec-12-2021, 07:14 PM
(This post was last modified: Dec-12-2021, 08:40 PM by Yoriz.
Edit Reason: Fixed code tags
)
Is there a way to modify this code for it to search for the sentences generated to:
— always start with capitalized words ("This is beautiful.", "You are a great programmer!", etc.);
— not start with a word that ends with a sentence-ending punctuation mark ("Okay.", "Nice.", "Good.", "Look!", "Jon!", etc.);
— always end with a sentence-ending punctuation mark like ., !, or ?;
— should not be shorter than 5 tokens.
My code:
— always start with capitalized words ("This is beautiful.", "You are a great programmer!", etc.);
— not start with a word that ends with a sentence-ending punctuation mark ("Okay.", "Nice.", "Good.", "Look!", "Jon!", etc.);
— always end with a sentence-ending punctuation mark like ., !, or ?;
— should not be shorter than 5 tokens.
My code:
sentence_count = 10 while sentence_count != 0: generated_sentence = [] current_word = random.choice(text1) generated_sentence.append(current_word) count = 9 while count != 0: next_word = Counter(head_tail[current_word]).most_common(1)[0][0] generated_sentence.append(next_word) current_word = next_word count -= 1 print(" ".join(generated_sentence)) sentence_count -= 1