def create_lexicon(word_tags):
    """
    Create a lexicon in the right format for nltk.CFG.fromString() from
    a list with tuples with words and their tag.
    """

    # dictionary to filter the double tags
    word_dict = {}
    for word, tag in word_tags:
        if tag not in word_dict:
            word_dict[tag] = {word}
        else:
            word_dict[tag].add(word)

    # PRO is the tag for 's, but the 's is not removed on nouns.
    word_dict['NN'] = [x.replace('\'s', '') for x in word_dict['NN']]
    word_dict['JJ'] = [x.replace('\'s', '') for x in word_dict['JJ']]
    del word_dict[',']
    word_dict['PRP'].update(word_dict['PRP$'])
    del word_dict['PRP$']
    word_dict['POS'] = ['"s']

    # convert the dictionary to the right NLTK format
    lexicon = ''
    for key, val in word_dict.items():
        lexicon += key + ' -> '
        # add ' ' around every word
        val = [f'\'{v}\'' for v in val]
        # the words are seperated by a pipe
        lexicon += ' | '.join(val) + '\n'

    return lexicon