In this lecture we will look at representing metaphor in wordnets (slides).
omw-en:1.4.cn.xz. Note that it is newly made and I didn't transfer some information (such as counts and lexfiles, which you can get from omw-en:1.4)
import wn
wn.add('omw-en:1.4.cn.xz')
ewncn=wn.Wordnet('omw-en:1.4.cn')
for s in ewncn.senses('lamb', pos='n'):
print(s.id, s.synset().definition())
print(s.relations())
To make it a little easier to read:
for s in ewncn.senses('lamb', pos='n'):
print(f"{s.id} «{s.synset().definition()}» {s.counts()}")
for (rel, tgts) in s.relations().items():
for t in tgts:
print(f"{rel} → «{t.synset().definition()}»")
omw-nl:1.4. There may be quite a few!
## All senses
for s in ewncn.senses(pos='n'):
## senses related by metaphor
targets = s.get_related('metaphor')
for t in targets:
## translations
lg='nl'
slems = [l.word().lemma() for l in s.translate(lang=lg)]
tlems = [l.word().lemma() for l in t.translate(lang=lg)]
## shared translations
overlap = [l for l in slems if l in tlems]
if slems and tlems:
print(f"{s.id} ({slems}) «{s.synset().definition()}» {s.counts()}")
print(f" → ({tlems}) «{t.synset().definition()}»")
print(f" OVERLAP {overlap}")
Sample output
...
omw-en-windmill-04587559-n (['windmolen']) «a mill that is powered by the wind» []
→ (['winddynamo', 'windgenerator', 'windmolen', 'windturbine']) «generator that extracts usable energy from winds»
OVERLAP ['windmolen']
...
omw-en-window-04587648-n (['glasraam', 'licht', 'raam', 'raampje', 'venster', 'vensterraam']) «a framework of wood or metal that contains a glass windowpane and is built into a wall or roof to admit light or air» []
→ (['venster']) «a transparent panel (as of an envelope) inserted in an otherwise opaque material»
OVERLAP ['venster']
...
Take a look at the output, does it seem reasonable to you?