From 16252b21457b3229f955386b20d1141558ae99d9 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:36:20 +0300 Subject: [PATCH] Improve derivation check algorithm --- rsconcept/frontend/src/models/rsformAPI.ts | 28 +++++++++++++++++-- .../frontend/src/models/rslangAPI.test.ts | 1 + .../ConstituentaToolbar.tsx | 2 +- .../EditorConstituenta/EditorConstituenta.tsx | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/rsconcept/frontend/src/models/rsformAPI.ts b/rsconcept/frontend/src/models/rsformAPI.ts index 05be1929..68010bca 100644 --- a/rsconcept/frontend/src/models/rsformAPI.ts +++ b/rsconcept/frontend/src/models/rsformAPI.ts @@ -53,6 +53,9 @@ export function loadRSFormData(input: IRSFormData): IRSForm { // Calculate derivation of constituents based on formal definition analysis result.graph.topologicalOrder().forEach(id => { const cst = result.items.find(item => item.id === id)!; + if (cst.cst_type === CstType.STRUCTURED) { + return; + } const resolvedInput: Set = new Set(); let definition = ''; if (!isFunctional(cst.cst_type)) { @@ -62,13 +65,34 @@ export function loadRSFormData(input: IRSFormData): IRSForm { } else { const expression = splitTemplateDefinition(cst.definition_formal); definition = expression.body; - const dependencies = extractGlobals(definition); - dependencies.forEach(alias => { + const bodyDependencies = extractGlobals(definition); + bodyDependencies.forEach(alias => { const targetCst = result.items.find(item => item.alias === alias); if (targetCst) { resolvedInput.add(derivationLookup.get(targetCst.id)!); } }); + const needCheckHead = () => { + if (resolvedInput.size === 0) { + return true; + } else if (resolvedInput.size !== 1) { + return false; + } else { + const base = result.items.find(item => item.id === resolvedInput.values().next().value)!; + return ( + !isFunctional(base.cst_type) || splitTemplateDefinition(base.definition_formal).head !== expression.head + ); + } + }; + if (needCheckHead()) { + const headDependencies = extractGlobals(expression.head); + headDependencies.forEach(alias => { + const targetCst = result.items.find(item => item.alias === alias); + if (targetCst && !isBaseSet(targetCst.cst_type)) { + resolvedInput.add(derivationLookup.get(targetCst.id)!); + } + }); + } } if (resolvedInput.size === 1 && isSimpleExpression(definition)) { const parent = result.items.find(item => item.id === resolvedInput.values().next().value)!; diff --git a/rsconcept/frontend/src/models/rslangAPI.test.ts b/rsconcept/frontend/src/models/rslangAPI.test.ts index d1e7a483..ab4282dd 100644 --- a/rsconcept/frontend/src/models/rslangAPI.test.ts +++ b/rsconcept/frontend/src/models/rslangAPI.test.ts @@ -22,6 +22,7 @@ const simpleExpressionData = [ ['ℬℬ(X1)', 'false'], ['ℬ(X1)', 'false'], ['D{(α,β)∈D6×D6 | α≠β & α∩β≠∅}', 'false'], + ['D{ξ ∈ X1 | (ξ,ξ)∈S1 }', 'false'], ['I{(β,α) | α:∈D2; σ:=F5[α]; β:∈σ}', 'false'], ['∀σ∈S1 (F1[σ]×F1[σ])∩D11=∅', 'false'] ]; diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ConstituentaToolbar.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ConstituentaToolbar.tsx index 4b253628..be560e5b 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ConstituentaToolbar.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ConstituentaToolbar.tsx @@ -29,7 +29,7 @@ function ConstituentaToolbar({ onCreate }: ConstituentaToolbarProps) { return ( - + } diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx index 11d42276..4ed2ef99 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx @@ -97,7 +97,7 @@ function EditorConstituenta({ activeCst, isModified, setIsModified, onOpenEdit } className={clsx( 'max-w-[95rem]', // prettier: split lines 'flex', - { 'flex-col items-center': isNarrow } + { 'flex-col md:items-center': isNarrow } )} onKeyDown={handleInput} >