liwenzhu / bosonnlp Goto Github PK
View Code? Open in Web Editor NEWbosonnlp node sdk.
bosonnlp node sdk.
运行:
var bosonnlp = require('bosonnlp');
var nlp = new bosonnlp.BosonNLP('这里是我的key');
nlp.ner('成都商报记者 姚永忠', function (result) {
console.log(result);
});
结果:
PS F:\workspace\bosonAPITest> node apiTest
在运行
from future import print_function, unicode_literals
import json
import requests
SENTIMENT_URL = 'http://api.bosonnlp.com/sentiment/analysis?weibo'
headers = {
'X-Token': 'YOUR_API_TOKEN',
'Content-Type': 'application/json'
}
s = ['他是个**']
data = json.dumps(s)
resp = requests.post(SENTIMENT_URL, headers=headers, data=data.encode('utf-8'))
print(resp.text)
telnet api.bosonnlp.com 80显示
Trying 120.79.151.233...
Connected to aliyun-1500.bosondata.net.
Escape character is '^]'.
Connection closed by foreign host.
你好,我尝试运行suggest 的方法,获取到的结果是502.
代码片段如下
const bosonnlp = require('bosonnlp')
const nlp = new bosonnlp.BosonNLP(bosonKey)
const term = '粉丝'
nlp.suggest(term, function (data) {
console.log("suggest:", data)
})
返回结果如下:
suggest: <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty/1.11.2.3</center>
</body>
</html>
nodejs_lib node index.js
events.js:141
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND api.bosonnlp.com api.bosonnlp.com:80
at errnoException (dns.js:27:10)
at GetAddrInfoReqWrap.onlookup as oncomplete
➜ nodejs_lib node index.js
{"status":403,"message":"malformed token format"}
no timeout option
During encoding the string that contains character double quote ("), it may construct a wrong http request body as for the API request.
It is because
function encodeString (data) { data = "\"" + escape(data).replace(/\%/g, '\\') + "\""; data = restorePunctuation(data); return data; };
It is easy to fix the issue. In the restorePunctuation function, make below changes:
OLD:
data = data.replace(/\\22/g, "\"");
NEW:
data = data.replace(/\\22/g, "\\\"");
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.