lhcb-ntuple-wizard-test 1.1.12 → 1.1.14
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/ConfigNode.js +1 -5
- package/dist/components/DecayTree.js +0 -4
- package/dist/config.json +1 -1
- package/package.json +2 -25
- package/dist/components/loki/LokiDict.js +0 -180
- package/dist/components/loki/LokiEditor.js +0 -200
- package/dist/components/loki/LokiForm.js +0 -112
- package/dist/components/semform.js +0 -182
- package/dist/lib/semantic.js +0 -99
- package/dist/lib/worker.js +0 -196
|
@@ -12,7 +12,6 @@ var _ConfigValue = _interopRequireDefault(require("./ConfigValue"));
|
|
|
12
12
|
var _ConfigList = _interopRequireDefault(require("./ConfigList"));
|
|
13
13
|
var _ConfigDict = _interopRequireDefault(require("./ConfigDict"));
|
|
14
14
|
var _DeleteButton = _interopRequireDefault(require("./DeleteButton"));
|
|
15
|
-
var _LokiDict = _interopRequireDefault(require("./loki/LokiDict"));
|
|
16
15
|
var _reactBootstrap = require("react-bootstrap");
|
|
17
16
|
var _reactBootstrapIcons = require("react-bootstrap-icons");
|
|
18
17
|
var _MetadataContext = _interopRequireDefault(require("../contexts/MetadataContext"));
|
|
@@ -270,10 +269,7 @@ class ParticleConfig extends _react.default.Component {
|
|
|
270
269
|
const inputBox = type.match(list_re) !== null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigList.default, {
|
|
271
270
|
type: type.match(list_re)[1],
|
|
272
271
|
...configProps
|
|
273
|
-
}) : type.match(dict_re) !== null ?
|
|
274
|
-
lokiVars: this.context.metadata.lokiVariables,
|
|
275
|
-
...configProps
|
|
276
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigDict.default, {
|
|
272
|
+
}) : type.match(dict_re) !== null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigDict.default, {
|
|
277
273
|
keyType: type.match(dict_re)[1],
|
|
278
274
|
valType: type.match(dict_re)[2],
|
|
279
275
|
...configProps
|
|
@@ -19,7 +19,6 @@ var _mathjax = _interopRequireDefault(require("../lib/mathjax"));
|
|
|
19
19
|
var _config = _interopRequireDefault(require("../config.json"));
|
|
20
20
|
var _DTTConfig = _interopRequireDefault(require("../lib/DTTConfig"));
|
|
21
21
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
22
|
-
var _semform = _interopRequireDefault(require("./semform"));
|
|
23
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
24
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
24
|
/*****************************************************************************\
|
|
@@ -392,9 +391,6 @@ class DecayTree extends _react.default.Component {
|
|
|
392
391
|
})
|
|
393
392
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card.Title, {
|
|
394
393
|
children: ["Current selection: ", selectedName]
|
|
395
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Card.Title, {
|
|
396
|
-
className: "d-flex justify-content-between align-items-center flex-column",
|
|
397
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_semform.default, {})
|
|
398
394
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigNode.default, {
|
|
399
395
|
dtt: this.state.dtt,
|
|
400
396
|
particleID: selection,
|
package/dist/config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lhcb-ntuple-wizard-test",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "An application to access large-scale open data from LHCb",
|
|
5
5
|
"url": "https://gitlab.cern.ch/lhcb-dpa/wp6-analysis-preservation-and-open-data/lhcb-ntuple-wizard-frontend/issues",
|
|
6
6
|
"private": false,
|
|
@@ -10,21 +10,8 @@
|
|
|
10
10
|
"dist",
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
|
-
"browser": {
|
|
14
|
-
"fs": false,
|
|
15
|
-
"path": false,
|
|
16
|
-
"os": false
|
|
17
|
-
},
|
|
18
13
|
"dependencies": {
|
|
19
|
-
"@avcs/autosuggest": "latest",
|
|
20
|
-
"@emotion/react": "latest",
|
|
21
|
-
"@emotion/styled": "latest",
|
|
22
|
-
"@monaco-editor/react": "^4.6.0",
|
|
23
|
-
"@mui/joy": "latest",
|
|
24
|
-
"@mui/material": "latest",
|
|
25
14
|
"@vitejs/plugin-react": "^4.2.1",
|
|
26
|
-
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
|
|
27
|
-
"@xenova/transformers": "^2.16.1",
|
|
28
15
|
"bootstrap": "^5.1.3",
|
|
29
16
|
"email-validator": "^2.0.4",
|
|
30
17
|
"js-yaml": "^4.1.0",
|
|
@@ -32,26 +19,16 @@
|
|
|
32
19
|
"lodash": "^4.17.21",
|
|
33
20
|
"lodash.memoize": "^4.1.2",
|
|
34
21
|
"mathjax-react": "^2.0.1",
|
|
35
|
-
"monaco-editor": "^0.44.0",
|
|
36
|
-
"monaco-editor-core": "^0.44.0",
|
|
37
|
-
"monaco-editor-nls": "^3.1.0",
|
|
38
|
-
"monaco-editor-webpack-plugin": "^7.1.0",
|
|
39
|
-
"monaco-languageclient": "0.13.1-next.9",
|
|
40
22
|
"pako": "^2.1.0",
|
|
41
23
|
"react": "^17.0.2",
|
|
42
|
-
"react-app-polyfill": "^3.0.0",
|
|
43
24
|
"react-bootstrap": "^2.0.3",
|
|
44
25
|
"react-bootstrap-icons": "^1.6.1",
|
|
45
|
-
"react-dev-utils": "^12.0.1",
|
|
46
26
|
"react-dom": "^17.0.2",
|
|
47
27
|
"react-graph-vis": "^1.0.7",
|
|
48
28
|
"react-infinite-scroll-component": "^6.1.0",
|
|
49
|
-
"react-monaco-editor": "^0.55.0",
|
|
50
|
-
"react-overlays": "5.2.1",
|
|
51
29
|
"react-router-dom": "^5.2.0",
|
|
52
30
|
"react-select": "^4.3.1",
|
|
53
|
-
"vite": "^5.1.1"
|
|
54
|
-
"web-vitals": "^2.1.4"
|
|
31
|
+
"vite": "^5.1.1"
|
|
55
32
|
},
|
|
56
33
|
"overrides": {
|
|
57
34
|
"autoprefixer": "10.4.5"
|
|
@@ -1,180 +0,0 @@
|
|
|
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"));
|
|
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"));
|
|
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;
|
|
@@ -1,200 +0,0 @@
|
|
|
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;
|
|
@@ -1,112 +0,0 @@
|
|
|
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"));
|
|
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;
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _Form = _interopRequireDefault(require("react-bootstrap/Form"));
|
|
8
|
-
var _Button = _interopRequireDefault(require("react-bootstrap/Button"));
|
|
9
|
-
var _semantic = require("../lib/semantic");
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
var _MetadataContext = _interopRequireDefault(require("../contexts/MetadataContext"));
|
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
var _DeleteButton = _interopRequireDefault(require("./DeleteButton"));
|
|
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
|
-
function getmetafromcontext() {
|
|
28
|
-
const context = (0, _react.useContext)(_MetadataContext.default);
|
|
29
|
-
return context;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Make the output of the search more readable
|
|
34
|
-
* @param {Array} data
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
function FormatOutput(_ref) {
|
|
38
|
-
let {
|
|
39
|
-
data
|
|
40
|
-
} = _ref;
|
|
41
|
-
let topchoice_ttool = [data.ttool[0]];
|
|
42
|
-
let data_ttool = data.ttool.slice(1);
|
|
43
|
-
let topchoice_loki = [data.loki[0]];
|
|
44
|
-
let data_loki = data.loki.slice(1);
|
|
45
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
46
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
47
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
48
|
-
children: "Best match (TupleTools):"
|
|
49
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
50
|
-
children: topchoice_ttool.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
51
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
52
|
-
children: "Matched TupleTool:"
|
|
53
|
-
}), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
54
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
55
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
56
|
-
children: "Variable name:"
|
|
57
|
-
}), " ", item[1]]
|
|
58
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
59
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
60
|
-
children: "Definition:"
|
|
61
|
-
}), " ", item[0]]
|
|
62
|
-
})]
|
|
63
|
-
})]
|
|
64
|
-
}, index))
|
|
65
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
66
|
-
children: "Other matches (TupleTools):"
|
|
67
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
68
|
-
children: data_ttool.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
69
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
70
|
-
children: "Matched TupleTool:"
|
|
71
|
-
}), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
72
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
73
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
74
|
-
children: "Variable name:"
|
|
75
|
-
}), " ", item[1]]
|
|
76
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
77
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
78
|
-
children: "Definition:"
|
|
79
|
-
}), " ", item[0]]
|
|
80
|
-
})]
|
|
81
|
-
})]
|
|
82
|
-
}, index))
|
|
83
|
-
})]
|
|
84
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
85
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
86
|
-
children: "Best match (LoKi functors):"
|
|
87
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
88
|
-
children: topchoice_loki.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
89
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
90
|
-
children: "Matched TupleTool:"
|
|
91
|
-
}), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
92
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
93
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
94
|
-
children: "Variable name:"
|
|
95
|
-
}), " ", item[1]]
|
|
96
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
97
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
98
|
-
children: "Definition:"
|
|
99
|
-
}), " ", item[0]]
|
|
100
|
-
})]
|
|
101
|
-
})]
|
|
102
|
-
}, index))
|
|
103
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
104
|
-
children: "Other matches (LoKi functors):"
|
|
105
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
106
|
-
children: data_loki.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
107
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
108
|
-
children: "Matched TupleTool:"
|
|
109
|
-
}), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
110
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
111
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
112
|
-
children: "Variable name:"
|
|
113
|
-
}), " ", item[1]]
|
|
114
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
115
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
116
|
-
children: "Definition:"
|
|
117
|
-
}), " ", item[0]]
|
|
118
|
-
})]
|
|
119
|
-
})]
|
|
120
|
-
}, index))
|
|
121
|
-
})]
|
|
122
|
-
})]
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
FormatOutput.propTypes = {
|
|
126
|
-
data: _propTypes.default.objectOf(_propTypes.default.array).isRequired
|
|
127
|
-
};
|
|
128
|
-
const SearchTTool = () => {
|
|
129
|
-
const [inputData, setInputData] = (0, _react.useState)({
|
|
130
|
-
query: ""
|
|
131
|
-
});
|
|
132
|
-
const [responseData, setResponseData] = (0, _react.useState)(null);
|
|
133
|
-
let metadata = getmetafromcontext();
|
|
134
|
-
// Load the model and embed the corpus when the component mounts
|
|
135
|
-
(0, _react.useMemo)(async () => {
|
|
136
|
-
await (0, _semantic.loadModel)("TaylorAI/gte-tiny");
|
|
137
|
-
await (0, _semantic.embedCorpus)(metadata);
|
|
138
|
-
}, []);
|
|
139
|
-
const handleChange = event => {
|
|
140
|
-
setInputData({
|
|
141
|
-
...inputData,
|
|
142
|
-
query: event.target.value
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
const handleSubmit = async event => {
|
|
146
|
-
event.preventDefault();
|
|
147
|
-
// clean input field
|
|
148
|
-
setInputData({
|
|
149
|
-
query: ""
|
|
150
|
-
});
|
|
151
|
-
let response = await (0, _semantic.getSimilarity)(inputData.query);
|
|
152
|
-
setResponseData(response);
|
|
153
|
-
};
|
|
154
|
-
const handleDelete = () => {
|
|
155
|
-
setResponseData(null);
|
|
156
|
-
};
|
|
157
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Form.default, {
|
|
158
|
-
onSubmit: handleSubmit,
|
|
159
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Form.default.Group, {
|
|
160
|
-
controlId: "formQuery",
|
|
161
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Form.default.Label, {
|
|
162
|
-
children: "Search for TupleTools"
|
|
163
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Form.default.Control, {
|
|
164
|
-
type: "text",
|
|
165
|
-
value: inputData.query,
|
|
166
|
-
onChange: handleChange
|
|
167
|
-
})]
|
|
168
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
169
|
-
variant: "primary",
|
|
170
|
-
type: "submit",
|
|
171
|
-
children: "Submit"
|
|
172
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_DeleteButton.default, {
|
|
173
|
-
disabled: !responseData,
|
|
174
|
-
action: handleDelete
|
|
175
|
-
}), responseData && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
176
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FormatOutput, {
|
|
177
|
-
data: responseData
|
|
178
|
-
})
|
|
179
|
-
})]
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
var _default = exports.default = SearchTTool;
|
package/dist/lib/semantic.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
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.js", import.meta.url), {
|
|
26
|
-
type: "module"
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @type {function}
|
|
31
|
-
* Promise resolve function for loading the model
|
|
32
|
-
*/
|
|
33
|
-
let loadResolve;
|
|
34
|
-
/**
|
|
35
|
-
* @type {function}
|
|
36
|
-
*/
|
|
37
|
-
let queryResolve;
|
|
38
|
-
worker.onmessage = function (event) {
|
|
39
|
-
const message = event.data;
|
|
40
|
-
switch (message.type) {
|
|
41
|
-
case "progress":
|
|
42
|
-
if (message.progress.status === "ready") {
|
|
43
|
-
loadResolve();
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
case "corpus":
|
|
47
|
-
// the corpus is embedded
|
|
48
|
-
queryResolve();
|
|
49
|
-
break;
|
|
50
|
-
case "result":
|
|
51
|
-
queryResolve(message.result);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @param {string} modelname
|
|
58
|
-
* Load the model with the provided model name
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
async function loadModel(modelname) {
|
|
62
|
-
worker.postMessage({
|
|
63
|
-
type: "init",
|
|
64
|
-
model: modelname
|
|
65
|
-
});
|
|
66
|
-
return new Promise(resolve => {
|
|
67
|
-
loadResolve = resolve;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Passes corpus embedding from backend to the worker
|
|
72
|
-
* @returns
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
async function embedCorpus(metadata) {
|
|
76
|
-
worker.postMessage({
|
|
77
|
-
type: "corpus",
|
|
78
|
-
kgdoc: metadata.metadata.kgdoc,
|
|
79
|
-
emb: metadata.metadata.embedding
|
|
80
|
-
});
|
|
81
|
-
return new Promise(resolve => {
|
|
82
|
-
queryResolve = resolve;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
* @param {string} query#
|
|
88
|
-
* Calculate the similarity between the query and the corpus
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
async function getSimilarity(query) {
|
|
92
|
-
worker.postMessage({
|
|
93
|
-
type: "similarity",
|
|
94
|
-
query: query
|
|
95
|
-
});
|
|
96
|
-
return new Promise(resolve => {
|
|
97
|
-
queryResolve = resolve;
|
|
98
|
-
});
|
|
99
|
-
}
|
package/dist/lib/worker.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _transformers = require("@xenova/transformers");
|
|
4
|
-
/*****************************************************************************\
|
|
5
|
-
* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
|
|
6
|
-
* *
|
|
7
|
-
* This software is distributed under the terms of the GNU General Public *
|
|
8
|
-
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
9
|
-
* *
|
|
10
|
-
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
11
|
-
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
12
|
-
* or submit itself to any jurisdiction. *
|
|
13
|
-
\*****************************************************************************/
|
|
14
|
-
|
|
15
|
-
// This is so that we will download the models from huggingface.co
|
|
16
|
-
_transformers.env.allowLocalModels = false;
|
|
17
|
-
_transformers.env.useBrowserCache = false;
|
|
18
|
-
// store the embeddings in a dict
|
|
19
|
-
let query_embedding;
|
|
20
|
-
/**
|
|
21
|
-
* @type {Object.<string, Array>}
|
|
22
|
-
*/
|
|
23
|
-
let embedding_dict = {};
|
|
24
|
-
/**
|
|
25
|
-
* @type {pipeline}
|
|
26
|
-
*/
|
|
27
|
-
let embedder;
|
|
28
|
-
|
|
29
|
-
// these will hold the information to tie variable explanations to TupleTools
|
|
30
|
-
let dataKeys;
|
|
31
|
-
let paths;
|
|
32
|
-
/**
|
|
33
|
-
* @type {Array}
|
|
34
|
-
* */
|
|
35
|
-
let vars;
|
|
36
|
-
/**
|
|
37
|
-
* This function calculates the embedding and stores it in a dict.
|
|
38
|
-
* If the text is already embedded, it will return the embedding from the dict.
|
|
39
|
-
* @param {string} text
|
|
40
|
-
* @param {bool} embedNew
|
|
41
|
-
* @returns embeddingVector
|
|
42
|
-
*/
|
|
43
|
-
async function embed(text) {
|
|
44
|
-
let embedNew = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
45
|
-
if (text in embedding_dict) {
|
|
46
|
-
return embedding_dict[text];
|
|
47
|
-
}
|
|
48
|
-
const e0 = await embedder(text, {
|
|
49
|
-
pooling: "mean",
|
|
50
|
-
normalize: true
|
|
51
|
-
});
|
|
52
|
-
if (embedNew) {
|
|
53
|
-
embedding_dict[text] = e0.data;
|
|
54
|
-
}
|
|
55
|
-
return e0.data;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* This function calculates the cosine similarity between two embeddings.
|
|
59
|
-
* @param {Array} corpus_embedding
|
|
60
|
-
* @param {Array} query_embedding
|
|
61
|
-
* @returns cosine similarity
|
|
62
|
-
* */
|
|
63
|
-
function calcCosSim(corpus_embedding, query_embedding) {
|
|
64
|
-
let dotProduct = 0;
|
|
65
|
-
let queryMag = 0;
|
|
66
|
-
let embMag = 0;
|
|
67
|
-
let loop_length = query_embedding.length;
|
|
68
|
-
// because the embeddings might have different dimensions
|
|
69
|
-
if (query_embedding.length > corpus_embedding.length) {
|
|
70
|
-
loop_length = corpus_embedding.length;
|
|
71
|
-
}
|
|
72
|
-
for (let i = 0; i < loop_length; i++) {
|
|
73
|
-
dotProduct += query_embedding[i] * corpus_embedding[i];
|
|
74
|
-
queryMag += query_embedding[i] * query_embedding[i];
|
|
75
|
-
embMag += corpus_embedding[i] * corpus_embedding[i];
|
|
76
|
-
}
|
|
77
|
-
const sim = dotProduct / (Math.sqrt(queryMag) * Math.sqrt(embMag));
|
|
78
|
-
return sim;
|
|
79
|
-
}
|
|
80
|
-
/**This is a helper function to read the nested json file containing the documentation.
|
|
81
|
-
* @returns [vars, paths, dataKeys]
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
function readJsonFile(data) {
|
|
85
|
-
// go through nested object
|
|
86
|
-
vars = [];
|
|
87
|
-
paths = [];
|
|
88
|
-
const iterateObject = function (obj) {
|
|
89
|
-
let path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
90
|
-
Object.keys(obj).forEach(key => {
|
|
91
|
-
const currentPath = path ? `${path}.${key}` : key;
|
|
92
|
-
if (obj[key] instanceof Object) {
|
|
93
|
-
iterateObject(obj[key], currentPath);
|
|
94
|
-
} else {
|
|
95
|
-
vars.push(obj[key]);
|
|
96
|
-
paths.push(currentPath);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// go through data and put it into an array
|
|
102
|
-
const dataArray = Object.values(data);
|
|
103
|
-
dataKeys = Object.keys(data);
|
|
104
|
-
iterateObject(dataArray);
|
|
105
|
-
return [vars, paths, dataKeys];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// worker on message definition
|
|
109
|
-
self.onmessage = async event => {
|
|
110
|
-
const message = event.data;
|
|
111
|
-
switch (message.type) {
|
|
112
|
-
case "init":
|
|
113
|
-
// load the model and reset the embedding dict
|
|
114
|
-
embedding_dict = {};
|
|
115
|
-
embedder = await (0, _transformers.pipeline)("feature-extraction", message.model, {
|
|
116
|
-
progress_callback: progress => {
|
|
117
|
-
self.postMessage({
|
|
118
|
-
type: "progress",
|
|
119
|
-
progress: progress
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
break;
|
|
124
|
-
case "corpus":
|
|
125
|
-
{
|
|
126
|
-
// embed the corpus or load the embeddings
|
|
127
|
-
readJsonFile(message.kgdoc); // this is so we can later match variables to tupletools
|
|
128
|
-
|
|
129
|
-
Object.keys(message.emb).forEach(key => {
|
|
130
|
-
let embarr = [];
|
|
131
|
-
for (const fl of message.emb[key].split(",")) {
|
|
132
|
-
embarr.push(fl.replace("[", "").replace("]", "").replace("np.float32", "").replace("(", "").replace(")", "").replace(" ", ""));
|
|
133
|
-
}
|
|
134
|
-
embedding_dict[key] = embarr;
|
|
135
|
-
});
|
|
136
|
-
self.postMessage({
|
|
137
|
-
type: "corpus"
|
|
138
|
-
});
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
case "similarity":
|
|
142
|
-
{
|
|
143
|
-
//calculate query embedding and then calculate similarity
|
|
144
|
-
query_embedding = await embed(message.query, false);
|
|
145
|
-
let sim_dict = {};
|
|
146
|
-
Object.keys(embedding_dict).forEach(key => {
|
|
147
|
-
sim_dict[key] = calcCosSim(embedding_dict[key], query_embedding);
|
|
148
|
-
});
|
|
149
|
-
// sort by highest similarity (closest to 1)
|
|
150
|
-
const sortedSimDict = Object.fromEntries(Object.entries(sim_dict).sort((_ref, _ref2) => {
|
|
151
|
-
let [, a] = _ref;
|
|
152
|
-
let [, b] = _ref2;
|
|
153
|
-
return b - a;
|
|
154
|
-
}));
|
|
155
|
-
const top5 = Object.fromEntries(Object.entries(sortedSimDict).slice(0, 20));
|
|
156
|
-
let loki_result = [];
|
|
157
|
-
let ttool_result = [];
|
|
158
|
-
let result = {
|
|
159
|
-
loki: loki_result,
|
|
160
|
-
ttool: ttool_result
|
|
161
|
-
};
|
|
162
|
-
Object.keys(top5).forEach(key => {
|
|
163
|
-
if (key === "basic,charged: : ") {
|
|
164
|
-
return;
|
|
165
|
-
} // This is a workaround until we implement a fix in Analysis (and corresponding DaVinci release)
|
|
166
|
-
let description = key.substring(key.indexOf(":") + 2);
|
|
167
|
-
let variable = key.substring(0, key.indexOf(":") - 1);
|
|
168
|
-
let varpath = paths[vars.indexOf(description)];
|
|
169
|
-
let tupletool = dataKeys[varpath.split(".")[0]];
|
|
170
|
-
if (tupletool === "LoKi_functors") {
|
|
171
|
-
if (top5[key] > 0.86) {
|
|
172
|
-
if (loki_result.length < 5) {
|
|
173
|
-
loki_result.push([description, variable, tupletool]);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
if (top5[key] > 0.75) {
|
|
178
|
-
if (ttool_result.length < 5) {
|
|
179
|
-
ttool_result.push([description, variable, tupletool]);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
if (loki_result.length === 0) {
|
|
185
|
-
loki_result.push(["No matches found", "No matches found", "No matches found"]);
|
|
186
|
-
}
|
|
187
|
-
if (ttool_result.length === 0) {
|
|
188
|
-
ttool_result.push(["No matches found", "No matches found", "No matches found"]);
|
|
189
|
-
}
|
|
190
|
-
self.postMessage({
|
|
191
|
-
type: "result",
|
|
192
|
-
result: result
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|