@orkg/scidquest 1.1.0 → 1.1.4

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.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/pdf.worker.min.mjs +28 -0
  3. package/dist/components/AI/AIConfigurationButton.d.ts +3 -0
  4. package/dist/components/AI/AIConfigurationDialog.d.ts +7 -0
  5. package/dist/components/TemplateQuestionaire/AIAssistantButton.d.ts +33 -0
  6. package/dist/components/TemplateQuestionaire/BufferedTextField.d.ts +19 -0
  7. package/dist/components/TemplateQuestionaire/FieldRow.d.ts +8 -0
  8. package/dist/components/TemplateQuestionaire/ImportDialog.d.ts +12 -0
  9. package/dist/components/TemplateQuestionaire/InfoTooltip.d.ts +7 -0
  10. package/dist/components/TemplateQuestionaire/InlineValidationFeedback.d.ts +8 -0
  11. package/dist/components/TemplateQuestionaire/NodeWrapper.d.ts +8 -0
  12. package/dist/components/TemplateQuestionaire/QuestionnaireAIHistoryDialog.d.ts +15 -0
  13. package/dist/components/TemplateQuestionaire/Questions/GroupQuestion.d.ts +30 -0
  14. package/dist/components/TemplateQuestionaire/Questions/MultiSelectQuestion.d.ts +31 -0
  15. package/dist/components/TemplateQuestionaire/Questions/QuestionRenderer.d.ts +32 -0
  16. package/dist/components/TemplateQuestionaire/Questions/RepeatGroupQuestion.d.ts +30 -0
  17. package/dist/components/TemplateQuestionaire/Questions/RepeatTextQuestion.d.ts +31 -0
  18. package/dist/components/TemplateQuestionaire/Questions/SelectQuestion.d.ts +31 -0
  19. package/dist/components/TemplateQuestionaire/Questions/TextQuestion.d.ts +32 -0
  20. package/dist/components/TemplateQuestionaire/SectionAccordion.d.ts +42 -0
  21. package/dist/components/TemplateQuestionaire/SuggestionBox.d.ts +30 -0
  22. package/dist/components/TemplateQuestionaire/TopSummaryBar.d.ts +43 -0
  23. package/dist/components/TemplateQuestionaire/ValidationStatusButton.d.ts +33 -0
  24. package/dist/context/QuestionnaireAIContext.d.ts +48 -0
  25. package/dist/hooks/useSuggestionGenerator.d.ts +30 -0
  26. package/dist/lib/adapter.d.ts +3 -0
  27. package/dist/lib/components/PDFUpload.d.ts +10 -0
  28. package/dist/lib/components/PdfViewer.d.ts +27 -0
  29. package/dist/lib/components/ResearchQuestionnaireApp.d.ts +32 -0
  30. package/dist/lib/components/ResearchQuestionnaireFieldAiWrapper.d.ts +25 -0
  31. package/dist/lib/components/TemplateQuestionnaire.d.ts +27 -0
  32. package/dist/lib/context.d.ts +14 -0
  33. package/dist/lib/hooks/useSuggestionGenerator.d.ts +26 -0
  34. package/dist/lib/index.d.ts +25 -0
  35. package/dist/lib/questionnaire-template-helpers.d.ts +10 -0
  36. package/dist/lib/research-questionnaire-workspace.d.ts +33 -0
  37. package/dist/lib/types.d.ts +121 -0
  38. package/dist/lib/utils/createLLMServiceFromAIService.d.ts +3 -0
  39. package/dist/scidquest.es.js +6441 -64432
  40. package/dist/semanticChunker-CNi7GgV8.js +84 -0
  41. package/dist/services/aiService.d.ts +39 -0
  42. package/dist/services/backendAIService.d.ts +191 -0
  43. package/dist/store/hooks.d.ts +4 -0
  44. package/dist/store/slices/aiSlice.d.ts +21 -0
  45. package/dist/store/store.d.ts +9 -0
  46. package/dist/types/context.d.ts +39 -0
  47. package/dist/utils/contextGatherer.d.ts +39 -0
  48. package/dist/utils/fuzzyPdfMatcher.d.ts +15 -0
  49. package/dist/utils/pdf.d.ts +25 -0
  50. package/dist/utils/pdfWorker.d.ts +10 -0
  51. package/dist/utils/robustPdfMatcher.d.ts +22 -0
  52. package/dist/utils/semanticChunker.d.ts +27 -0
  53. package/dist/utils/simplePdfMatcher.d.ts +13 -0
  54. package/dist/utils/structuredPdfExtractor.d.ts +34 -0
  55. package/dist/utils/suggestions.d.ts +88 -0
  56. package/dist/utils/theme.d.ts +6 -0
  57. package/dist/utils/tokenEstimator.d.ts +32 -0
  58. package/dist/utils/tokenPdfMatcher.d.ts +14 -0
  59. package/dist/utils/unicodeNormalizer.d.ts +13 -0
  60. package/dist/utils/validationRules.d.ts +51 -0
  61. package/package.json +30 -8
  62. package/dist/semanticChunker-CEckDeUn.js +0 -102
