def lyric(): engine = GrammarEngine(file_path="grammars/lyric.txt") for i in range(1): output = engine.generate(start_symbol_name="lyrics", debug=False) output_list = output.split("\\n") for i in range(len(output_list)): print(f"{output_list[i]}")
def debug(): """Generate an output with 'debug' mode on.""" # Prepare a grammar engine using the "basic.txt" grammar file engine = GrammarEngine(file_path="grammars/basic.txt") # Generate an output, with debug printout showing each # step in its derivation engine.generate(start_symbol_name="SENTENCE", debug=True)
def component1d(): engine = GrammarEngine(file_path="grammars/c1_grammar.txt") for i in range(3): output = engine.generate(start_symbol_name="PARAGRAPH", debug=False) print(f"{i} {output}\n")
def component1a(): engine = GrammarEngine(file_path="grammars/c1_grammar.txt") for i in range(5): output = engine.generate(start_symbol_name="NO_CORPUS", debug=False) output = output.capitalize() print(f"{i} {output}")
def component2d(): initial_state = {"name":"Yemi Shin","ID":"1998419","dorm":"Watson"} engine = GrammarEngine(file_path="grammars/c2_grammar.txt",initial_state=initial_state) for i in range(1): output = engine.generate(start_symbol_name="INTRO", debug=False) print(f"{output}\n")
def component2c(): engine = GrammarEngine(file_path="grammars/c2_grammar.txt") for i in range(3): output1 = engine.generate(start_symbol_name="ACT1", debug=False) output2 = engine.generate(start_symbol_name="ACT2",debug=False) print(f"{i} {output1}\n{output2}") print(" ")
def component5a(): engine = GrammarEngine(file_path="grammars/c5a_grammar.txt") for i in range(5): output = engine.generate(start_symbol_name="origin", debug=False) output_list = output.split('\\n') for j in range(len(output_list)): print(f"{output_list[j]}")
def component6(): engine = GrammarEngine(file_path="grammars/c6_grammar.txt") print(engine.generate(start_symbol_name="INTRO")) print(" ") output = engine.generate(start_symbol_name="SCREENPLAY") output_list = output.split('\\n') for j in range(len(output_list)): print(f"{output_list[j]}")
def component4(): engine = GrammarEngine(file_path="grammars/c4_grammar.txt") for _ in range(10): output = engine.generate(start_symbol_name="sentence") final_output = "" for i in range(len(output)): final_output += output[i].capitalize() print(f"* {final_output}") print(" ")
def component7(): engine = GrammarEngine(file_path="grammars/c6_grammar.txt") print(engine.generate(start_symbol_name="INTRO")) print(" ") output = engine.generate(start_symbol_name="SCREENPLAY") output_list = output.split('\\n') for j in range(len(output_list)): print(f"{output_list[j]}") state = engine.export_state() engine2 = GrammarEngine(file_path="grammars/c7_grammar.txt", initial_state=state) output3 = engine2.generate(start_symbol_name="SYNOPSIS") print("_________SYNOPSIS_________\n") print(output3) print(" ")
def state_usage_demo(): """Generate content that makes use of the engine state.""" # Prepare a grammar engine using the "state.txt" grammar file engine = GrammarEngine(file_path="grammars/state.txt") # Generate a "story" in which random elements recur. This is # made possible by writing to and reading from the engine state. output = engine.generate(start_symbol_name="STORY", debug=False) print(f"{output}\n") # Finally, print out the contents of the engine state after the # generation instance (if debug=True above, this will be printed) # at the beginning and at the end of the generation isinstance, # in which case there's no point to call it again here. engine.inspect_state() # To export the engine state (for use in another engine), use # the following method exported_state = engine.export_state() # To clear the engine state (prior to a subsequent call to # engine.generate(), if you want a fresh state for that call), # use this method engine.clear_state()
def component2b(): engine = GrammarEngine(file_path="grammars/c2_grammar.txt") for i in range(3): output = engine.generate(start_symbol_name="INDIRECT_REFERENCE", debug=False) print(f"{i} {output}\n")
def component9(): engine = GrammarEngine(file_path="grammars/c9_grammar.txt") for _ in range(3): print(engine.generate(start_symbol_name="sentence")) print(" ")