Skip to content

Commit ddee366

Browse files
committed
Added region to input.
1 parent d45a914 commit ddee366

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"del": "^2.0.2",
2929
"envify": "^3.4.0",
3030
"git-branch": "^0.3.0",
31-
"gulp": "^3.9.0",
31+
"gulp": "^3.9.1",
3232
"gulp-awspublish": "^3.0.1",
3333
"gulp-babel": "^6.1.2",
3434
"gulp-browserify": "^0.5.1",

src/Input.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
let axios = require('axios');
22
let Concepts = require('./Concepts');
3+
let Regions = require('./Regions');
34
let {API} = require('./constants');
45
let {INPUTS_PATH} = API;
56

@@ -13,6 +14,9 @@ class Input {
1314
this.createdAt = data.created_at || data.createdAt;
1415
this.imageUrl = data.data.image.url;
1516
this.concepts = new Concepts(_config, data.data.concepts);
17+
if (data.data.regions) {
18+
this.regions = new Regions(_config, data.data.regions);
19+
}
1620
this.score = data.score;
1721
this.metadata = data.data.metadata;
1822
if (data.data.geo && data.data.geo['geo_point']) {

src/Inputs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class Inputs {
195195
}
196196

197197
/**
198-
* @param {object[]} inputs List of concepts to update (max of 128 inputs/call; passing > 128 will throw an exception)
198+
* @param {object[]} inputs List of inputs to update (max of 128 inputs/call; passing > 128 will throw an exception)
199199
* @param {object} inputs[].input
200200
* @param {string} inputs[].input.id The id of the input to update
201201
* @param {object} inputs[].input.metadata Object with key values to attach to the input (optional)

src/Region.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Region / bounding box. Region points are percentages from the edge.
3+
* E.g. top of 0.2 means the cropped input will start 20% down from the original edge.
4+
* @class
5+
*/
6+
class Region {
7+
constructor(_config, data) {
8+
this.id = data.id;
9+
this.top = data.region_info.bounding_box.top_row;
10+
this.left = data.region_info.bounding_box.left_col;
11+
this.bottom = data.region_info.bounding_box.bottom_row;
12+
this.right = data.region_info.bounding_box.right_col;
13+
}
14+
}
15+
16+
module.exports = Region;

src/Regions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
let Region = require('./Region');
2+
3+
/**
4+
* A collection of regions.
5+
* @class
6+
*/
7+
class Regions {
8+
constructor(_config, rawData = []) {
9+
this._config = _config;
10+
this.rawData = rawData;
11+
rawData.forEach((regionData, index) => {
12+
this[index] = new Region(this._config, regionData);
13+
});
14+
this.length = rawData.length;
15+
}
16+
17+
[Symbol.iterator]() {
18+
let index = -1;
19+
return {
20+
next: () => ({ value: this[++index], done: index >= this.length })
21+
};
22+
};
23+
}
24+
25+
module.exports = Regions;

0 commit comments

Comments
 (0)