def get_initial_state(Namespace, Domain, L1):
    State = initial_state()
    process_call_message(
        ['set_namespace_domain_and_language', Namespace, Domain, L1], State)
    import_course_info_into_state(State)
    L2 = State['l2']
    FirstLesson = get_available_lessons(State)['lessons'][0]
    AbstractAction = process_call_message(['set_lesson', FirstLesson], State)
    InitialAction = output_manager.abstract_call_action_to_action(
        AbstractAction, L1, L2)
    if 'text_to_repeat' in InitialAction:
        State['text_to_repeat'] = InitialAction['text_to_repeat']
    if 'visual_text_to_repeat' in InitialAction:
        State['visual_text_to_repeat'] = InitialAction['visual_text_to_repeat']
    output_manager.prepend_invocation_name_and_introduction_to_action_text(
        InitialAction, State)
    DontUnderstandAction = output_manager.dont_understand_action(L1, L2, State)
    log.print_log_message([
        'initialised', {
            'state': State,
            'initial_action': InitialAction,
            'dont_understand_action': DontUnderstandAction
        }
    ])
    return (State, InitialAction, DontUnderstandAction)
def update_state_from_forward_or_back_list_item(State, Item):
    (Prompt, VisualPrompt, Example,
     Canonical) = (Item['prompt'], Item['visual_prompt'], Item['example'],
                   Item['canonical'])
    State['prompt'] = Prompt
    State['visual_prompt'] = VisualPrompt
    State['example'] = Example
    State['canonical'] = Canonical
    State['attempts'] = 0
    State['helpgiven'] = 0
    scores.start_new_prompt(State)
    log.print_log_message(
        ['set_prompt', {
            'prompt': Prompt,
            'canonical': Canonical
        }])
def load_tables(TableFile, RobustMatchFile):
    random.seed()
    log.print_log_message(['load_tables', TableFile])
    NamespaceEtc = tables.load_data(TableFile)
    (Namespace, Domain, L2,
     L1) = (NamespaceEtc['namespace'], NamespaceEtc['domain'],
            NamespaceEtc['l2'], NamespaceEtc['l1'])
    log.print_log_message([
        'load_tables_succeeded', {
            'namespace': Namespace,
            'domain': Domain,
            'l2': L2,
            'l1': L1
        }
    ])
    log.print_log_message(['load_robust_matching_tables', RobustMatchFile])
    lgm_tables.load_data(RobustMatchFile, Namespace)
    log.print_log_message(
        ['load_robust_matching_tables_succeeded', RobustMatchFile, Namespace])
    return (Namespace, Domain, L1)
def string_and_state_to_action_main(String0, State):
    log.print_log_message(['process_string', String0])
    check_tables_are_loaded()
    String = robust_process_string_for_call(String0, State)
    L1 = State['language']
    L2 = State['l2']
    MessageInterpretation = string_as_call_message(String, State)
    if MessageInterpretation:
        log.print_log_message(['interpretation', MessageInterpretation])
        AbstractAction1 = process_call_message(MessageInterpretation, State)
    else:
        log.print_log_message(['interpretation', ['match', String0, String]])
        AbstractAction1 = process_call_message(['match', String0, String],
                                               State)
    Action1 = output_manager.abstract_call_action_to_action(
        AbstractAction1, L1, L2)
    Action = do_auto_next_if_necessary(Action1, State, L1, L2)
    if 'text_to_repeat' in Action:
        State['text_to_repeat'] = Action['text_to_repeat']
    if 'visual_text_to_repeat' in Action:
        State['visual_text_to_repeat'] = Action['visual_text_to_repeat']
    log.print_log_message(['response', Action])
    return Action
def default_help_action(State):
    log.print_log_message(['default_help_action'])
    check_tables_are_loaded()
    DefaultHelpText = output_manager.default_help_text(State)
    Action = {'text': DefaultHelpText, 'visual_text': DefaultHelpText}
    return Action