@@ -0,0 +1,6 @@
1
+ import { PaletteMode, ThemeOptions } from '@mui/material/styles';
2
+ declare const getDesignTokens: (mode: PaletteMode) => ThemeOptions;
3
+ declare const theme: import("@mui/material").Theme;
4
+ export declare const createAppTheme: (mode?: PaletteMode) => import("@mui/material").Theme;
5
+ export { getDesignTokens };
6
+ export default theme;
@@ -0,0 +1,32 @@
1
+ import type { ParentContext, SiblingContext, PreviousEntryContext, TokenLimits } from '../types/context';
2
+ export declare class TokenEstimator {
3
+ private tokenLimits;
4
+ constructor(tokenLimits?: Partial<TokenLimits>);
5
+ estimateTokens(text: string): number;
6
+ estimateParentContextTokens(parentContext: ParentContext): number;
7
+ estimateSiblingContextTokens(siblingContext: SiblingContext[]): number;
8
+ estimatePreviousEntryContextTokens(previousEntryContext: PreviousEntryContext[]): number;
9
+ calculateTotalTokens(contexts: {
10
+ parentContext?: ParentContext;
11
+ siblingContext?: SiblingContext[];
12
+ previousEntryContext?: PreviousEntryContext[];
13
+ }): {
14
+ parentTokens: number;
15
+ siblingTokens: number;
16
+ previousEntryTokens: number;
17
+ totalTokens: number;
18
+ };
19
+ checkLimits(contexts: {
20
+ parentContext?: ParentContext;
21
+ siblingContext?: SiblingContext[];
22
+ previousEntryContext?: PreviousEntryContext[];
23
+ }): {
24
+ parentExceeded: boolean;
25
+ siblingExceeded: boolean;
26
+ previousEntryExceeded: boolean;
27
+ anyExceeded: boolean;
28
+ };
29
+ getTokenLimits(): TokenLimits;
30
+ updateTokenLimits(limits: Partial<TokenLimits>): void;
31
+ }
32
+ export declare const tokenEstimator: TokenEstimator;
@@ -0,0 +1,14 @@
1
+ export interface TokenMatchResult {
2
+ found: boolean;
3
+ startIndex: number;
4
+ endIndex: number;
5
+ confidence: number;
6
+ matchedText: string;
7
+ skippedTokens: string[];
8
+ }
9
+ export declare function findTokenMatch(pdfText: string, searchText: string, options?: {
10
+ allowSkipReferences?: boolean;
11
+ minTokenMatch?: number;
12
+ maxSkippedTokens?: number;
13
+ }): TokenMatchResult;
14
+ export declare function stripReferences(text: string): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Unicode Normalization for PDF Text Matching
3
+ * Handles special characters that look the same but have different Unicode values
4
+ */
5
+ /**
6
+ * Normalize Unicode characters to their ASCII equivalents
7
+ */
8
+ export declare function normalizeUnicode(text: string): string;
9
+ export declare function aggressiveUnicodeNormalize(text: string): string;
10
+ export declare function debugUnicode(text: string): string;
11
+ export declare function unicodeEquals(str1: string, str2: string): boolean;
12
+ export declare function unicodeFindIndex(haystack: string, needle: string): number;
13
+ export declare function unicodeIncludes(haystack: string, needle: string): boolean;
@@ -0,0 +1,51 @@
1
+ export type ValidationRuleType = 'required' | 'format' | 'range' | 'custom' | 'minLength' | 'maxLength';
2
+ export type FormatType = 'email' | 'url' | 'date' | 'phone' | 'number';
3
+ export interface ValidationRule {
4
+ type: ValidationRuleType;
5
+ errorMessage?: string;
6
+ }
7
+ export interface RequiredRule extends ValidationRule {
8
+ type: 'required';
9
+ }
10
+ export interface FormatRule extends ValidationRule {
11
+ type: 'format';
12
+ format: FormatType;
13
+ pattern?: string;
14
+ }
15
+ export interface RangeRule extends ValidationRule {
16
+ type: 'range';
17
+ min?: number;
18
+ max?: number;
19
+ }
20
+ export interface MinLengthRule extends ValidationRule {
21
+ type: 'minLength';
22
+ value: number;
23
+ }
24
+ export interface MaxLengthRule extends ValidationRule {
25
+ type: 'maxLength';
26
+ value: number;
27
+ }
28
+ export interface CustomRule extends ValidationRule {
29
+ type: 'custom';
30
+ validator: (value: any) => boolean;
31
+ errorMessage: string;
32
+ }
33
+ export type AnyValidationRule = RequiredRule | FormatRule | RangeRule | MinLengthRule | MaxLengthRule | CustomRule;
34
+ export interface ValidationResult {
35
+ isValid: boolean;
36
+ error?: string;
37
+ }
38
+ export declare function executeValidationRule(value: any, rule: AnyValidationRule): ValidationResult;
39
+ export declare function validateValue(value: any, rules: AnyValidationRule[]): ValidationResult;
40
+ export declare function parseValidationRules(questionConfig: any): AnyValidationRule[];
41
+ export interface FieldValidationState {
42
+ isValid: boolean;
43
+ error?: string;
44
+ touched: boolean;
45
+ }
46
+ export interface ValidationState {
47
+ fields: Record<string, FieldValidationState>;
48
+ }
49
+ export declare function createValidationState(): ValidationState;
50
+ export declare function updateFieldValidation(state: ValidationState, fieldId: string, result: ValidationResult, touched?: boolean): ValidationState;
51
+ export declare function getFieldValidation(state: ValidationState, fieldId: string): FieldValidationState | undefined;
package/package.json CHANGED
@@ -1,27 +1,42 @@
1
1
  {
2
2
  "name": "@orkg/scidquest",
3
- "version": "1.1.0",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "SciD-QuESt: From Scientific Documents to Knowledge - Questionnaire-Based Extraction and Structuring of Knowledge in the Open Research Knowledge Graph with LLMs and Human Validation",
7
7
  "main": "./dist/scidquest.es.js",
8
8
  "module": "./dist/scidquest.es.js",
9
- "types": "./dist/index.d.ts",
9
+ "types": "./dist/lib/index.d.ts",
10
10
  "files": [
11
- "dist"
11
+ "dist/scidquest.es.js",
12
+ "dist/scidquest.css",
13
+ "dist/contribute-standalone.css",
14
+ "dist/semanticChunker*.js",
15
+ "dist/assets/logo.png",
16
+ "dist/assets/pdf.worker.min.mjs",
17
+ "dist/lib",
18
+ "dist/lib/index.d.ts",
19
+ "dist/components",
20
+ "dist/context",
21
+ "dist/store",
22
+ "dist/services",
23
+ "dist/utils",
24
+ "dist/types",
25
+ "dist/hooks"
12
26
  ],
13
27
  "exports": {
14
28
  ".": {
15
- "types": "./dist/index.d.ts",
29
+ "types": "./dist/lib/index.d.ts",
16
30
  "import": "./dist/scidquest.es.js",
17
31
  "default": "./dist/scidquest.es.js"
18
32
  },
19
33
  "./assets/logo.png": "./dist/assets/logo.png",
34
+ "./dist/scidquest.css": "./dist/scidquest.css",
20
35
  "./dist/contribute-standalone.css": "./dist/contribute-standalone.css"
21
36
  },
22
37
  "scripts": {
23
- "dev": "vite",
24
- "build": "tsc && vite build && node ./scripts/copy-logo.mjs && node ./scripts/copy-css.mjs",
38
+ "dev": "node ./scripts/copy-pdf-worker.mjs && vite",
39
+ "build": "vite build && tsc -p tsconfig.lib.json && node ./scripts/prune-dist-declarations.mjs && node ./scripts/copy-pdf-worker.mjs && node ./scripts/copy-logo.mjs && node ./scripts/copy-css.mjs",
25
40
  "preview": "vite preview",
26
41
  "prepublishOnly": "npm run build"
27
42
  },
@@ -30,7 +45,11 @@
30
45
  "@emotion/styled": "^11.14.0",
31
46
  "@mui/material": "^6.4.11",
32
47
  "react": "^18.3.1",
33
- "react-dom": "^18.3.1"
48
+ "react-dom": "^18.3.1",
49
+ "react-redux": "^9.2.0",
50
+ "@reduxjs/toolkit": "^2.8.2",
51
+ "pdfjs-dist": "5.4.296",
52
+ "react-pdf": "^10.3.0"
34
53
  },
