简体   繁体   English

browserify Wordnet 同义词库

[英]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.我正在为我的 JavaScript 网络应用程序使用同义词库 API (altervista),但我希望能够发出大量同义词请求而不必担心 API 配额等。我想在我的网络主机上自托管同义词库,我想要在浏览器中从 JavaScript 发送单词和接收它们的同义词。

As research I tried node, and within node I was able to get synonyms with these packages:作为研究,我尝试了 node,并且在 node 中我能够获得这些包的同义词:

" natural " and " wordnet-magic " 自然”和“ wordnet-magic

so then I tried to browserify "natural" and "wordnet-magic" node packages.所以后来我试图browserify “自然”和“共发现魔法”节点程序包。 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." “lapack 似乎是一个依赖于原生操作系统的共享库,所以它不能被浏览器化。” https://github.com/moos/wordpos/issues/9 https://github.com/moos/wordpos/issues/9

Also I had no luck browserifying "wordnet-magic":我也没有运气浏览“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可能相关(因为 sqlite3 在我的 wordnet-magic 包中),这里报告了同样的错误,但仍未解决: https : //github.com/mapbox/node-sqlite3/issues/512

My second choice would be a PHP solution should it be impossible in JavaScript.如果在 JavaScript 中不可能,我的第二个选择是 PHP 解决方案。 It does not have to use Browserify or Wordnet, but Wordnet would be such an amazing thing to have in the browser.它不必使用 Browserify 或 Wordnet,但 Wordnet 将在浏览器中拥有如此惊人的东西。 Thanks.谢谢。

Okay I can get synonyms in the browser (thanks to Stuart Watt):好的,我可以在浏览器中获取同义词(感谢 Stuart Watt):

I followed instructions to setup a javascript wordnet app here: https://github.com/morungos/wordnet我按照说明在这里设置了一个 javascript wordnet 应用程序: https : //github.com/morungos/wordnet

then did然后做了

npm install express npm 安装快递

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然后您可以在浏览器中看到 wordnet,例如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它是可见的,它可以工作,并在您的 html 中使用它,请参阅此答案: https : //stackoverflow.com/a/36526208/5350539

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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