import re


def get_relations(corpus):
    """
    Extract a list of binary syntactic relations from the corpus
    input: Corpus object (see corpus_classes.py)
    output: list of all binary syntactic relations in the corpus
    """
    relations = []
    no_of_complex_verbs = 0
    for text in corpus.files:
        for sentence in text.sentences:
            for word in sentence.words:
                if word.head == 0:      # skip the root
                    continue
                head = sentence.words[word.head - 1]        # identify head of current token
                relations.append((word.lemma, word.deprel, head.lemma))     # append token, relation and head token
                # additional handling of complex verb forms:
                if re.match('VA', head.pos):        # if head is auxiliary verb, search for dependent full verb
                    for word2 in sentence.words:
                        if word2.head == head.id and re.match('VV', word2.pos) and word2 != word:
                            relations.append((word.lemma, word.deprel, word2.lemma))
                            no_of_complex_verbs += 1

        print('Relations from {} extracted.'.format(text.path))

    print('(Added {} complex verbs)\n'.format(no_of_complex_verbs))

    return relations