lhcb-ntuple-wizard-test 1.2.1 → 1.3.0

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.
@@ -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"));
@@ -271,9 +270,7 @@ class ParticleConfig extends _react.default.Component {
271
270
  };
272
271
  const inputBox = type.match(list_re) !== null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigList.default, _objectSpread({
273
272
  type: type.match(list_re)[1]
274
- }, configProps)) : type.match(dict_re) !== null ? selectedTool.includes("LoKi__Hybrid__") ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiDict.default, _objectSpread({
275
- lokiVars: this.context.metadata.lokiVariables
276
- }, configProps)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigDict.default, _objectSpread({
273
+ }, configProps)) : type.match(dict_re) !== null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigDict.default, _objectSpread({
277
274
  keyType: type.match(dict_re)[1],
278
275
  valType: type.match(dict_re)[2]
279
276
  }, configProps)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigValue.default, _objectSpread({
@@ -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
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -382,9 +381,6 @@ class DecayTree extends _react.default.Component {
382
381
  })
383
382
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card.Title, {
384
383
  children: ["Current selection: ", selectedName]
385
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Card.Title, {
386
- className: "d-flex justify-content-between align-items-center flex-column",
387
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_semform.default, {})
388
384
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfigNode.default, {
389
385
  dtt: this.state.dtt,
390
386
  particleID: selection,
@@ -188,9 +188,8 @@ class LinesTable extends _react.default.Component {
188
188
  const index = this.state.rows.findIndex(item => item.id === id); // All choices have the same value (row.id)
189
189
 
190
190
  if (choices.length > 1) {
191
- if (!confirm("Choosing multiple stripping lines... This can result in duplication of candidates within a given event! Are you sure you want to continue?")) {
192
- choices.pop();
193
- }
191
+ alert("Choosing multiple stripping lines per row can result in duplication of candidates within a given event and is therefore forbidden. To choose a different stripping line, remove the current selection.");
192
+ choices.pop();
194
193
  }
195
194
  rows[index].lines = choices.map(choice => Object({
196
195
  stream: choice.group,
@@ -311,10 +310,6 @@ class LinesTable extends _react.default.Component {
311
310
  _defineProperty(this, "createInfoYaml", () => {
312
311
  const rows = [...this.state.rows];
313
312
  const uniquePaths = new Set([].concat(...rows.map(row => row.paths)));
314
- let email = this.state.contactEmail;
315
- if (this.state.emailIsKnown) {
316
- email = [localStorage.getItem("email")] || [];
317
- }
318
313
  const uniquePathList = [...uniquePaths].sort();
319
314
  let info = {
320
315
  defaults: {
@@ -322,7 +317,6 @@ class LinesTable extends _react.default.Component {
322
317
  wg: "OpenData",
323
318
  // TODO: get input from (LHCb) user. keep "OpenData" if open data
324
319
  automatically_configure: true,
325
- inform: email,
326
320
  output: "DVNtuple.root" // Probably okay to leave this as the default
327
321
  }
328
322
  };
@@ -415,7 +409,6 @@ class LinesTable extends _react.default.Component {
415
409
  }
416
410
  });
417
411
  } else {
418
- email.push(config.defaults.inform[0]);
419
412
  rows.forEach(row => {
420
413
  Object.keys(config).forEach(job => {
421
414
  if (job !== "defaults" && job !== "name" && job !== "blob") {
package/dist/config.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "metadata_baseurl": "https://lbwizard-metadata.web.cern.ch/3.0.1/",
2
+ "metadata_baseurl": "https://lbwizard-metadata.web.cern.ch/3.1.0/",
3
3
  "metadata_files": {
4
4
  "particleProperties": "particle_properties",
5
5
  "lokiVariables": "loki",
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _reactDom = _interopRequireDefault(require("react-dom"));
3
+ var _client = require("react-dom/client");
4
4
  var _App = _interopRequireDefault(require("./components/App"));
5
5
  var _jsxRuntime = require("react/jsx-runtime");
6
6
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -15,4 +15,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
15
15
  * or submit itself to any jurisdiction. *
16
16
  \*****************************************************************************/
17
17
 
18
- _reactDom.default.render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_App.default, {}), document.getElementById("root"));
18
+ const container = document.getElementById("root");
19
+ const root = (0, _client.createRoot)(container);
20
+ root.render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_App.default, {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lhcb-ntuple-wizard-test",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
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,48 +10,25 @@
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
- "@vitejs/plugin-react": "^4.2.1",
20
- "bootstrap": "^5.1.3",
21
- "email-validator": "^2.0.4",
22
- "js-yaml": "^4.1.0",
23
- "jszip": "^3.7.1",
24
- "lodash": "^4.17.21",
25
- "lodash.memoize": "^4.1.2",
26
- "mathjax-react": "^2.0.1",
27
- "pako": "^2.1.0",
28
- "react": "^17.0.2",
29
- "react-bootstrap": "^2.0.3",
30
- "react-bootstrap-icons": "^1.6.1",
31
- "react-dom": "^17.0.2",
32
- "react-app-polyfill": "^3.0.0",
33
- "react-dev-utils": "^12.0.1",
34
- "react-graph-vis": "^1.0.7",
35
- "react-infinite-scroll-component": "^6.1.0",
36
- "react-router-dom": "^5.2.0",
37
- "react-select": "^4.3.1",
38
- "react-overlays": "5.2.1",
39
- "@mui/material": "latest",
40
- "@emotion/react": "latest",
41
- "@emotion/styled": "latest",
42
- "@mui/joy": "latest",
43
- "@avcs/autosuggest": "latest",
44
- "@webscopeio/react-textarea-autocomplete": "^4.9.2",
45
- "@monaco-editor/react": "^4.6.0",
46
- "monaco-editor-nls": "^3.1.0",
47
- "monaco-editor": "^0.44.0",
48
- "monaco-editor-core": "^0.44.0",
49
- "monaco-languageclient": "0.13.1-next.9",
50
- "react-monaco-editor": "^0.55.0",
51
- "monaco-editor-webpack-plugin": "^7.1.0",
52
- "vite": "^5.1.1",
53
- "@xenova/transformers": "^2.16.1",
54
- "web-vitals": "^2.1.4"
14
+ "@vitejs/plugin-react": "5.0.3",
15
+ "bootstrap": "5.3.8",
16
+ "email-validator": "2.0.4",
17
+ "js-yaml": "4.1.0",
18
+ "jszip": "3.10.1",
19
+ "lodash": "4.17.21",
20
+ "lodash.memoize": "4.1.2",
21
+ "mathjax-react": "2.0.1",
22
+ "pako": "2.1.0",
23
+ "react": "18.3.1",
24
+ "react-bootstrap": "2.10.10",
25
+ "react-bootstrap-icons": "1.11.6",
26
+ "react-dom": "18.3.1",
27
+ "react-graph-vis": "1.0.7",
28
+ "react-infinite-scroll-component": "6.1.0",
29
+ "react-router-dom": "5.3.4",
30
+ "react-select": "5.10.2",
31
+ "vite": "7.1.7"
55
32
  },
56
33
  "overrides": {
57
34
  "autoprefixer": "10.4.5"
@@ -81,9 +58,12 @@
81
58
  "last 1 safari version"
82
59
  ]
83
60
  },
61
+ "engines": {
62
+ "node": ">=22.16.0"
63
+ },
84
64
  "devDependencies": {
85
- "@babel/cli": "^7.21.0",
86
- "@babel/preset-env": "^7.21.4",
87
- "@babel/preset-react": "^7.18.6"
65
+ "@babel/cli": "7.28.3",
66
+ "@babel/preset-env": "7.28.3",
67
+ "@babel/preset-react": "7.27.1"
88
68
  }
89
69
  }
@@ -1,184 +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
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
18
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*****************************************************************************\
19
- * (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
20
- * *
21
- * This software is distributed under the terms of the GNU General Public *
22
- * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
23
- * *
24
- * In applying this licence, CERN does not waive the privileges and immunities *
25
- * granted to it by virtue of its status as an Intergovernmental Organization *
26
- * or submit itself to any jurisdiction. *
27
- \*****************************************************************************/
28
- class LokiDict extends _react.default.Component {
29
- constructor() {
30
- super(...arguments);
31
- _defineProperty(this, "state", {
32
- lines: this.props.value,
33
- error: "",
34
- add: false,
35
- currentKey: "",
36
- currentValue: ""
37
- });
38
- _defineProperty(this, "handleClose", () => {
39
- this.setState({
40
- add: false
41
- });
42
- });
43
- _defineProperty(this, "handleAdd", () => {
44
- var lines = this.state.lines;
45
- const key = this.state.currentKey;
46
- const value = this.state.currentValue;
47
- lines[key] = value;
48
- this.setState({
49
- lines: lines
50
- });
51
- this.setState({
52
- currentKey: ""
53
- });
54
- this.setState({
55
- currentValue: ""
56
- });
57
- this.props.callback(this.state.lines);
58
- });
59
- _defineProperty(this, "handleRemove", key => {
60
- var lines = this.state.lines;
61
- delete lines[key];
62
- this.setState({
63
- lines: lines
64
- });
65
- this.props.callback(this.state.lines);
66
- });
67
- _defineProperty(this, "setValueByKey", (key, value) => {
68
- var lines = this.state.lines;
69
- lines[key] = value;
70
- this.setState({
71
- lines: lines
72
- });
73
- this.props.callback(this.state.lines);
74
- });
75
- _defineProperty(this, "setAddLine", () => {
76
- this.setState({
77
- add: true
78
- });
79
- });
80
- _defineProperty(this, "changeKey", value => {
81
- this.setState({
82
- currentKey: value
83
- });
84
- });
85
- _defineProperty(this, "validKey", value => {
86
- if (value in this.state.lines) {
87
- return false;
88
- }
89
- return true;
90
- });
91
- _defineProperty(this, "changeValue", value => {
92
- this.setState({
93
- currentValue: value
94
- });
95
- });
96
- }
97
- render() {
98
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card, {
99
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Card.Header, {
100
- className: "d-flex justify-content-between align-items-start",
101
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Card.Title, {
102
- children: "Loki Lines"
103
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
104
- variant: "success",
105
- size: "sm",
106
- onClick: this.setAddLine,
107
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrapIcons.PlusLg, {})
108
- })]
109
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup, {
110
- variant: "flush",
111
- children: Object.keys(this.state.lines).map(key => {
112
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup.Item, {
113
- className: "d-flex justify-content-between align-items-start",
114
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
115
- container: true,
116
- spacing: 1,
117
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
118
- className: "d-flex",
119
- item: true,
120
- form: "maincomponent",
121
- xs: true,
122
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
123
- children: [key, ": "]
124
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiEditor.default, {
125
- callback: value => {
126
- this.setValueByKey(key, value);
127
- },
128
- value: this.state.lines[key],
129
- lokiVars: this.props.lokiVars,
130
- oneLine: true,
131
- height: "24px",
132
- width: "40dvw"
133
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
134
- variant: "danger",
135
- size: "sm",
136
- onClick: () => this.handleRemove(key),
137
- children: "Remove"
138
- })]
139
- })
140
- })
141
- }, key);
142
- })
143
- }), this.state.add ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal, {
144
- show: true,
145
- onHide: this.handleClose,
146
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Header, {
147
- closeButton: true,
148
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Title, {
149
- children: "Add Dict Item"
150
- })
151
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Body, {
152
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiForm.default, {
153
- value: "",
154
- keyCallback: this.changeKey,
155
- valueCallback: this.changeValue,
156
- lokiVars: this.props.lokiVars,
157
- validateKey: this.validKey
158
- }, "")
159
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal.Footer, {
160
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
161
- variant: "secondary",
162
- onClick: this.handleClose,
163
- children: "Close"
164
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
165
- variant: "primary",
166
- onClick: () => {
167
- this.handleAdd();
168
- this.handleClose();
169
- },
170
- disabled: this.state.currentKey === "" || this.state.currentValue === "" || !this.validKey(this.state.currentKey),
171
- children: "Save Changes"
172
- })]
173
- })]
174
- }) : ""]
175
- });
176
- }
177
- }
178
- LokiDict.propTypes = {
179
- callback: _propTypes.default.func,
180
- defaulValue: _propTypes.default.string,
181
- value: _propTypes.default.object,
182
- lokiVars: _propTypes.default.object
183
- };
184
- var _default = exports.default = LokiDict;
@@ -1,199 +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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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
- // import { monaco } from 'react-monaco-editor';
28
-
29
- _react2.loader.config({
30
- monaco
31
- });
32
- let LokiData = {};
33
- function createDependencyProposals(range) {
34
- // returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
35
- // here you could do a server side lookup
36
- let listOfFunctors = [];
37
- Object.keys(LokiData).forEach((key, _index) => {
38
- listOfFunctors.push({
39
- label: key,
40
- kind: monaco.languages.CompletionItemKind.Function,
41
- documentation: LokiData[key].description,
42
- insertText: key,
43
- range: range
44
- });
45
- });
46
- return listOfFunctors;
47
- }
48
- _react2.loader.init().then(monaco => {
49
- monaco.languages.registerCompletionItemProvider("python", {
50
- provideCompletionItems: function (model, position) {
51
- var word = model.getWordUntilPosition(position);
52
- var range = {
53
- startLineNumber: position.lineNumber,
54
- endLineNumber: position.lineNumber,
55
- startColumn: word.startColumn,
56
- endColumn: word.endColumn
57
- };
58
- return {
59
- suggestions: createDependencyProposals(range)
60
- };
61
- }
62
- });
63
- monaco.languages.registerHoverProvider("python", {
64
- provideHover: function (model, position) {
65
- let hoverObjects = [];
66
- let matches = Object.keys(LokiData).filter(name => {
67
- return model.findMatches(name, false, false, true, " (:,)*").length !== 0;
68
- });
69
- if (matches.length > 0) {
70
- matches.forEach(match => model.findMatches(match, false, false, true).forEach(range => hoverObjects.push({
71
- match: match,
72
- position: position,
73
- range: range,
74
- contents: [{
75
- supportHtml: true,
76
- value: LokiData[match].documentation
77
- }]
78
- })));
79
- for (const element of hoverObjects) {
80
- if (contains(element.range, position)) {
81
- // alert(element.contents[0].value)
82
- return element;
83
- }
84
- }
85
- }
86
- return {
87
- range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
88
- contents: [{
89
- supportHtml: true,
90
- value: '<span style="color red;">No matches</span>',
91
- isTrusted: true
92
- }]
93
- };
94
- }
95
- });
96
- });
97
- function contains(range, position) {
98
- if (range.range.startLineNumber <= position.lineNumber && range.range.endLineNumber >= position.lineNumber) {
99
- if (range.range.startColumn <= position.column && range.range.endColumn >= position.column) {
100
- return true;
101
- }
102
- }
103
- return false;
104
- }
105
- class LokiEditor extends _react.default.Component {
106
- constructor(props) {
107
- super(props);
108
- this.state = {
109
- code: this.props.returnList ? this.props.value.join("\n") : this.props.value,
110
- loaded: true
111
- };
112
- }
113
- editorDidMount(editor, _monaco) {
114
- editor.focus();
115
- }
116
- onChange(newValue, _e) {
117
- if (this.props.oneLine) {
118
- newValue = newValue.replace(/[\n\r]/g, "");
119
- }
120
- this.setState({
121
- code: newValue
122
- });
123
- if (this.props.returnList) {
124
- newValue = newValue.split(/\r?\n/);
125
- }
126
- this.props.callback(newValue);
127
- }
128
- render() {
129
- const code = this.state.code;
130
- const lokiVars = this.props.lokiVars.lokiVariables;
131
- Object.keys(lokiVars).forEach(key => {
132
- LokiData[key] = lokiVars[key];
133
- });
134
- const options = {
135
- autoIndent: "full",
136
- contextmenu: false,
137
- fontFamily: "monospace",
138
- fontSize: 18,
139
- lineHeight: 24,
140
- hideCursorInOverviewRuler: true,
141
- matchBrackets: "always",
142
- lineNumbers: "off",
143
- lineDecorationsWidth: 0,
144
- lineNumbersMinChars: 0,
145
- glyphMargin: false,
146
- wordWrap: "on",
147
- minimap: {
148
- enabled: false
149
- },
150
- scrollbar: {
151
- horizontal: "hidden",
152
- vertical: "hidden",
153
- horizontalSliderSize: 0,
154
- verticalSliderSize: 0,
155
- horizontalScrollbarSize: 0,
156
- verticalScrollbarSize: 0
157
- },
158
- scrollBeyondLastLine: false,
159
- selectOnLineNumbers: true,
160
- roundedSelection: false,
161
- readOnly: false,
162
- cursorStyle: "line",
163
- automaticLayout: true,
164
- fixedOverflowWidgets: true,
165
- links: true
166
- };
167
- return this.state.loaded ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactMonacoEditor.default, {
168
- width: this.props.width,
169
- height: this.props.height,
170
- language: "python",
171
- theme: "vs-light",
172
- value: code,
173
- options: options,
174
- onChange: this.onChange.bind(this),
175
- editorDidMount: this.editorDidMount.bind(this)
176
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {
177
- animation: "border",
178
- role: "status"
179
- });
180
- }
181
- }
182
- LokiEditor.defaultProps = {
183
- value: "",
184
- oneLine: false,
185
- width: "30vh",
186
- height: "10vh",
187
- returnList: false
188
- };
189
- LokiEditor.propTypes = {
190
- callback: _propTypes.default.func,
191
- value: _propTypes.default.string,
192
- defaultValue: _propTypes.default.string,
193
- lokiVars: _propTypes.default.object,
194
- oneLine: _propTypes.default.bool,
195
- height: _propTypes.default.string,
196
- width: _propTypes.default.string,
197
- returnList: _propTypes.default.bool
198
- };
199
- var _default = exports.default = LokiEditor;
@@ -1,116 +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
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
15
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
16
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*****************************************************************************\
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
- class LokiForm extends _react.default.Component {
27
- constructor() {
28
- super(...arguments);
29
- _defineProperty(this, "state", {
30
- key: this.props.key,
31
- value: this.props.value,
32
- err: false,
33
- errMsg: ""
34
- });
35
- _defineProperty(this, "keyCallback", event => {
36
- const key = event.target.value.replaceAll(/[^\w]/g, "");
37
- if (!this.props.validateKey(key)) {
38
- this.setState({
39
- err: true,
40
- errMsg: "Key must be unique and not empty!"
41
- });
42
- } else {
43
- this.setState({
44
- err: false,
45
- errMsg: ""
46
- });
47
- }
48
- this.setState({
49
- key: key
50
- });
51
- this.props.keyCallback(key);
52
- });
53
- _defineProperty(this, "valueCallback", value => {
54
- this.setState({
55
- value: value
56
- });
57
- this.props.valueCallback(value);
58
- });
59
- }
60
- render() {
61
- const errorMessage = this.state.err ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Alert, {
62
- variant: "danger",
63
- children: this.state.errMsg
64
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
65
- const margin = {
66
- "margin-left": "7px"
67
- };
68
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.InputGroup, {
69
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
70
- container: true,
71
- spacing: 1,
72
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
73
- className: "d-flex",
74
- item: true,
75
- form: "maincomponent",
76
- xs: true,
77
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
78
- children: [errorMessage, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.FormControl, {
79
- placeholder: "Varibale Name",
80
- onChange: this.keyCallback,
81
- value: this.state.key
82
- })]
83
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
84
- style: margin,
85
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LokiEditor.default, {
86
- callback: this.valueCallback,
87
- value: this.state.value,
88
- lokiVars: this.props.lokiVars,
89
- oneLine: true,
90
- height: "24px",
91
- width: "10dvw"
92
- })
93
- })]
94
- })
95
- })
96
- });
97
- }
98
- }
99
- LokiForm.defaultProps = {
100
- key: "",
101
- value: "",
102
- validateKey: () => {
103
- true;
104
- },
105
- lokiActive: true
106
- };
107
- LokiForm.propTypes = {
108
- key: _propTypes.default.string,
109
- value: _propTypes.default.string,
110
- keyCallback: _propTypes.default.func,
111
- valueCallback: _propTypes.default.func,
112
- validateKey: _propTypes.default.func,
113
- lokiVars: _propTypes.default.object,
114
- lokiActive: _propTypes.default.bool
115
- };
116
- var _default = exports.default = LokiForm;
@@ -1,97 +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", 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
- }
@@ -1,184 +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("./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
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*****************************************************************************\
21
- * (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration *
22
- * *
23
- * This software is distributed under the terms of the GNU General Public *
24
- * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
25
- * *
26
- * In applying this licence, CERN does not waive the privileges and immunities *
27
- * granted to it by virtue of its status as an Intergovernmental Organization *
28
- * or submit itself to any jurisdiction. *
29
- \*****************************************************************************/
30
- function getmetafromcontext() {
31
- const context = (0, _react.useContext)(_MetadataContext.default);
32
- return context;
33
- }
34
-
35
- /**
36
- * Make the output of the search more readable
37
- * @param {Array} data
38
- * @returns
39
- */
40
- function FormatOutput(_ref) {
41
- let {
42
- data
43
- } = _ref;
44
- let topchoice_ttool = [data.ttool[0]];
45
- let data_ttool = data.ttool.slice(1);
46
- let topchoice_loki = [data.loki[0]];
47
- let data_loki = data.loki.slice(1);
48
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
49
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
50
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
51
- children: "Best match (TupleTools):"
52
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
53
- children: topchoice_ttool.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
54
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
55
- children: "Matched TupleTool:"
56
- }), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
57
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
58
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
59
- children: "Variable name:"
60
- }), " ", item[1]]
61
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
62
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
63
- children: "Definition:"
64
- }), " ", item[0]]
65
- })]
66
- })]
67
- }, index))
68
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
69
- children: "Other matches (TupleTools):"
70
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
71
- children: data_ttool.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
72
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
73
- children: "Matched TupleTool:"
74
- }), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
75
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
76
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
77
- children: "Variable name:"
78
- }), " ", item[1]]
79
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
80
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
81
- children: "Definition:"
82
- }), " ", item[0]]
83
- })]
84
- })]
85
- }, index))
86
- })]
87
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
88
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
89
- children: "Best match (LoKi functors):"
90
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
91
- children: topchoice_loki.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
92
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
93
- children: "Matched TupleTool:"
94
- }), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
95
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
96
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
97
- children: "Variable name:"
98
- }), " ", item[1]]
99
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
100
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
101
- children: "Definition:"
102
- }), " ", item[0]]
103
- })]
104
- })]
105
- }, index))
106
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
107
- children: "Other matches (LoKi functors):"
108
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
109
- children: data_loki.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
110
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
111
- children: "Matched TupleTool:"
112
- }), " ", item[2] === "LoKi_functors" ? "LoKi__Hybrid__TupleTool" : item[2], /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
113
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
114
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
115
- children: "Variable name:"
116
- }), " ", item[1]]
117
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
118
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
119
- children: "Definition:"
120
- }), " ", item[0]]
121
- })]
122
- })]
123
- }, index))
124
- })]
125
- })]
126
- });
127
- }
128
- FormatOutput.propTypes = {
129
- data: _propTypes.default.objectOf(_propTypes.default.array).isRequired
130
- };
131
- const SearchTTool = () => {
132
- const [inputData, setInputData] = (0, _react.useState)({
133
- query: ""
134
- });
135
- const [responseData, setResponseData] = (0, _react.useState)(null);
136
- let metadata = getmetafromcontext();
137
- // Load the model and embed the corpus when the component mounts
138
- (0, _react.useMemo)(async () => {
139
- await (0, _semantic.loadModel)("TaylorAI/gte-tiny");
140
- await (0, _semantic.embedCorpus)(metadata);
141
- }, []);
142
- const handleChange = event => {
143
- setInputData(_objectSpread(_objectSpread({}, inputData), {}, {
144
- query: event.target.value
145
- }));
146
- };
147
- const handleSubmit = async event => {
148
- event.preventDefault();
149
- // clean input field
150
- setInputData({
151
- query: ""
152
- });
153
- let response = await (0, _semantic.getSimilarity)(inputData.query);
154
- setResponseData(response);
155
- };
156
- const handleDelete = () => {
157
- setResponseData(null);
158
- };
159
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Form.default, {
160
- onSubmit: handleSubmit,
161
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Form.default.Group, {
162
- controlId: "formQuery",
163
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Form.default.Label, {
164
- children: "Search for TupleTools"
165
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Form.default.Control, {
166
- type: "text",
167
- value: inputData.query,
168
- onChange: handleChange
169
- })]
170
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
171
- variant: "primary",
172
- type: "submit",
173
- children: "Submit"
174
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_DeleteButton.default, {
175
- disabled: !responseData,
176
- action: handleDelete
177
- }), responseData && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
178
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FormatOutput, {
179
- data: responseData
180
- })
181
- })]
182
- });
183
- };
184
- var _default = exports.default = SearchTTool;
@@ -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 ? "".concat(path, ".").concat(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
- };