Skip to content

Commit

Permalink
Fixed issue with Russian language text processing.
Browse files Browse the repository at this point in the history
Fixed issue #2.  There was a problem converting the JSON objects for
the post to AlchemyAPI.  JSON.stringify caused Russian and probably
other languages text to not be properly encoded and return incorrect
results form AlchemyAPI.

Added unit test for Russian keyword extraction.
  • Loading branch information
framingeinstein committed Apr 27, 2013
1 parent 7cc00c5 commit eb391f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ AlchemyAPI.prototype._doRequest = function(request_query, cb) {
});

});

//console.dir(req);
//req.setEncoding("utf8");
req.on('socket', function(socket) {
socket.on('error', function(err) {
//console.log('socket error : ' + err);
Expand All @@ -131,9 +132,16 @@ AlchemyAPI.prototype._doRequest = function(request_query, cb) {
});

if(req.method == "POST") {
//console.log("POSTING");
//console.log(querystring.stringify(request_query.post));
req.end(querystring.stringify(request_query.post));

/*
Removed this because JSON.stringify was causing issue with unicode characters
//console.log(querystring.stringify(request_query.post));
*/
if (request_query.post.text) {
req.end("text=" + request_query.post.text);
} else if (request_query.post.html) {
req.end("html=" + request_query.post.text);
}
} else {
req.end();
}
Expand Down Expand Up @@ -194,21 +202,24 @@ AlchemyAPI.prototype._getQuery = function(data, opts, method) {
query.headers = {
'content-length': '0'
}
//console.log("======================1==================");
}
else if(!this._htmlCheck(data)){
query.apimethod = "Text" + method;
query.post = {text: data};
query.headers = {
'content-length': '' + data.length + ''
,'content-type': 'application/x-www-form-urlencoded'
,'content-type': 'multipart/form-data'
};
//console.log("======================2==================");
}
else {
query.post = {html: data};
query.headers = {
'content-length': '' + data.length + ''
,'content-type': 'application/x-www-form-urlencoded'
};
//console.log("======================3==================");
}

query.nice = this._generateNiceUrl(query.url, options, query.apimethod);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alchemy-api",
"description": "An Alchemy API library for Node.js",
"tags": ["Alchemy", "Natural Language Processing", "util"],
"version": "0.8.8",
"version": "0.8.9",
"author": "Jason Morgan <[email protected]>",
"contributors": [
],
Expand Down
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ module.exports = {
test.done();
});
},
'get russian keywords': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.keywords("http://www.framingeinstein.com/russian.html", {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},
'get russian keywords from text': function(test) {
var alchemy = new Alchemy(apikey);
var text = "сервис, который поможет все успеть и ничего не пропустить Создание событий добавьте в календарь напоминание о фильме или концерте или создавайте напоминания о своих делах Оповещение настройте оповещение и календарь предупредит вас Используйте другие службы Яндекса добавляйте события из Телепрограммы или Афиши";
alchemy.keywords(text, {}, function(error, result) {
//console.log(result);
test.ifError(error);
//test.deepEqual(result.status, "OK");
test.done();
});
},

'get category': function(test) {
var alchemy = new Alchemy(apikey);
alchemy.category(testURL, {}, function(error, result) {
Expand Down

0 comments on commit eb391f1

Please sign in to comment.