简体   繁体   中英

browserify Wordnet thesaurus

I am using a thesaurus API (altervista) for my JavaScript web app but I want to be able to make lots of synonym requests without worrying about API quotas, etc. I want to self-host a thesaurus on my web host and I would like to send words and receive their synonyms from JavaScript in the browser.

As research I tried node, and within node I was able to get synonyms with these packages:

" natural " and " wordnet-magic "

so then I tried to browserify "natural" and "wordnet-magic" node packages. On attempting to browserify "natural":

"Error: Cannot find module 'lapack'"

"lapack seems to be a native OS-dependent shared library, so it can't be browserified." https://github.com/moos/wordpos/issues/9

Also I had no luck browserifying "wordnet-magic":

"Uncaught TypeError: Cannot read property '_ansicursor' of undefined"

Possibly related (since sqlite3 is in my wordnet-magic packages), instances of same error reported here but still unresolved: https://github.com/mapbox/node-sqlite3/issues/512

My second choice would be a PHP solution should it be impossible in JavaScript. It does not have to use Browserify or Wordnet, but Wordnet would be such an amazing thing to have in the browser. Thanks.

Okay I can get synonyms in the browser (thanks to Stuart Watt):

I followed instructions to setup a javascript wordnet app here: https://github.com/morungos/wordnet

then did

npm install express

and then ran this code with node:

var express = require('express');
var app = express();
var WordNet = require('node-wordnet');
var wordnet = new WordNet();
app.get('/lookup', function(req, res) {
    wordnet.lookup(req.query.word, function(results) {
        res.send(results);
    });
});
app.listen(3000, function() {
    console.log('Example app listening on port 3000!');
});

and you can then see wordnet in your browser, eg http://localhost:3000/lookup?word=wind

It's visible, it works, and to consume it in your html, see this answer: https://stackoverflow.com/a/36526208/5350539

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM