Exemple #1
0
def test_update_state_check_goal_words():
    from trigrams import update_state, initialize_state
    old_state = initialize_state()
    state = initialize_state()
    state['q_goal'] = 'w5'
    state['p_goal'] = 'w6'
    state['b_goal'] = 'w7'
    state['q_word_count'] = 5
    state['p_word_count'] = 6
    state['b_word_count'] = 7
    frmt_word = ' dog'
    source_meta = {'proper_names': [],
                   'quotes': ['s3'],
                   'parens': ['w8'],
                   'brackets': []}
    also_print, state = update_state(old_state, state, frmt_word, source_meta)
    assert also_print == '")]'
    assert state['q_word_count'] == 0
    assert state['q_sentc_count'] == 0
    assert state['q_goal'] == ''
    assert not state['in_q']
    assert state['p_word_count'] == 0
    assert state['p_sentc_count'] == 0
    assert state['p_goal'] == ''
    assert not state['in_p']
    assert state['b_word_count'] == 0
    assert state['b_sentc_count'] == 0
    assert state['b_goal'] == ''
    assert not state['in_b']
Exemple #2
0
def test_update_state_end_sentc_no_q():
    from trigrams import update_state, initialize_state
    old_state = initialize_state()
    state = initialize_state()
    old_state['in_s'] = True
    state['in_s'] = False
    frmt_word = ''
    source_meta = {}
    also_print, state = update_state(old_state, state, frmt_word, source_meta)
    assert also_print == ''
    assert state['q_sentc_count'] == 0
Exemple #3
0
def test_check_state_changes():
    from trigrams import check_state_changes, initialize_state
    old_state = initialize_state()
    state = initialize_state()
    old_state['in_s'] = True
    state['in_p'] = True
    state['in_b'] = True
    state['in_q'] = True
    results = check_state_changes(old_state, state)
    assert 'end sentc' in results
    assert 'start quote' in results
    assert 'start parens' in results
    assert 'start brackets' in results
Exemple #4
0
def test_update_state_start_quote():
    from trigrams import update_state, initialize_state
    old_state = initialize_state()
    state = initialize_state()
    old_state['in_q'] = False
    state['in_q'] = True
    frmt_word = ''
    source_meta = {'proper_names': [],
                   'quotes': ['s3'],
                   'parens': ['w8'],
                   'brackets': []}
    also_print, state = update_state(old_state, state, frmt_word, source_meta)
    assert also_print == ''
    assert state['q_goal'] == 's3'
Exemple #5
0
def test_format_word_extra_quote():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    state['in_q'] = True
    next_word, state = format_word('frog', '"', state)
    assert next_word == ''
    assert state['in_q']
Exemple #6
0
def test_format_word_out_sentc_end():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    state['in_s'] = False
    next_word, state = format_word('frog', '.', state)
    assert next_word == '.'
    assert not state['in_s']
Exemple #7
0
def test_format_word_in_sentc_alpha():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    state['in_s'] = True
    next_word, state = format_word("", 'apple', state)
    assert next_word == ' apple'
    assert state['in_s']
Exemple #8
0
def test_update_state_space():
    from trigrams import update_state, initialize_state
    old_state = initialize_state()
    state = initialize_state()
    old_state['in_q'] = True
    old_state['in_p'] = True
    old_state['in_b'] = True
    state['in_q'] = True
    state['in_p'] = True
    state['in_b'] = True
    frmt_word = ' dog'
    source_meta = {'proper_names': [],
                   'quotes': ['s3'],
                   'parens': ['w8'],
                   'brackets': []}
    also_print, state = update_state(old_state, state, frmt_word, source_meta)
    assert also_print == ''
    assert state['q_word_count'] == 1
    assert state['p_word_count'] == 1
    assert state['b_word_count'] == 1
Exemple #9
0
def test_format_word_em_dash():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    state['in_s'] = True
    next_word, state = format_word(u'\u2014', 'really', state)
    assert next_word == 'really'
Exemple #10
0
def test_format_word_start_brackets():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    next_word, state = format_word('frog', '[', state)
    assert next_word == ' ['
    assert state['in_b']
Exemple #11
0
def test_format_word_start_parens():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    next_word, state = format_word('frog', '(', state)
    assert next_word == ' ('
    assert state['in_p']
Exemple #12
0
def test_format_word_out_sentc_num():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    next_word, state = format_word("", '18', state)
    assert next_word == ' 18'
    assert not state['in_s']
Exemple #13
0
def test_format_word_nls_yes():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    next_word, state = format_word('hop', '!', state)
    assert next_word == '!'
Exemple #14
0
def test_format_word_nls_no():
    from trigrams import format_word, initialize_state
    state = initialize_state()
    state['in_s'] = True
    next_word, state = format_word('hop', 'hop', state)
    assert next_word == ' hop'