Expert Mode - Query Builder Switch Parser v1

This commit is contained in:
Inga Kirschnick 2023-09-25 14:40:39 +02:00
parent b50147a66a
commit b8ae221987

View File

@ -233,7 +233,7 @@ class GeneralFunctionsQueryBuilder {
let expertModeInputField = document.querySelector('#corpus-analysis-concordance-form-query'); let expertModeInputField = document.querySelector('#corpus-analysis-concordance-form-query');
expertModeInputField.value = ''; expertModeInputField.value = '';
let queryBuilderInputFieldValue = Utils.unescape(document.querySelector('#corpus-analysis-concordance-query-preview').innerHTML.trim()); let queryBuilderInputFieldValue = Utils.unescape(document.querySelector('#corpus-analysis-concordance-query-preview').innerHTML.trim());
if (queryBuilderInputFieldValue !== "") { if (queryBuilderInputFieldValue !== "" && queryBuilderInputFieldValue !== ";") {
expertModeInputField.value = queryBuilderInputFieldValue; expertModeInputField.value = queryBuilderInputFieldValue;
} }
} }
@ -246,6 +246,7 @@ class GeneralFunctionsQueryBuilder {
this.queryChipFactory(chipElement['type'], chipElement['pretty'], chipElement['query']); this.queryChipFactory(chipElement['type'], chipElement['pretty'], chipElement['query']);
} }
} }
parseTextToChip(query) { parseTextToChip(query) {
const parsingElementDict = { const parsingElementDict = {
@ -301,12 +302,11 @@ class GeneralFunctionsQueryBuilder {
pretty: '', pretty: '',
type: 'token-incidence-modifier' type: 'token-incidence-modifier'
} }
} }
let chipElements = []; let chipElements = [];
let regexPattern = Object.keys(parsingElementDict).map(pattern => `(${pattern})`).join('|');
const regex = new RegExp(`<s>|<\/s>|<ent>|<ent_type="([A-Z]+)">|<\\\/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]+="[^"]+"|(?<!\\[) ?(\\+|\\?|\\*|{[0-9]+(,[0-9]+)?}) ?(?![^\\]]\\])`, 'gi'); const regex = new RegExp(regexPattern, 'gi');
let match; let match;
while ((match = regex.exec(query)) !== null) { while ((match = regex.exec(query)) !== null) {
@ -318,6 +318,7 @@ class GeneralFunctionsQueryBuilder {
for (let [pattern, chipElement] of Object.entries(parsingElementDict)) { for (let [pattern, chipElement] of Object.entries(parsingElementDict)) {
const parsingRegex = new RegExp(pattern, 'gi'); const parsingRegex = new RegExp(pattern, 'gi');
if (parsingRegex.exec(stringElement)) { if (parsingRegex.exec(stringElement)) {
// Creating the pretty text for the chip element
let prettyText; let prettyText;
switch (pattern) { switch (pattern) {
case '<ent_type="([A-Z]+)">': case '<ent_type="([A-Z]+)">':