def emit(id):
if not id in hctx:
return (id, {})
hvector, candidates = v.transform(hctx[id]), Counter()
for hypernym in hctx[id]:
hsenses = Counter({hid: sim(v.transform(Counter(synsets[hid])), hvector).item(0) for hid in index[hypernym]})
for hid, cosine in hsenses.most_common(1):
if cosine > 0:
candidates[(hypernym, hid)] = cosine
matches = [(hypernym, hid, cosine) for (hypernym, hid), cosine in candidates.most_common(len(candidates) if args.k == 0 else args.k) if hypernym not in synsets[id]]
return (id, matches)
评论列表
文章目录