Created
November 18, 2018 04:03
-
-
Save drusepth/4d7cd5d526edf3b8a042fdec734293a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def markov_chain(initial_word=None, heuristic_function=lambda x, y: 0): | |
chain_words = [initial_word] | |
while chain_words[-1] != None: | |
current_word = chain_words[-1] | |
# Generate a pool of potential antecedents to choose from | |
potential_followup_words = followup_words_for(current_word) | |
# Rank that pool of antecedents by a heuristic comparing options | |
ranked_followup_words = sorted(potential_followup_words, key=functools.cmp_to_key(heuristic_function)) | |
# Choose a word and advance forward through the chain | |
selected_word = ranked_followup_words[0] | |
chain_words.append(selected_word) | |
return " ".join(chain_words[0:-1]) | |
def frequency_heuristic(option_one, option_two): | |
print("in heuristic") | |
print(option_one) | |
print(option_two) | |
print(markov_chain(initial_word="There", heuristic_function=frequency_heuristic)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment