# Path: lxmls/data.py
# def find(filename):


import sys
import os
import numpy as np
import pytest
import warnings
import lxmls.readers.pos_corpus as pcc
import lxmls.readers.simple_sequence as ssr
import lxmls.sequences.hmm as hmmc
from lxmls import data
    from lxmls.sequences.log_domain import logsum

        y_pred = hmm.posterior_decode(simple.test.seq_list[1])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'rainy', 'rainy']

        hmm.train_supervised(simple.train, smoothing=0.1)

        y_pred = hmm.posterior_decode(simple.test.seq_list[0])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'sunny', 'sunny']

        y_pred = hmm.posterior_decode(simple.test.seq_list[1])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['sunny', 'sunny', 'sunny', 'sunny']


def test_exercise_8(hmm, simple):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        y_pred, score = hmm.viterbi_decode(simple.test.seq_list[0])
    assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'sunny', 'sunny']
    assert abs(score - -6.02050124698) < 0.5 # Check why in pytest this gives a different result from the notebook execution

    y_pred, score = hmm.viterbi_decode(simple.test.seq_list[1])
    assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['sunny', 'sunny', 'sunny', 'sunny']
    assert abs(score - -11.713974074) < tolerance


@pytest.fixture(scope='module')
def corpus_and_sequences():
    corpus = pcc.PostagCorpus()
    train_seq = corpus.read_sequence_list_conll(data.find('train-02-21.conll'), max_sent_len=15, max_nr_sent=1000)
    dev_seq = corpus.read_sequence_list_conll(data.find('dev-22.conll'), max_sent_len=15, max_nr_sent=1000)

# Path: lxmls/data.py
# def find(filename):


# Path: tests/test_sequence_models.py
import sys
import os
import numpy as np
import pytest
import warnings
import lxmls.readers.pos_corpus as pcc
import lxmls.readers.simple_sequence as ssr
import lxmls.sequences.hmm as hmmc
from lxmls import data
    from lxmls.sequences.log_domain import logsum


        y_pred = hmm.posterior_decode(simple.test.seq_list[1])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'rainy', 'rainy']

        hmm.train_supervised(simple.train, smoothing=0.1)

        y_pred = hmm.posterior_decode(simple.test.seq_list[0])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'sunny', 'sunny']

        y_pred = hmm.posterior_decode(simple.test.seq_list[1])
        assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['sunny', 'sunny', 'sunny', 'sunny']


def test_exercise_8(hmm, simple):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        y_pred, score = hmm.viterbi_decode(simple.test.seq_list[0])
    assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['rainy', 'rainy', 'sunny', 'sunny']
    assert abs(score - -6.02050124698) < 0.5 # Check why in pytest this gives a different result from the notebook execution

    y_pred, score = hmm.viterbi_decode(simple.test.seq_list[1])
    assert [y_pred.sequence_list.y_dict.get_label_name(yi) for yi in y_pred.y] == ['sunny', 'sunny', 'sunny', 'sunny']
    assert abs(score - -11.713974074) < tolerance


@pytest.fixture(scope='module')
def corpus_and_sequences():
    corpus = pcc.PostagCorpus()
    train_seq = corpus.read_sequence_list_conll(data.find('train-02-21.conll'), max_sent_len=15, max_nr_sent=1000)
    dev_seq = corpus.read_sequence_list_conll(data.find('dev-22.conll'), max_sent_len=15, max_nr_sent=1000)

    test_seq = corpus.read_sequence_list_conll(data.find('test-23.conll'), max_sent_len=15, max_nr_sent=1000)