from pathlib import Path
import re


def read_tsv(file_path):
    """
    Reads the data in

    Arguments:
    * data file path
    Returns:
    *sen_seq: a list of (sentence, corresponding supertags) pairs
    *sen_words: a list of sentences, 2 dim
    *sen_stags: a list of supertags, 2 dim
    """


    file_path = Path(file_path)

    raw_text = file_path.read_text().strip()
    raw_doc = re.split(r'\n\t?\n', raw_text)
    sen_seq = []
    sen_words = []
    sen_stags = []
    for doc in raw_doc:
        words = []
        stags = []

        for line in doc.split('\n'):
            _, word, _, supertags = line.split('\t')
            words.append(word)
            parts = supertags.split(":")
            stag = ':'.join(parts[:-1])
            stags.append(stag)
        sen_seq.append((words, stags))
        sen_words.append(words)
        sen_stags.append(stags)
      
    return sen_seq, sen_words, sen_stags