07 May 2007 01:14:59 UTC
- Distribution: WordNet-QueryData
- Module version: 1.46
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (4)
- KwaliteeBus factor: 0
- License: unknown
- Activity24 month
- Download (17.03KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- SEE ALSO
WordNet::QueryData - direct perl interface to WordNet database
use WordNet::QueryData; my $wn = WordNet::QueryData->new; 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";
WordNet::QueryData provides a direct interface to the WordNet database files. It requires the WordNet package (http://www.cogsci.princeton.edu/~wn/). It allows the user direct access to the full WordNet semantic lexicon. All parts of speech are supported and access is generally very efficient because the index and morphical exclusion tables are loaded at initialization. This initialization step is slow (appx. 10-15 seconds), but queries are very fast thereafter---thousands of queries can be completed every second.
To use QueryData, you must tell it where your WordNet database is. There are two ways you can do this: 1) by setting the appropriate environment variables, or 2) by passing the location to QueryData when you invoke the "new" function.
QueryData knows about two environment variables, WNHOME and WNSEARCHDIR. If WNSEARCHDIR is set, QueryData looks for WordNet data files there. Otherwise, QueryData looks for WordNet data files in WNHOME/dict (WNHOME\dict on a PC). If WNHOME is not set, it defaults to "/usr/local/WordNet-3.0" on Unix and "C:\Program Files\WordNet\3.0" on a PC. Normally, all you have to do is to set the WNHOME variable to the location where you unpacked your WordNet distribution. The database files are normally unpacked to the "dict" subdirectory.
You can also pass the location of the database files directly to QueryData. To do this, pass the location to "new":
my $wn = new WordNet::QueryData->new("/usr/local/wordnet/dict")
When calling "new" in this fashion, you can give it a second verbosity argument; a true value will have QueryData print debugging information.
There are two primary query functions, 'querySense' and 'queryWord'. querySense accesses semantic (sense to sense) relations; queryWord accesses 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:
Both functions take as their first argument a query string that takes one of three types:
(1) word (e.g. "dog") (2) word#pos (e.g. "house#n") (3) 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 see ants - antonyms deri - 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 see glos - word definition syns - synset words hype - hypernyms inst - instance of hypes - hypernyms and "instance of" hypo - hyponyms hasi - has instance hypos - hyponums and "has instance" mmem - member meronyms msub - substance meronyms mprt - part meronyms mero - all meronyms hmem - member holonyms hsub - substance holonyms hprt - part holonyms holo - all holonyms attr - attributes (?) sim - similar to (adjectives only) enta - entailment (verbs only) caus - cause (verbs only) domn - domain - all dmnc - domain - category dmnu - domain - usage dmnr - domain - region domt - 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 querySense specifies a synset. A type (3) string passed to queryWord specifies a specific sense of a specific word.
"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 the tagsense_cnt value 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.
Requires access to WordNet database files (data.noun/noun.dat, index.noun/noun.idx, etc.)
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.
Module Install Instructions
To install WordNet::QueryData, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install WordNet::QueryData
For more information on module installation, please visit the detailed CPAN module installation guide.