WNUTIL(3)

πŸ“¦
version 3.0 Β· 2 versions
, in fedora 43, fedora 44, opensuse-leap 16.0

✨ WNUTIL(3) β€” WordNetβ„’ Library Functions ✨

okay bestie, pull up a chair πŸͺ‘ because this is the utility function page for the WordNetβ„’ library β€” all the little helper girlies that the interface code, the other library functions, and a whole bunch of applications and tools lean on. let's get into it πŸ’…


🌸 NAME 🌸

wninit, re_wninit, cntwords, strtolower, ToLowerCase, strsubst, getptrtype, getpos, getsstype, StrToPos, GetSynsetForSense, GetDataOffset, GetPolyCount, WNSnsToStr, GetValidIndexPointer, GetWNSense, GetSenseIndex, default_display_message β€” utility functions used by the interface code 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include "wn.h"

int wninit(void);

int re_wninit(void);

int cntwords(char *str, char separator);

char *strtolower(char *str);

char *ToLowerCase(char *str);

char *strsubst(char *str, char from, char to);

int getptrtype(char *ptr_symbol);

int getpos(char *ss_type);

int getsstype(char *ss_type);

int StrToPos(char **pos);

SynsetPtr GetSynsetForSense(char *sense_key);

long GetDataOffset(char *sense_key);

int GetPolyCount(char *sense_key);

char *WNSnsToStr(IndexPtr idx, int sense_num);

IndexPtr GetValidIndexPointer(char *str, int pos);

int GetWNSense(char *lemma, *lex_sense);

SnsIndexPtr GetSenseIndex(char *sense_key);

int GetTagcnt(IndexPtr idx, int sense);

int default_display_message(char *msg);

πŸ’– DESCRIPTION πŸ’–

so the WordNet library is absolutely packed with utility functions β€” like, the interface code uses them, other library functions use them, all kinds of applications and tools use them. but this page? this page only covers the ones that matter to the WordNet search code, or the ones that are just generally useful. not me being selective, it's giving curated πŸ’…


wninit() β€” opens up all the files you need to actually use WordNet with the WordNet library functions. the database files get opened, and morphinit() is called to open the exception list files. returns 0 if it worked, -1 if it didn't 😭

⚠️ real talk: the database and exception list files have to be open before you use the WordNet search and morphology functions. no skipping this step, bestie.

if the database opens successfully, the global variable OpenDB gets set to 1. and here's the lil plot twist β€” it's totally possible for the database files to be open (OpenDB == 1) while the exception list files are not. so don't assume, okay? πŸ‘€


re_wninit() β€” closes the database files and reopens them. and when I say it's used exclusively for WordNet development, I mean exclusively. re_morphinit() gets called to close and reopen the exception list files. return codes are the same as described above, no cap.


cntwords() β€” counts the number of underscore- or space-separated words in str. a hyphen gets passed in separator if it's supposed to count as a word delimiter. otherwise separator can be any other character you want, or an underscore if you don't want another character. your call, queen πŸ‘‘


strtolower() β€” converts str to lower case and removes a trailing adjective marker if there is one. heads up though: str is actually modified by this function, and a pointer to the modified string gets returned. it's not a copy situation, it's a glow-up-in-place situation ✨


ToLowerCase() β€” does the lower-case conversion exactly like above, but without removing an adjective marker. the chill, non-destructive cousin 🌈


strsubst() β€” replaces every single occurrence of from with to inside str, and returns the resulting string. find and replace, but make it library function πŸ’…


getptrtype() β€” returns the integer ptr_type that corresponds to the pointer character you pass in ptr_symbol. want the full table of pointer symbols and types? that lives in wnsearch(3), go peek πŸ‘€


getpos() β€” returns the integer constant corresponding to the synset type you passed. ss_type can be one of these: n, v, a, r, s. if you pass s, you get ADJ back. and if ss_type is invalid? it exits with -1. dramatic, but fair πŸ’€


getsstype() β€” works just like getpos(), except when ss_type is s it returns SATELLITE. same energy, different answer πŸ›°οΈ


StrToPos() β€” returns the integer constant corresponding to the syntactic category passed in pos. the string has to be one of these: noun, verb, adj, adv. and if pos is invalid, you get -1 back.


GetSynsetForSense() β€” returns the synset containing the word sense sense_key, and NULL if something went wrong 😭


GetDataOffset() β€” returns the synset offset for the synset containing the word sense sense_key, and 0 if sense_key isn't in the sense index file.


GetPolyCount() β€” returns the polysemy count (that's the number of senses in WordNet, iykyk) for the lemma encoded in sense_key, and 0 if the word isn't found. obsessed with a function that tells you how many senses a word has 🫢


WNSnsToStr() β€” returns the sense key encoding for the sense_num entry in idx.


GetValidIndexPointer() β€” returns the Index structure for the word in pos. and it calls morphstr(3) to hunt down a valid base form if the word happens to be inflected. teamwork makes the dream work 🧚


GetWNSense() β€” returns the WordNet sense number for the sense key encoding represented by lemma and lex_sense.


GetSenseIndex() β€” returns the parsed sense index entry for sense_key, and NULL if sense_key isn't in the sense index.


GetTagcnt() β€” returns how many times the sense you passed has been tagged, according to the cntlist file. counting receipts, literally πŸ“‹


default_display_message() β€” simply returns -1. that's the whole job. iconic honestly.

this is the default value for the global variable display_message, which points to a function to call when you want to display an error message. and in general, applications (the WordNet interfaces included) define their own application-specific function and set display_message to point at that instead. so this one's the placeholder queen πŸ‘‘


πŸ“ NOTES πŸ“

include/wn.h lists all the pointer and search types along with their corresponding constant values. but β€” and this is the annoying part β€” there's no description of what each search type actually is or what results it returns πŸ™ˆ

the best way to see what types of searches are available, and what data comes back for each one, is to just use the WordNet interface yourself. hands-on learning, periodt.


πŸ‘€ SEE ALSO πŸ‘€


🚨 WARNINGS 🚨

error checking on passed arguments is not rigorous. like, at all. passing NULL pointers or invalid values will often cause an application to die. no warning, no graceful exit, just gone πŸ’€ so please, bestie, check your arguments before you pass them. do it for me.

WordNet 3.0 🌸 Dec 2006 β€” that's the version and date of this lil masterpiece, mwah, and honestly? she ate. thanks for reading all the way to the bottom, you're a real one πŸ«Άβœ¨πŸ’–

πŸ“¦ where this page comes from