Skip to content
Snippets Groups Projects
Commit a02ce1fe authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Reorganized scripts and generator

parent 480ec4e5
No related branches found
No related tags found
No related merge requests found
__pycache__/*
output/*
*Add a good description / documenation
\ No newline at end of file
import os
import re
def create_autoilias_script(type, title, author, question, solution,
points=9999, answer=None, gapLength=None, number=1):
with open("templates/generic.class.php", "r", encoding='utf-8') as script:
script = script.read()
if not gapLength:
gapComment = ""
gapLength = int(gapLength)
else:
gapComment = "//"
gapLength = ""
script = script.format(
type=type, title=title, author=author, number=number, points=points,
gapComment=gapComment, gapLength=gapLength, question=question,
solution=solution,
)
with open("output/" + title.replace(' ', "_") + ".class.php", 'w', encoding='utf-8') as output:
print(script, file=output)
for script in filter(lambda dat: re.search('\d+_\w+\.py', dat), os.listdir('./src')):
with open('./src/' + script) as script_f:
exec(script_f.read())
create_autoilias_script(**meta)
\ No newline at end of file
...@@ -41,8 +41,8 @@ def parse(grammer): ...@@ -41,8 +41,8 @@ def parse(grammer):
P, T, N = parse(delta) P, T, N = parse(delta)
print(('\n'.join(map(str, P)))) # print(('\n'.join(map(str, P))))
print() # print()
letters_to_kill = {p.left for p in P if not p.right} letters_to_kill = {p.left for p in P if not p.right}
new_P = set() | P new_P = set() | P
...@@ -56,23 +56,33 @@ for p in P: ...@@ -56,23 +56,33 @@ for p in P:
new_P |= {rule(p.left, r.format(*prod).replace("0", ""))} new_P |= {rule(p.left, r.format(*prod).replace("0", ""))}
P = {p for p in new_P if p.right} P = {p for p in new_P if p.right}
print(('\n'.join(map(str, P)))) # print(('\n'.join(map(str, P))))
print() # print()
for t in T: for t in T:
P |= {rule("T_" + t, t)} P |= {rule("T_" + t, t)}
print(T) # print(T)
new_P = set() | P new_P = set() | P
for p in P: for p in P:
p.right = ["T_" + p if p in T else p for p in p.right] p.right = ["T_" + p if p in T else p for p in p.right]
P = new_P P = new_P
print(('\n'.join(map(str, P)))) # print(('\n'.join(map(str, P))))
print() # print()
new_P = set() | P new_P = set() | P
for p in P: for p in P:
if len(p.right) > 2: if len(p.right) > 2:
pass pass
### END OF SCRIPT ##############################################################
meta = {
"type" : "GAP",
"title" : "Grammatik in Chomsky Normalform umwandeln",
"author" : "Jan Maximilian Michal",
"gapLength" : 10,
"question" : "Empty",
"solution" : "TODO",
}
\ No newline at end of file
from DFA import *
from itertools import product from itertools import product
from graphviz import Digraph from graphviz import Digraph
...@@ -141,6 +140,14 @@ F = ["s2"] ...@@ -141,6 +140,14 @@ F = ["s2"]
F2 = ["s0", "s3", "s4", "s6"] F2 = ["s0", "s3", "s4", "s6"]
A = Automaton(states2, "ab", delta2, "s0", F2) A = Automaton(states2, "ab", delta2, "s0", F2)
A.minimize()
print(A.generate_ilias())
### END OF SCRIPT ##############################################################
meta = {
"type" : "GAP",
"title" : "Minimieren eines deterministischen Automaten",
"author" : "Jan Maximilian Michal",
"gapLength" : 10,
"question" : A.generate_ilias(),
"solution" : "TODO",
}
\ No newline at end of file
from collections import deque from collections import deque
from functools import reduce from functools import reduce
from graphviz import Digraph from graphviz import Digraph
# from pprint import pprint as print
class NEA: class NEA:
...@@ -54,7 +52,7 @@ class NEA: ...@@ -54,7 +52,7 @@ class NEA:
f.view() f.view()
# return str(f.pipe(), encoding='utf-8') # return str(f.pipe(), encoding='utf-8')
def generate_ilias(self): def _generate_ilias(self):
table = self.to_dea() table = self.to_dea()
aufgabe = ''' Aufgabentext\n\n''' aufgabe = ''' Aufgabentext\n\n'''
...@@ -69,14 +67,17 @@ class NEA: ...@@ -69,14 +67,17 @@ class NEA:
aufgabe += tr.format(''.join(td.format(','.join(sorted(s))) for s in row)) aufgabe += tr.format(''.join(td.format(','.join(sorted(s))) for s in row))
aufgabe += '</table>' aufgabe += '</table>'
print(aufgabe.replace('"', r'\"')) yield(aufgabe.replace('"', r'\"'))
print("{:>25}{:>25}{:>25}".format("delta", "a", "b")) yield("{:>25}{:>25}{:>25}".format("delta", "a", "b"))
for row in table: for row in table:
print("{:>25}{:>25}{:>25}".format(*map(', '.join, (sorted(s) for s in row)))) yield("{:>25}{:>25}{:>25}".format(*map(', '.join, (sorted(s) for s in row))))
def generate_ilias(self):
return ''.join(self._generate_ilias())
# Define one Automaton
def delta(state, char): def delta(state, char):
return { return {
('s0', 'a'): {'s0', 's1'}, ('s0', 'a'): {'s0', 's1'},
...@@ -95,7 +96,15 @@ def delta(state, char): ...@@ -95,7 +96,15 @@ def delta(state, char):
states = ["s{}".format(i) for i in range(4)] states = ["s{}".format(i) for i in range(4)]
F = ["s3"] F = ["s3"]
# create
N = NEA(states, "ab", delta, 's0', F) N = NEA(states, "ab", delta, 's0', F)
N.to_dea()
# N.graph_output() ### END OF SCRIPT ##############################################################
N.generate_ilias() meta = {
\ No newline at end of file "type" : "GAP",
"title" : "NEA to DEA",
"author" : "Jan Maximilian Michal",
"gapLength" : 10,
"question" : N.generate_ilias(),
"solution" : "TODO",
}
File moved
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "FREE";
$this->qTitle = "Freitext Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10;
}
function exe(){
$question = "Fragentext...";
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "m" => $ml);
}
}
?>
<?php
class autoILIASscript{{
function autoILIASscript(){{
$this->qType = "{type}";
$this->qTitle = "{title}";
$this->qAuthor = "{author}";
$this->qNumber = {number};
$this->qPoints = {points};
{isComment}$this->gapLength = {gapLength};
}}
function exe(){{
$question = "{question}";
$ml = "{solution}";
return array("q" => $question, "m" => $ml);
}}
}}
?>
<?php
class autoILIASscript{{
function autoILIASscript(){{
$this->qType = "{type}";
$this->qTitle = "{title}";
$this->qAuthor = "{author}";
$this->qNumber = {number};
$this->qPoints = {points};
{gapComment}$this->gapLength = {gapLength};
}}
function exe(){{
$question = "{question}";
$ml = "{solution}";
return array("q" => $question, "m" => $ml);
}}
}}
?>
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "MULTI";
$this->qTitle = "Mehrfach Auswahl Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10; // Gesamtpunktzahl = |Antwortmoeglichkeiten| * $this->qPoints
}
function exe(){
$question = "Fragentext...";
$answer = array(array("A", true), array("B", false), array("C", true));
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "a" => $answer, "m" => $ml);
}
}
?>
\ No newline at end of file
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "NUMERIC";
$this->qTitle = "Numerische Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10;
//$this->numericFormatstring = "";
}
function exe(){
$question = "Fragentext...";
$answer = 42;
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "a" => $answer, "m" => $ml);
}
}
?>
\ No newline at end of file
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "ORDER";
$this->qTitle = "Anordnungs Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10;
}
function exe(){
// <span style=\"font-size: x-small;\"><b>Hinweis: </b>GgF. m&uuml;ssen die Terme in der richtigen Reihenfolge durchnummeriert werden.</span>
$question = "Fragentext...";
$answer = array("A", "B", "C", "D");
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "a" => $answer, "m" => $ml);
}
}
?>
\ No newline at end of file
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "SELECT";
$this->qTitle = "Auswahll&uuml;cken Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10;
}
function exe(){
$question = "Fragentext mit L&uuml;cken zum Ausw&auml;hlen [select][i(2P)]richtig[/i][i(0P)]falsch[/i][/select]...";
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "m" => $ml);
}
}
?>
\ No newline at end of file
<?php
class autoILIASscript{
function autoILIASscript(){
$this->qType = "SINGLE";
$this->qTitle = "Auswahl Frage";
$this->qAuthor = "Vorname Name";
$this->qNumber = 100;
$this->qPoints = 10;
}
function exe(){
$question = "Fragentext...";
$answer = array(array("A", false), array("B", false), array("C", true));
$ml = "Musterl&ouml;sung...";
return array("q" => $question, "a" => $answer, "m" => $ml);
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment