def filtersubset(linking, el2kbid, gold_els):
    """
    remove from linking and rom el2kbid all mentions that are not in gold_els
    """
    newlinking = dict()
    new_el2kbid = dict()

    for kbid in linking.keys():
        mentions = linking[kbid]
        for m in mentions:
            if m in gold_els:
                if kbid in newlinking.keys():
                    newlinking[kbid].add(m)
                else:
                    newlinking[kbid] = set([m])

    for m in el2kbid.keys():
        if m in gold_els:
            new_el2kbid[m] = el2kbid[m]

    return (newlinking, new_el2kbid)