mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 02:44:18 +00:00
Add more form fields to corpus analysis
This commit is contained in:
parent
617cc06125
commit
0dc015b29c
@ -1,6 +1,6 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import (FileField, StringField, SubmitField,
|
from wtforms import (FileField, StringField, SubmitField,
|
||||||
ValidationError, IntegerField, SelectField)
|
ValidationError, IntegerField, SelectField, TextAreaField)
|
||||||
from wtforms.validators import DataRequired, Length
|
from wtforms.validators import DataRequired, Length
|
||||||
|
|
||||||
|
|
||||||
@ -26,7 +26,8 @@ class CreateCorpusForm(FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
class QueryForm(FlaskForm):
|
class QueryForm(FlaskForm):
|
||||||
query = StringField('CQP Query', validators=[DataRequired(), (Length(1, 1024))])
|
query = TextAreaField('CQP Query', validators=[DataRequired(),
|
||||||
|
(Length(1, 1024))])
|
||||||
hits_per_page = SelectField('Hits per page',
|
hits_per_page = SelectField('Hits per page',
|
||||||
choices=[('', 'Nr. of hits per page'),
|
choices=[('', 'Nr. of hits per page'),
|
||||||
('10', '10'),
|
('10', '10'),
|
||||||
@ -34,8 +35,7 @@ class QueryForm(FlaskForm):
|
|||||||
('30', '30'),
|
('30', '30'),
|
||||||
('40', '40'),
|
('40', '40'),
|
||||||
('50', '50')],
|
('50', '50')],
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()])
|
||||||
default='30')
|
|
||||||
context = SelectField('Context',
|
context = SelectField('Context',
|
||||||
choices=[('', 'Words of context around hit'),
|
choices=[('', 'Words of context around hit'),
|
||||||
('5', '5'),
|
('5', '5'),
|
||||||
@ -43,10 +43,14 @@ class QueryForm(FlaskForm):
|
|||||||
('15', '15'),
|
('15', '15'),
|
||||||
('20', '20'),
|
('20', '20'),
|
||||||
('25', '25')],
|
('25', '25')],
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()])
|
||||||
default='10')
|
|
||||||
submit = SubmitField('Start Query')
|
submit = SubmitField('Start Query')
|
||||||
|
|
||||||
|
|
||||||
class QueryDownloadForm(FlaskForm):
|
class QueryDownloadForm(FlaskForm):
|
||||||
pass
|
file_type = SelectField('File type',
|
||||||
|
choices=[('', 'Choose file type'),
|
||||||
|
('csv', 'csv'),
|
||||||
|
('json', 'json'),
|
||||||
|
('excel', 'excel')],
|
||||||
|
validators=[DataRequired()])
|
||||||
|
@ -3,7 +3,7 @@ from flask import (abort, current_app, flash, redirect, request,
|
|||||||
render_template, url_for, send_from_directory)
|
render_template, url_for, send_from_directory)
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from . import main
|
from . import main
|
||||||
from .forms import AddCorpusFileForm, CreateCorpusForm, QueryForm
|
from .forms import AddCorpusFileForm, CreateCorpusForm, QueryForm, QueryDownloadForm
|
||||||
from .. import db
|
from .. import db
|
||||||
from ..models import Corpus, CorpusFile, Job, JobInput, JobResult
|
from ..models import Corpus, CorpusFile, Job, JobInput, JobResult
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
@ -87,25 +87,35 @@ def corpus_download(corpus_id):
|
|||||||
@main.route('/corpora/<int:corpus_id>/analysis', methods=['GET', 'POST'])
|
@main.route('/corpora/<int:corpus_id>/analysis', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def corpus_analysis(corpus_id):
|
def corpus_analysis(corpus_id):
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
query = request.args.get('query')
|
query = request.args.get('query')
|
||||||
form = QueryForm()
|
logger.warning('Query first: {}'.format(query))
|
||||||
|
hits_per_page = request.args.get('hits_per_page', 30)
|
||||||
|
context = request.args.get('context', 10)
|
||||||
|
dl_form = QueryDownloadForm()
|
||||||
|
form = QueryForm(hits_per_page=hits_per_page, context=context, query=query)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.warning('Data has been sent!')
|
logger.warning('Data has been sent!')
|
||||||
logger.warning('Data labels: {data}'.format(data=[data for data in form.data]))
|
logger.warning('Data labels: {data}'.format(data=[data for data in form.data]))
|
||||||
logger.warning('Query: {q}'.format(q=form.query.data))
|
logger.warning('Query Second: {q}'.format(q=form.query.data))
|
||||||
logger.warning('Hits: {hits}'.format(hits=form.hits_per_page.data))
|
logger.warning('Hits: {hits}'.format(hits=form.hits_per_page.data))
|
||||||
logger.warning('Context: {context}'.format(context=form.context.data))
|
logger.warning('Context: {context}'.format(context=form.context.data))
|
||||||
flash('Query has been sent!')
|
flash('Query has been sent!')
|
||||||
query = form.query.data
|
query = form.query.data
|
||||||
logger.warning('Session query: {sq}'.format(sq=query))
|
hits_per_page = form.hits_per_page.data
|
||||||
return redirect(url_for('main.corpus_analysis', corpus_id=corpus_id,
|
context = form.context.data
|
||||||
query=query))
|
logger.warning('Query Thrid: {sq}'.format(sq=query))
|
||||||
|
return redirect(url_for('main.corpus_analysis',
|
||||||
|
corpus_id=corpus_id,
|
||||||
|
query=query,
|
||||||
|
hits_per_page=hits_per_page,
|
||||||
|
context=context))
|
||||||
return render_template('main/corpora/corpus_analysis.html.j2',
|
return render_template('main/corpora/corpus_analysis.html.j2',
|
||||||
corpus=corpus,
|
corpus=corpus,
|
||||||
form=form,
|
form=form,
|
||||||
query=query,
|
dl_form=dl_form,
|
||||||
title='Corpus: ' + corpus.title)
|
title='Corpus: ' + corpus.title)
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,4 +80,5 @@ indicator will show up how the column is sorted right now.; */
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
top: 80px;
|
top: 80px;
|
||||||
padding: 50px;
|
padding: 50px;
|
||||||
|
z-index: 999; /* tmp fix */
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,73 @@
|
|||||||
{% extends "full_width.html.j2" %}
|
{% extends "full_width.html.j2" %}
|
||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
|
<div class="col s12 m3 l3 sticky">
|
||||||
|
<div class="card">
|
||||||
|
<form method="POST">
|
||||||
|
<div class="card-content">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<span class="card-title">Query and analysis</span>
|
||||||
|
<br>
|
||||||
|
<div class="input-field">
|
||||||
|
{{ form.query(class='materialize-textarea') }}
|
||||||
|
{{ form.query.label }}
|
||||||
|
{% for error in form.query.errors %}
|
||||||
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="right-align">
|
||||||
|
<button class="btn" type="submit" name="action">Start Query
|
||||||
|
<i class="material-icons left">search</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<span class="card-title">Help</span>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">
|
||||||
|
CQP Query Language Tutorial</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<span class="card-title">Options</span>
|
||||||
|
<br>
|
||||||
|
<div class="input-field">
|
||||||
|
<i class="material-icons prefix">format_list_numbered</i>
|
||||||
|
{{ form.hits_per_page() }}
|
||||||
|
{{ form.hits_per_page.label }}
|
||||||
|
{% for error in form.hits_per_page.errors %}
|
||||||
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="input-field">
|
||||||
|
<i class="material-icons prefix">short_text</i>
|
||||||
|
{{ form.context() }}
|
||||||
|
{{ form.context.label }}
|
||||||
|
{% for error in form.context.errors %}
|
||||||
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
</form>
|
||||||
|
<span class="card-title">Download Results</span>
|
||||||
|
<p>Downlaod all results of the current query as csv, excel or json file.</p>
|
||||||
|
<div class="input-field">
|
||||||
|
<i class="material-icons prefix">insert_drive_file</i>
|
||||||
|
{{ dl_form.file_type() }}
|
||||||
|
{{ dl_form.file_type.label }}
|
||||||
|
{% for error in dl_form.file_type.errors %}
|
||||||
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="right-align">
|
||||||
|
<button class="btn" type="submit" name="action">Download
|
||||||
|
<i class="material-icons left">file_download</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col s12 m9 l9">
|
<div class="col s12 m9 l9">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
@ -27,54 +94,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col s12 m3 l3 sticky">
|
|
||||||
<div class="card">
|
|
||||||
<form method="POST">
|
|
||||||
<div class="card-content">
|
|
||||||
{{ form.hidden_tag() }}
|
|
||||||
<span class="card-title">Query and analysis</span>
|
|
||||||
<div class="input-field">
|
|
||||||
<i class="material-icons prefix">search</i>
|
|
||||||
<input autofocus size="1024" data-length="1024" id="{{ form.query.id }}" name="{{ form.query.id }}" required="" type="text" value="{{ query if query != None else '' }}"></input>
|
|
||||||
{{ form.query.label }}
|
|
||||||
{% for error in form.query.errors %}
|
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div class="right-align">
|
|
||||||
{{ form.submit(class='btn') }}
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
<span class="card-title">Help</span>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">
|
|
||||||
CQP Query Language Tutorial</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<br>
|
|
||||||
<span class="card-title">Options</span>
|
|
||||||
<br>
|
|
||||||
<div class="input-field">
|
|
||||||
<i class="material-icons prefix">format_list_numbered</i>
|
|
||||||
{{ form.hits_per_page() }}
|
|
||||||
{{ form.hits_per_page.label }}
|
|
||||||
{% for error in form.hits_per_page.errors %}
|
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
<div class="input-field">
|
|
||||||
<i class="material-icons prefix">short_text</i>
|
|
||||||
{{ form.context() }}
|
|
||||||
{{ form.context.label }}
|
|
||||||
{% for error in form.context.errors %}
|
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<span class="card-title">Download Results</span>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user