from typing import Tuple
from typing import List
from typing import Set


def get_sentences_and_labels(path: str) -> Tuple[List[str], List[List[str]], Set[str], Set[str]]:
    """Combines tokens into sentences and create vocab set for train data and labels.

    For simplicity tokens with 'O' entity are omitted.

    Args:
        path: Path to the downloaded dataset file.

    Returns:
        (sentences, labels, train_vocab, label_vocab)
    """
    words, tags = [], []
    word_vocab, label_vocab = set(), set()
    sentences, labels = [], []
    data = open(path)
    for line in data:
        if line != '\n':
            line = line.split()
            words.append(line[1])
            tags.append(line[0])
            word_vocab.add(line[1])
            label_vocab.add(line[0])
        else:
            sentences.append(" ".join([s for s in words]))
            labels.append([t for t in tags])
            words.clear()
            tags.clear()
    sentences = list(filter(None, sentences))
    labels = list(filter(None, labels))
    return sentences, labels, word_vocab, label_vocab