lhcb-ntuple-wizard-test 1.0.5 → 1.0.7
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/dist/components/App.js +1 -1
- package/dist/components/ConfigDict.js +39 -40
- package/dist/components/ConfigList.js +27 -31
- package/dist/components/ConfigNode.js +122 -121
- package/dist/components/ConfigValue.js +18 -21
- package/dist/components/Dataset.js +4 -8
- package/dist/components/Decay.js +2 -2
- package/dist/components/DecayItem.js +46 -50
- package/dist/components/DecayTag.js +4 -5
- package/dist/components/DecayTree.js +151 -151
- package/dist/components/DecaysList.js +35 -39
- package/dist/components/DeleteButton.js +1 -1
- package/dist/components/DescriptorsSearch.js +188 -192
- package/dist/components/EventTypeBadge.js +1 -1
- package/dist/components/ItemSearch.js +8 -12
- package/dist/components/LinesTable.js +463 -459
- package/dist/components/NtupleWizard.js +28 -32
- package/dist/components/ParticleTag.js +4 -5
- package/dist/components/PolarityBadge.js +1 -1
- package/dist/components/SearchItem.js +29 -33
- package/dist/components/SelectParticle.js +6 -10
- package/dist/components/SelectTag.js +5 -6
- package/dist/components/SelectTool.js +5 -6
- package/dist/components/SelectVariables.js +23 -24
- package/dist/components/StrippingBadge.js +4 -5
- package/dist/components/StrippingLine.js +2 -2
- package/dist/components/TupleTool.js +4 -5
- package/dist/components/VariablesSearch.js +8 -12
- package/dist/components/YearBadge.js +1 -1
- package/dist/components/loki/LokiDict.js +180 -0
- package/dist/components/loki/LokiEditor.js +200 -0
- package/dist/components/loki/LokiForm.js +112 -0
- package/dist/components/semantic.js +97 -0
- package/dist/components/semform.js +182 -0
- package/dist/components/worker.js +196 -0
- package/dist/config.json +4 -2
- package/dist/contexts/MetadataContext.js +2 -2
- package/dist/index.js +2 -2
- package/dist/lib/DTTConfig.js +13 -9
- package/dist/lib/utils.js +1 -1
- package/package.json +25 -2
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _LokiEditor = _interopRequireDefault(require("./LokiEditor.jsx"));
|
|
9
|
+
var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _reactBootstrap = require("react-bootstrap");
|
|
12
|
+
var _reactBootstrapIcons = require("react-bootstrap-icons");
|
|
13
|
+
var _LokiForm = _interopRequireDefault(require("./LokiForm.jsx"));
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
/*****************************************************************************\
|
|
17
|
+
* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
|
|
18
|
+
* *
|
|
19
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
20
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
21
|
+
* *
|
|
22
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
23
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
24
|
+
* or submit itself to any jurisdiction. *
|
|
25
|
+
\*****************************************************************************/
|
|
26
|
+
|
|
27
|
+
class LokiDict extends _react.default.Component {
|
|
28
|
+
state = {
|
|
29
|
+
lines: this.props.value,
|
|
30
|
+
error: "",
|
|
31
|
+
add: false,
|
|
32
|
+
currentKey: "",
|
|
33
|
+
currentValue: ""
|
|
34
|
+
};
|
|
35
|
+
handleClose = () => {
|
|
36
|
+
this.setState({
|
|
37
|
+
add: false
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
handleAdd = () => {
|
|
41
|
+
var lines = this.state.lines;
|
|
42
|
+
const key = this.state.currentKey;
|
|
43
|
+
const value = this.state.currentValue;
|
|
44
|
+
lines[key] = value;
|
|
45
|
+
this.setState({
|
|
46
|
+
lines: lines
|
|
47
|
+
});
|
|
48
|
+
this.setState({
|
|
49
|
+
currentKey: ""
|
|
50
|
+
});
|
|
51
|
+
this.setState({
|
|
52
|
+
currentValue: ""
|
|
53
|
+
});
|
|
54
|
+
this.props.callback(this.state.lines);
|
|
55
|
+
};
|
|
56
|
+
handleRemove = key => {
|
|
57
|
+
var lines = this.state.lines;
|
|
58
|
+
delete lines[key];
|
|
59
|
+
this.setState({
|
|
60
|
+
lines: lines
|
|
61
|
+
});
|
|
62
|
+
this.props.callback(this.state.lines);
|
|
63
|
+
};
|
|
64
|
+
setValueByKey = (key, value) => {
|
|
65
|
+
var lines = this.state.lines;
|
|
66
|
+
lines[key] = value;
|
|
67
|
+
this.setState({
|
|
68
|
+
lines: lines
|
|
69
|
+
});
|
|
70
|
+
this.props.callback(this.state.lines);
|
|
71
|
+
};
|
|
72
|
+
setAddLine = () => {
|
|
73
|
+
this.setState({
|
|
74
|
+
add: true
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
changeKey = value => {
|
|
78
|
+
this.setState({
|
|
79
|
+
currentKey: value
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
validKey = value => {
|
|
83
|
+
if (value in this.state.lines) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
};
|
|
88
|
+
changeValue = value => {
|
|
89
|
+
this.setState({
|
|
90
|
+
currentValue: value
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
render() {
|
|
94
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card, {
|
|
95
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card.Header, {
|
|
96
|
+
className: "d-flex justify-content-between align-items-start",
|
|
97
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Card.Title, {
|
|
98
|
+
children: "Loki Lines"
|
|
99
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
|
|
100
|
+
variant: "success",
|
|
101
|
+
size: "sm",
|
|
102
|
+
onClick: this.setAddLine,
|
|
103
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrapIcons.PlusLg, {})
|
|
104
|
+
})]
|
|
105
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup, {
|
|
106
|
+
variant: "flush",
|
|
107
|
+
children: Object.keys(this.state.lines).map(key => {
|
|
108
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup.Item, {
|
|
109
|
+
className: "d-flex justify-content-between align-items-start",
|
|
110
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
|
|
111
|
+
container: true,
|
|
112
|
+
spacing: 1,
|
|
113
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
|
|
114
|
+
className: "d-flex",
|
|
115
|
+
item: true,
|
|
116
|
+
form: "maincomponent",
|
|
117
|
+
xs: true,
|
|
118
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
119
|
+
children: [key, ": "]
|
|
120
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiEditor.default, {
|
|
121
|
+
callback: value => {
|
|
122
|
+
this.setValueByKey(key, value);
|
|
123
|
+
},
|
|
124
|
+
value: this.state.lines[key],
|
|
125
|
+
lokiVars: this.props.lokiVars,
|
|
126
|
+
oneLine: true,
|
|
127
|
+
height: "24px",
|
|
128
|
+
width: "40dvw"
|
|
129
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
|
|
130
|
+
variant: "danger",
|
|
131
|
+
size: "sm",
|
|
132
|
+
onClick: () => this.handleRemove(key),
|
|
133
|
+
children: "Remove"
|
|
134
|
+
})]
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
}, key);
|
|
138
|
+
})
|
|
139
|
+
}), this.state.add ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal, {
|
|
140
|
+
show: true,
|
|
141
|
+
onHide: this.handleClose,
|
|
142
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Header, {
|
|
143
|
+
closeButton: true,
|
|
144
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Title, {
|
|
145
|
+
children: "Add Dict Item"
|
|
146
|
+
})
|
|
147
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Body, {
|
|
148
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiForm.default, {
|
|
149
|
+
value: "",
|
|
150
|
+
keyCallback: this.changeKey,
|
|
151
|
+
valueCallback: this.changeValue,
|
|
152
|
+
lokiVars: this.props.lokiVars,
|
|
153
|
+
validateKey: this.validKey
|
|
154
|
+
}, "")
|
|
155
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal.Footer, {
|
|
156
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
|
|
157
|
+
variant: "secondary",
|
|
158
|
+
onClick: this.handleClose,
|
|
159
|
+
children: "Close"
|
|
160
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
|
|
161
|
+
variant: "primary",
|
|
162
|
+
onClick: () => {
|
|
163
|
+
this.handleAdd();
|
|
164
|
+
this.handleClose();
|
|
165
|
+
},
|
|
166
|
+
disabled: this.state.currentKey === "" || this.state.currentValue === "" || !this.validKey(this.state.currentKey),
|
|
167
|
+
children: "Save Changes"
|
|
168
|
+
})]
|
|
169
|
+
})]
|
|
170
|
+
}) : ""]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
LokiDict.propTypes = {
|
|
175
|
+
callback: _propTypes.default.func,
|
|
176
|
+
defaulValue: _propTypes.default.string,
|
|
177
|
+
value: _propTypes.default.object,
|
|
178
|
+
lokiVars: _propTypes.default.object
|
|
179
|
+
};
|
|
180
|
+
var _default = exports.default = LokiDict;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _reactMonacoEditor = _interopRequireDefault(require("react-monaco-editor"));
|
|
9
|
+
var monaco = _interopRequireWildcard(require("monaco-editor"));
|
|
10
|
+
var _react2 = require("@monaco-editor/react");
|
|
11
|
+
var _Spinner = _interopRequireDefault(require("react-bootstrap/Spinner"));
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
/*****************************************************************************\
|
|
18
|
+
* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
|
|
19
|
+
* *
|
|
20
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
21
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
22
|
+
* *
|
|
23
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
24
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
25
|
+
* or submit itself to any jurisdiction. *
|
|
26
|
+
\*****************************************************************************/
|
|
27
|
+
|
|
28
|
+
// import { monaco } from 'react-monaco-editor';
|
|
29
|
+
|
|
30
|
+
_react2.loader.config({
|
|
31
|
+
monaco
|
|
32
|
+
});
|
|
33
|
+
let LokiData = {};
|
|
34
|
+
function createDependencyProposals(range) {
|
|
35
|
+
// returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
|
|
36
|
+
// here you could do a server side lookup
|
|
37
|
+
let listOfFunctors = [];
|
|
38
|
+
Object.keys(LokiData).forEach((key, _index) => {
|
|
39
|
+
listOfFunctors.push({
|
|
40
|
+
label: key,
|
|
41
|
+
kind: monaco.languages.CompletionItemKind.Function,
|
|
42
|
+
documentation: LokiData[key].description,
|
|
43
|
+
insertText: key,
|
|
44
|
+
range: range
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return listOfFunctors;
|
|
48
|
+
}
|
|
49
|
+
_react2.loader.init().then(monaco => {
|
|
50
|
+
monaco.languages.registerCompletionItemProvider("python", {
|
|
51
|
+
provideCompletionItems: function (model, position) {
|
|
52
|
+
var word = model.getWordUntilPosition(position);
|
|
53
|
+
var range = {
|
|
54
|
+
startLineNumber: position.lineNumber,
|
|
55
|
+
endLineNumber: position.lineNumber,
|
|
56
|
+
startColumn: word.startColumn,
|
|
57
|
+
endColumn: word.endColumn
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
suggestions: createDependencyProposals(range)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
monaco.languages.registerHoverProvider("python", {
|
|
65
|
+
provideHover: function (model, position) {
|
|
66
|
+
let hoverObjects = [];
|
|
67
|
+
let matches = Object.keys(LokiData).filter(name => {
|
|
68
|
+
return model.findMatches(name, false, false, true, " (:,)*").length !== 0;
|
|
69
|
+
});
|
|
70
|
+
if (matches.length > 0) {
|
|
71
|
+
matches.forEach(match => model.findMatches(match, false, false, true).forEach(range => hoverObjects.push({
|
|
72
|
+
match: match,
|
|
73
|
+
position: position,
|
|
74
|
+
range: range,
|
|
75
|
+
contents: [{
|
|
76
|
+
supportHtml: true,
|
|
77
|
+
value: LokiData[match].documentation
|
|
78
|
+
}]
|
|
79
|
+
})));
|
|
80
|
+
for (const element of hoverObjects) {
|
|
81
|
+
if (contains(element.range, position)) {
|
|
82
|
+
// alert(element.contents[0].value)
|
|
83
|
+
return element;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
|
|
89
|
+
contents: [{
|
|
90
|
+
supportHtml: true,
|
|
91
|
+
value: '<span style="color red;">No matches</span>',
|
|
92
|
+
isTrusted: true
|
|
93
|
+
}]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
function contains(range, position) {
|
|
99
|
+
if (range.range.startLineNumber <= position.lineNumber && range.range.endLineNumber >= position.lineNumber) {
|
|
100
|
+
if (range.range.startColumn <= position.column && range.range.endColumn >= position.column) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
class LokiEditor extends _react.default.Component {
|
|
107
|
+
constructor(props) {
|
|
108
|
+
super(props);
|
|
109
|
+
this.state = {
|
|
110
|
+
code: this.props.returnList ? this.props.value.join("\n") : this.props.value,
|
|
111
|
+
loaded: true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
editorDidMount(editor, _monaco) {
|
|
115
|
+
editor.focus();
|
|
116
|
+
}
|
|
117
|
+
onChange(newValue, _e) {
|
|
118
|
+
if (this.props.oneLine) {
|
|
119
|
+
newValue = newValue.replace(/[\n\r]/g, "");
|
|
120
|
+
}
|
|
121
|
+
this.setState({
|
|
122
|
+
code: newValue
|
|
123
|
+
});
|
|
124
|
+
if (this.props.returnList) {
|
|
125
|
+
newValue = newValue.split(/\r?\n/);
|
|
126
|
+
}
|
|
127
|
+
this.props.callback(newValue);
|
|
128
|
+
}
|
|
129
|
+
render() {
|
|
130
|
+
const code = this.state.code;
|
|
131
|
+
const lokiVars = this.props.lokiVars.lokiVariables;
|
|
132
|
+
Object.keys(lokiVars).forEach(key => {
|
|
133
|
+
LokiData[key] = lokiVars[key];
|
|
134
|
+
});
|
|
135
|
+
const options = {
|
|
136
|
+
autoIndent: "full",
|
|
137
|
+
contextmenu: false,
|
|
138
|
+
fontFamily: "monospace",
|
|
139
|
+
fontSize: 18,
|
|
140
|
+
lineHeight: 24,
|
|
141
|
+
hideCursorInOverviewRuler: true,
|
|
142
|
+
matchBrackets: "always",
|
|
143
|
+
lineNumbers: "off",
|
|
144
|
+
lineDecorationsWidth: 0,
|
|
145
|
+
lineNumbersMinChars: 0,
|
|
146
|
+
glyphMargin: false,
|
|
147
|
+
wordWrap: "on",
|
|
148
|
+
minimap: {
|
|
149
|
+
enabled: false
|
|
150
|
+
},
|
|
151
|
+
scrollbar: {
|
|
152
|
+
horizontal: "hidden",
|
|
153
|
+
vertical: "hidden",
|
|
154
|
+
horizontalSliderSize: 0,
|
|
155
|
+
verticalSliderSize: 0,
|
|
156
|
+
horizontalScrollbarSize: 0,
|
|
157
|
+
verticalScrollbarSize: 0
|
|
158
|
+
},
|
|
159
|
+
scrollBeyondLastLine: false,
|
|
160
|
+
selectOnLineNumbers: true,
|
|
161
|
+
roundedSelection: false,
|
|
162
|
+
readOnly: false,
|
|
163
|
+
cursorStyle: "line",
|
|
164
|
+
automaticLayout: true,
|
|
165
|
+
fixedOverflowWidgets: true,
|
|
166
|
+
links: true
|
|
167
|
+
};
|
|
168
|
+
return this.state.loaded ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactMonacoEditor.default, {
|
|
169
|
+
width: this.props.width,
|
|
170
|
+
height: this.props.height,
|
|
171
|
+
language: "python",
|
|
172
|
+
theme: "vs-light",
|
|
173
|
+
value: code,
|
|
174
|
+
options: options,
|
|
175
|
+
onChange: this.onChange.bind(this),
|
|
176
|
+
editorDidMount: this.editorDidMount.bind(this)
|
|
177
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {
|
|
178
|
+
animation: "border",
|
|
179
|
+
role: "status"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
LokiEditor.defaultProps = {
|
|
184
|
+
value: "",
|
|
185
|
+
oneLine: false,
|
|
186
|
+
width: "30vh",
|
|
187
|
+
height: "10vh",
|
|
188
|
+
returnList: false
|
|
189
|
+
};
|
|
190
|
+
LokiEditor.propTypes = {
|
|
191
|
+
callback: _propTypes.default.func,
|
|
192
|
+
value: _propTypes.default.string,
|
|
193
|
+
defaultValue: _propTypes.default.string,
|
|
194
|
+
lokiVars: _propTypes.default.object,
|
|
195
|
+
oneLine: _propTypes.default.bool,
|
|
196
|
+
height: _propTypes.default.string,
|
|
197
|
+
width: _propTypes.default.string,
|
|
198
|
+
returnList: _propTypes.default.bool
|
|
199
|
+
};
|
|
200
|
+
var _default = exports.default = LokiEditor;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _LokiEditor = _interopRequireDefault(require("./LokiEditor.jsx"));
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _reactBootstrap = require("react-bootstrap");
|
|
11
|
+
var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
/*****************************************************************************\
|
|
15
|
+
* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
|
|
16
|
+
* *
|
|
17
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
18
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
19
|
+
* *
|
|
20
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
21
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
22
|
+
* or submit itself to any jurisdiction. *
|
|
23
|
+
\*****************************************************************************/
|
|
24
|
+
|
|
25
|
+
class LokiForm extends _react.default.Component {
|
|
26
|
+
state = {
|
|
27
|
+
key: this.props.key,
|
|
28
|
+
value: this.props.value,
|
|
29
|
+
err: false,
|
|
30
|
+
errMsg: ""
|
|
31
|
+
};
|
|
32
|
+
keyCallback = event => {
|
|
33
|
+
const key = event.target.value.replaceAll(/[^\w]/g, "");
|
|
34
|
+
if (!this.props.validateKey(key)) {
|
|
35
|
+
this.setState({
|
|
36
|
+
err: true,
|
|
37
|
+
errMsg: "Key must be unique and not empty!"
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
this.setState({
|
|
41
|
+
err: false,
|
|
42
|
+
errMsg: ""
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
this.setState({
|
|
46
|
+
key: key
|
|
47
|
+
});
|
|
48
|
+
this.props.keyCallback(key);
|
|
49
|
+
};
|
|
50
|
+
valueCallback = value => {
|
|
51
|
+
this.setState({
|
|
52
|
+
value: value
|
|
53
|
+
});
|
|
54
|
+
this.props.valueCallback(value);
|
|
55
|
+
};
|
|
56
|
+
render() {
|
|
57
|
+
const errorMessage = this.state.err ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Alert, {
|
|
58
|
+
variant: "danger",
|
|
59
|
+
children: this.state.errMsg
|
|
60
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
|
|
61
|
+
const margin = {
|
|
62
|
+
"margin-left": "7px"
|
|
63
|
+
};
|
|
64
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.InputGroup, {
|
|
65
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
|
|
66
|
+
container: true,
|
|
67
|
+
spacing: 1,
|
|
68
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
|
|
69
|
+
className: "d-flex",
|
|
70
|
+
item: true,
|
|
71
|
+
form: "maincomponent",
|
|
72
|
+
xs: true,
|
|
73
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
74
|
+
children: [errorMessage, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.FormControl, {
|
|
75
|
+
placeholder: "Varibale Name",
|
|
76
|
+
onChange: this.keyCallback,
|
|
77
|
+
value: this.state.key
|
|
78
|
+
})]
|
|
79
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
80
|
+
style: margin,
|
|
81
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiEditor.default, {
|
|
82
|
+
callback: this.valueCallback,
|
|
83
|
+
value: this.state.value,
|
|
84
|
+
lokiVars: this.props.lokiVars,
|
|
85
|
+
oneLine: true,
|
|
86
|
+
height: "24px",
|
|
87
|
+
width: "10dvw"
|
|
88
|
+
})
|
|
89
|
+
})]
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
LokiForm.defaultProps = {
|
|
96
|
+
key: "",
|
|
97
|
+
value: "",
|
|
98
|
+
validateKey: () => {
|
|
99
|
+
true;
|
|
100
|
+
},
|
|
101
|
+
lokiActive: true
|
|
102
|
+
};
|
|
103
|
+
LokiForm.propTypes = {
|
|
104
|
+
key: _propTypes.default.string,
|
|
105
|
+
value: _propTypes.default.string,
|
|
106
|
+
keyCallback: _propTypes.default.func,
|
|
107
|
+
valueCallback: _propTypes.default.func,
|
|
108
|
+
validateKey: _propTypes.default.func,
|
|
109
|
+
lokiVars: _propTypes.default.object,
|
|
110
|
+
lokiActive: _propTypes.default.bool
|
|
111
|
+
};
|
|
112
|
+
var _default = exports.default = LokiForm;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.embedCorpus = embedCorpus;
|
|
7
|
+
exports.getSimilarity = getSimilarity;
|
|
8
|
+
exports.loadModel = loadModel;
|
|
9
|
+
var _transformers = require("@xenova/transformers");
|
|
10
|
+
/*****************************************************************************\
|
|
11
|
+
* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
|
|
12
|
+
* *
|
|
13
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
14
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
15
|
+
* *
|
|
16
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
17
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
18
|
+
* or submit itself to any jurisdiction. *
|
|
19
|
+
\*****************************************************************************/
|
|
20
|
+
|
|
21
|
+
// To always download the model from huggingface.com
|
|
22
|
+
_transformers.env.allowLocalModels = false;
|
|
23
|
+
_transformers.env.useBrowserCache = false;
|
|
24
|
+
// Create a new worker
|
|
25
|
+
const worker = new Worker(new URL("./worker.jsx", import.meta.url), {
|
|
26
|
+
type: "module"
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* @type {function}
|
|
30
|
+
* Promise resolve function for loading the model
|
|
31
|
+
*/
|
|
32
|
+
let loadResolve;
|
|
33
|
+
/**
|
|
34
|
+
* @type {function}
|
|
35
|
+
*/
|
|
36
|
+
let queryResolve;
|
|
37
|
+
worker.onmessage = function (event) {
|
|
38
|
+
const message = event.data;
|
|
39
|
+
switch (message.type) {
|
|
40
|
+
case "progress":
|
|
41
|
+
if (message.progress.status === "ready") {
|
|
42
|
+
loadResolve();
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "corpus":
|
|
46
|
+
// the corpus is embedded
|
|
47
|
+
queryResolve();
|
|
48
|
+
break;
|
|
49
|
+
case "result":
|
|
50
|
+
queryResolve(message.result);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {string} modelname
|
|
57
|
+
* Load the model with the provided model name
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
async function loadModel(modelname) {
|
|
61
|
+
worker.postMessage({
|
|
62
|
+
type: "init",
|
|
63
|
+
model: modelname
|
|
64
|
+
});
|
|
65
|
+
return new Promise(resolve => {
|
|
66
|
+
loadResolve = resolve;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Passes corpus embedding from backend to the worker
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
async function embedCorpus(metadata) {
|
|
74
|
+
worker.postMessage({
|
|
75
|
+
type: "corpus",
|
|
76
|
+
kgdoc: metadata.metadata.kgdoc,
|
|
77
|
+
emb: metadata.metadata.embedding
|
|
78
|
+
});
|
|
79
|
+
return new Promise(resolve => {
|
|
80
|
+
queryResolve = resolve;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {string} query#
|
|
86
|
+
* Calculate the similarity between the query and the corpus
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
async function getSimilarity(query) {
|
|
90
|
+
worker.postMessage({
|
|
91
|
+
type: "similarity",
|
|
92
|
+
query: query
|
|
93
|
+
});
|
|
94
|
+
return new Promise(resolve => {
|
|
95
|
+
queryResolve = resolve;
|
|
96
|
+
});
|
|
97
|
+
}
|