From: Christian Heller Date: Fri, 5 Feb 2016 13:20:56 +0000 (+0100) Subject: Minor improvements to markov generator. X-Git-Url: https://plomlompom.com/repos/day_todos?a=commitdiff_plain;h=3c640fc4f1d19ac34cf871eb32369b90d9381a8c;p=plomlombot-irc.git Minor improvements to markov generator. --- diff --git a/plomlombot.py b/plomlombot.py index ed02792..7bf2208 100755 --- a/plomlombot.py +++ b/plomlombot.py @@ -190,16 +190,23 @@ def handle_command(command, argument, notice, target, session): if not os.access(markovfeed_name, os.F_OK): notice("NOT ENOUGH TEXT TO MARKOV.") return + + # Lowercase incoming lines, ensure they end in a sentence end mark. file = open(markovfeed_name, "r") lines = file.readlines() file.close() tokens = [] for line in lines: - line = line.replace("\n", "").lower() + line = line.lower().replace("\n", "") + if line[-1] not in ".!?": + line += "." tokens += line.split() if len(tokens) <= select_length: notice("NOT ENOUGH TEXT TO MARKOV.") return + + # Replace URLs with escape string for now, so that the Markov selector + # won't see them as different strings. Stash replaced URLs in urls. urls = [] url_escape = "\nURL" url_starts = ["http://", "https://", " 200: break @@ -236,12 +247,16 @@ def handle_command(command, argument, notice, target, session): for i in range(select_length - 1): snippet[i] = snippet[i + 1] snippet[select_length - 1] = new_end + + # Replace occurences of url escape string with random choice from urls. while True: index = msg.find(url_escape) if index < 0: break msg = msg.replace(url_escape, choice(urls), 1) - notice(msg + "malkovich.") + + # More meaningful ways to randomly end sentences. + notice(msg + malkovich + ".") def twt(): def try_open(mode):