From a02ce1fefab9c16df6c3df1c5edfe0fa4cb954ca Mon Sep 17 00:00:00 2001
From: janmax <mail-github@jmx.io>
Date: Thu, 7 Jul 2016 13:00:57 +0200
Subject: [PATCH] Reorganized scripts and generator

---
 .gitignore                                    |  2 ++
 README.md                                     |  1 +
 generator.py                                  | 29 ++++++++++++++++++
 .../02_chomsky_grammar.py                     | 24 ++++++++++-----
 04_minimize_dea.py => src/04_minimize_dea.py  | 13 ++++++--
 05_nea_to_dea.py => src/05_nea_to_dea.py      | 27 +++++++++++------
 __init__.py => src/__init__.py                |  0
 templates/free.class.php                      | 17 +++++++++++
 templates/gap.class.php                       | 18 +++++++++++
 templates/generic.class.php                   | 18 +++++++++++
 templates/multi.class.php                     | 29 ++++++++++++++++++
 templates/numeric.class.php                   | 30 +++++++++++++++++++
 templates/order.class.php                     | 30 +++++++++++++++++++
 templates/select.class.php                    | 27 +++++++++++++++++
 templates/single.class.php                    | 29 ++++++++++++++++++
 15 files changed, 275 insertions(+), 19 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 README.md
 create mode 100644 generator.py
 rename 02_chomsky_grammar.py => src/02_chomsky_grammar.py (78%)
 rename 04_minimize_dea.py => src/04_minimize_dea.py (93%)
 rename 05_nea_to_dea.py => src/05_nea_to_dea.py (81%)
 rename __init__.py => src/__init__.py (100%)
 create mode 100755 templates/free.class.php
 create mode 100755 templates/gap.class.php
 create mode 100755 templates/generic.class.php
 create mode 100755 templates/multi.class.php
 create mode 100755 templates/numeric.class.php
 create mode 100755 templates/order.class.php
 create mode 100755 templates/select.class.php
 create mode 100755 templates/single.class.php

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9e97696
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+__pycache__/*
+output/*
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bcefd2b
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+*Add a good description / documenation
\ No newline at end of file
diff --git a/generator.py b/generator.py
new file mode 100644
index 0000000..0948e36
--- /dev/null
+++ b/generator.py
@@ -0,0 +1,29 @@
+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
diff --git a/02_chomsky_grammar.py b/src/02_chomsky_grammar.py
similarity index 78%
rename from 02_chomsky_grammar.py
rename to src/02_chomsky_grammar.py
index f1085a2..bc2eb47 100644
--- a/02_chomsky_grammar.py
+++ b/src/02_chomsky_grammar.py
@@ -41,8 +41,8 @@ def parse(grammer):
 
 P, T, N = parse(delta)
 
-print(('\n'.join(map(str, P))))
-print()
+# print(('\n'.join(map(str, P))))
+# print()
 
 letters_to_kill = {p.left for p in P if not p.right}
 new_P = set() | P
@@ -56,23 +56,33 @@ for p in P:
             new_P |= {rule(p.left, r.format(*prod).replace("0", ""))}
 
 P = {p for p in new_P if p.right}
-print(('\n'.join(map(str, P))))
-print()
+# print(('\n'.join(map(str, P))))
+# print()
 
 for t in T:
     P |= {rule("T_" + t, t)}
 
-print(T)
+# print(T)
 
 new_P = set() | P
 for p in P:
     p.right = ["T_" + p if p in T else p for p in p.right]
 
 P = new_P
-print(('\n'.join(map(str, P))))
-print()
+# print(('\n'.join(map(str, P))))
+# print()
 
 new_P = set() | P
 for p in P:
     if len(p.right) > 2:
         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
diff --git a/04_minimize_dea.py b/src/04_minimize_dea.py
similarity index 93%
rename from 04_minimize_dea.py
rename to src/04_minimize_dea.py
index c712279..5bc579c 100644
--- a/04_minimize_dea.py
+++ b/src/04_minimize_dea.py
@@ -1,4 +1,3 @@
-from DFA import *
 from itertools import product
 from graphviz import Digraph
 
@@ -141,6 +140,14 @@ F = ["s2"]
 F2 = ["s0", "s3", "s4", "s6"]
 
 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
diff --git a/05_nea_to_dea.py b/src/05_nea_to_dea.py
similarity index 81%
rename from 05_nea_to_dea.py
rename to src/05_nea_to_dea.py
index 51f22c1..3378d92 100644
--- a/05_nea_to_dea.py
+++ b/src/05_nea_to_dea.py
@@ -1,8 +1,6 @@
 from collections import deque
 from functools import reduce
 from graphviz import Digraph
-# from pprint import pprint as print
-
 
 class NEA:
 
@@ -54,7 +52,7 @@ class NEA:
         f.view()
         # return str(f.pipe(), encoding='utf-8')
 
-    def generate_ilias(self):
+    def _generate_ilias(self):
         table = self.to_dea()
 
         aufgabe = ''' Aufgabentext\n\n'''
@@ -69,14 +67,17 @@ class NEA:
             aufgabe += tr.format(''.join(td.format(','.join(sorted(s))) for s in row))
         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:
-            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):
     return {
         ('s0', 'a'): {'s0', 's1'},
@@ -95,7 +96,15 @@ def delta(state, char):
 states = ["s{}".format(i) for i in range(4)]
 F = ["s3"]
 
+# create
 N = NEA(states, "ab", delta, 's0', F)
-N.to_dea()
-# N.graph_output()
-N.generate_ilias()
\ No newline at end of file
+
+### END OF SCRIPT ##############################################################
+meta = {
+    "type"      : "GAP",
+    "title"     : "NEA to DEA",
+    "author"    : "Jan Maximilian Michal",
+    "gapLength" : 10,
+    "question"  : N.generate_ilias(),
+    "solution"  : "TODO",
+}
diff --git a/__init__.py b/src/__init__.py
similarity index 100%
rename from __init__.py
rename to src/__init__.py
diff --git a/templates/free.class.php b/templates/free.class.php
new file mode 100755
index 0000000..5c058b0
--- /dev/null
+++ b/templates/free.class.php
@@ -0,0 +1,17 @@
+<?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);
+		}
+	}
+?>
diff --git a/templates/gap.class.php b/templates/gap.class.php
new file mode 100755
index 0000000..7dcdb7d
--- /dev/null
+++ b/templates/gap.class.php
@@ -0,0 +1,18 @@
+<?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);
+		}}
+	}}
+?>
diff --git a/templates/generic.class.php b/templates/generic.class.php
new file mode 100755
index 0000000..7b23e92
--- /dev/null
+++ b/templates/generic.class.php
@@ -0,0 +1,18 @@
+<?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);
+		}}
+	}}
+?>
diff --git a/templates/multi.class.php b/templates/multi.class.php
new file mode 100755
index 0000000..21b8d08
--- /dev/null
+++ b/templates/multi.class.php
@@ -0,0 +1,29 @@
+<?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
diff --git a/templates/numeric.class.php b/templates/numeric.class.php
new file mode 100755
index 0000000..8751992
--- /dev/null
+++ b/templates/numeric.class.php
@@ -0,0 +1,30 @@
+<?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
diff --git a/templates/order.class.php b/templates/order.class.php
new file mode 100755
index 0000000..7c00c66
--- /dev/null
+++ b/templates/order.class.php
@@ -0,0 +1,30 @@
+<?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
diff --git a/templates/select.class.php b/templates/select.class.php
new file mode 100755
index 0000000..2b95cf3
--- /dev/null
+++ b/templates/select.class.php
@@ -0,0 +1,27 @@
+<?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
diff --git a/templates/single.class.php b/templates/single.class.php
new file mode 100755
index 0000000..cb440d1
--- /dev/null
+++ b/templates/single.class.php
@@ -0,0 +1,29 @@
+<?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
-- 
GitLab