'Parse bAbI data into stories, queries, and answers.
Arguments:
babi_data (string): String of bAbI data.
babi_file (string): Filename with bAbI data.
Returns:
list of tuples : List of (story, query, answer) words.'

@staticmethod
def parse_babi(babi_file):

    babi_data = open(babi_file).read()
    lines = BABI.data_to_list(babi_data)
    (data, story) = ([], [])
    for line in lines:
        (nid, line) = line.split('    ', 1)
        if (int(nid) == 1):
            story = []
        if (' DCTB ' in line):
            (q, a, supporting) = line.split(' DCTB ')
            substory = [x for x in story if x]
            data.append((substory, BABI.tokenize(q), a))
            story.append('')
        else:
            sent = BABI.tokenize(line)
            story.append(sent)
    return [(BABI.flatten(_story), _question, answer) for (_story, _question, answer) in data]
