QueryData(3pm)
π NAME π
WordNet::QueryData β it's a direct perl interface to the WordNet database, bestie. That's the whole vibe. π«Ά
β¨ SYNOPSIS β¨
use WordNet::QueryData;
my $wn = WordNet::QueryData->new( noload => 1);
print "Synset: ", join(", ", $wn->querySense("cat#n#7", "syns")), "\n";
print "Hyponyms: ", join(", ", $wn->querySense("cat#n#1", "hypo")), "\n";
print "Parts of Speech: ", join(", ", $wn->querySense("run")), "\n";
print "Senses: ", join(", ", $wn->querySense("run#v")), "\n";
print "Forms: ", join(", ", $wn->validForms("lay down#v")), "\n";
print "Noun count: ", scalar($wn->listAllWords("noun")), "\n";
print "Antonyms: ", join(", ", $wn->queryWord("dark#n#1", "ants")), "\n";
πΈ DESCRIPTION πΈ
Okay so WordNet::QueryData is your direct interface to the WordNet database files, no middleman, no nothing. π
It needs the WordNet package itself to exist first (http://www.cogsci.princeton.edu/~wn/), so like, get that. Then this module hands you direct access to the full WordNet semantic lexicon and you can do whatever you want with it. Every part of speech is supported, and access is generally very efficient because the index and morphical exclusion tables get loaded at initialization. And if you want extra-fast lookups, you can optionally make it load the indexes into memory. Obsessed. π
π¦ USAGE π¦
π LOCATING THE WORDNET DATABASE π
So to use QueryData you gotta tell it where your WordNet database lives. Two ways, pick your fighter:
- set the appropriate environment variables
- pass the location to QueryData when you invoke the
newfunction
QueryData knows about two environment variables: WNHOME and WNSEARCHDIR. Here's the tea β:
- If
WNSEARCHDIRis set, QueryData looks for WordNet data files there. - Otherwise, QueryData looks for WordNet data files in
WNHOME/dict(WNHOME\dicton a PC). - If
WNHOMEisn't set at all, it defaults to/usr/local/WordNet-3.0on Unix andC:\Program Files\WordNet\3.0on a PC.
Normally all you have to do is set the WNHOME variable to wherever you unpacked your WordNet distribution, and the database files are normally unpacked to the dict subdirectory. Easy. β¨
You can also just pass the location of the database files directly to QueryData. To do that, pass the location to new:
my $wn = WordNet::QueryData->new("/usr/local/wordnet/dict");
Or instead, call the constructor with a hash of params, like:
my $wn = WordNet::QueryData->new(
dir => "/usr/local/wordnet/dict",
verbose => 0,
noload => 1
);
When you call new like this, two extra arguments are supported:
verboseβ will output debugging information.noloadβ will cause the object to not load the indexes at startup.
π CACHING VERSUS NOLOAD π
The noload option means data gets retrieved using a dictionary lookup instead of caching the indexes in RAM. This method gives you an immediate startup time but slightly β though less than you might think β longer lookup time. π
For the curious, here are some profile data for each method on a duo core intel mac, averaged seconds over 10000 iterations:
Caching versus noload times in seconds
noload => 1 noload => 0
------------------------------------------------------------------
new() 0.00001 2.55
queryWord("descending") 0.0009 0.0001
querySense("sunset#n#1", "hype") 0.0007 0.0001
validForms ("lay down#2") 0.0004 0.0001
Obviously the new() comparison is not very useful, because nothing is happening with the constructor in the case of noload => 1. Similarly, lookups with caching are basically just hash lookups, and therefore very fast. The lookup times for noload => 1 illustrate the tradeoff between caching at new() time and using dictionary lookups.
Because of the lookup speed increase when noload => 0, many users will find it useful to set noload to 1 during development cycles, and to 0 when RAM is less of a concern than speed. The bottom line, fr fr: noload => 1 saves you over 2 seconds of startup time, and costs you about 0.0005 seconds per lookup. βοΈ
π₯ QUERYING THE DATABASE π₯
There are two primary query functions: querySense and queryWord. Let's break it down:
querySenseaccesses semantic (sense to sense) relations.queryWordaccesses lexical (word to word) relations.
The majority of relations are semantic. Some relations β including "also see", antonym, pertainym, "participle of verb", and derived forms β are lexical. See the following WordNet documentation for additional information:
http://wordnet.princeton.edu/man/wninput.5WN#sect3
Both functions take as their first argument a query string, and it comes in one of three types:
- word (e.g.
"dog") - word#pos (e.g.
"house#n") - word#pos#sense (e.g.
"ghostly#a#1")
Types (1) or (2) passed to querySense or queryWord will return a list of possible query strings at the next level of specificity. When type (3) is passed to querySense or queryWord, it requires a second argument: a relation. Relations generally only work with one function or the other, though some relations can be either semantic or lexical, hence they may work for both functions. β¨
Below is a list of known relations, grouped according to the function they're most likely to work with:
π queryWord π
alsoβ also seeantsβ antonymsderiβ derived forms (nouns and verbs only)partβ participle of verb (adjectives only)pertβ pertainym (pertains to noun) (adjectives only)vgrpβ verb group (verbs only)
π§ querySense π§
alsoβ also seeglosβ word definitionsynsβ synset wordshypeβ hypernymsinstβ instance ofhypesβ hypernyms and "instance of"hypoβ hyponymshasiβ has instancehyposβ hyponums and "has instance"mmemβ member meronymsmsubβ substance meronymsmprtβ part meronymsmeroβ all meronymshmemβ member holonymshsubβ substance holonymshprtβ part holonymsholoβ all holonymsattrβ attributes (?)simβ similar to (adjectives only)entaβ entailment (verbs only)causβ cause (verbs only)domnβ domain - alldmncβ domain - categorydmnuβ domain - usagedmnrβ domain - regiondomtβ member of domain - all (nouns only)dmtcβ member of domain - category (nouns only)dmtuβ member of domain - usage (nouns only)dmtrβ member of domain - region (nouns only)
When called in this manner, querySense and queryWord will return a list of related words/senses. Note that as of WordNet 2.1, many hypernyms have become "instance of" and many hyponyms have become "has instance." π
Note that querySense and queryWord use type (3) query strings in different ways:
- A type (3) string passed to
querySensespecifies a synset. - A type (3) string passed to
queryWordspecifies a specific sense of a specific word.
β OTHER FUNCTIONS β
validFormsβ accepts a type (1) or (2) query string. It returns a list of all alternate forms (alternate spellings, conjugations, plural/singular forms, etc.). The type (1) query returns alternates for all parts of speech (noun, verb, adjective, adverb).
WARNING: Only the first argument returned by validForms is certain to be valid (i.e. recognized by WordNet). Remaining arguments may not be valid. π
listAllWordsβ accepts a part of speech and returns the full list of words in the WordNet database for that part of speech.levelβ accepts a type (3) query string and returns a distance (not necessarily the shortest or longest) to the root in the hypernym directed acyclic graph.offsetβ accepts a type (3) query string and returns the binary offset of that sense's location in the corresponding data file.tagSenseCntβ accepts a type (2) query string and returns thetagsense_cntvalue for that lemma: "number of senses of lemma that are ranked according to their frequency of occurrence in semantic concordance texts."lexnameβ accepts a type (3) query string and returns the lexname of the sense; see WordNet lexnames man page for more information.frequencyβ accepts a type (3) query string and returns the frequency count of the sense from tagged text; see WordNet cntlist man page for more information.
See test.pl for additional example usage. π
π NOTES π
Requires access to WordNet database files (data.noun/noun.dat, index.noun/noun.idx, etc.) β like, no files, no vibes. π«
π COPYRIGHT π
Copyright 2000-2005 Jason Rennie. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π SEE ALSO π
Okay that's the whole page, bestie! This one's from perl v5.34.0, dated 2022-06-28, living in the User Contributed Perl Documentation corner of the manual, filed under QueryData(3pm). Slay, go query some words. π
β¨π¦
π¦ where this page comes from
- debian bookworm: libwordnet-querydata-perl 1.49-2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- debian trixie: libwordnet-querydata-perl 1.49-2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu noble: libwordnet-querydata-perl 1.49-2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu resolute: libwordnet-querydata-perl 1.49-2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu stonking: libwordnet-querydata-perl 1.49-2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms