@inseefr/lunatic 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/commons/components/lunatic-component-with-label.js +5 -6
- package/lib/components/component-set/html/component-set-component-container.js +20 -0
- package/lib/components/component-set/html/component-set-components.js +59 -0
- package/lib/components/component-set/html/component-set.js +32 -0
- package/lib/components/component-set/html/legend/index.js +13 -0
- package/lib/components/component-set/html/legend/legend.js +31 -0
- package/lib/components/component-set/index.js +20 -0
- package/lib/components/component-set/lunatic-component-set.js +69 -0
- package/lib/components/components.js +9 -1
- package/lib/components/declarations/declarations.scss +8 -2
- package/lib/components/input/html/input.scss +1 -1
- package/lib/components/radio/html/radio-group-content.js +4 -2
- package/lib/components/radio/html/radio-group-content.spec.js +14 -0
- package/lib/components/radio/html/radio-group.js +8 -4
- package/lib/components/radio/html/radio-option.js +14 -10
- package/lib/components/radio/lunatic-radio-group.js +6 -3
- package/lib/components/radio/radio-group.js +5 -2
- package/lib/components/suggester/html/suggester.js +2 -1
- package/lib/i18n/dictionary.js +4 -0
- package/lib/src/i18n/dictionary.d.ts +4 -0
- package/lib/src/i18n/index.d.ts +1 -1
- package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +2 -2
- package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.d.ts +1 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
- package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +39 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +30 -0
- package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +1 -1
- package/lib/src/use-lunatic/reducer/commons/is-loop-component.d.ts +2 -2
- package/lib/src/use-lunatic/reducer/resolve-component-controls/index.d.ts +1 -0
- package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-roundabout-control.d.ts +10 -0
- package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.d.ts +3 -0
- package/lib/src/use-lunatic/replace-component-sequence.d.ts +9 -0
- package/lib/src/use-lunatic/type-source.d.ts +14 -3
- package/lib/src/use-lunatic/use-lunatic.d.ts +1 -1
- package/lib/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.d.ts +2 -0
- package/lib/src/utils/suggester-workers/searching/compute-score.d.ts +3 -0
- package/lib/src/utils/suggester-workers/searching/meloto-order.d.ts +24 -0
- package/lib/stories/Introduction.stories.mdx +4 -4
- package/lib/stories/checkboxGroup/source.json +4 -5
- package/lib/stories/component-set/component-set.stories.js +56 -0
- package/lib/stories/component-set/data.json +18 -0
- package/lib/stories/component-set/data1.json +18 -0
- package/lib/stories/component-set/data2.json +18 -0
- package/lib/stories/component-set/source.json +99 -0
- package/lib/stories/component-set/source1.json +287 -0
- package/lib/stories/component-set/source2.json +413 -0
- package/lib/stories/custom-mui/suggester-mui/suggester-mui.js +1 -2
- package/lib/stories/declaration/source.json +24 -0
- package/lib/stories/loop/paginated-loop.stories.js +34 -0
- package/lib/stories/loop/source-paginated.json +126 -0
- package/lib/stories/paste-questionnaire/test.stories.js +1 -1
- package/lib/stories/questionnaires-test/controls/controls-externes.json +75 -0
- package/lib/stories/questionnaires-test/controls/controls-externes.stories.js +62 -0
- package/lib/stories/questionnaires-test/controls/controls.stories.js +1 -1
- package/lib/stories/questionnaires-test/test.stories.js +1 -1
- package/lib/stories/questionnaires2023/bySequence/source.json +5054 -0
- package/lib/stories/questionnaires2023/bySequence/ticWeb.stories.js +64 -0
- package/lib/stories/questionnaires2023/famille/famille.stories.js +64 -0
- package/lib/stories/questionnaires2023/famille/source.json +50344 -0
- package/lib/stories/questionnaires2023/simpsons/simpsons.stories.js +64 -0
- package/lib/stories/questionnaires2023/simpsons/source.json +5176 -0
- package/lib/stories/questionnaires2023/ticTel/source.json +12888 -0
- package/lib/stories/questionnaires2023/ticTel/ticWeb.stories.js +64 -0
- package/lib/stories/questionnaires2023/ticWeb/source.json +11331 -0
- package/lib/stories/questionnaires2023/ticWeb/ticWeb.stories.js +64 -0
- package/lib/stories/resizing-questionnaire/source.json +789 -0
- package/lib/stories/resizing-questionnaire/test.stories.js +84 -0
- package/lib/stories/roundabout/source.json +16 -0
- package/lib/stories/suggester/SuggesterNotification.js +26 -0
- package/lib/stories/suggester/suggester-workers.stories.js +8 -5
- package/lib/stories/suggester/suggester.stories.js +1 -0
- package/lib/use-lunatic/actions.js +4 -4
- package/lib/use-lunatic/commons/calculated-variables.js +1 -1
- package/lib/use-lunatic/commons/compile-controls.js +4 -3
- package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +155 -0
- package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +3 -2
- package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +128 -0
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +4 -1
- package/lib/use-lunatic/reducer/reduce-on-init.js +1 -2
- package/lib/use-lunatic/reducer/resolve-component-controls/index.js +12 -0
- package/lib/use-lunatic/reducer/{validate-controls/validation-utils.js → resolve-component-controls/resolve-component-control.js} +10 -34
- package/lib/use-lunatic/reducer/resolve-component-controls/resolve-roundabout-control.js +54 -0
- package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +44 -0
- package/lib/use-lunatic/replace-component-sequence.js +28 -0
- package/lib/use-lunatic/type-source.js +15 -9
- package/lib/use-lunatic/use-lunatic.js +1 -1
- package/lib/use-lunatic/use-suggesters.js +5 -5
- package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -2
- package/lib/utils/suggester-workers/append-to-index/dist/create-append-task.js +4 -2
- package/lib/utils/suggester-workers/commons-tokenizer/get-stemmer.spec.js +11 -0
- package/lib/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.spec.js +10 -0
- package/lib/utils/suggester-workers/searching/compute-score.js +7 -12
- package/lib/utils/suggester-workers/searching/meloto-order.js +53 -0
- package/lib/utils/suggester-workers/searching/meloto-order.spec.js +67 -0
- package/lib/utils/suggester-workers/searching/searching.js +3 -3
- package/lib/utils/suggester-workers/searching/searching.worker.js +4 -2
- package/package.json +1 -1
- /package/lib/src/use-lunatic/reducer/{validate-controls/validation-utils.d.ts → resolve-component-controls/resolve-component-control.d.ts} +0 -0
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveComponentControls = resolveComponentControls;
|
|
7
|
+
var _resolveRoundaboutControl = require("./resolve-roundabout-control");
|
|
8
|
+
var _typeSource = require("../../type-source");
|
|
9
|
+
var _resolveSimpleControl = require("./resolve-simple-control");
|
|
7
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
11
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -11,40 +14,13 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
|
11
14
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
15
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
16
|
function resolveControl(state, control) {
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
id = control.id,
|
|
22
|
-
typeOfControl = control.typeOfControl;
|
|
23
|
-
var _control$control = control.control,
|
|
24
|
-
_control$control2 = _control$control === void 0 ? {} : _control$control,
|
|
25
|
-
_control$control2$val = _control$control2.value,
|
|
26
|
-
value = _control$control2$val === void 0 ? 'true' : _control$control2$val;
|
|
27
|
-
try {
|
|
28
|
-
var result = executeExpression(value, {
|
|
29
|
-
iteration: iteration,
|
|
30
|
-
linksIterations: linksIterations
|
|
31
|
-
});
|
|
32
|
-
if (!result) {
|
|
33
|
-
var label = executeExpression(errorMessage, {
|
|
34
|
-
iteration: iteration,
|
|
35
|
-
linksIterations: linksIterations
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
criticality: criticality,
|
|
39
|
-
errorMessage: label,
|
|
40
|
-
id: id,
|
|
41
|
-
typeOfControl: typeOfControl
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.warn("Error on validating control ".concat(value));
|
|
47
|
-
return undefined;
|
|
17
|
+
var type = control.type;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case _typeSource.ControlTypeEnum.roundabout:
|
|
20
|
+
return (0, _resolveRoundaboutControl.resolveRoundaboutControl)(state, control);
|
|
21
|
+
case _typeSource.ControlTypeEnum.simple:
|
|
22
|
+
default:
|
|
23
|
+
return (0, _resolveSimpleControl.resolveSimpleControl)(state, control);
|
|
48
24
|
}
|
|
49
25
|
}
|
|
50
26
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveRoundaboutControl = resolveRoundaboutControl;
|
|
7
|
+
/**
|
|
8
|
+
* Pour le Roundabout, le controle doit être validé pour chaque itération
|
|
9
|
+
* composants l'unité enquêtée.
|
|
10
|
+
* Itération prend pour valeur le rang de l'unité stat au sein de l'unité enquêté.
|
|
11
|
+
* Le rondpoint ne peut pas être placé dans une boucle car l'itération est effacée.
|
|
12
|
+
* TODO intégrer cela dans le cadre de boucle de bloucle.
|
|
13
|
+
*/
|
|
14
|
+
function resolveRoundaboutControl(state, control) {
|
|
15
|
+
var _control$control$valu, _control$control;
|
|
16
|
+
var executeExpression = state.executeExpression;
|
|
17
|
+
var criticality = control.criticality,
|
|
18
|
+
errorMessage = control.errorMessage,
|
|
19
|
+
id = control.id,
|
|
20
|
+
typeOfControl = control.typeOfControl,
|
|
21
|
+
iterations = control.iterations;
|
|
22
|
+
var value = (_control$control$valu = control === null || control === void 0 ? void 0 : (_control$control = control.control) === null || _control$control === void 0 ? void 0 : _control$control.value) !== null && _control$control$valu !== void 0 ? _control$control$valu : 'true';
|
|
23
|
+
if (!iterations || iterations <= 0) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
var errors = Array.from({
|
|
27
|
+
length: iterations
|
|
28
|
+
}, function (_, k) {
|
|
29
|
+
return k;
|
|
30
|
+
})
|
|
31
|
+
/**
|
|
32
|
+
* Currently, the controls are lifted when the condition is false.
|
|
33
|
+
* An evolution is planned on the questionnaire generation side (Eno) to come back to a more coherent logic (i.e. lift the control when the condition is true)
|
|
34
|
+
*
|
|
35
|
+
* After this change, we have to change the next line to `.filter((iteration) => executeExpression(value, { iteration }))`
|
|
36
|
+
*/.filter(function (iteration) {
|
|
37
|
+
return !executeExpression(value, {
|
|
38
|
+
iteration: iteration
|
|
39
|
+
});
|
|
40
|
+
}).map(function (iteration) {
|
|
41
|
+
return executeExpression(errorMessage, {
|
|
42
|
+
iteration: iteration
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (errors.length) {
|
|
46
|
+
return {
|
|
47
|
+
criticality: criticality,
|
|
48
|
+
errorMessage: errors,
|
|
49
|
+
id: id,
|
|
50
|
+
typeOfControl: typeOfControl
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveSimpleControl = resolveSimpleControl;
|
|
7
|
+
function resolveSimpleControl(state, control) {
|
|
8
|
+
var _state$pager, _control$control$valu, _control$control;
|
|
9
|
+
var executeExpression = state.executeExpression;
|
|
10
|
+
var _ref = (_state$pager = state.pager) !== null && _state$pager !== void 0 ? _state$pager : {},
|
|
11
|
+
iteration = _ref.iteration,
|
|
12
|
+
linksIterations = _ref.linksIterations;
|
|
13
|
+
var criticality = control.criticality,
|
|
14
|
+
errorMessage = control.errorMessage,
|
|
15
|
+
id = control.id,
|
|
16
|
+
typeOfControl = control.typeOfControl;
|
|
17
|
+
var value = (_control$control$valu = control === null || control === void 0 ? void 0 : (_control$control = control.control) === null || _control$control === void 0 ? void 0 : _control$control.value) !== null && _control$control$valu !== void 0 ? _control$control$valu : 'true';
|
|
18
|
+
var result = executeExpression(value, {
|
|
19
|
+
iteration: iteration,
|
|
20
|
+
linksIterations: linksIterations
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
/**
|
|
24
|
+
* Currently, the controls are lifted when the condition is false.
|
|
25
|
+
* An evolution is planned on the questionnaire generation side (Eno) to come back to a more coherent logic (i.e. lift the control when the condition is true)
|
|
26
|
+
*
|
|
27
|
+
* After this change, we have to change the next line to `if (!result) return undefined;`
|
|
28
|
+
*/
|
|
29
|
+
if (result) return undefined;
|
|
30
|
+
var label = executeExpression(errorMessage, {
|
|
31
|
+
iteration: iteration,
|
|
32
|
+
linksIterations: linksIterations
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
criticality: criticality,
|
|
36
|
+
errorMessage: label,
|
|
37
|
+
id: id,
|
|
38
|
+
typeOfControl: typeOfControl
|
|
39
|
+
};
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.warn("Error on validating control ".concat(value));
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.replaceComponentSequence = replaceComponentSequence;
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
/**
|
|
14
|
+
* Pour le ComponentSet : les composants du fieldset n'existe pas dans pages.
|
|
15
|
+
* Ils échappent donc aux controls. On les substitue ici au ComponentSet.
|
|
16
|
+
* On ne peut pas les ajouter directement dans pages (en spécifiant un page), car ils s'afficheraient 2 fois : dans le fieldset et en dessus, comme
|
|
17
|
+
* des composant à part entière.
|
|
18
|
+
* D'autres composant pourraient un jour figurer ici.
|
|
19
|
+
*/
|
|
20
|
+
function replaceComponentSequence(components) {
|
|
21
|
+
return components.reduce(function (acc, component) {
|
|
22
|
+
var componentType = component.componentType;
|
|
23
|
+
if (componentType === 'ComponentSet') {
|
|
24
|
+
return [].concat(_toConsumableArray(acc), _toConsumableArray(component.components));
|
|
25
|
+
}
|
|
26
|
+
return [].concat(_toConsumableArray(acc), [component]);
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
@@ -3,22 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TypeOfControl = exports.Criticality = void 0;
|
|
6
|
+
exports.TypeOfControl = exports.Criticality = exports.ControlTypeEnum = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Types used for source data (lunatic models and data.json)
|
|
9
9
|
*
|
|
10
10
|
* These types should not be used outside of use-lunatic
|
|
11
11
|
*/
|
|
12
|
-
var Criticality
|
|
13
|
-
exports.Criticality = Criticality;
|
|
14
|
-
(function (Criticality) {
|
|
12
|
+
var Criticality = /*#__PURE__*/function (Criticality) {
|
|
15
13
|
Criticality["INFO"] = "INFO";
|
|
16
14
|
Criticality["WARN"] = "WARN";
|
|
17
15
|
Criticality["ERROR"] = "ERROR";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.
|
|
21
|
-
|
|
16
|
+
return Criticality;
|
|
17
|
+
}({});
|
|
18
|
+
exports.Criticality = Criticality;
|
|
19
|
+
var TypeOfControl = /*#__PURE__*/function (TypeOfControl) {
|
|
22
20
|
TypeOfControl["FORMAT"] = "FORMAT";
|
|
23
21
|
TypeOfControl["CONSISTENCY"] = "CONSISTENCY";
|
|
24
|
-
|
|
22
|
+
return TypeOfControl;
|
|
23
|
+
}({});
|
|
24
|
+
exports.TypeOfControl = TypeOfControl;
|
|
25
|
+
var ControlTypeEnum = /*#__PURE__*/function (ControlTypeEnum) {
|
|
26
|
+
ControlTypeEnum["roundabout"] = "roundabout";
|
|
27
|
+
ControlTypeEnum["simple"] = "simple";
|
|
28
|
+
return ControlTypeEnum;
|
|
29
|
+
}({});
|
|
30
|
+
exports.ControlTypeEnum = ControlTypeEnum;
|
|
@@ -26,7 +26,7 @@ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructur
|
|
|
26
26
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
27
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
28
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
29
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
29
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // @ts-ignore
|
|
30
30
|
var empty = {}; // Keep the same empty object (to avoid problem with useEffect dependencies)
|
|
31
31
|
var emptyFn = function emptyFn() {};
|
|
32
32
|
var DEFAULT_DATA = empty;
|
|
@@ -23,16 +23,16 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
23
23
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
24
24
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
25
25
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
-
var SuggesterStatus
|
|
27
|
-
exports.SuggesterStatus = SuggesterStatus;
|
|
28
|
-
(function (SuggesterStatus) {
|
|
26
|
+
var SuggesterStatus = /*#__PURE__*/function (SuggesterStatus) {
|
|
29
27
|
SuggesterStatus[SuggesterStatus["unused"] = 0] = "unused";
|
|
30
28
|
SuggesterStatus[SuggesterStatus["idle"] = 1] = "idle";
|
|
31
29
|
SuggesterStatus[SuggesterStatus["pending"] = 2] = "pending";
|
|
32
30
|
SuggesterStatus[SuggesterStatus["success"] = 3] = "success";
|
|
33
31
|
SuggesterStatus[SuggesterStatus["unknown"] = 4] = "unknown";
|
|
34
32
|
SuggesterStatus[SuggesterStatus["error"] = 5] = "error";
|
|
35
|
-
|
|
33
|
+
return SuggesterStatus;
|
|
34
|
+
}({});
|
|
35
|
+
exports.SuggesterStatus = SuggesterStatus;
|
|
36
36
|
function nothing() {}
|
|
37
37
|
|
|
38
38
|
// with side effect !
|
|
@@ -153,6 +153,6 @@ function useSuggesters(_ref) {
|
|
|
153
153
|
});
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
}, [suggesters, getReferentiel, status]);
|
|
156
|
+
}, [suggesters, auto, getReferentiel, status]);
|
|
157
157
|
return getSuggesterStatus;
|
|
158
158
|
}
|
|
@@ -22,7 +22,8 @@ function createAppendTask(info, version) {
|
|
|
22
22
|
var log = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : consoleLogging;
|
|
23
23
|
var name = info.name,
|
|
24
24
|
fields = info.fields,
|
|
25
|
-
stopWords = info.stopWords
|
|
25
|
+
stopWords = info.stopWords,
|
|
26
|
+
meloto = info.meloto;
|
|
26
27
|
var worker = (0, _createWorkerTs.createWorker)(workerPath);
|
|
27
28
|
var start = false;
|
|
28
29
|
var stop = false;
|
|
@@ -49,7 +50,8 @@ function createAppendTask(info, version) {
|
|
|
49
50
|
version: version,
|
|
50
51
|
fields: fields,
|
|
51
52
|
stopWords: stopWords,
|
|
52
|
-
entities: entities
|
|
53
|
+
entities: entities,
|
|
54
|
+
meloto: meloto
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
});
|
|
@@ -22,7 +22,8 @@ function createAppendTask(info, version, log) {
|
|
|
22
22
|
}
|
|
23
23
|
var name = info.name,
|
|
24
24
|
fields = info.fields,
|
|
25
|
-
stopWords = info.stopWords
|
|
25
|
+
stopWords = info.stopWords,
|
|
26
|
+
meloto = info.meloto;
|
|
26
27
|
var worker = create_worker_ts_1.createWorker(workerPath);
|
|
27
28
|
var start = false;
|
|
28
29
|
var stop = false;
|
|
@@ -51,7 +52,8 @@ function createAppendTask(info, version, log) {
|
|
|
51
52
|
version: version,
|
|
52
53
|
fields: fields,
|
|
53
54
|
stopWords: stopWords,
|
|
54
|
-
entities: entities
|
|
55
|
+
entities: entities,
|
|
56
|
+
meloto: meloto
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _getStemmer = _interopRequireDefault(require("./get-stemmer"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
6
|
+
(0, _vitest.describe)('common-tokenizer', function () {
|
|
7
|
+
(0, _vitest.it)('getStemmer', function () {
|
|
8
|
+
var stemmer = (0, _getStemmer["default"])();
|
|
9
|
+
(0, _vitest.expect)(stemmer('bâtiment')).toEqual('bât');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _prepareStringIndexation = _interopRequireDefault(require("./prepare-string-indexation"));
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
6
|
+
(0, _vitest.describe)('String indexation', function () {
|
|
7
|
+
(0, _vitest.it)('bâtiment', function () {
|
|
8
|
+
(0, _vitest.expect)((0, _prepareStringIndexation["default"])('bâtiment')).toEqual('batiment');
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -4,25 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
var _melotoOrder = require("./meloto-order");
|
|
7
8
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
9
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
11
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
12
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
13
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
-
function sort(withScore
|
|
14
|
+
function sort(withScore) {
|
|
14
15
|
return withScore.sort(function (a, b) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (a.score < b.score) {
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
return 0;
|
|
22
|
-
}).slice(0, max);
|
|
16
|
+
return b.score - a.score;
|
|
17
|
+
});
|
|
23
18
|
}
|
|
24
|
-
function computeScore(documents) {
|
|
25
|
-
var
|
|
19
|
+
function computeScore(documents, tokens) {
|
|
20
|
+
var meloto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
26
21
|
var withScore = documents.map(function (doc) {
|
|
27
22
|
var tokensSearch = doc.tokensSearch;
|
|
28
23
|
var score = Object.keys(tokensSearch).length;
|
|
@@ -30,7 +25,7 @@ function computeScore(documents) {
|
|
|
30
25
|
score: score
|
|
31
26
|
});
|
|
32
27
|
});
|
|
33
|
-
return sort(withScore,
|
|
28
|
+
return (0, _melotoOrder.melotoOrder)(sort(withScore), tokens, meloto);
|
|
34
29
|
}
|
|
35
30
|
var _default = computeScore;
|
|
36
31
|
exports["default"] = _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.melotoOrder = melotoOrder;
|
|
7
|
+
exports.value = value;
|
|
8
|
+
var _prepareStringIndexation = _interopRequireDefault(require("../commons-tokenizer/prepare-string-indexation"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
function value(entity) {
|
|
11
|
+
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
12
|
+
var suggestion = entity.suggestion;
|
|
13
|
+
var label = suggestion.label;
|
|
14
|
+
var prepared = (0, _prepareStringIndexation["default"])(label);
|
|
15
|
+
if (label && label.length) {
|
|
16
|
+
return tokens.reduce(function (score, token, i) {
|
|
17
|
+
var index = prepared.search(token);
|
|
18
|
+
if (index >= 0) {
|
|
19
|
+
var how = label.length - index;
|
|
20
|
+
how /= label.length;
|
|
21
|
+
var weight = tokens.length - i;
|
|
22
|
+
weight /= tokens.length;
|
|
23
|
+
return score + how * weight;
|
|
24
|
+
}
|
|
25
|
+
return score;
|
|
26
|
+
}, 0);
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Applique une fonction de score supplémentaire pour approcher au mieux
|
|
33
|
+
* la classification obtenue avec l'outil Meloto, developpé par un prestataire
|
|
34
|
+
* pour le compte de l'Insee.
|
|
35
|
+
* Le nouveau classement favorise l'ordre d'apparation des token de recherche
|
|
36
|
+
* dans la chaine label des entités indéxées. Si la recherche contient électricien,
|
|
37
|
+
* la suggestion avec un label électricien sera mieux classée que celle avec chef électricien.
|
|
38
|
+
* S'il y a plusieur tokens de recherche, un poid dégréssif leur est appliqué lors du tri.
|
|
39
|
+
*
|
|
40
|
+
* @param {*} entities
|
|
41
|
+
* @param {*} tokens
|
|
42
|
+
* @param {*} active
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
function melotoOrder(entities, tokens) {
|
|
46
|
+
var active = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
47
|
+
if (active) {
|
|
48
|
+
return entities.sort(function (a, b) {
|
|
49
|
+
return value(b, tokens) - value(a, tokens);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return entities;
|
|
53
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _melotoOrder = require("./meloto-order");
|
|
5
|
+
(0, _vitest.describe)('meloto', function () {
|
|
6
|
+
(0, _vitest.it)('value', function () {
|
|
7
|
+
var score = (0, _melotoOrder.value)({
|
|
8
|
+
suggestion: {
|
|
9
|
+
label: 'otat'
|
|
10
|
+
}
|
|
11
|
+
}, ['tat']);
|
|
12
|
+
var expected = (4 - 1) / 4;
|
|
13
|
+
(0, _vitest.expect)(score).toEqual(expected);
|
|
14
|
+
});
|
|
15
|
+
(0, _vitest.it)('value2', function () {
|
|
16
|
+
var score = (0, _melotoOrder.value)({
|
|
17
|
+
suggestion: {
|
|
18
|
+
label: 'otatxu'
|
|
19
|
+
}
|
|
20
|
+
}, ['tat', 'xu']);
|
|
21
|
+
var expected = (6 - 1) / 6 + (6 - 4) / 6 * 0.5;
|
|
22
|
+
(0, _vitest.expect)(score).toEqual(expected);
|
|
23
|
+
});
|
|
24
|
+
(0, _vitest.it)('sort', function () {
|
|
25
|
+
var entities = [{
|
|
26
|
+
suggestion: {
|
|
27
|
+
label: 'after culture',
|
|
28
|
+
id: 1
|
|
29
|
+
},
|
|
30
|
+
score: 1
|
|
31
|
+
}, {
|
|
32
|
+
suggestion: {
|
|
33
|
+
label: 'culture before',
|
|
34
|
+
id: 2
|
|
35
|
+
},
|
|
36
|
+
score: 1
|
|
37
|
+
}];
|
|
38
|
+
(0, _melotoOrder.melotoOrder)(entities, ['culture']);
|
|
39
|
+
(0, _vitest.expect)(entities[0].suggestion.id).toEqual(2);
|
|
40
|
+
(0, _vitest.expect)(entities[1].suggestion.id).toEqual(1);
|
|
41
|
+
});
|
|
42
|
+
(0, _vitest.it)('sort2', function () {
|
|
43
|
+
var entities = [{
|
|
44
|
+
suggestion: {
|
|
45
|
+
label: 'after after culture',
|
|
46
|
+
id: 1
|
|
47
|
+
},
|
|
48
|
+
score: 1
|
|
49
|
+
}, {
|
|
50
|
+
suggestion: {
|
|
51
|
+
label: 'after culture before',
|
|
52
|
+
id: 2
|
|
53
|
+
},
|
|
54
|
+
score: 1
|
|
55
|
+
}, {
|
|
56
|
+
suggestion: {
|
|
57
|
+
label: 'culture before before',
|
|
58
|
+
id: 3
|
|
59
|
+
},
|
|
60
|
+
score: 1
|
|
61
|
+
}];
|
|
62
|
+
(0, _melotoOrder.melotoOrder)(entities, ['cultu']);
|
|
63
|
+
(0, _vitest.expect)(entities[0].suggestion.id).toEqual(3);
|
|
64
|
+
(0, _vitest.expect)(entities[1].suggestion.id).toEqual(2);
|
|
65
|
+
(0, _vitest.expect)(entities[2].suggestion.id).toEqual(1);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -83,11 +83,11 @@ function searching(_x3, _x4) {
|
|
|
83
83
|
}
|
|
84
84
|
function _searching() {
|
|
85
85
|
_searching = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(search, _ref2) {
|
|
86
|
-
var name, _ref2$version, version, db, info, queryParser, max, order, parser, transaction, store, index, tokens, documents;
|
|
86
|
+
var name, _ref2$version, version, _ref2$meloto, meloto, db, info, queryParser, max, order, parser, transaction, store, index, tokens, documents;
|
|
87
87
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
88
88
|
while (1) switch (_context2.prev = _context2.next) {
|
|
89
89
|
case 0:
|
|
90
|
-
name = _ref2.name, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1' : _ref2$version;
|
|
90
|
+
name = _ref2.name, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1' : _ref2$version, _ref2$meloto = _ref2.meloto, meloto = _ref2$meloto === void 0 ? true : _ref2$meloto;
|
|
91
91
|
_context2.prev = 1;
|
|
92
92
|
if (!isValideSearch(search)) {
|
|
93
93
|
_context2.next = 21;
|
|
@@ -115,7 +115,7 @@ function _searching() {
|
|
|
115
115
|
case 19:
|
|
116
116
|
documents = _context2.sent;
|
|
117
117
|
return _context2.abrupt("return", {
|
|
118
|
-
results: prepare((0, _order["default"])(order)(filterSize((0, _computeScore["default"])(documents), max), order)),
|
|
118
|
+
results: prepare((0, _order["default"])(order)(filterSize((0, _computeScore["default"])(documents, tokens, meloto), max), order)),
|
|
119
119
|
search: search,
|
|
120
120
|
tokens: tokens
|
|
121
121
|
});
|
|
@@ -10,10 +10,12 @@ self.onmessage = function (e) {
|
|
|
10
10
|
var _e$data = e.data,
|
|
11
11
|
search = _e$data.search,
|
|
12
12
|
name = _e$data.name,
|
|
13
|
-
version = _e$data.version
|
|
13
|
+
version = _e$data.version,
|
|
14
|
+
meloto = _e$data.meloto;
|
|
14
15
|
(0, _searching["default"])(search, {
|
|
15
16
|
name: name,
|
|
16
|
-
version: version
|
|
17
|
+
version: version,
|
|
18
|
+
meloto: meloto
|
|
17
19
|
}).then(function (result) {
|
|
18
20
|
self.postMessage(result);
|
|
19
21
|
});
|
package/package.json
CHANGED