From 3942694ef631536ad2c8cf3b5d05f20f9e8ab753 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Mon, 17 Feb 2025 17:46:46 +0300 Subject: [PATCH] Beauty --- src/api/i18n.js | 3 + src/components/CognateAnalysisModal/index.js | 128 ++++++------------- 2 files changed, 39 insertions(+), 92 deletions(-) diff --git a/src/api/i18n.js b/src/api/i18n.js index f6096efc..a58fd126 100644 --- a/src/api/i18n.js +++ b/src/api/i18n.js @@ -588,6 +588,9 @@ export const stringsToTranslate = [ "Naumova Alexandra Vladimirovna", "negation, negative", "Neologism", + "Neuro cognate multi-language suggestions", + "Neuro cognate suggestions", + "Neuro cognates computation", "neuter", "New organization", "New password", diff --git a/src/components/CognateAnalysisModal/index.js b/src/components/CognateAnalysisModal/index.js index 5faddb43..85283dde 100644 --- a/src/components/CognateAnalysisModal/index.js +++ b/src/components/CognateAnalysisModal/index.js @@ -2422,90 +2422,31 @@ class CognateAnalysisModal extends React.Component { return; } - this.props.client.query({ - query: wordsQuery, - variables: { - perspectiveId, - xcriptFldId: info[2], - xlatFldId: info[3] - } - }).then(({ data: { words }}) => { - - // We are going to get predictions for a group at once - // So we don't have to wait for all the process completion, - // and we don't have to initialize prediction model for every single word + this.setState({ computing: true }) - const groups = []; - const group_size = words.length; //4 - - for (let i = 0; i < words.length; i += group_size) { - groups.push(words.slice(i, i + group_size)); + computeNeuroCognateAnalysis({ + variables: { + matchTranslations: this.state.matchTranslationsFlag, + sourcePerspectiveId: perspectiveId, + baseLanguageId: this.baseLanguageId, + truthThreshold, + perspectiveInfoList } - - const start = Date.now(); - const total = groups.length; - - // Initialize states for new process - this.setState( - { - computing: start, - result: null, - estimate: null, - suggestion_list: null, - sg_select_list: null, - sg_state_list: null, - sg_count: null, - sg_entry_map: null, - dictionary_count: 0, - transcription_count: 0, - total - }, - // Running after setstate - async () => { - for (const [done, pairs] of groups.entries()) { - this.setState({ done }); - - const { data, error } = await computeNeuroCognateAnalysis({ - variables: { - inputPairs: pairs, - matchTranslations: this.state.matchTranslationsFlag, - sourcePerspectiveId: perspectiveId, - baseLanguageId: this.baseLanguageId, - truthThreshold, - perspectiveInfoList - } - }); - - // On Stop button click - if (!this.state.computing) { - console.log("Killed!"); - return; - } - - if (error) { - this.handleError(error); - return; - } - - // If any troubles in response - if (!this.handleNeuroResult(data)) { - this.setState({ computing: false }); - return; - } - - const duration = (Date.now() - start) / 1000; - const estimate = duration / (done + 1) * total - duration; - const days = Math.trunc(estimate / 86400); - const hours = Math.trunc((estimate - days * 86400) / 3600); - const minutes = Math.round((estimate - days * 86400 - hours * 3600) / 60); - - this.setState({ estimate: `${days}d:${hours}h:${minutes}m` }); - } - - this.setState({ computing: false }); + }).then( + ({ data: {neuro_cognate_analysis: {triumph, message} }}) => { + if (triumph) { + window.logger.suc(this.context("Neuro cognate analysis is launched. Please check out tasks for details.")); + this.props.closeModal(); + } else { + window.logger.err(message); } - ); - }); + this.setState({ computing: false }); + }, + () => { + window.logger.err(this.context("Failed to launch neuro cognate analysis!")); + this.setState({ computing: false }); + } + ); } else { @@ -3319,20 +3260,23 @@ class CognateAnalysisModal extends React.Component {
{this.state.dictionary_count}
{this.context("dictionaries")}
-
-
{this.state.group_count}
-
{this.context("cognate groups")}
-
{this.state.transcription_count}
{this.context("transcriptions analysed")}
- -
- {`${this.state.not_enough_count} ${this.context( - "cognate groups were excluded from the analysis due to not having lexical entries in at least two selected dictionaries" - )}.`} -
+ { mode !== "view_suggestions" && ( + <> +
+
{this.state.group_count}
+
{this.context("cognate groups")}
+
+
+ {`${this.state.not_enough_count} ${this.context( + "cognate groups were excluded from the analysis due to not having lexical entries in at least two selected dictionaries" + )}.`} +
+ + )}
@@ -3362,7 +3306,7 @@ class CognateAnalysisModal extends React.Component { )}
- {this.state.result.length <= 0 && ( + {this.state.result.length <= 0 && mode !== "view_suggestions" &&(
{this.context("No data for cognate analysis")}.