Skip to content

Commit

Permalink
Added retrieve and rank
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Oct 1, 2015
1 parent 398febd commit b08179f
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 5 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ node_modules/*
npm-debug.log
coverage
.DS_Store
test/resources/auth.js
test/resources/mobydick.txt
test/test.all-services.js
test/resources/tts-output.ogg
test/resources/face.jpg
test/integration/*
121 changes: 121 additions & 0 deletions services/retrieve_and_rank/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var url = require('url');
var extend = require('extend');
var requestFactory = require('../../lib/requestwrapper');
var solr = require('solr-client');
var pick = require('object.pick');
var omit = require('object.omit');
var isStream = require('isstream');

function RetrieveAndRank(options) {
var serviceDefaults = {
Expand All @@ -32,6 +35,124 @@ function RetrieveAndRank(options) {
this._options = extend(serviceDefaults, options);
}

/**
* Creates a ranker
*/
RetrieveAndRank.prototype.createRanker = function(params, callback) {
params = params || {};

if (!params || !params.training_data) {
callback(new Error('Missing required parameters: training_data'));
return;
}
if ((typeof params.training_data !== 'string') || (!isStream(params.training_data))) {
callback(new Error('training_data needs to be a String or Stream'));
return;
}

var parameters = {
options: {
url: '/v1/rankers',
method: 'POST',
json: true,
formData: {
training_data: params.training_data,
training_metadata: JSON.stringify(omit(params, ['training_data']))
}
},
defaultOptions: this._options
};
return requestFactory(parameters, callback);
};

/**
* Returns the ranked candidates
*/
RetrieveAndRank.prototype.rank = function(params, callback) {
params = params || {};

if (!params || !params.answer_data) {
callback(new Error('Missing required parameters: answer_data'));
return;
}
if ((typeof params.answer_data !== 'string') || (!isStream(params.answer_data))) {
callback(new Error('answer_data needs to be a String or Stream'));
return;
}

var parameters = {
options: {
url: '/v1/rankers/{ranker_id}/rank',
method: 'POST',
json: true,
formData: {
answer_data: params.answer_data,
answer_metadata: JSON.stringify(omit(params, ['answer_data']))
},
path: pick(params, ['ranker_id'])
},
requiredParams: ['ranker_id'],
defaultOptions: this._options
};
return requestFactory(parameters, callback);
};

/**
* Returns the training status of the ranker
*/
RetrieveAndRank.prototype.rankerStatus = function(params, callback) {
params = params || {};

var parameters = {
options: {
url: '/v1/rankers/{ranker_id}',
method: 'GET',
json: true,
path: params
},
requiredParams: ['ranker_id'],
defaultOptions: this._options
};

return requestFactory(parameters, callback);
};

/**
* Retrieves the list of rankers for the user
*/
RetrieveAndRank.prototype.listRankers = function(params, callback) {
var parameters = {
options: {
url: '/v1/rankers',
method: 'GET',
json: true
},
defaultOptions: this._options
};

return requestFactory(parameters, callback);
};

/**
* Deletes a ranker
*/
RetrieveAndRank.prototype.deleteRanker = function(params, callback) {
params = params || {};

var parameters = {
options: {
url: '/v1/rakers/{ranker_id}',
method: 'DELETE',
path: params,
json: true
},
requiredParams: ['ranker_id'],
defaultOptions: this._options
};

return requestFactory(parameters, callback);
};

// Solr cluster lifecycle operations

/**
Expand Down

0 comments on commit b08179f

Please sign in to comment.