diff --git a/app/static/css/queryBuilder.css b/app/static/css/queryBuilder.css index f48a4a64..31c13113 100644 --- a/app/static/css/queryBuilder.css +++ b/app/static/css/queryBuilder.css @@ -1,9 +1,6 @@ -#corpus-analysis-concordance-query-builder-input-field-container { - border-bottom: #9E9E9E 1px solid; - height: 60px; -} - #corpus-analysis-concordance-query-builder-input-field { + border-bottom: #9E9E9E 1px solid; + min-height: 38px; margin-top: 23px; } diff --git a/app/static/js/CorpusAnalysis/QueryBuilder.js b/app/static/js/CorpusAnalysis/QueryBuilder.js index 8d86c06b..c51bc4a5 100644 --- a/app/static/js/CorpusAnalysis/QueryBuilder.js +++ b/app/static/js/CorpusAnalysis/QueryBuilder.js @@ -23,7 +23,7 @@ class ConcordanceQueryBuilder { if (modalId === 'corpus-analysis-concordance-exactly-n-token-modal' || modalId === 'corpus-analysis-concordance-between-nm-token-modal') { button.addEventListener('click', () => this.generalFunctions.tokenNMSubmitHandler(modalId)); } else if (modalId === 'corpus-analysis-concordance-exactly-n-character-modal' || modalId === 'corpus-analysis-concordance-between-nm-character-modal') { - button.addEventListener('click', () => this.generalFunctions.characterNMSubmitHandler(modalId)); + button.addEventListener('click', () => this.tokenAttributeBuilderFunctions.characterNMSubmitHandler(modalId)); } }); diff --git a/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js b/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js index bfe4fa7b..d6e09303 100644 --- a/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js +++ b/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js @@ -9,6 +9,13 @@ class GeneralFunctionsQueryBuilder { }); } + resetQueryInputField() { + this.elements.queryInputField.innerHTML = ''; + this.addPlaceholder(); + this.updateChipList(); + this.queryPreviewBuilder(); + } + updateChipList() { this.elements.queryChipElements = this.elements.queryInputField.querySelectorAll('.query-component'); } @@ -210,7 +217,7 @@ class GeneralFunctionsQueryBuilder { let input_n = modal.querySelector('.n-m-input[data-value-type="n"]').value; let input_m = modal.querySelector('.n-m-input[data-value-type="m"]') || undefined; input_m = input_m !== undefined ? input_m.value : ''; - let input = `{${input_n},${input_m}}`; + let input = `{${input_n}${input_m !== '' ? ',' : ''}${input_m}}`; let pretty_input = `between ${input_n} and ${input_m} (${input})`; if (input_m === '') { pretty_input = `exactly ${input_n} (${input})`; @@ -220,7 +227,137 @@ class GeneralFunctionsQueryBuilder { instance.close(); this.tokenIncidenceModifierHandler(input, pretty_input); - } + + switchToExpertModeParser() { + let expertModeInputField = document.querySelector('#corpus-analysis-concordance-form-query'); + expertModeInputField.value = ''; + let queryBuilderInputFieldValue = Utils.unescape(document.querySelector('#corpus-analysis-concordance-query-preview').innerHTML.trim()); + if (queryBuilderInputFieldValue !== "") { + expertModeInputField.value = queryBuilderInputFieldValue; + } + } + + switchToQueryBuilderParser() { + this.resetQueryInputField(); + let expertModeInputFieldValue = document.querySelector('#corpus-analysis-concordance-form-query').value; + let chipElements = this.parseTextToChip(expertModeInputFieldValue); + for (let chipElement of chipElements) { + this.queryChipFactory(chipElement['type'], chipElement['pretty'], chipElement['query']); + } + } + + parseTextToChip(query) { + const parsingElementDict = { + '': { + pretty: 'Sentence Start', + type: 'start-sentence' + }, + '<\/s>': { + pretty: 'Sentence End', + type: 'end-sentence' + }, + '': { + pretty: 'Entity Start', + type: 'start-empty-entity' + }, + '': { + pretty: '', + type: 'start-entity' + }, + '<\\\/ent(_type)?>': { + pretty: 'Entity End', + type: 'end-entity' + }, + ':: ?match\\.text_[A-Za-z]+="[^"]+"': { + pretty: '', + type: 'text-annotation' + }, + '\\[(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?((\\&|\\|) ?(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?)*\\]': { + pretty: '', + type: 'token' + }, + '\\[\\]': { + pretty: 'Empty Token', + type: 'token' + }, + '(?|<\/s>|||<\\\/ent(_type)?>|\\[(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?((\\&|\\|) ?(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?)*\\]|:: ?match\\.text_[A-Za-z]+="[^"]+"|(?': + prettyText = `Entity Type=${stringElement.replace(//g, '')}`; + break; + case ':: ?match\\.text_[A-Za-z]+="[^"]+"': + prettyText = stringElement.replace(/:: ?match\.text_|"|"/g, ''); + break; + case '\\[(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?((\\&|\\|) ?(word|lemma|pos|simple_pos)=(("[^"]+")|(\\u0027[^\\u0027]+\\u0027)) ?(%c)? ?)*\\]': + let doubleQuotes = /(word|lemma|pos|simple_pos)="[^"]+"/gi; + let singleQuotes = /(word|lemma|pos|simple_pos)='[^']+'/gi; + if (doubleQuotes.exec(stringElement)) { + prettyText = stringElement.replace(/^\[|\]$|"/g, ''); + } else if (singleQuotes.exec(stringElement)) { + prettyText = stringElement.replace(/^\[|\]$|'/g, ''); + } + prettyText = prettyText.replace(/\&/g, ' and ').replace(/\|/g, ' or '); + break; + case '(? const corpusAnalysisConcordance = new CorpusAnalysisConcordance(corpusAnalysisApp); + const concordanceQueryBuilder = new ConcordanceQueryBuilder(); let queryBuilderDisplay = document.getElementById("corpus-analysis-concordance-query-builder-display"); let expertModeDisplay = document.getElementById("corpus-analysis-concordance-expert-mode-display"); @@ -138,11 +139,12 @@ if (this.checked) { queryBuilderDisplay.classList.add("hide"); expertModeDisplay.classList.remove("hide"); + concordanceQueryBuilder.generalFunctions.switchToExpertModeParser(); } else { queryBuilderDisplay.classList.remove("hide"); expertModeDisplay.classList.add("hide"); + concordanceQueryBuilder.generalFunctions.switchToQueryBuilderParser(); } }); -{{ query_builder.scripts(id_prefix) }} {% endmacro %} diff --git a/app/templates/corpora/_analysis/query_builder/_expert_mode.html.j2 b/app/templates/corpora/_analysis/query_builder/_expert_mode.html.j2 index f0a1133e..7ebf4643 100644 --- a/app/templates/corpora/_analysis/query_builder/_expert_mode.html.j2 +++ b/app/templates/corpora/_analysis/query_builder/_expert_mode.html.j2 @@ -3,7 +3,7 @@
search - + help Corpus Query Language tutorial | diff --git a/app/templates/corpora/_analysis/query_builder/_query_builder.html.j2 b/app/templates/corpora/_analysis/query_builder/_query_builder.html.j2 index d6343e95..c4f63943 100644 --- a/app/templates/corpora/_analysis/query_builder/_query_builder.html.j2 +++ b/app/templates/corpora/_analysis/query_builder/_query_builder.html.j2 @@ -434,8 +434,8 @@
{% endmacro %} -{% macro scripts(id_prefix) %} +{# {% macro scripts(id_prefix) %} -{% endmacro %} +{% endmacro %} #}