1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8 |
|
9 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var LabelEncoder = function () {
|
30 | |
31 |
|
32 |
|
33 | function LabelEncoder() {
|
34 | _classCallCheck(this, LabelEncoder);
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | this.labelsClassIndex = {};
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | this.classIndicesLabel = [];
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 | this.numLabels = 0;
|
56 | }
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | _createClass(LabelEncoder, [{
|
69 | key: 'encode',
|
70 | value: function encode(labels) {
|
71 | var _this = this;
|
72 |
|
73 |
|
74 | if (Array.isArray(labels)) {
|
75 | return labels.map(function (label) {
|
76 | return _this.encode(label);
|
77 | });
|
78 | }
|
79 |
|
80 |
|
81 | var labelString = labels.toString();
|
82 |
|
83 | if (typeof this.labelsClassIndex[labelString] === 'undefined') {
|
84 | this.labelsClassIndex[labelString] = this.numLabels;
|
85 | this.classIndicesLabel.push(labelString);
|
86 | this.numLabels += 1;
|
87 | }
|
88 |
|
89 | return this.labelsClassIndex[labelString];
|
90 | }
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | }, {
|
100 | key: 'decode',
|
101 | value: function decode(encodedLabels) {
|
102 | var _this2 = this;
|
103 |
|
104 |
|
105 | if (Array.isArray(encodedLabels)) {
|
106 | return encodedLabels.map(function (label) {
|
107 | return _this2.decode(label);
|
108 | });
|
109 | }
|
110 |
|
111 |
|
112 | return typeof this.classIndicesLabel[encodedLabels] === 'undefined' ? -1 : this.classIndicesLabel[encodedLabels];
|
113 | }
|
114 | }]);
|
115 |
|
116 | return LabelEncoder;
|
117 | }();
|
118 |
|
119 | exports.default = LabelEncoder;
|
120 | module.exports = exports.default; |
\ | No newline at end of file |