Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,27 @@ conceptNet.lookup("/c/en/toast",{
})
```

### `.URIstd(language, text, callback)`

This method finds out what the [ConceptNet URI](https://github.com/commonsense/conceptnet5/wiki/API#uri-standardization) is for a given text, applying steps such as reducing English words to their root form.

Example code:
```
conceptNet.URIstd('en', 'ground beef', function(err, result){
// insert code here
})
```

### `.search(params, callback)`

The search method takes a parameter object and hands the retrieved results to the callback function.
The official ConceptNet API documentation provides a full overview of the possible search parameters:
[ConceptNet API documentation](https://github.com/commonsense/conceptnet5/wiki/API).
[ConceptNet API documentation](https://github.com/commonsense/conceptnet5/wiki/API#search).

Example code:
```
conceptNet.search({
text: "donut"}, function(err, result){
start: "/c/en/donut"}, function(err, result){
// insert code here
})
```
Expand Down
11 changes: 10 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function ConceptNet( host, port, version ) {
}

this.host = host || 'conceptnet5.media.mit.edu';
this.version = version || '5.2';
this.version = version || '5.4';
this.port = parseInt(port || 80);
}

Expand All @@ -39,6 +39,15 @@ ConceptNet.prototype.lookup = function( URI, params, callback ) {
this.makeHtppRequest(this.buildOptions(path), callback);
};

ConceptNet.prototype.URIstd = function( language, text, callback ) {

text = text.replace(/\s+/g, '_');

var path = "/data/" + this.version + "/uri?language=" + language + "&text=" + String( encodeURIComponent(text) );

this.makeHtppRequest(this.buildOptions(path), callback);
};

ConceptNet.prototype.search = function( params, callback ) {

var path = "/data/" + this.version + "/search?";
Expand Down
36 changes: 29 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe( 'conceptNet', function tests() {

it( 'has default version', function test( done ) {
var cnet = new conceptNet();
assert( cnet.version === '5.2' );
assert( cnet.version === '5.4' );
done();
});
});
Expand Down Expand Up @@ -106,24 +106,46 @@ describe( 'conceptNet', function tests() {
it( 'handles concepts in other languages', function otherLangTest( done ) {
this.timeout(2000);
var cnet = new conceptNet();
cnet.lookup('c/ar/سلام/',{
cnet.lookup('/c/ja/車',{
filter: 'core'}, function( err, result ) {
assert( result.edges.length === 7 );
assert( result.edges.length === 50 );
done();
}
);
});
});

it( 'is possible to use search method to retrieve results', function test( done ) {
it( 'is possible to use search method to find ConceptNet edges for multiple requirements', function test( done ) {
this.timeout(2000);
var cnet = new conceptNet();
cnet.search({text: 'donut'}, function( err, result ) {
cnet.search({start: '/c/en/donut'}, function( err, result ) {
assert( result.numFound > 0 );
done();
});
});

describe( '.URIstd()', function tests() {

it( 'looks up the ConceptNet URI for text (english)', function test( done ) {
this.timeout(2000);
var cnet = new conceptNet();
cnet.URIstd('en', 'ground beef', function( err, result ) {
assert( result.uri == '/c/en/grind_beef' );
done();
}
);
});

it( 'looks up the ConceptNet URI for text (foreign language)', function test( done ) {
this.timeout(2000);
var cnet = new conceptNet();
cnet.URIstd('ja', '車', function( err, result ) {
assert( result.uri == '/c/ja/車' );
done();
}
);
});
});

describe( '.association()', function tests() {

Expand All @@ -142,10 +164,10 @@ describe( 'conceptNet', function tests() {
this.timeout(3000);
var cnet = new conceptNet();
cnet.association('/c/en/cat', {
limit: 4,
limit: 1,
filter: '/c/en/dog'},
function( err, result ) {
assert( result.similar.length === 4 );
assert( result.similar.length === 1 );
done();
});
});
Expand Down