import os
import string
from pprint import pprint
from random import choice, randint


def load_text(filename="./data/genius.txt"):
    lines = filter_lines(get_lines(filename))
    print("Loaded %i lines of data: %s." % (len(lines), lines[0]))
    return lines


def load_texts(root="./"):
    data_dir = root + 'data/'
    all_lines = []
    files = os.listdir(data_dir)
    print("%i files in data folder." % len(files))
    for filename in files:
        all_lines.extend(get_lines(data_dir + "/" + filename))

    all_lines = filter_lines(all_lines)
    print("Loaded %i lines of data: %s." % (len(all_lines), all_lines[0]))
    return all_lines


def filter_lines(all_lines):
    all_lines = [h for h in all_lines if h[0] not in ["[", "#"]]
    return all_lines


def get_lines(filename):
    all_lines = []
    with open(filename) as f:
        content = f.readlines()
        all_lines.extend(content)

    return all_lines


def load_seeds(corpus=None, nb_seeds=10):
    if corpus is None:
        corpus = load_texts()
    seeds = []
    for i in range(nb_seeds):
        plain_lines = filter(lambda k: k != "\n", corpus)
        chosen = choice(list(plain_lines))
        split = chosen.split(" ")
        nb_words = randint(1, len(split))
        seeds.append(" ".join(split[:nb_words]))
    return seeds


def main():
    lines = load_texts("../")
    print("Some seeds:")
    pprint(load_seeds(lines))


if __name__ == '__main__':
    main()
