Merge branch 'query-builder' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into query-builder

This commit is contained in:
Inga Kirschnick 2023-08-08 14:15:44 +02:00
commit dd04623278
7 changed files with 231 additions and 233 deletions

View File

@ -1,31 +1,30 @@
class CorpusAnalysisConcordance {
name = 'Concordance';
constructor(app) {
constructor(app, idPrefix) {
this.app = app;
this.data = {};
this.elements = {
// TODO: Prefix elements with "corpus-analysis-app-"
container: document.querySelector('#concordance-extension-container'),
error: document.querySelector('#concordance-extension-error'),
UIForm: document.querySelector('#concordance-extension-ui-form'),
form: document.querySelector('#concordance-extension-form'),
progress: document.querySelector('#concordance-extension-progress'),
subcorpusInfo: document.querySelector('#concordance-extension-subcorpus-info'),
subcorpusActions: document.querySelector('#concordance-extension-subcorpus-actions'),
subcorpusItems: document.querySelector('#concordance-extension-subcorpus-items'),
subcorpusList: document.querySelector('#concordance-extension-subcorpus-list'),
subcorpusPagination: document.querySelector('#concordance-extension-subcorpus-pagination')
container: document.querySelector(`#${idPrefix}-container`),
error: document.querySelector(`#${idPrefix}-error`),
userInterfaceForm: document.querySelector(`#${idPrefix}-user-interface-form`),
form: document.querySelector(`#${idPrefix}-form`),
progress: document.querySelector(`#${idPrefix}-progress`),
subcorpusInfo: document.querySelector(`#${idPrefix}-subcorpus-info`),
subcorpusActions: document.querySelector(`#${idPrefix}-subcorpus-actions`),
subcorpusItems: document.querySelector(`#${idPrefix}-subcorpus-items`),
subcorpusList: document.querySelector(`#${idPrefix}-subcorpus-list`),
subcorpusPagination: document.querySelector(`#${idPrefix}-subcorpus-pagination`)
};
this.settings = {
context: parseInt(this.elements.UIForm['context'].value),
perPage: parseInt(this.elements.UIForm['per-page'].value),
context: parseInt(this.elements.userInterfaceForm['context'].value),
perPage: parseInt(this.elements.userInterfaceForm['per-page'].value),
selectedSubcorpus: undefined,
textStyle: parseInt(this.elements.UIForm['text-style'].value),
tokenRepresentation: this.elements.UIForm['token-representation'].value
textStyle: parseInt(this.elements.userInterfaceForm['text-style'].value),
tokenRepresentation: this.elements.userInterfaceForm['token-representation'].value
};
this.app.registerExtension(this);
@ -77,21 +76,24 @@ class CorpusAnalysisConcordance {
event.preventDefault();
this.submitForm();
});
this.elements.UIForm.addEventListener('change', (event) => {
if (event.target === this.elements.UIForm['context']) {
this.settings.context = parseInt(this.elements.UIForm['context'].value);
this.elements.userInterfaceForm.addEventListener('change', (event) => {
if (event.target === this.elements.userInterfaceForm['context']) {
console.log(this.settings.context);
console.log(parseInt(this.elements.userInterfaceForm['context'].value));
this.settings.context = parseInt(this.elements.userInterfaceForm['context'].value);
console.log(this.settings.context);
this.submitForm();
}
if (event.target === this.elements.UIForm['per-page']) {
this.settings.perPage = parseInt(this.elements.UIForm['per-page'].value);
if (event.target === this.elements.userInterfaceForm['per-page']) {
this.settings.perPage = parseInt(this.elements.userInterfaceForm['per-page'].value);
this.submitForm();
}
if (event.target === this.elements.UIForm['text-style']) {
this.settings.textStyle = parseInt(this.elements.UIForm['text-style'].value);
if (event.target === this.elements.userInterfaceForm['text-style']) {
this.settings.textStyle = parseInt(this.elements.userInterfaceForm['text-style'].value);
this.setTextStyle();
}
if (event.target === this.elements.UIForm['token-representation']) {
this.settings.tokenRepresentation = this.elements.UIForm['token-representation'].value;
if (event.target === this.elements.userInterfaceForm['token-representation']) {
this.settings.tokenRepresentation = this.elements.userInterfaceForm['token-representation'].value;
this.setTokenRepresentation();
}
});
@ -379,7 +381,9 @@ class CorpusAnalysisConcordance {
document.getSelection().removeAllRanges();
document.getSelection().addRange(range);
});
this.app.elements.m.extensionTabs.select('reader-extension-container');
this.app.elements.m.extensionTabs.select(
this.app.extensions.Reader.elements.container.id
);
});
}
for (let selectTriggerElement of this.elements.subcorpusItems.querySelectorAll('.select-trigger')) {

View File

@ -1,25 +1,24 @@
class CorpusAnalysisReader {
name = 'Reader';
constructor(app) {
constructor(app, idPrefix) {
this.app = app;
this.data = {};
this.elements = {
// TODO: Prefix elements with "corpus-analysis-app-"
container: document.querySelector('#reader-extension-container'),
error: document.querySelector('#reader-extension-error'),
form: document.querySelector('#reader-extension-form'),
progress: document.querySelector('#reader-extension-progress'),
corpus: document.querySelector('#reader-extension-corpus'),
corpusPagination: document.querySelector('#reader-extension-corpus-pagination')
container: document.querySelector(`#${idPrefix}-container`),
corpus: document.querySelector(`#${idPrefix}-corpus`),
corpusPagination: document.querySelector(`#${idPrefix}-corpus-pagination`),
error: document.querySelector(`#${idPrefix}-error`),
progress: document.querySelector(`#${idPrefix}-progress`),
userInterfaceForm: document.querySelector(`#${idPrefix}-user-interface-form`)
};
this.settings = {
perPage: parseInt(this.elements.form['per-page'].value),
textStyle: parseInt(this.elements.form['text-style'].value),
tokenRepresentation: this.elements.form['token-representation'].value,
perPage: parseInt(this.elements.userInterfaceForm['per-page'].value),
textStyle: parseInt(this.elements.userInterfaceForm['text-style'].value),
tokenRepresentation: this.elements.userInterfaceForm['token-representation'].value,
pagination: {
innerWindow: 5,
outerWindow: 1
@ -57,21 +56,21 @@ class CorpusAnalysisReader {
// Init data
this.data.corpus = this.app.data.corpus;
// Add event listeners
this.elements.form.addEventListener('submit', (event) => {
this.elements.userInterfaceForm.addEventListener('submit', (event) => {
event.preventDefault();
this.submitForm();
});
this.elements.form.addEventListener('change', (event) => {
if (event.target === this.elements.form['per-page']) {
this.settings.perPage = parseInt(this.elements.form['per-page'].value);
this.elements.userInterfaceForm.addEventListener('change', (event) => {
if (event.target === this.elements.userInterfaceForm['per-page']) {
this.settings.perPage = parseInt(this.elements.userInterfaceForm['per-page'].value);
this.submitForm();
}
if (event.target === this.elements.form['text-style']) {
this.settings.textStyle = parseInt(this.elements.form['text-style'].value);
if (event.target === this.elements.userInterfaceForm['text-style']) {
this.settings.textStyle = parseInt(this.elements.userInterfaceForm['text-style'].value);
this.setTextStyle();
}
if (event.target === this.elements.form['token-representation']) {
this.settings.tokenRepresentation = this.elements.form['token-representation'].value;
if (event.target === this.elements.userInterfaceForm['token-representation']) {
this.settings.tokenRepresentation = this.elements.userInterfaceForm['token-representation'].value;
this.setTokenRepresentation();
}
});

View File

@ -2,11 +2,10 @@
{% import 'corpora/_analysis/query_builder/_query_builder.html.j2' as query_builder with context %}
{% set icon = 'list_alt' %}
{% set name = 'Concordance' %}
{% set description = 'Query your corpus with the CQP query language utilizing a KWIC view.' %}
{% set description %}
Query your corpus with the CQP query language utilizing a KWIC view.
{% endset %}
{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %}
@ -43,95 +42,93 @@ Query your corpus with the CQP query language utilizing a KWIC view.
</div>
</div>
<div class="col s12">
<div id="{{ id_prefix }}-subcorpus-list"></div>
<div id="{{ id_prefix }}-subcorpus-list"></div>
<div class="card">
<div class="card-content">
<span class="card-title">Results</span>
<p></p>
<br>
<div class="progress hide" id="{{ id_prefix }}-progress">
<div class="indeterminate"></div>
</div>
<form id="{{ id_prefix }}-ui-form">
<div class="card">
<div class="card-content">
<span class="card-title">Results</span>
<p></p>
<br>
<div class="progress hide" id="{{ id_prefix }}-progress">
<div class="indeterminate"></div>
</div>
<form id="{{ id_prefix }}-user-interface-form">
<div class="row">
<div class="col s12 m9 l9">
<div class="row">
<div class="col s12 m9 l9">
<div class="row">
<div class="input-field col s4 l3">
<i class="material-icons prefix">short_text</i>
<select class="corpus-analysis-action" name="context">
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
</select>
<label>Context</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_list_numbered</i>
<select class="corpus-analysis-action" name="per-page">
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
</select>
<label>Matches per page</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_shapes</i>
<select name="text-style">
<option value="0">Plain text</option>
<option value="1" selected>Highlight entities</option>
<option value="2">Token text</option>
</select>
<label>Text style</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_quote</i>
<select name="token-representation">
<option value="lemma">lemma</option>
<option value="pos">pos</option>
<option value="simple_pos">simple_pos</option>
<option value="word" selected>word</option>
</select>
<label>Token representation</label>
</div>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">short_text</i>
<select class="corpus-analysis-action" name="context">
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
</select>
<label>Context</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_list_numbered</i>
<select class="corpus-analysis-action" name="per-page">
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
</select>
<label>Matches per page</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_shapes</i>
<select name="text-style">
<option value="0">Plain text</option>
<option value="1" selected>Highlight entities</option>
<option value="2">Token text</option>
</select>
<label>Text style</label>
</div>
<div class="input-field col s4 l3">
<i class="material-icons prefix">format_quote</i>
<select name="token-representation">
<option value="lemma">lemma</option>
<option value="pos">pos</option>
<option value="simple_pos">simple_pos</option>
<option value="word" selected>word</option>
</select>
<label>Token representation</label>
</div>
</div>
</form>
<div class="row">
<div class="col s9"><p class="hide" id="{{ id_prefix }}-subcorpus-info"></p></div>
<div class="col s3 right-align" id="{{ id_prefix }}-subcorpus-actions"></div>
</div>
<table class="highlight">
<thead>
<tr>
<th style="width: 2%;"></th>
<th style="width: 8%;">Source</th>
<th class="right-align" style="width: 22.5%;">Left context</th>
<th class="center-align" style="width: 40%;">KWIC</th>
<th class="left-align" style="width: 22.5%;">Right Context</th>
<th class="left-align" style="width: 5%;"></th>
</tr>
</thead>
<tbody id="{{ id_prefix }}-subcorpus-items"></tbody>
</table>
<ul class="pagination hide" id="{{ id_prefix }}-subcorpus-pagination"></ul>
</div>
</form>
<div class="row">
<div class="col s9"><p class="hide" id="{{ id_prefix }}-subcorpus-info"></p></div>
<div class="col s3 right-align" id="{{ id_prefix }}-subcorpus-actions"></div>
</div>
<table class="highlight">
<thead>
<tr>
<th style="width: 2%;"></th>
<th style="width: 8%;">Source</th>
<th class="right-align" style="width: 22.5%;">Left context</th>
<th class="center-align" style="width: 40%;">KWIC</th>
<th class="left-align" style="width: 22.5%;">Right Context</th>
<th class="left-align" style="width: 5%;"></th>
</tr>
</thead>
<tbody id="{{ id_prefix }}-subcorpus-items"></tbody>
</table>
<ul class="pagination hide" id="{{ id_prefix }}-subcorpus-pagination"></ul>
</div>
</div>
{% endset %}
{% endmacro %}
{% set modals %}
{{ query_builder.structural_attribute_modal() }}
{{ query_builder.positional_attribute_modal() }}
{% endset %}
{% set scripts %}
{# The extension scripts #}
{% macro scripts(id_prefix) %}
<script>
const corpusAnalysisConcordance = new CorpusAnalysisConcordance(corpusAnalysisApp);

View File

@ -1,89 +1,84 @@
{# The extension icon #}
{% set icon = 'chrome_reader_mode' %}
{# The extension name #}
{% set name = 'Reader' %}
{% set description %}
Inspect your corpus in detail with a full text view, including annotations.
{% endset %}
{# The extension description #}
{% set description = 'Inspect your corpus in detail with a full text view, including annotations.' %}
{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %}
{% set tab_content %}
<i class="material-icons left">chrome_reader_mode</i>{{ name }}</a>
{% endset %}
{% set container_content %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<form id="reader-extension-form">
{# The extension container content #}
{% macro container_content(id_prefix) %}
<div class="card">
<div class="card-content">
<form id="{{ id_prefix }}-user-interface-form">
<div class="row">
<div class="col s12 m9 l10">
<div class="row">
<div class="col s12 m9 l10">
<div class="row">
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_list_numbered</i>
<select class="corpus-analysis-action" name="per-page">
<option value="500" selected>500</option>
<option value="1000">1000</option>
<option value="1500">1500</option>
</select>
<label>Tokens per page</label>
</div>
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_shapes</i>
<select name="text-style">
<option value="0">Plain text</option>
<option value="1" selected>Highlight entities</option>
<option value="2">Token text</option>
</select>
<label>Text style</label>
</div>
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_quote</i>
<select name="token-representation">
<option value="lemma">lemma</option>
<option value="pos">pos</option>
<option value="simple_pos">simple_pos</option>
<option value="word" selected>word</option>
</select>
<label>Token representation</label>
</div>
<div class="col s12">
<span class="error-color-text helper-text hide" id="reader-extension-error"></span>
</div>
</div>
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_list_numbered</i>
<select class="corpus-analysis-action" name="per-page">
<option value="500" selected>500</option>
<option value="1000">1000</option>
<option value="1500">1500</option>
</select>
<label>Tokens per page</label>
</div>
<div class="col s12 m3 l2 right-align">
<p class="hide-on-small-only">&nbsp;</p>
<button class="btn hide waves-effect waves-light corpus-analysis-action" id="reader-extension-form-submit" type="submit" name="submit">Send <i class="material-icons right">send</i></button>
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_shapes</i>
<select name="text-style">
<option value="0">Plain text</option>
<option value="1" selected>Highlight entities</option>
<option value="2">Token text</option>
</select>
<label>Text style</label>
</div>
<div class="input-field col s4 m3">
<i class="material-icons prefix">format_quote</i>
<select name="token-representation">
<option value="lemma">lemma</option>
<option value="pos">pos</option>
<option value="simple_pos">simple_pos</option>
<option value="word" selected>word</option>
</select>
<label>Token representation</label>
</div>
<div class="col s12">
<span class="error-color-text helper-text hide" id="{{ id_prefix }}-error"></span>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col s12">
<div class="card">
<div class="card-content">
<div class="progress hide" id="reader-extension-progress">
<div class="indeterminate"></div>
</div>
<table>
<tbody>
<tr><td id="reader-extension-corpus"></td></tr>
</tbody>
</table>
<ul class="pagination hide" id="reader-extension-corpus-pagination"></ul>
<div class="col s12 m3 l2 right-align">
<p class="hide-on-small-only">&nbsp;</p>
<button class="btn hide waves-effect waves-light corpus-analysis-action" id="{{ id_prefix }}-form-submit" type="submit" name="submit">Send <i class="material-icons right">send</i></button>
</div>
</div>
</div>
</form>
</div>
</div>
{% endset %}
{% set modals = '' %}
<div class="card">
<div class="card-content">
<div class="progress hide" id="{{ id_prefix }}-progress">
<div class="indeterminate"></div>
</div>
<table>
<tbody>
<tr><td id="{{ id_prefix }}-corpus"></td></tr>
</tbody>
</table>
<ul class="pagination hide" id="{{ id_prefix }}-corpus-pagination"></ul>
</div>
</div>
{% endmacro %}
{% set scripts %}
{# The extension modals #}
{% macro modals(id_prefix) %}{% endmacro %}
{# The extension scripts #}
{% macro scripts(id_prefix) %}
<script>
const corpusAnalysisReader = new CorpusAnalysisReader(corpusAnalysisApp);
const corpusAnalysisReader = new CorpusAnalysisReader(corpusAnalysisApp, "{{ id_prefix }}");
</script>
{% endset %}
{% endmacro %}

View File

@ -1,12 +1,15 @@
{# The extension icon #}
{% set icon = '' %}
{# The extension name #}
{% set name = 'Static Visualization (beta)' %}
{# The extension description #}
{% set description = '' %}
{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %}
{% set tab_content = '' %}
{% set container_content %}
{# The extension container content #}
{% macro container_content(id_prefix) %}
<div class="row">
<div class="col s12">
<h4><i class="material-icons left">query_stats</i>{{ name }}</h4>
@ -119,9 +122,9 @@
<div class="row">
</div>
{% endset %}
{% endmacro %}
{% set modals %}
{% macro modals(id_prefix) %}
<div class="modal modal-fixed-footer" id="frequencies-stopwords-setting-modal">
<div class="modal-content">
<h4>Settings</h4>
@ -151,11 +154,11 @@
<a class="modal-close waves-effect waves-green btn frequencies-stopword-setting-modal-action-buttons" data-action="cancel">Cancel</a>
<a class="modal-close waves-effect waves-green btn frequencies-stopword-setting-modal-action-buttons" data-action="submit">Submit</a>
</div>
{% endset %}
{% endmacro %}
{% set scripts %}
{% macro scripts(id_prefix) %}
<script>
const corpusAnalysisStaticVisualization = new CorpusAnalysisStaticVisualization(corpusAnalysisApp);
const corpusAnalysisStaticVisualization = new CorpusAnalysisStaticVisualization(corpusAnalysisApp, "{{ id_prefix }}");
</script>
{% endset %}
{% endmacro %}

View File

@ -1,3 +1,5 @@
{# The extension icon #}
{% set icon = '' %}
{# The extension name #}
{% set name = '' %}
@ -5,22 +7,12 @@
{# The extension description #}
{% set description = '' %}
{#
The extension id prefix, used for related HTML elements with an id.
The prefix is used to avoid id conflicts with other extensions.
Reserved ids (do not use):
- <id_prefix>-extension-container
#}
{% set id_prefix = name.lower().replace(' ', '-') + '-extension' %}
{# The extension tab content #}
{% set tab_content = name %}
{# The extension container content #}
{% set container_content = '' %}
{% macro container_content(id_prefix) %}{% endmacro %}
{# The extension modals #}
{% set modals = '' %}
{% macro modals(id_prefix) %}{% endmacro %}
{# The extension scripts #}
{% set scripts = '' %}
{% macro scripts(id_prefix) %}{% endmacro %}

View File

@ -4,16 +4,25 @@
{% import 'corpora/_analysis/reader.html.j2' as reader_extension %}
{% import 'corpora/_analysis/static_visualization.html.j2' as static_visualization_extension %}
{% set extensions = [concordance_extension, reader_extension, static_visualization_extension] %}
{% block main_attribs %} class="service-scheme" data-service="corpus-analysis" id="corpus-analysis-app-container"{% endblock main_attribs %}
{% set extensions =
{
'corpus-analysis-app-concordance-extension': concordance_extension,
'corpus-analysis-app-reader-extension': reader_extension,
'corpus-analysis-app-static-visualizations-extension': static_visualization_extension
}
%}
{% block main_attribs %} class="service-scheme" data-service="corpus-analysis" id="corpus-analysis-app-container"{% endblock main_attribs %}
{% block page_content %}
<ul class="row tabs no-autoinit" id="corpus-analysis-app-extension-tabs">
<li class="tab col s3"><a class="active" href="#corpus-analysis-app-home-container"><i class="nopaque-icons service-icons left" data-service="corpus-analysis"></i>Corpus analysis</a></li>
{% for extension in extensions if extension.name != 'Static Visualization (beta)' %}
<li class="tab col s3"><a href="#{{ extension.id_prefix }}-container">{{ extension.tab_content }}</a></li>
{% for id, extension in extensions.items() if extension.name != 'Static Visualization (beta)' %}
<li class="tab col s3">
<a href="#{{ id }}-container"><i class="material-icons left">{{ extension.icon }}</i>{{ extension.name }}</a>
</li>
{% endfor %}
</ul>
@ -21,9 +30,9 @@
<h1>{{ title }}</h1>
<div class="row" id="corpus-analysis-app-extension-cards">
{% for extension in extensions if extension.name != 'Static Visualization (beta)' %}
{% for id, extension in extensions.items() if extension.name != 'Static Visualization (beta)' %}
<div class="col s3">
<div class="card extension-selector hoverable" data-target="{{ extension.id_prefix }}-container">
<div class="card extension-selector hoverable" data-target="{{ id }}-container">
<div class="card-content">
<span class="card-title">{{ extension.name }}</span>
<p>{{ extension.description }}</p>
@ -33,13 +42,13 @@
{% endfor %}
</div>
{{ static_visualization_extension.container_content }}
{{ static_visualization_extension.container_content('corpus-analysis-app-static-visualizations-extension') }}
</div>
{% for extension in extensions if extension.name != 'Static Visualization (beta)' %}
<div id="{{ extension.id_prefix }}-container">
{{ extension.container_content }}
{% for id, extension in extensions.items() if extension.name != 'Static Visualization (beta)' %}
<div id="{{ id }}-container">
{{ extension.container_content(id) }}
</div>
{% endfor %}
{% endblock page_content %}
@ -61,10 +70,9 @@
</div>
</div>
{% for extension in extensions %}
{{ extension.modals }}
{% for id, extension in extensions.items() %}
{{ extension.modals(id) }}
{% endfor %}
{% endblock modals %}
{% block scripts %}
@ -73,8 +81,8 @@
const corpusAnalysisApp = new CorpusAnalysisApp({{ corpus.hashid|tojson }});
</script>
{% for extension in extensions %}
{{ extension.scripts }}
{% for id, extension in extensions.items() %}
{{ extension.scripts(id) }}
{% endfor %}
<script>