35
54
  "dependencies": {
36
55
  "@ai-sdk/groq": "^1.2.9",
@@ -43,7 +62,7 @@
43
62
  "@mui/material": "^6.4.11",
44
63
  "@reduxjs/toolkit": "^2.8.2",
45
64
  "ai": "^5.0.86",
46
- "pdfjs-dist": "^5.4.296",
65
+ "pdfjs-dist": "5.4.296",
47
66
  "react": "^18.3.1",
48
67
  "react-dom": "^18.3.1",
49
68
  "react-pdf": "^10.3.0",
@@ -61,5 +80,8 @@
61
80
  },
62
81
  "publishConfig": {
63
82
  "access": "public"
83
+ },
84
+ "overrides": {
85
+ "pdfjs-dist": "5.4.296"
64
86
  }
65
87
  }
@@ -1,102 +0,0 @@
1
- var g = Object.defineProperty;
2
- var p = (a, e, n) => e in a ? g(a, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[e] = n;
3
- var u = (a, e, n) => p(a, typeof e != "symbol" ? e + "" : e, n);
4
- import { pipeline as k } from "@huggingface/transformers";
5
- class f {
6
- constructor() {
7
- u(this, "model", null);
8
- u(this, "modelLoading", null);
9
- }
10
- async initialize() {
11
- if (!this.model) {
12
- if (this.modelLoading) return this.modelLoading;
13
- console.log("[FrontendSemanticChunker] Initializing model..."), this.modelLoading = (async () => {
14
- try {
15
- this.model = await k(
16
- "feature-extraction",
17
- "Xenova/all-MiniLM-L6-v2",
18
- { dtype: "q8" }
19
- ), console.log("[FrontendSemanticChunker] Model loaded successfully");
20
- } catch (e) {
21
- throw console.error("[FrontendSemanticChunker] Model initialization failed:", e), this.modelLoading = null, e;
22
- }
23
- })(), await this.modelLoading;
24
- }
25
- }
26
- splitIntoChunks(e) {
27
- const n = [];
28
- for (const s of e) {
29
- if (!s.text || s.text.trim().length === 0) continue;
30
- const o = s.text.split(new RegExp("(?<=[.!?])(?=\\s)"));
31
- let t = "", r = 0;
32
- for (const h of o) {
33
- const m = h.trim();
34
- m && (t && t.length + m.length + 1 > 2e3 ? (n.push({
35
- text: t.trim(),
36
- pageNumber: s.pageNumber,
37
- startIndex: r,
38
- endIndex: r + t.length,
39
- tokenEstimate: Math.ceil(t.length / 4)
40
- }), t = t.trim().split(/\s+/).slice(-Math.ceil(400 / 5)).join(" ") + " " + m, r += t.length - 400) : t += (t ? " " : "") + m);
41
- }
42
- t.trim() && (n.push({
43
- text: t.trim(),
44
- pageNumber: s.pageNumber,
45
- startIndex: r,
46
- endIndex: r + t.length,
47
- tokenEstimate: Math.ceil(t.length / 4)
48
- }), t = "", r = 0);
49
- }
50
- return console.log(
51
- `[FrontendSemanticChunker] Total chunks: ${n.length}, Target size: 2000 chars`
52
- ), n;
53
- }
54
- async embed(e) {
55
- const n = await this.model(e, { pooling: "mean", normalize: !0 });
56
- return Array.from(n.data);
57
- }
58
- cosineSimilarity(e, n) {
59
- let c = 0, l = 0, s = 0;
60
- for (let o = 0; o < e.length; o++)
61
- c += e[o] * n[o], l += e[o] * e[o], s += n[o] * n[o];
62
- return c / (Math.sqrt(l) * Math.sqrt(s));
63
- }
64
- async findRelevantChunks(e, n, c = 4e3) {
65
- console.log(
66
- `[FrontendSemanticChunker] Finding relevant chunks for question (max ${c} tokens)`
67
- ), await this.initialize();
68
- const l = this.splitIntoChunks(n);
69
- console.log(
70
- `[FrontendSemanticChunker] Created ${l.length} chunks from ${n.length} pages`
71
- ), console.log("[FrontendSemanticChunker] Generating embeddings...");
72
- const s = await Promise.all(
73
- l.map((i) => this.embed(i.text))
74
- ), o = await this.embed(e), t = l.map((i, d) => ({
75
- ...i,
76
- similarity: this.cosineSimilarity(o, s[d])
77
- }));
78
- t.sort((i, d) => d.similarity - i.similarity), console.log(
79
- "[FrontendSemanticChunker] Top 5 similarity scores:",
80
- t.slice(0, 5).map((i) => `page ${i.pageNumber}: ${i.similarity.toFixed(4)}`)
81
- );
82
- const r = [];
83
- let h = 0;
84
- for (const i of t)
85
- h + i.tokenEstimate <= c && (r.push(i), h += i.tokenEstimate);
86
- console.log(
87
- `[FrontendSemanticChunker] Selected ${r.length} chunks (${h} tokens)`
88
- ), r.sort((i, d) => i.pageNumber - d.pageNumber);
89
- const m = Array.from(new Set(r.map((i) => i.pageNumber)));
90
- return console.log(
91
- "[FrontendSemanticChunker] Chunks span pages:",
92
- m.join(", ")
93
- ), r;
94
- }
95
- isInitialized() {
96
- return this.model !== null;
97
- }
98
- }
99
- const y = new f();
100
- export {
101
- y as frontendSemanticChunker
102
- };