You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 KiB
18 KiB
Wordnet¶
In [1]:
import random import nltk from nltk.corpus import wordnet
In [2]:
# You only need to run this once # nltk.download('wordnet')
In [4]:
lines = open('../txt/language.txt').readlines() sentence = random.choice(lines) print(sentence)
Access to hardware functions is limited not only through the software application, but through the syntax the software application may use for storing and transmitting the information it processes.
In [5]:
words = sentence.split() for word in words: print('----------') print('word:', word) for synset in wordnet.synsets(word): print('synset:', synset) print('lemmas:', synset.lemma_names)
---------- word: Access synset: Synset('entree.n.02') lemmas: <bound method Synset.lemma_names of Synset('entree.n.02')> synset: Synset('access.n.02') lemmas: <bound method Synset.lemma_names of Synset('access.n.02')> synset: Synset('access.n.03') lemmas: <bound method Synset.lemma_names of Synset('access.n.03')> synset: Synset('access.n.04') lemmas: <bound method Synset.lemma_names of Synset('access.n.04')> synset: Synset('access.n.05') lemmas: <bound method Synset.lemma_names of Synset('access.n.05')> synset: Synset('access.n.06') lemmas: <bound method Synset.lemma_names of Synset('access.n.06')> synset: Synset('access.v.01') lemmas: <bound method Synset.lemma_names of Synset('access.v.01')> synset: Synset('access.v.02') lemmas: <bound method Synset.lemma_names of Synset('access.v.02')> ---------- word: to ---------- word: hardware synset: Synset('hardware.n.01') lemmas: <bound method Synset.lemma_names of Synset('hardware.n.01')> synset: Synset('hardware.n.02') lemmas: <bound method Synset.lemma_names of Synset('hardware.n.02')> synset: Synset('hardware.n.03') lemmas: <bound method Synset.lemma_names of Synset('hardware.n.03')> ---------- word: functions synset: Synset('function.n.01') lemmas: <bound method Synset.lemma_names of Synset('function.n.01')> synset: Synset('function.n.02') lemmas: <bound method Synset.lemma_names of Synset('function.n.02')> synset: Synset('function.n.03') lemmas: <bound method Synset.lemma_names of Synset('function.n.03')> synset: Synset('function.n.04') lemmas: <bound method Synset.lemma_names of Synset('function.n.04')> synset: Synset('function.n.05') lemmas: <bound method Synset.lemma_names of Synset('function.n.05')> synset: Synset('affair.n.03') lemmas: <bound method Synset.lemma_names of Synset('affair.n.03')> synset: Synset('routine.n.03') lemmas: <bound method Synset.lemma_names of Synset('routine.n.03')> synset: Synset('function.v.01') lemmas: <bound method Synset.lemma_names of Synset('function.v.01')> synset: Synset('serve.v.01') lemmas: <bound method Synset.lemma_names of Synset('serve.v.01')> synset: Synset('officiate.v.02') lemmas: <bound method Synset.lemma_names of Synset('officiate.v.02')> ---------- word: is synset: Synset('be.v.01') lemmas: <bound method Synset.lemma_names of Synset('be.v.01')> synset: Synset('be.v.02') lemmas: <bound method Synset.lemma_names of Synset('be.v.02')> synset: Synset('be.v.03') lemmas: <bound method Synset.lemma_names of Synset('be.v.03')> synset: Synset('exist.v.01') lemmas: <bound method Synset.lemma_names of Synset('exist.v.01')> synset: Synset('be.v.05') lemmas: <bound method Synset.lemma_names of Synset('be.v.05')> synset: Synset('equal.v.01') lemmas: <bound method Synset.lemma_names of Synset('equal.v.01')> synset: Synset('constitute.v.01') lemmas: <bound method Synset.lemma_names of Synset('constitute.v.01')> synset: Synset('be.v.08') lemmas: <bound method Synset.lemma_names of Synset('be.v.08')> synset: Synset('embody.v.02') lemmas: <bound method Synset.lemma_names of Synset('embody.v.02')> synset: Synset('be.v.10') lemmas: <bound method Synset.lemma_names of Synset('be.v.10')> synset: Synset('be.v.11') lemmas: <bound method Synset.lemma_names of Synset('be.v.11')> synset: Synset('be.v.12') lemmas: <bound method Synset.lemma_names of Synset('be.v.12')> synset: Synset('cost.v.01') lemmas: <bound method Synset.lemma_names of Synset('cost.v.01')> ---------- word: limited synset: Synset('express.n.02') lemmas: <bound method Synset.lemma_names of Synset('express.n.02')> synset: Synset('restrict.v.03') lemmas: <bound method Synset.lemma_names of Synset('restrict.v.03')> synset: Synset('limit.v.02') lemmas: <bound method Synset.lemma_names of Synset('limit.v.02')> synset: Synset('specify.v.02') lemmas: <bound method Synset.lemma_names of Synset('specify.v.02')> synset: Synset('limited.a.01') lemmas: <bound method Synset.lemma_names of Synset('limited.a.01')> synset: Synset('circumscribed.s.01') lemmas: <bound method Synset.lemma_names of Synset('circumscribed.s.01')> synset: Synset('limited.s.03') lemmas: <bound method Synset.lemma_names of Synset('limited.s.03')> synset: Synset('limited.s.04') lemmas: <bound method Synset.lemma_names of Synset('limited.s.04')> synset: Synset('limited.s.05') lemmas: <bound method Synset.lemma_names of Synset('limited.s.05')> synset: Synset('limited.s.06') lemmas: <bound method Synset.lemma_names of Synset('limited.s.06')> synset: Synset('limited.s.07') lemmas: <bound method Synset.lemma_names of Synset('limited.s.07')> ---------- word: not synset: Synset('not.r.01') lemmas: <bound method Synset.lemma_names of Synset('not.r.01')> ---------- word: only synset: Synset('lone.s.03') lemmas: <bound method Synset.lemma_names of Synset('lone.s.03')> synset: Synset('alone.s.03') lemmas: <bound method Synset.lemma_names of Synset('alone.s.03')> synset: Synset('merely.r.01') lemmas: <bound method Synset.lemma_names of Synset('merely.r.01')> synset: Synset('entirely.r.02') lemmas: <bound method Synset.lemma_names of Synset('entirely.r.02')> synset: Synset('only.r.03') lemmas: <bound method Synset.lemma_names of Synset('only.r.03')> synset: Synset('only.r.04') lemmas: <bound method Synset.lemma_names of Synset('only.r.04')> synset: Synset('only.r.05') lemmas: <bound method Synset.lemma_names of Synset('only.r.05')> synset: Synset('only.r.06') lemmas: <bound method Synset.lemma_names of Synset('only.r.06')> synset: Synset('only.r.07') lemmas: <bound method Synset.lemma_names of Synset('only.r.07')> ---------- word: through synset: Synset('done.s.01') lemmas: <bound method Synset.lemma_names of Synset('done.s.01')> synset: Synset('through.s.02') lemmas: <bound method Synset.lemma_names of Synset('through.s.02')> synset: Synset('through.r.01') lemmas: <bound method Synset.lemma_names of Synset('through.r.01')> synset: Synset('through.r.02') lemmas: <bound method Synset.lemma_names of Synset('through.r.02')> synset: Synset('through.r.03') lemmas: <bound method Synset.lemma_names of Synset('through.r.03')> synset: Synset('through.r.04') lemmas: <bound method Synset.lemma_names of Synset('through.r.04')> synset: Synset('through.r.05') lemmas: <bound method Synset.lemma_names of Synset('through.r.05')> ---------- word: the ---------- word: software synset: Synset('software.n.01') lemmas: <bound method Synset.lemma_names of Synset('software.n.01')> ---------- word: application, ---------- word: but synset: Synset('merely.r.01') lemmas: <bound method Synset.lemma_names of Synset('merely.r.01')> ---------- word: through synset: Synset('done.s.01') lemmas: <bound method Synset.lemma_names of Synset('done.s.01')> synset: Synset('through.s.02') lemmas: <bound method Synset.lemma_names of Synset('through.s.02')> synset: Synset('through.r.01') lemmas: <bound method Synset.lemma_names of Synset('through.r.01')> synset: Synset('through.r.02') lemmas: <bound method Synset.lemma_names of Synset('through.r.02')> synset: Synset('through.r.03') lemmas: <bound method Synset.lemma_names of Synset('through.r.03')> synset: Synset('through.r.04') lemmas: <bound method Synset.lemma_names of Synset('through.r.04')> synset: Synset('through.r.05') lemmas: <bound method Synset.lemma_names of Synset('through.r.05')> ---------- word: the ---------- word: syntax synset: Synset('syntax.n.01') lemmas: <bound method Synset.lemma_names of Synset('syntax.n.01')> synset: Synset('syntax.n.02') lemmas: <bound method Synset.lemma_names of Synset('syntax.n.02')> synset: Synset('syntax.n.03') lemmas: <bound method Synset.lemma_names of Synset('syntax.n.03')> ---------- word: the ---------- word: software synset: Synset('software.n.01') lemmas: <bound method Synset.lemma_names of Synset('software.n.01')> ---------- word: application synset: Synset('application.n.01') lemmas: <bound method Synset.lemma_names of Synset('application.n.01')> synset: Synset('application.n.02') lemmas: <bound method Synset.lemma_names of Synset('application.n.02')> synset: Synset('application.n.03') lemmas: <bound method Synset.lemma_names of Synset('application.n.03')> synset: Synset('application.n.04') lemmas: <bound method Synset.lemma_names of Synset('application.n.04')> synset: Synset('lotion.n.02') lemmas: <bound method Synset.lemma_names of Synset('lotion.n.02')> synset: Synset('application.n.06') lemmas: <bound method Synset.lemma_names of Synset('application.n.06')> synset: Synset('application.n.07') lemmas: <bound method Synset.lemma_names of Synset('application.n.07')> ---------- word: may synset: Synset('may.n.01') lemmas: <bound method Synset.lemma_names of Synset('may.n.01')> synset: Synset('whitethorn.n.01') lemmas: <bound method Synset.lemma_names of Synset('whitethorn.n.01')> ---------- word: use synset: Synset('use.n.01') lemmas: <bound method Synset.lemma_names of Synset('use.n.01')> synset: Synset('function.n.02') lemmas: <bound method Synset.lemma_names of Synset('function.n.02')> synset: Synset('use.n.03') lemmas: <bound method Synset.lemma_names of Synset('use.n.03')> synset: Synset('consumption.n.03') lemmas: <bound method Synset.lemma_names of Synset('consumption.n.03')> synset: Synset('habit.n.02') lemmas: <bound method Synset.lemma_names of Synset('habit.n.02')> synset: Synset('manipulation.n.01') lemmas: <bound method Synset.lemma_names of Synset('manipulation.n.01')> synset: Synset('use.n.07') lemmas: <bound method Synset.lemma_names of Synset('use.n.07')> synset: Synset('use.v.01') lemmas: <bound method Synset.lemma_names of Synset('use.v.01')> synset: Synset('use.v.02') lemmas: <bound method Synset.lemma_names of Synset('use.v.02')> synset: Synset('use.v.03') lemmas: <bound method Synset.lemma_names of Synset('use.v.03')> synset: Synset('use.v.04') lemmas: <bound method Synset.lemma_names of Synset('use.v.04')> synset: Synset('practice.v.04') lemmas: <bound method Synset.lemma_names of Synset('practice.v.04')> synset: Synset('use.v.06') lemmas: <bound method Synset.lemma_names of Synset('use.v.06')> ---------- word: for ---------- word: storing synset: Synset('store.v.01') lemmas: <bound method Synset.lemma_names of Synset('store.v.01')> synset: Synset('store.v.02') lemmas: <bound method Synset.lemma_names of Synset('store.v.02')> ---------- word: and ---------- word: transmitting synset: Synset('transmission.n.01') lemmas: <bound method Synset.lemma_names of Synset('transmission.n.01')> synset: Synset('convey.v.03') lemmas: <bound method Synset.lemma_names of Synset('convey.v.03')> synset: Synset('impart.v.03') lemmas: <bound method Synset.lemma_names of Synset('impart.v.03')> synset: Synset('air.v.03') lemmas: <bound method Synset.lemma_names of Synset('air.v.03')> synset: Synset('transmit.v.04') lemmas: <bound method Synset.lemma_names of Synset('transmit.v.04')> ---------- word: the ---------- word: information synset: Synset('information.n.01') lemmas: <bound method Synset.lemma_names of Synset('information.n.01')> synset: Synset('information.n.02') lemmas: <bound method Synset.lemma_names of Synset('information.n.02')> synset: Synset('information.n.03') lemmas: <bound method Synset.lemma_names of Synset('information.n.03')> synset: Synset('data.n.01') lemmas: <bound method Synset.lemma_names of Synset('data.n.01')> synset: Synset('information.n.05') lemmas: <bound method Synset.lemma_names of Synset('information.n.05')> ---------- word: it synset: Synset('information_technology.n.01') lemmas: <bound method Synset.lemma_names of Synset('information_technology.n.01')> ---------- word: processes.
In [ ]:
In [6]:
for lemma in wordnet.lemmas('car'): print(lemma.name)
<bound method Lemma.name of Lemma('car.n.01.car')> <bound method Lemma.name of Lemma('car.n.02.car')> <bound method Lemma.name of Lemma('car.n.03.car')> <bound method Lemma.name of Lemma('car.n.04.car')> <bound method Lemma.name of Lemma('cable_car.n.01.car')>
In [7]:
for synset in wordnet.synsets('car'): print(synset.examples)
<bound method Synset.examples of Synset('car.n.01')> <bound method Synset.examples of Synset('car.n.02')> <bound method Synset.examples of Synset('car.n.03')> <bound method Synset.examples of Synset('car.n.04')> <bound method Synset.examples of Synset('cable_car.n.01')>
In [ ]: