Skip to content

Commit 7fd539c

Browse files
committed
Merge pull request #27 from yllieth/dataset-update
add a type to the dataset resource
2 parents db8e5e2 + 5dee944 commit 7fd539c

File tree

6 files changed

+50
-38
lines changed

6 files changed

+50
-38
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"authors": [
55
"Yllieth <[email protected]>",
66
"Dehau"

dist/predicsis-jsSDK.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,15 @@ angular
308308
* <pre>
309309
* {
310310
* id: 'learning_dataset',
311+
* type: 'uploaded_dataset',
311312
* created_at: '2014-12-14T15:09:08.112Z',
312313
* updated_at: '2014-12-14T15:08:57.970Z',
313314
* name: 'Learning dataset',
314315
* header: null,
315316
* separator: null,
316317
* user_id: '541b06dc617070006d060000',
317318
* source_ids: ['54904b136170700007330000'],
318-
* parent_dataset_id: null,
319+
* dataset_id: null,
319320
* sampling: 100,
320321
* nb_of_lines: 50002,
321322
* children_dataset_ids: [],
@@ -341,7 +342,8 @@ angular
341342
* {
342343
* ...
343344
* source_ids: [],
344-
* parent_dataset_id: 'learning_dataset_with_model',
345+
* type: 'subset',
346+
* dataset_id: 'learning_dataset_with_model',
345347
* sampling: 70,
346348
* nb_of_lines: null,
347349
* preview: null
@@ -354,7 +356,8 @@ angular
354356
* {
355357
* ...
356358
* source_ids: [],
357-
* parent_dataset_id: 'learning_dataset_with_model',
359+
* type: 'subset',
360+
* dataset_id: 'learning_dataset_with_model',
358361
* sampling: -70,
359362
* nb_of_lines: null,
360363
* preview: null
@@ -393,6 +396,7 @@ angular
393396
* <pre>
394397
* {
395398
* ...
399+
* type: 'scoreset'
396400
* classifier_id: '5436431070632d15f4260000',
397401
* dataset_id: 'scoring_dataset',
398402
* modalities_set_id: '53fdfa7070632d0fc5030000',
@@ -426,7 +430,8 @@ angular
426430
* source_ids: ['original_source_id'],
427431
* header: true,
428432
* separator: '\t',
429-
* data_file: { filename: 'source.csv' }
433+
* data_file: { filename: 'source.csv' },
434+
* type: 'uploaded_dataset'
430435
* }
431436
* </pre>
432437
*
@@ -442,7 +447,8 @@ angular
442447
* main_modality: $main_modality$,
443448
* separator: $separator$,
444449
* header: $header$,
445-
* data_file: { filename: $name$ }
450+
* data_file: { filename: $name$ },
451+
* type: 'scoreset'
446452
* }
447453
* </pre>
448454
*
@@ -481,6 +487,7 @@ angular
481487
return Sources.create(source)
482488
.then(function(source) {
483489
return self.create({
490+
type: 'uploaded_dataset',
484491
name: fileName,
485492
source_ids: [source.id],
486493
data_file: { filename: fileName }
@@ -523,14 +530,16 @@ angular
523530
sampling = sampling || DEFAULT_SAMPLING;
524531

525532
var learn = {
526-
parent_dataset_id: id,
533+
type: 'subset',
534+
dataset_id: id,
527535
name: 'learned_' + name,
528536
data_file: {filename: 'learned_' + filename},
529537
sampling: sampling
530538
};
531539

532540
var test = {
533-
parent_dataset_id: id,
541+
type: 'subset',
542+
dataset_id: id,
534543
name: 'tested_' + name,
535544
data_file: {filename: 'tested_' + filename},
536545
sampling: -sampling
@@ -612,7 +621,7 @@ angular
612621
})
613622
.then(function(childrenCandidates) {
614623
return childrenCandidates.reduce(function(memo, child) {
615-
if (child.parent_dataset_id === datasetId) {
624+
if (child.dataset_id === datasetId) {
616625
if (self.isTrainPart(child, DEFAULT_SAMPLING)) {
617626
memo.train = child;
618627
} else if (self.isTestPart(child, -DEFAULT_SAMPLING)) {
@@ -716,33 +725,32 @@ angular
716725
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
717726
*/
718727
this.hasChildren = function(dataset) {
719-
return Boolean(dataset.children_dataset_ids.length > 0);
728+
return Boolean(dataset.children_dataset_ids && dataset.children_dataset_ids.length > 0);
720729
};
721730

722731
/**
723732
* @ngdoc function
724733
* @methodOf predicsis.jsSDK.models.Datasets
725734
* @name isParent
726735
* @description Tells if a dataset is a parent dataset.
727-
* <b>Note:</b> A parent may have any children, but its <kbd>parent_dataset_id</kbd> must be null
736+
* <b>Note:</b> A parent may have any children, but its <kbd>dataset_id</kbd> must be null
728737
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
729738
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
730739
*/
731740
this.isParent = function(dataset) {
732-
return Boolean(dataset.parent_dataset_id === null);
741+
return Boolean(dataset.type === 'uploaded_dataset');
733742
};
734743

735744
/**
736745
* @ngdoc function
737746
* @methodOf predicsis.jsSDK.models.Datasets
738747
* @name isChild
739748
* @description Tells if a dataset is a child dataset
740-
* <b>Note:</b> A dataset is considered as a child if it has a parent. There is no orphan among datasets!
741749
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
742750
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
743751
*/
744752
this.isChild = function(dataset) {
745-
return Boolean(dataset.parent_dataset_id !== null);
753+
return Boolean(dataset.type === 'subset');
746754
};
747755

748756
/**
@@ -810,14 +818,12 @@ angular
810818
* <li><code>dataset.classifier !== null</code></li>
811819
* <li><code>dataset.dataset_id !== null</code></li>
812820
* </ul>
821+
* Since the API implements a type attribute, this check is really simpler
813822
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
814823
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
815824
*/
816825
this.isScore = function(dataset) {
817-
return Boolean(dataset.source_ids.length === 0)
818-
&& Boolean(dataset.main_modality !== null)
819-
&& Boolean(dataset.classifier !== null)
820-
&& Boolean(dataset.dataset_id !== null);
826+
return Boolean(dataset.type === 'scoreset');
821827
};
822828
});
823829

dist/predicsis-jsSDK.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/predicsis-jsSDK.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/model/Datasets.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@
8181
* <pre>
8282
* {
8383
* id: 'learning_dataset',
84+
* type: 'uploaded_dataset',
8485
* created_at: '2014-12-14T15:09:08.112Z',
8586
* updated_at: '2014-12-14T15:08:57.970Z',
8687
* name: 'Learning dataset',
8788
* header: null,
8889
* separator: null,
8990
* user_id: '541b06dc617070006d060000',
9091
* source_ids: ['54904b136170700007330000'],
91-
* parent_dataset_id: null,
92+
* dataset_id: null,
9293
* sampling: 100,
9394
* nb_of_lines: 50002,
9495
* children_dataset_ids: [],
@@ -114,7 +115,8 @@
114115
* {
115116
* ...
116117
* source_ids: [],
117-
* parent_dataset_id: 'learning_dataset_with_model',
118+
* type: 'subset',
119+
* dataset_id: 'learning_dataset_with_model',
118120
* sampling: 70,
119121
* nb_of_lines: null,
120122
* preview: null
@@ -127,7 +129,8 @@
127129
* {
128130
* ...
129131
* source_ids: [],
130-
* parent_dataset_id: 'learning_dataset_with_model',
132+
* type: 'subset',
133+
* dataset_id: 'learning_dataset_with_model',
131134
* sampling: -70,
132135
* nb_of_lines: null,
133136
* preview: null
@@ -166,6 +169,7 @@
166169
* <pre>
167170
* {
168171
* ...
172+
* type: 'scoreset'
169173
* classifier_id: '5436431070632d15f4260000',
170174
* dataset_id: 'scoring_dataset',
171175
* modalities_set_id: '53fdfa7070632d0fc5030000',
@@ -199,7 +203,8 @@ angular
199203
* source_ids: ['original_source_id'],
200204
* header: true,
201205
* separator: '\t',
202-
* data_file: { filename: 'source.csv' }
206+
* data_file: { filename: 'source.csv' },
207+
* type: 'uploaded_dataset'
203208
* }
204209
* </pre>
205210
*
@@ -215,7 +220,8 @@ angular
215220
* main_modality: $main_modality$,
216221
* separator: $separator$,
217222
* header: $header$,
218-
* data_file: { filename: $name$ }
223+
* data_file: { filename: $name$ },
224+
* type: 'scoreset'
219225
* }
220226
* </pre>
221227
*
@@ -254,6 +260,7 @@ angular
254260
return Sources.create(source)
255261
.then(function(source) {
256262
return self.create({
263+
type: 'uploaded_dataset',
257264
name: fileName,
258265
source_ids: [source.id],
259266
data_file: { filename: fileName }
@@ -296,14 +303,16 @@ angular
296303
sampling = sampling || DEFAULT_SAMPLING;
297304

298305
var learn = {
299-
parent_dataset_id: id,
306+
type: 'subset',
307+
dataset_id: id,
300308
name: 'learned_' + name,
301309
data_file: {filename: 'learned_' + filename},
302310
sampling: sampling
303311
};
304312

305313
var test = {
306-
parent_dataset_id: id,
314+
type: 'subset',
315+
dataset_id: id,
307316
name: 'tested_' + name,
308317
data_file: {filename: 'tested_' + filename},
309318
sampling: -sampling
@@ -385,7 +394,7 @@ angular
385394
})
386395
.then(function(childrenCandidates) {
387396
return childrenCandidates.reduce(function(memo, child) {
388-
if (child.parent_dataset_id === datasetId) {
397+
if (child.dataset_id === datasetId) {
389398
if (self.isTrainPart(child, DEFAULT_SAMPLING)) {
390399
memo.train = child;
391400
} else if (self.isTestPart(child, -DEFAULT_SAMPLING)) {
@@ -489,33 +498,32 @@ angular
489498
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
490499
*/
491500
this.hasChildren = function(dataset) {
492-
return Boolean(dataset.children_dataset_ids.length > 0);
501+
return Boolean(dataset.children_dataset_ids && dataset.children_dataset_ids.length > 0);
493502
};
494503

495504
/**
496505
* @ngdoc function
497506
* @methodOf predicsis.jsSDK.models.Datasets
498507
* @name isParent
499508
* @description Tells if a dataset is a parent dataset.
500-
* <b>Note:</b> A parent may have any children, but its <kbd>parent_dataset_id</kbd> must be null
509+
* <b>Note:</b> A parent may have any children, but its <kbd>dataset_id</kbd> must be null
501510
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
502511
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
503512
*/
504513
this.isParent = function(dataset) {
505-
return Boolean(dataset.parent_dataset_id === null);
514+
return Boolean(dataset.type === 'uploaded_dataset');
506515
};
507516

508517
/**
509518
* @ngdoc function
510519
* @methodOf predicsis.jsSDK.models.Datasets
511520
* @name isChild
512521
* @description Tells if a dataset is a child dataset
513-
* <b>Note:</b> A dataset is considered as a child if it has a parent. There is no orphan among datasets!
514522
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
515523
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
516524
*/
517525
this.isChild = function(dataset) {
518-
return Boolean(dataset.parent_dataset_id !== null);
526+
return Boolean(dataset.type === 'subset');
519527
};
520528

521529
/**
@@ -583,13 +591,11 @@ angular
583591
* <li><code>dataset.classifier !== null</code></li>
584592
* <li><code>dataset.dataset_id !== null</code></li>
585593
* </ul>
594+
* Since the API implements a type attribute, this check is really simpler
586595
* @param {Object} dataset Instance of {@link predicsis.jsSDK.models.Datasets dataset}
587596
* @return {Boolean} <kbd>true</kbd> / <kbd>false</kbd>
588597
*/
589598
this.isScore = function(dataset) {
590-
return Boolean(dataset.source_ids.length === 0)
591-
&& Boolean(dataset.main_modality !== null)
592-
&& Boolean(dataset.classifier !== null)
593-
&& Boolean(dataset.dataset_id !== null);
599+
return Boolean(dataset.type === 'scoreset');
594600
};
595601
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Javascript SDK for PredicSis ML API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)