Comparing version 0.1.0 to 0.2.1
292
index.js
var _ = require('lodash') | ||
var needle = require('needle') | ||
var formatSingleResult = function(body) { | ||
var result = _.first(body.results) | ||
var tagResults = _.zip(result.result.tag.classes, result.result.tag.concept_ids, result.result.tag.probs) | ||
var tags = _.map(tagResults, function(tag) { | ||
return { | ||
class: tag[0], | ||
conceptId: tag[1], | ||
probability: tag[2] | ||
} | ||
}) | ||
var ret = { | ||
docId: result.docid, | ||
tags: tags | ||
} | ||
return ret | ||
} | ||
var baseUrl = 'https://api.clarifai.com' | ||
var tokenPath = '/v1/token/' | ||
var tagPath = '/v1/tag/' | ||
var feedbackPath = '/v1/feedback/' | ||
var infoPath = '/v1/info/' | ||
var formatResults = function(body) { | ||
var formatImageResults = function(body) { | ||
var results = body.results | ||
@@ -34,2 +23,3 @@ results = _.map(results, function(result) { | ||
docId: result.docid, | ||
docIdStr: result.docid_str, | ||
tags: tags | ||
@@ -46,6 +36,40 @@ } | ||
var formatVideoResults = function(body) { | ||
var results = body.results | ||
results = _.map(results, function(result) { | ||
var tagResults = _.zip(result.result.tag.timestamps, result.result.tag.classes, result.result.tag.concept_ids, result.result.tag.probs) | ||
var timestamps = _.map(tagResults, function(tag) { | ||
var timeStampResults = _.zip(tag[1], tag[2], tag[3]) | ||
return { | ||
timestamp: tag[0], | ||
tags: _.map(timeStampResults, function(tsResult) { | ||
return { | ||
class: tsResult[0], | ||
conceptId: tsResult[1], | ||
probability: tsResult[2] | ||
} | ||
}) | ||
} | ||
}) | ||
var ret = { | ||
docId: result.docid, | ||
docIdStr: result.docid_str, | ||
timestamps: timestamps | ||
} | ||
return ret | ||
}) | ||
if (results.length < 2) { | ||
results = _.first(results) | ||
} | ||
return results | ||
} | ||
Clarifai.prototype.headers = function() { | ||
return { 'Authorization': this.tokenType + ' ' + this.accessToken } | ||
} | ||
Clarifai.prototype.getAccessToken = function(cb) { | ||
_this = this | ||
needle.post('https://api.clarifai.com/v1/token/', { | ||
var _this = this | ||
needle.post(baseUrl + tokenPath, { | ||
grant_type: 'client_credentials', | ||
@@ -59,24 +83,63 @@ client_id: this.id, | ||
_this.tokenType = body.token_type | ||
console.log("Access Token :: " + _this.accessToken) | ||
cb(err, body) | ||
_this.options = { headers: _this.headers() } | ||
cb(err, _this.accessToken) | ||
}) | ||
} | ||
Clarifai.prototype.addTags = function(docIds, tags, cb) { | ||
if (!_.isArray(docIds)) { | ||
urls = [docIds] | ||
} | ||
if (!_.isArray(tags)) { | ||
urls = [tags] | ||
} | ||
var data = '' | ||
data +='docids=' + docIds.join(',') | ||
data +='&add_tags=' + tags.join(',') | ||
var _this = this | ||
needle.post(baseUrl + feedbackPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.addTags(docIds, tags, cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, body) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.tagImageFromUrl = function(url, cb) { | ||
var data = { | ||
url: url | ||
Clarifai.prototype.removeTags = function(docIds, tags, cb) { | ||
if (!_.isArray(docIds)) { | ||
urls = [docIds] | ||
} | ||
var options = { | ||
headers: { 'Authorization': this.tokenType + ' ' + this.accessToken } | ||
if (!_.isArray(tags)) { | ||
urls = [tags] | ||
} | ||
_this = this | ||
needle.request('get', 'https://api.clarifai.com/v1/tag/', data, options, function(err, resp, body) { | ||
if (body.status_code == 'TOKEN_INVALID') { | ||
_this.getAccessToken(function(err, resp) { | ||
_this.tagImageFromUrl(url, cb) | ||
var data = '' | ||
data +='docids=' + docIds.join(',') | ||
data +='&remove_tags=' + tags.join(',') | ||
var _this = this | ||
needle.post(baseUrl + feedbackPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.removeTags(docIds, tags, cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, formatResults(body)) | ||
cb(err, body) | ||
} | ||
@@ -86,4 +149,111 @@ }); | ||
Clarifai.prototype.addSimilarDocIds = function(docIds, otherIds, cb) { | ||
if (!_.isArray(docIds)) { | ||
urls = [docIds] | ||
} | ||
if (!_.isArray(otherIds)) { | ||
urls = [otherIds] | ||
} | ||
var data = '' | ||
data +='docids=' + docIds.join(',') | ||
data +='&similar_docids=' + otherIds.join(',') | ||
var _this = this | ||
needle.post(baseUrl + feedbackPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.addSimilarDocIds(docIds, otherIds, cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, body) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.addDissimilarDocIds = function(docIds, otherIds, cb) { | ||
if (!_.isArray(docIds)) { | ||
urls = [docIds] | ||
} | ||
if (!_.isArray(otherIds)) { | ||
urls = [otherIds] | ||
} | ||
var data = '' | ||
data +='docids=' + docIds.join(',') | ||
data +='&dissimilar_docids=' + otherIds.join(',') | ||
var _this = this | ||
needle.post(baseUrl + feedbackPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.addDissimilarDocIds(docIds, otherIds, cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, body) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.associateSearchTerms = function(docIds, terms, cb) { | ||
if (!_.isArray(docIds)) { | ||
urls = [docIds] | ||
} | ||
if (!_.isArray(terms)) { | ||
urls = [terms] | ||
} | ||
var data = '' | ||
data +='docids=' + docIds.join(',') | ||
data +='&search_click=' + terms.join(',') | ||
var _this = this | ||
needle.post(baseUrl + feedbackPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.associateSearchTerms(docIds, terms, cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, body) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.getAPIDetails = function(cb) { | ||
var _this = this | ||
needle.get(baseUrl + infoPath, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.getAPIDetails(cb) | ||
} | ||
}) | ||
} else { | ||
cb(err, body.results) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.tagImagesFromUrls = function(urls, cb, lang) { | ||
var data = "" | ||
var data = '' | ||
@@ -95,21 +265,52 @@ if (!_.isArray(urls)) { | ||
for (var url of urls) { | ||
data += encodeURI("url=" + url) + "&" | ||
data += encodeURI('url=' + url) + '&' | ||
} | ||
if (lang) { | ||
data += "language=" + lang | ||
data += 'language=' + lang | ||
} | ||
var options = { | ||
headers: { 'Authorization': this.tokenType + ' ' + this.accessToken }, | ||
var _this = this | ||
needle.post(baseUrl + tagPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.tagImagesFromUrls(urls, cb, lang) | ||
} | ||
}) | ||
} else { | ||
cb(err, formatImageResults(body)) | ||
} | ||
}); | ||
} | ||
Clarifai.prototype.tagVideosFromUrls = function(urls, cb, lang) { | ||
var data = '' | ||
if (!_.isArray(urls)) { | ||
urls = [urls] | ||
} | ||
_this = this | ||
needle.post('https://api.clarifai.com/v1/tag/', data, options, function(err, resp, body) { | ||
if (body.status_code == 'TOKEN_INVALID') { | ||
_this.getAccessToken(function(err, resp) { | ||
_this.tagImageFromUrl(url, cb) | ||
for (var url of urls) { | ||
data += encodeURI('url=' + url) + '&' | ||
} | ||
if (lang) { | ||
data += 'language=' + lang | ||
} | ||
var _this = this | ||
needle.post(baseUrl + tagPath, data, this.options, function(err, resp, body) { | ||
if (body.status_code === 'TOKEN_INVALID' || body.status_code === 'TOKEN_NONE') { | ||
_this.getAccessToken(function(err) { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
_this.tagVideosFromUrls(urls, cb, lang) | ||
} | ||
}) | ||
} else { | ||
cb(err, formatResults(body)) | ||
cb(err, formatVideoResults(body)) | ||
} | ||
@@ -120,2 +321,7 @@ }); | ||
function Clarifai (opts) { | ||
opts = opts || { | ||
id: process.env.CLARIFAI_ID, | ||
secret: process.env.CLARIFAI_SECRET, | ||
} | ||
this.id = opts.id | ||
@@ -122,0 +328,0 @@ this.secret = opts.secret |
{ | ||
"name": "clarifai", | ||
"version": "0.1.0", | ||
"version": "0.2.1", | ||
"description": "A Node integration library for clarifai", | ||
"main": "index.js", | ||
"engines": { | ||
"node": "0.12.9", | ||
"npm": "2.14.9" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
"test": "CODACY_PROJECT_TOKEN=fe3ce92230f143c889e36ae30d4b4425 ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage", | ||
"2npm": "publish" | ||
}, | ||
@@ -30,3 +35,7 @@ "repository": { | ||
"chai": "3.4.1", | ||
"mocha": "2.3.4" | ||
"codacy-coverage": "1.1.3", | ||
"istanbul": "0.4.1", | ||
"mocha": "2.3.4", | ||
"mocha-lcov-reporter": "1.0.0", | ||
"publish": "0.5.0" | ||
}, | ||
@@ -36,3 +45,14 @@ "dependencies": { | ||
"needle": "0.11.0" | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": [ | ||
"" | ||
], | ||
"data-cover-never": [ | ||
"node_modules", | ||
"tests" | ||
] | ||
} | ||
} | ||
} |
283
README.md
@@ -0,2 +1,285 @@ | ||
[![Circle CI](https://circleci.com/gh/ctartist621/clarifai/tree/master.svg?style=svg&circle-token=e15ad7ff3e856e1b86fb002868fb4c9e98d4e22e)](https://circleci.com/gh/ctartist621/clarifai/tree/master) [![npm version](https://badge.fury.io/js/clarifai.svg)](https://badge.fury.io/js/clarifai) [![Codacy Badge](https://api.codacy.com/project/badge/grade/fd34502ca14c4c0ba556e90a81d77991)](https://www.codacy.com/app/ctartist621/clarifai) | ||
# clarifai | ||
clarifai api wrapper | ||
## Installation | ||
First, the all necessary | ||
``` | ||
npm install clarifai --save | ||
``` | ||
To initialize the library, you can either pass it in a settings object with the Clarifai ID & Secret, | ||
``` | ||
client = new Clarifai({ | ||
id: <clarafai id>, | ||
secret: <clarafai secret> | ||
}) | ||
``` | ||
Or save them as environment variables, as the library will also look for them in these two variables: | ||
``` | ||
process.env.CLARIFAI_ID | ||
process.env.CLARIFAI_SECRET | ||
``` | ||
And initializing is simply | ||
``` | ||
client = new Clarifai() | ||
``` | ||
##Authentication | ||
Once initialized, the library will take care of renewing the access token as it expires. If you need to OAuth for an access token, you can simply call: | ||
``` | ||
client.getAccessToken(function(err, accessToken) { | ||
// Callback code here | ||
}) | ||
``` | ||
##Tagging | ||
###Image Tagging via url | ||
``` | ||
client.tagImagesFromUrls(url(s), function(err, results) { | ||
// Callback code here | ||
}, [language]) | ||
``` | ||
This function will take one image url, or many image urls as an array. The language parameter is optional, and will request tags from clarifai in the appropriate language. | ||
The callback returns the standard error / results. The results object returned has the following structure: | ||
``` | ||
{ docId: 15512461224882630000, | ||
docIdStr: '31fdb2316ff87fb5d747554ba5267313', | ||
tags: | ||
[ { class: 'train', | ||
conceptId: 'ai_HLmqFqBf', | ||
probability: 0.9989112019538879 }, | ||
{ class: 'railway', | ||
conceptId: 'ai_fvlBqXZR', | ||
probability: 0.9975532293319702 }, | ||
{ class: 'transportation system', | ||
conceptId: 'ai_Xxjc3MhT', | ||
probability: 0.9959157705307007 }, | ||
{ class: 'station', | ||
conceptId: 'ai_6kTjGfF6', | ||
probability: 0.9925730228424072 }, | ||
{ class: 'train', | ||
conceptId: 'ai_RRXLczch', | ||
probability: 0.9925559759140015 }, | ||
{ class: 'travel', | ||
conceptId: 'ai_VRmbGVWh', | ||
probability: 0.9878921508789062 }, | ||
{ class: 'tube', | ||
conceptId: 'ai_SHNDcmJ3', | ||
probability: 0.9816359281539917 }, | ||
{ class: 'commuter', | ||
conceptId: 'ai_jlb9q33b', | ||
probability: 0.9712483286857605 }, | ||
{ class: 'railway', | ||
conceptId: 'ai_46lGZ4Gm', | ||
probability: 0.9690325260162354 }, | ||
{ class: 'traffic', | ||
conceptId: 'ai_tr0MBp64', | ||
probability: 0.9687051773071289 }, | ||
{ class: 'blur', | ||
conceptId: 'ai_l4WckcJN', | ||
probability: 0.9667078256607056 }, | ||
{ class: 'platform', | ||
conceptId: 'ai_2gkfMDsM', | ||
probability: 0.9624242782592773 }, | ||
{ class: 'urban', | ||
conceptId: 'ai_CpFBRWzD', | ||
probability: 0.960752010345459 }, | ||
{ class: 'no person', | ||
conceptId: 'ai_786Zr311', | ||
probability: 0.9586490392684937 }, | ||
{ class: 'business', | ||
conceptId: 'ai_6lhccv44', | ||
probability: 0.9572030305862427 }, | ||
{ class: 'track', | ||
conceptId: 'ai_971KsJkn', | ||
probability: 0.9494642019271851 }, | ||
{ class: 'city', | ||
conceptId: 'ai_WBQfVV0p', | ||
probability: 0.940894365310669 }, | ||
{ class: 'fast', | ||
conceptId: 'ai_dSCKh8xv', | ||
probability: 0.9399334192276001 }, | ||
{ class: 'road', | ||
conceptId: 'ai_TZ3C79C6', | ||
probability: 0.9312160611152649 }, | ||
{ class: 'terminal', | ||
conceptId: 'ai_VSVscs9k', | ||
probability: 0.9230834245681763 } ] } | ||
``` | ||
If one image was passed in, the results object will be the single object representing the results for that image. If more than one was passed in, it will be an array of results objects. | ||
###Video Tagging via url | ||
``` | ||
client.tagVideosFromUrls(url(s), function(err, results) { | ||
// Callback code here | ||
}, [language]) | ||
``` | ||
This function will take one video url, or many video urls as an array. The language parameter is optional, and will request tags from clarifai in the appropriate language. | ||
The callback returns the standard error / results. The results object returned has the following structure: | ||
``` | ||
{ | ||
"docId": 13756317490038290000, | ||
"docIdStr": "9b1c7eabd9ac0932bee841df8339b916", | ||
"timestamps": [ | ||
{ | ||
"timestamp": 0, | ||
"tags": [ | ||
{ | ||
"class": "snow", | ||
"conceptId": "ai_l09WQRHT", | ||
"probability": 0.9933538436889648 | ||
}, | ||
{ | ||
"class": "ice", | ||
"conceptId": "ai_jGkHfX9T", | ||
"probability": 0.9898617267608643 | ||
} | ||
... | ||
{ | ||
"class": "sea", | ||
"conceptId": "ai_7bRKqWjp", | ||
"probability": 0.8838980793952942 | ||
} | ||
] | ||
}, | ||
{ | ||
"timestamp": 1, | ||
"tags": [ | ||
{ | ||
"class": "water", | ||
"conceptId": "ai_BlL0wSQh", | ||
"probability": 0.9734385013580322 | ||
}, | ||
{ | ||
"class": "snow", | ||
"conceptId": "ai_l09WQRHT", | ||
"probability": 0.9672313332557678 | ||
} | ||
... | ||
{ | ||
"class": "fair weather", | ||
"conceptId": "ai_41s912fX", | ||
"probability": 0.7390187978744507 | ||
} | ||
] | ||
}, | ||
{ | ||
"timestamp": 2, | ||
"tags": [ | ||
{ | ||
"class": "frosty", | ||
"conceptId": "ai_LMNcLLVR", | ||
"probability": 0.9763497114181519 | ||
}, | ||
{ | ||
"class": "water", | ||
"conceptId": "ai_BlL0wSQh", | ||
"probability": 0.9734385013580322 | ||
} | ||
... | ||
{ | ||
"class": "recreation", | ||
"conceptId": "ai_8Qw6PFLZ", | ||
"probability": 0.7853384017944336 | ||
} | ||
] | ||
} | ||
... | ||
] | ||
} | ||
``` | ||
Each classification is taken at 1 second keyframes by clarifai, so each keyframe has a set of tags associated with it. So the document results object will have a timestamps array, and each timestamp will have an array of tags associated with that timestamp. | ||
If one video was passed in, the results object will be the single object representing the results for that image. If more than one was passed in, it will be an array of results objects. | ||
##Feedback | ||
For all the feedback functions, any input parameters can be a single string, or an array of strings. | ||
Any positive response will look like: | ||
``` | ||
{ | ||
"status_code": "OK", | ||
"status_msg": "Feedback sucessfully recorded." | ||
} | ||
``` | ||
### Add tags or give positive feedback for tags to a docid | ||
``` | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var tags = ['car','dashboard','driving'] | ||
client.addTags(docIds, tags, function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
### Remove tags or give negative feedback for tags to a docid | ||
``` | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var tags = ['sky','clean','red'] | ||
client.removeTags(docIds, tags, function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
### Add similar docids for a given docid | ||
``` | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var similarIds = ['fc957ec10abcc0f4507475827626200a'] | ||
client.addSimilarDocIds(docIds, similarIds, function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
### Add dissimilar docids for a given docid | ||
``` | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var dissimilarIds = ['acd57ec10abcc0f4507475827626785f'] | ||
client.addDissimilarDocIds(docIds, dissimilarIds, function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
### Associate search tags for which the input docids were clicked | ||
``` | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var terms = ['cat'] | ||
client.associateSearchTerms(docIds, terms, function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
##API Info | ||
Retrieves information about the API. | ||
``` | ||
client.getAPIDetails(function(err, resp) { | ||
// Callback code here | ||
}) | ||
``` | ||
Response will look like: | ||
``` | ||
{ | ||
max_image_size: 100000, | ||
default_language: 'en', | ||
max_video_size: 100000, | ||
max_image_bytes: 10485760, | ||
min_image_size: 1, | ||
default_model: 'general-v1.3', | ||
max_video_bytes: 104857600, | ||
max_video_duration: 1800, | ||
max_batch_size: 128, | ||
max_video_batch_size: 1, | ||
min_video_size: 1, | ||
api_version: 0.1 | ||
} | ||
``` |
var should = require('chai').should(), | ||
Clarifai = require('../index'), | ||
client = new Clarifai(require('../testCreds.json')) | ||
client | ||
if (process.env.CIRCLECI) { | ||
client = new Clarifai() | ||
} else { | ||
client = new Clarifai(require('../testCreds.json')) | ||
} | ||
describe('#Authentication', function() { | ||
@@ -9,3 +15,4 @@ it('should authenticate and save an access token', function(done) { | ||
should.not.exist(err) | ||
resp.access_token.should.be.a('string') | ||
client.accessToken.should.be.a('string') | ||
resp.should.be.a('string') | ||
done() | ||
@@ -17,34 +24,160 @@ }) | ||
describe('#Tagging', function() { | ||
it('should tag an image from a url', function(done) { | ||
var url = 'http://www.clarifai.com/img/metro-north.jpg' | ||
client.tagImagesFromUrls(url, function(err, resp) { | ||
describe('#Images', function() { | ||
it('should tag an image from a url', function(done) { | ||
var url = 'http://www.clarifai.com/img/metro-north.jpg' | ||
client.tagImagesFromUrls(url, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('docIdStr') | ||
resp.should.have.property('tags').with.length.above(0) | ||
resp.tags[0].should.have.property('class') | ||
resp.tags[0].should.have.property('conceptId') | ||
resp.tags[0].should.have.property('probability') | ||
done() | ||
}) | ||
}); | ||
it('should tag an image from a url in another language', function(done) { | ||
var url = 'http://www.clarifai.com/img/metro-north.jpg' | ||
client.tagImagesFromUrls(url, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('docIdStr') | ||
resp.should.have.property('tags').with.length.above(0) | ||
resp.tags[0].should.have.property('class') | ||
resp.tags[0].should.have.property('conceptId') | ||
resp.tags[0].should.have.property('probability') | ||
done() | ||
}, 'es') | ||
}); | ||
it('should tag multiple images from a set of urls', function(done) { | ||
var urls = [ | ||
'http://www.clarifai.com/img/metro-north.jpg', | ||
'http://www.clarifai.com/img/metro-north.jpg', | ||
] | ||
client.tagImagesFromUrls(urls, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.length(2) | ||
resp[0].should.have.property('docId') | ||
resp[0].should.have.property('docIdStr') | ||
resp[0].should.have.property('tags').with.length.above(0) | ||
resp[0].tags[0].should.have.property('class') | ||
resp[0].tags[0].should.have.property('conceptId') | ||
resp[0].tags[0].should.have.property('probability') | ||
done() | ||
}) | ||
}); | ||
}); | ||
describe.skip('#Videos', function() { | ||
it('should tag a video from a url', function(done) { | ||
this.timeout(20000); | ||
var url = 'https://archive.org/download/test-mpeg/test-mpeg.mpg' | ||
client.tagVideosFromUrls(url, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('docIdStr') | ||
resp.should.have.property('timestamps').with.length.above(0) | ||
resp.timestamps[0].should.have.property('timestamp') | ||
resp.timestamps[0].should.have.property('tags').with.length.above(0) | ||
resp.timestamps[0].tags[0].should.have.property('class') | ||
resp.timestamps[0].tags[0].should.have.property('conceptId') | ||
resp.timestamps[0].tags[0].should.have.property('probability') | ||
done() | ||
}) | ||
}); | ||
it('should tag an video from a url in another language', function(done) { | ||
var url = 'https://archive.org/download/test-mpeg/test-mpeg.mpg' | ||
this.timeout(20000); | ||
client.tagVideosFromUrls(url, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('docIdStr') | ||
resp.should.have.property('timestamps').with.length.above(0) | ||
resp.timestamps[0].should.have.property('timestamp') | ||
resp.timestamps[0].should.have.property('tags').with.length.above(0) | ||
resp.timestamps[0].tags[0].should.have.property('class') | ||
resp.timestamps[0].tags[0].should.have.property('conceptId') | ||
resp.timestamps[0].tags[0].should.have.property('probability') | ||
done() | ||
}, 'es') | ||
}); | ||
it('should tag multiple videos from a set of urls', function(done) { | ||
this.timeout(60000); | ||
var urls = [ | ||
'https://archive.org/download/test-mpeg/test-mpeg.mpg', | ||
'https://archive.org/download/test-mpeg/test-mpeg.mpg', | ||
] | ||
client.tagVideosFromUrls(urls, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.length(2) | ||
resp[0].should.have.property('docId') | ||
resp[0].should.have.property('docIdStr') | ||
resp[0].should.have.property('timestamps').with.length.above(0) | ||
resp[0].timestamps[0].should.have.property('timestamp') | ||
resp[0].timestamps[0].should.have.property('tags').with.length.above(0) | ||
resp[0].timestamps[0].tags[0].should.have.property('class') | ||
resp[0].timestamps[0].tags[0].should.have.property('conceptId') | ||
resp[0].timestamps[0].tags[0].should.have.property('probability') | ||
done() | ||
}) | ||
}); | ||
}); | ||
}); | ||
describe('#Information', function() { | ||
it('should get current API Details', function(done) { | ||
client.getAPIDetails(function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('tags').with.length.above(0) | ||
resp.should.have.property('max_image_size') | ||
resp.should.have.property('default_language') | ||
resp.should.have.property('max_video_size') | ||
resp.should.have.property('max_image_bytes') | ||
resp.should.have.property('min_image_size') | ||
resp.should.have.property('default_model') | ||
resp.should.have.property('max_video_bytes') | ||
resp.should.have.property('max_video_duration') | ||
resp.should.have.property('max_batch_size') | ||
resp.should.have.property('max_video_batch_size') | ||
resp.should.have.property('min_video_size') | ||
resp.should.have.property('api_version') | ||
done() | ||
}) | ||
}); | ||
}); | ||
it('should tag an image from a url in another language', function(done) { | ||
var url = 'http://www.clarifai.com/img/metro-north.jpg' | ||
client.tagImagesFromUrls(url, function(err, resp) { | ||
describe('#Feedback', function() { | ||
it('should add tags or give positive feedback for tags to a docid', function(done) { | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var tags = ['car','dashboard','driving'] | ||
client.addTags(docIds, tags, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('docId') | ||
resp.should.have.property('tags').with.length.above(0) | ||
resp.should.have.property('status_code').with.string('OK') | ||
resp.should.have.property('status_msg') | ||
done() | ||
}, 'es') | ||
}) | ||
}); | ||
it('should tag multiple images from a set of urls', function(done) { | ||
var urls = [ | ||
'http://www.clarifai.com/img/metro-north.jpg', | ||
'http://www.clarifai.com/img/metro-north.jpg', | ||
'http://www.clarifai.com/img/metro-north.jpg' | ||
] | ||
it('should remove tags or give negative feedback for tags to a docid', function(done) { | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var tags = ['sky','clean','red'] | ||
client.removeTags(docIds, tags, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('status_code').with.string('OK') | ||
resp.should.have.property('status_msg') | ||
done() | ||
}) | ||
}); | ||
client.tagImagesFromUrls(urls, function(err, resp) { | ||
it('should add similar docids for a given docid', function(done) { | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var similarIds = ['fc957ec10abcc0f4507475827626200a'] | ||
client.addSimilarDocIds(docIds, similarIds, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.length(3) | ||
resp[0].should.have.property('docId') | ||
resp[0].should.have.property('tags').with.length.above(0) | ||
resp.should.have.property('status_code').with.string('OK') | ||
resp.should.have.property('status_msg') | ||
done() | ||
@@ -54,2 +187,23 @@ }) | ||
it('should add dissimilar docids for a given docid', function(done) { | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var dissimilarIds = ['acd57ec10abcc0f4507475827626785f'] | ||
client.addDissimilarDocIds(docIds, dissimilarIds, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('status_code').with.string('OK') | ||
resp.should.have.property('status_msg') | ||
done() | ||
}) | ||
}); | ||
it('should associate search tags for which the input docids were clicked', function(done) { | ||
var docIds = ['78c742b9dee940c8cf2a06f860025141'] | ||
var terms = ['cat'] | ||
client.associateSearchTerms(docIds, terms, function(err, resp) { | ||
should.not.exist(err) | ||
resp.should.have.property('status_code').with.string('OK') | ||
resp.should.have.property('status_msg') | ||
done() | ||
}) | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27910
8
503
286
6
1
3
1