-
Notifications
You must be signed in to change notification settings - Fork 1
GWordNet Tutorial
Le Tuan Anh edited this page Nov 22, 2016
·
1 revision
import stuff
import yawlib
from yawlib import YLConfig
from yawlib import SQLiteGWordNet
Create an instance of SQLiteGWordNet
WORDNET_30_GLOSS_DB_PATH = YLConfig.WORDNET_30_GLOSS_DB_PATH
gwn = SQLiteGWordNet(WORDNET_30_GLOSS_DB_PATH)
Select all synsets (slow operation)
synsets = gwn.all_synsets()
print(synsets[0])
Search synsets by term
cats = gwn.get_synsets_by_term('cat')
print(len(cats))
print(cats[0])
Output:
10
sid: n00901476 | terms: [t:`computerized tomography', t:`computed tomography', t:`CT', t:`computerized axial tomography', t:`computed axial tomography', t:`CAT'] | keys: [sk:`computerized_tomography%1:04:00::', sk:`computed_tomography%1:04:00::', sk:`ct%1:04:00::', sk:`computerized_axial_tomography%1:04:00::', sk:`computed_axial_tomography%1:04:00::', sk:`cat%1:04:00::'] | glosses: [gloss-def] | ofs-pos: 00901476-n
Search synsets by synset-id(s)
synsets = gwn.get_synset_by_id('n02121620')
dcat = synsets[0]
Accessing synset information
>>> dcat.get_synsetid()
'02121620-n'
>>> dcat.terms
[t:`cat', t:`true cat']
>>> dcat.get_orig_gloss()
'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats'
>>> dcat.glosses
[gloss-def]
>>> dcat.glosses[0].items
['feline', 'mammal', 'usually', 'having', 'thick', 'soft', 'fur', 'and', 'no', 'ability', 'to', 'roar', ':', 'domestic', 'cats', ';', 'wildcats', ';']
>>> dcat.glosses[0].tags
[feline (sk:feline%3:01:00::), mammal (sk:mammal%1:05:00::), usually (sk:usually%4:02:00::), fur (sk:fur%1:05:00::), roar (sk:roar%2:32:05::), domestic cat (sk:domestic_cat%1:05:00::), wildcat (sk:wildcat%1:05:00::)]