WordNet with Node.JS

David Janes
Oct 20, 2020

WordNet is, well: a large lexical database of English. Nouns, verbs, adjectives and adverbs are grouped into sets of cognitive synonyms (synsets), each expressing a distinct concept.

Here’s an example of WordNet lookup for the word “dog”.

A few notes:

  • t̶h̶e̶r̶e̶’̶s̶ ̶n̶o̶ ̶l̶i̶n̶k̶i̶n̶g̶ ̶f̶r̶o̶m̶ ̶t̶h̶e̶ ̶f̶i̶r̶s̶t̶ ̶c̶o̶n̶c̶e̶p̶t̶ ̶o̶f̶ ̶”̶d̶o̶g̶”̶ ̶t̶o̶ ̶”̶a̶n̶i̶m̶a̶l̶”̶,̶ ̶e̶x̶c̶e̶p̶t̶ ̶t̶h̶r̶o̶u̶g̶h̶ ̶E̶n̶g̶l̶i̶s̶h̶ ̶l̶a̶n̶g̶u̶a̶g̶e̶ ̶t̶e̶x̶t̶.̶ ̶T̶h̶i̶s̶ ̶m̶a̶y̶ ̶b̶e̶ ̶a̶v̶a̶i̶l̶a̶b̶l̶e̶ ̶i̶n̶ ̶a̶n̶c̶i̶l̶l̶a̶r̶y̶ ̶d̶a̶t̶a̶s̶e̶t̶s̶ ̶t̶h̶a̶t̶ ̶a̶r̶e̶ ̶n̶o̶t̶ ̶f̶r̶e̶e̶l̶y̶ ̶a̶v̶a̶i̶l̶a̶b̶l̶e̶.̶ My bad — this is the lexFilenum. “5” is “<noun.animal>”.
  • WordNet is very liberally licensed and can be used in commercial products
  • WordNet hasn’t been updated since 2005 (not that it has to be!)

So on to the good part: here’s how you can access it in Node.JS:

npm install wordnet-db
npm install node-wordnet

Then:

const WordNet = require("node-wordnet")
const wordnet = new WordNet("../node_modules/wordnet-db/dict")
wordnet.lookup('dog', function(results) {
results.forEach(function(result) {
console.log(JSON.stringify(result, null, 2))
})
})

Which gives output like:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

David Janes
David Janes

Written by David Janes

Entrepreneur. Technologist. Mercenary Programmer.

No responses yet

Write a response