Planeshifter / node-concept-net

node.js interface to the ConceptNet semantic network API [DEPRECATED; ConceptNet API has changed]
MIT License
29 stars 3 forks source link

search method #1

Closed auch188 closed 9 years ago

auch188 commented 9 years ago

Hi

I was wondering whether uri strings are supported in the search method, i.e (end=/c/en/car)?

I looked through the code in src/store.js and in line 34 of the code "path += querystring.stringify(params)" it uses querystring to stringify the params part of the method. So if the params in the path variable was "end=/c/en/car" it will be translated to "end=%2Fc%2Fen%2Fcar" which will cause nothing to be found.

What might be ways to get around this?

Planeshifter commented 9 years ago

Hello auch188,

could you post some example code where the search function fails to return the requested results? The options have to be encoded, otherwise they are not valid querytsrings. However, the code should work as expected. Could you try the following and tell me whether it fails for you:

var ConceptNet = require('concept-net');
var conceptNet = ConceptNet();
conceptNet.search({
    end:'/c/en/car'}, function(err, result){
        console.log(result);
});

Best wishes, Philipp

auch188 commented 9 years ago

Hi Philipp

I tried the code you mentioned above already and it doesn't work. The reason why it does not work is because the querystring.stringify function is escaped meaning that characters like "/' will change to "%2F".

I have however amended the code in a local version of src/store.js starting in line 31;

"ConceptNet.prototype.search = function(params, callback){ var path = "/data/5.2/search?";

path += querystring.stringify(params);"

I changed the code in line 34 to

"var str = querystring.stringify(params); str = querystring.unescape(str); path += str;"

The amended code works. Please consider merging my amendments.

Regards

Auch188

On Fri, Dec 12, 2014 at 4:14 AM, Philipp Burckhardt < notifications@github.com> wrote:

Hello auch188,

could you post some example code where the search function fails to return the requested results? The options have to be encoded, otherwise they are not valid querytsrings. However, the code should work as expected. Could you try the following code and tell me whether it fails for you:

var ConceptNet = require('concept-net'); var conceptNet = ConceptNet(); conceptNet.search({ end:'/c/en/car'}, function(err, result){ console.log(result); });

Best wishes, Philipp

— Reply to this email directly or view it on GitHub https://github.com/Planeshifter/node-concept-net/issues/1#issuecomment-66653419 .

Planeshifter commented 9 years ago

Strange, for me both versions return the same result. But in case that it might help someone who runs into the same problem as you, I merged in your changes and pushed a new version of the package to npm. Thanks for your input!