コード例 #1
0
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]}")
コード例 #2
0
ファイル: main.py プロジェクト: yemi33/Grammar
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)
コード例 #3
0
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")
コード例 #4
0
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}")
コード例 #5
0
ファイル: component2.py プロジェクト: yemi33/Grammar
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")
コード例 #6
0
ファイル: component2.py プロジェクト: yemi33/Grammar
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(" ")
コード例 #7
0
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]}")
コード例 #8
0
ファイル: component6.py プロジェクト: yemi33/Grammar
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]}")
コード例 #9
0
ファイル: component4.py プロジェクト: yemi33/Grammar
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(" ")
コード例 #10
0
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(" ")
コード例 #11
0
ファイル: main.py プロジェクト: yemi33/Grammar
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()
コード例 #12
0
ファイル: component2.py プロジェクト: yemi33/Grammar
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")
コード例 #13
0
ファイル: component9.py プロジェクト: yemi33/Grammar
def component9():
    engine = GrammarEngine(file_path="grammars/c9_grammar.txt")
    for _ in range(3):
        print(engine.generate(start_symbol_name="sentence"))
        print(" ")