Exercitia kinda work
This commit is contained in:
parent
2d3ea50106
commit
ac3e6b62b9
@ -9,7 +9,7 @@ As I've started learning Latin from Lingua Latina Per Se Illustrata I've encourt
|
||||
|
||||
```text2pensum.py``` takes text file as an input and generates HTML form from it. Marking is as follows:
|
||||
- all vowel-dash-vowel combinations (```i-i```) are transformed into a long vowel marked with macron (```ī```)
|
||||
- underscore-string-underscore combinations (```_us_```) are transformed intorequiered html text input field with string between underscores as a value of ```data-expected``` atribute (```<input type="text" data-expected="us" required>```).
|
||||
- underscore-string-underscore combinations (```_us_```) are transformed into requiered html text input field with string between underscores as a value of ```data-expected``` atribute (```<input type="text" data-expected="us">```).
|
||||
|
||||
# TODO
|
||||
- [x] text to html parser to swiftly migrate the cloze Pensa
|
||||
@ -18,4 +18,4 @@ As I've started learning Latin from Lingua Latina Per Se Illustrata I've encourt
|
||||
|
||||
# Development
|
||||
|
||||
To run the app on your own machine run ```pipenv install``` to install requested packages based on the Pipfile and then run ```pipenv shell 'gunicorn --chdir app --bind 0.0.0.0:5000 app:app'```.
|
||||
To run the app on your own machine run ```pipenv install``` to install requested packages based on the Pipfile and then run ```pipenv shell 'gunicorn --bind 0.0.0.0:5000 app:app'``` or ```flask run```.
|
@ -38,8 +38,8 @@ def pensum(pensum_id):
|
||||
with open(filename, 'r') as file:
|
||||
return render_template('Pensum_cloze.html', pensum_title=pensum_id.replace('_', ' '), pensum_content=file.read())
|
||||
|
||||
@app.route('/llpsi/pensum/<path:exercitium_id>')
|
||||
@app.route('/llpsi/exercitium/<path:exercitium_id>')
|
||||
def exercitium(exercitium_id):
|
||||
filename = app.root_path + '/templates/Exercitia/' + exercitium_id + '.html'
|
||||
with open(filename, 'r') as file:
|
||||
return render_template('Exercitium_choice.html', exercitium_title=exercitium_id.replace('_', ' '), exercitium_content=file.read())
|
||||
return render_template('Exercitium_cloze.html', exercitium_title=exercitium_id.replace('_', ' '), exercitium_content=file.read())
|
||||
|
@ -3,3 +3,8 @@ Italia in Eurōpā _est_.
|
||||
Gallia in Eurōpā _est_.
|
||||
Italia et Gallia in Eurōpā _sunt_.
|
||||
Arabia in Eurōpā nōn _est_.
|
||||
Arabia in Asiā _est_.
|
||||
Syria quoque in Asiā _est_.
|
||||
Syria et Arabia in Asiā _sunt_.
|
||||
Histānia in Asiā nōn _est_.
|
||||
Hispānia et Gallia et Italia in Eurōpā _sunt_.
|
@ -0,0 +1,12 @@
|
||||
volabula: est, sunt
|
||||
<br><ol>
|
||||
<li>Italia in Eurōpā <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Gallia in Eurōpā <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Italia et Gallia in Eurōpā <span><input type="text" data-expected="sunt"/>.</span></li>
|
||||
<li>Arabia in Eurōpā nōn <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Arabia in Asiā <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Syria quoque in Asiā <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Syria et Arabia in Asiā <span><input type="text" data-expected="sunt"/>.</span></li>
|
||||
<li>Histānia in Asiā nōn <span><input type="text" data-expected="est"/>.</span></li>
|
||||
<li>Hispānia et Gallia et Italia in Eurōpā <span><input type="text" data-expected="sunt"/>.</span></li>
|
||||
</ol>
|
8
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_2
Normal file
8
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_2
Normal file
@ -0,0 +1,8 @@
|
||||
et|fluvius|in|-ne|nōn|quoque|sed|ubi
|
||||
Italia _in_ Eurōpā est; Gracia _quoque_ in Eurōpā est.
|
||||
Italia _et_ Gracia in Eurōpā sunt.
|
||||
Est_ne_ Arabia in Eurōpā? Arabia in Eurōpā _nōn_ est.
|
||||
_Ubi_ est Arabia? In Asiā est Arabia.
|
||||
Arabia nōn est in Eurōpā, _sed_ in Asiā.
|
||||
Germānia _nōn_ in Asiā, _sed_ in Eurōpā est.
|
||||
Rhēnus est in Germānia. Rhēnus _fluvius_ est.
|
@ -0,0 +1,10 @@
|
||||
volabula: et, fluvius, in, -ne, nōn, quoque, sed, ubi
|
||||
<br><ol>
|
||||
<li>Italia <span><input type="text" data-expected="in"/></span> Eurōpā est; Gracia <span><input type="text" data-expected="quoque"/></span> in Eurōpā est.</li>
|
||||
<li>Italia <span><input type="text" data-expected="et"/></span> Gracia in Eurōpā sunt.</li>
|
||||
<li><span>Est<input type="text" data-expected="ne"/></span> Arabia in Eurōpā? Arabia in Eurōpā <span><input type="text" data-expected="nōn"/></span> est.</li>
|
||||
<li><span><input type="text" data-expected="Ubi"/></span> est Arabia? In Asiā est Arabia.</li>
|
||||
<li>Arabia nōn est in Eurōpā, <span><input type="text" data-expected="sed"/></span> in Asiā.</li>
|
||||
<li>Germānia <span><input type="text" data-expected="nōn"/></span> in Asiā, <span><input type="text" data-expected="sed"/></span> in Eurōpā est.</li>
|
||||
<li>Rhēnus est in Germānia. Rhēnus <span><input type="text" data-expected="fluvius"/></span> est.</li>
|
||||
</ol>
|
2
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_3
Normal file
2
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_3
Normal file
@ -0,0 +1,2 @@
|
||||
Under
|
||||
Construction
|
2
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_4
Normal file
2
app/templates/Exercitia/01_Imperium_Romanum_Exercitium_4
Normal file
@ -0,0 +1,2 @@
|
||||
-us|-ī|-a|-ae|-um|-a
|
||||
Corsica īnsul_a_ est. Corsica et Sardinia īnsul_ae_ sunt.
|
@ -0,0 +1,4 @@
|
||||
volabula: -us, -ī, -a, -ae, -um, -a
|
||||
<br><ol>
|
||||
<li>Corsica ī<span>nsul<input type="text" data-expected="a"/></span> est. Corsica et Sardinia ī<span>nsul<input type="text" data-expected="ae"/></span> sunt.</li>
|
||||
</ol>
|
109
app/templates/Exercitium_cloze.html
Normal file
109
app/templates/Exercitium_cloze.html
Normal file
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="la">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>{{pensum_title}}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/LLPSI.css') }}">
|
||||
<script type="text/javascript">
|
||||
function adjust_size() {
|
||||
const exercitium = document.querySelector('.exercitium_content');
|
||||
const inputs = exercitium.querySelectorAll('input');
|
||||
inputs.forEach((input) => {
|
||||
if (input.type=="text") {
|
||||
input.setAttribute("value", "");
|
||||
input.setAttribute("style", "width: " + input.dataset.expected.length + "em");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function nomacron_to_macron(char) {
|
||||
var mapper = { 'A': 'Ā',
|
||||
'a': 'ā',
|
||||
'E': 'Ē',
|
||||
'e': 'ē',
|
||||
'I': 'Ī',
|
||||
'i': 'ī',
|
||||
'O': 'Ō',
|
||||
'o': 'ō',
|
||||
'U': 'Ū',
|
||||
'u': 'ū'};
|
||||
return mapper[char[0]];
|
||||
}
|
||||
|
||||
function macron_to_nomacron(char) {
|
||||
var mapper = { 'Ā': 'A',
|
||||
'ā': 'a',
|
||||
'Ē': 'E',
|
||||
'ē': 'e',
|
||||
'Ī': 'I',
|
||||
'ī': 'i',
|
||||
'Ō': 'O',
|
||||
'ō': 'o',
|
||||
'Ū': 'U',
|
||||
'ū': 'u'};
|
||||
return mapper[char];
|
||||
}
|
||||
|
||||
function to_nonmacron(input) {
|
||||
return input.replace(/Ā|ā|Ē|ē|Ī|ī/, macron_to_nomacron);
|
||||
}
|
||||
|
||||
function to_macron(input) {
|
||||
return input.replace(/(\w)\1/, nomacron_to_macron);
|
||||
}
|
||||
|
||||
|
||||
function validate() {
|
||||
const exercitium = document.querySelector('.exercitium_content');
|
||||
const inputs = exercitium.querySelectorAll('input');
|
||||
|
||||
inputs.forEach((input) => {
|
||||
if (input.type == "text") {
|
||||
is_nonmacron_ok = false;
|
||||
is_macron_ok = false;
|
||||
if (document.getElementById('vowel_length').checked == false) {
|
||||
is_nonmacron_ok = (to_nonmacron(input.value) == to_nonmacron(input.dataset.expected));
|
||||
} else {
|
||||
is_macron_ok = (input.value == input.dataset.expected);
|
||||
}
|
||||
if (is_nonmacron_ok || is_macron_ok) {
|
||||
input.setAttribute("class", "correct");
|
||||
} else {
|
||||
input.setAttribute("class", "incorrect");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function show_answers() {
|
||||
const pensum = document.querySelector('.exercitium_content');
|
||||
const inputs = pensum.querySelectorAll('input');
|
||||
|
||||
inputs.forEach((input) => {
|
||||
if (input.type=="text") {
|
||||
input.value = input.dataset.expected;
|
||||
input.removeAttribute("class");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="/llpsi">Lingua Latīna Per Sē Illūstrāta</a></h1>
|
||||
<h2>{{exercitium_title}}</h2>
|
||||
<label class="toggle">
|
||||
Quantitās: <input type="checkbox" id="vowel_length">
|
||||
</label>
|
||||
</header>
|
||||
<div class="exercitium_content">
|
||||
<p>{{exercitium_content|safe}}</p>
|
||||
<br>
|
||||
<button title="Check answers" onclick="return validate();">Mitte</button><button title="Show correct answers" onclick="return show_answers();">Responsa</button>
|
||||
</div>
|
||||
<script type="text/javascript">adjust_size();</script>
|
||||
</body>
|
||||
</html>
|
@ -1,31 +0,0 @@
|
||||
import sys
|
||||
import re
|
||||
|
||||
for filename in sys.argv[1:]:
|
||||
with open(filename, 'r') as infile:
|
||||
content = infile.readlines()
|
||||
|
||||
|
||||
to_use = content.pop(0).split('|')
|
||||
html_header = 'To use: ' + to_use.str() + '<br>'
|
||||
# Replace _string_ with html
|
||||
html_span_head = '<span>'
|
||||
html_input_head = '<input type="text" data-expected="'
|
||||
html_input_tail = '"/>'
|
||||
html_span_tail = '</span>'
|
||||
content = re.sub(r'(\s|\"|)([a-zA-Z\-\ÿ]+|)_([āēīōūa-zA-Z\-]+)_(\.|\,|)', r'\1' + html_span_head + r'\2' + html_input_head + r'\3' + html_input_tail + r'\4' + html_span_tail, content)
|
||||
|
||||
# Replace vowel-dash-vowel with vowels with macrons
|
||||
content = content.replace('A-A', 'Ā')
|
||||
content = content.replace('a-a', 'ā')
|
||||
content = content.replace('E-E', 'Ē')
|
||||
content = content.replace('e-e', 'ē')
|
||||
content = content.replace('I-I', 'Ī')
|
||||
content = content.replace('i-i', 'ī')
|
||||
content = content.replace('O-O', 'Ō')
|
||||
content = content.replace('o-o', 'ō')
|
||||
content = content.replace('U-U', 'Ū')
|
||||
content = content.replace('u-u', 'ū')
|
||||
|
||||
with open(filename + '.html', 'w') as outfile:
|
||||
outfile.write(content)
|
40
text2exercitium_cloze.py
Normal file
40
text2exercitium_cloze.py
Normal file
@ -0,0 +1,40 @@
|
||||
import sys
|
||||
import re
|
||||
|
||||
for filename in sys.argv[1:]:
|
||||
with open(filename, 'r') as infile:
|
||||
content = infile.readlines()
|
||||
|
||||
|
||||
to_use = content.pop(0).replace('|',', ')
|
||||
html_header = 'volabula: ' + ''.join(to_use) + '<br>'
|
||||
# Replace _string_ with html
|
||||
html_span_head = '<span>'
|
||||
html_input_head = '<input type="text" data-expected="'
|
||||
html_input_tail = '"/>'
|
||||
html_span_tail = '</span>'
|
||||
for i in range(len(content)):
|
||||
content[i] = re.sub(r'(\s|\"|)([a-zA-Z\-\ÿ]+|)_([āēīōūa-zA-Z\-]+)_(\.|\,|)', r'\1' + html_span_head + r'\2' + html_input_head + r'\3' + html_input_tail + r'\4' + html_span_tail, content[i].rstrip('\n'))
|
||||
# Replace vowel-dash-vowel with vowels with macrons
|
||||
content[i] = content[i].replace('A-A', 'Ā')
|
||||
content[i] = content[i].replace('a-a', 'ā')
|
||||
content[i] = content[i].replace('E-E', 'Ē')
|
||||
content[i] = content[i].replace('e-e', 'ē')
|
||||
content[i] = content[i].replace('I-I', 'Ī')
|
||||
content[i] = content[i].replace('i-i', 'ī')
|
||||
content[i] = content[i].replace('O-O', 'Ō')
|
||||
content[i] = content[i].replace('o-o', 'ō')
|
||||
content[i] = content[i].replace('U-U', 'Ū')
|
||||
content[i] = content[i].replace('u-u', 'ū')
|
||||
|
||||
html_list_header = '<ol>\n'
|
||||
html_list_element_header = '<li>'
|
||||
html_list_element_trailer = '</li>\n'
|
||||
html_list_trailer = '</ol>'
|
||||
|
||||
with open(filename + '.html', 'w') as outfile:
|
||||
outfile.write(html_header)
|
||||
outfile.write(html_list_header)
|
||||
for line in content:
|
||||
outfile.write(html_list_element_header + line.rstrip('\n') + html_list_element_trailer)
|
||||
outfile.write(html_list_trailer)
|
Loading…
Reference in New Issue
Block a user