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


import os
import sys
import codecs
import readers.pos_corpus as pcc
import readers.brown_pos_corpus as bpc
import sequences.extended_feature as exfc
import sequences.structured_perceptron as spc
import sequences.confusion_matrix as bcm
from lxmls import data
from sequences.sequence import *
from sequences.sequence_list import *

def eval_model(corpus, features, model):
    test_seq = corpus.read_sequence_list_conll(data.find('test-23.conll'))
    pred_test = model.viterbi_decode_corpus_log(test_seq.seq_list)
    eval_test = model.evaluate_corpus(test_seq.seq_list, pred_test)
    print("Accuracy on wsj test %f" % eval_test)


def eval_brown(corpus, features, model):
    categories = ['science_fiction']
    for cat in categories:
        brown_seq = corpus.read_sequence_list_brown(categories=cat)
        brown_pred = model.viterbi_decode_corpus_log(brown_seq.seq_list)
        brown_eval = model.evaluate_corpus(brown_seq.seq_list, brown_pred)
        print("Accuracy on Brown cat %s: %f" % (cat, brown_eval))


def load_model():
    corpus = pcc.PostagCorpus()
    corpus.load_corpus(MODEL_DIR)
    features = exfc.ExtendedFeatures(corpus)
    features.load_features(MODEL_DIR+"features.txt", corpus)
    model = spc.StructuredPercetron(corpus, features)
    model.load_model(MODEL_DIR)
    return corpus, features, model


def main():
    print("Building corpus")
    corpus, features = build_corpus_features()

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


# Path: lxmls/pos_tagging/all_train_pos_tag.py
import os
import sys
import codecs
import readers.pos_corpus as pcc
import readers.brown_pos_corpus as bpc
import sequences.extended_feature as exfc
import sequences.structured_perceptron as spc
import sequences.confusion_matrix as bcm
from lxmls import data
from sequences.sequence import *
from sequences.sequence_list import *


def eval_model(corpus, features, model):
    test_seq = corpus.read_sequence_list_conll(data.find('test-23.conll'))
    pred_test = model.viterbi_decode_corpus_log(test_seq.seq_list)
    eval_test = model.evaluate_corpus(test_seq.seq_list, pred_test)
    print("Accuracy on wsj test %f" % eval_test)


def eval_brown(corpus, features, model):
    categories = ['science_fiction']
    for cat in categories:
        brown_seq = corpus.read_sequence_list_brown(categories=cat)
        brown_pred = model.viterbi_decode_corpus_log(brown_seq.seq_list)
        brown_eval = model.evaluate_corpus(brown_seq.seq_list, brown_pred)
        print("Accuracy on Brown cat %s: %f" % (cat, brown_eval))


def load_model():
    corpus = pcc.PostagCorpus()
    corpus.load_corpus(MODEL_DIR)
    features = exfc.ExtendedFeatures(corpus)
    features.load_features(MODEL_DIR+"features.txt", corpus)
    model = spc.StructuredPercetron(corpus, features)
    model.load_model(MODEL_DIR)
    return corpus, features, model


def main():
    print("Building corpus")
    corpus, features = build_corpus_features()

    print("Training model")