open-language / en-dictionary

En-Dictonary is a node.js module which makes works and their relations available as a package.
MIT License
10 stars 3 forks source link

Ensure search results include all parts-of-speech #6

Closed rektdeckard closed 4 years ago

rektdeckard commented 4 years ago

This patch fixes a bug in which loading a lemma from the database would clobber any existing entries to the database from a different part of speech but with same lemma. For example, the adjective sense of the word "smart" ("showing mental alterness...") was overwritten by the noun sense ("a kind of pain such as that caused by a wound...") when the data.noun file was loaded on init().

The Database now stores lemmas as a Map<string, Map<string, Index>>, where the outer key is the lemma itself, pointing to a map of POS -> Index. In this way, you can access the requisite POS by calling indexLemmaIndex.get("smart")?.get("adjective");.

This affects the return signatures of searchFor() and searchSimpleFor(), and should be considered a major semver update.

rektdeckard commented 4 years ago

Apologies for all the formatting changes! I can resubmit without them if it's a problem.

sudhanshuraheja commented 4 years ago

Thanks @rektdeckard. Let me go through this now.

rektdeckard commented 4 years ago

0c7758c also should solve #2, so you only need to:

const Dictionary = require('en-dictionary');

When making use of the library.