Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
3e7393c3
Commit
3e7393c3
authored
Jul 15, 2020
by
Kateřina Sloupová
Browse files
web feedback: pictures and more language descriptions and tweaks
parent
70056451
Changes
8
Hide whitespace changes
Inline
Side-by-side
demo.py
View file @
3e7393c3
...
...
@@ -206,11 +206,11 @@ def main():
print
()
print
(
"Composition:"
)
union
=
dfa_1
.
composit
ion
(
dfa_1
,
dfa_2
,
comp
.
Union
)
union
=
dfa_1
.
un
ion
(
dfa_1
,
dfa_2
)
print
(
parser
.
dfa_to_str
(
union
,
True
))
print
()
print
(
"Intersection:"
)
intersection
=
dfa_1
.
composi
tion
(
dfa_1
,
dfa_2
,
comp
.
Intersection
)
intersection
=
dfa_1
.
intersec
tion
(
dfa_1
,
dfa_2
)
print
(
parser
.
dfa_to_str
(
intersection
,
True
))
print
()
...
...
evalweb.sh
100644 → 100755
View file @
3e7393c3
File mode changed from 100644 to 100755
evalweb/evalweb.py
View file @
3e7393c3
...
...
@@ -72,10 +72,11 @@ def compare():
missing_word_ce
=
checker
.
eq
.
right_counterexample
inf
=
checker
.
eq
.
inf
return
render_template
(
'result_compare.html'
,
compare
=
True
,
ok
=
result
,
inf
=
inf
,
task_solved
=
checker
.
task_solved
,
alphabets
=
checker
.
alphabets
,
extra_word_ce
=
extra_word_ce
,
missing_word_ce
=
missing_word_ce
,
is_task
=
checker
.
is_task
,
img_src
=
checker
.
img_src
,
is_task
=
checker
.
is_task
,
img_src
=
checker
.
img_src
,
langs
=
checker
.
languages
,
teacher
=
checker
.
teacher
,
student
=
checker
.
student
)
if
request
.
method
==
'POST'
and
'example_button'
in
request
.
form
:
...
...
evalweb/templates/compare.html
View file @
3e7393c3
...
...
@@ -13,7 +13,7 @@
<div
style=
"width:400px; float:right;"
>
<textarea
style=
"width:400px;"
name=
"teacher_string"
id=
"teacher_string"
>
{{ teacher_area }}
</textarea></div>
{{ teacher_form.hidden_tag() }}
<div
style=
"float:left;"
>
{{ teacher_form.make }}
</div>
<div
style=
"float:left;"
>
{{ teacher_form.make
(style="list-style:none")
}}
</div>
</div>
<label
for=
"student_string"
>
Moje řešení
</label><br>
...
...
@@ -21,7 +21,7 @@
<div
style=
"width:400px; float:right;"
>
<textarea
style=
"width:400px;"
name=
"student_string"
id=
"student_string"
>
{{ student_area }}
</textarea></div>
{{ student_form.hidden_tag() }}
<div
style=
"float:left;"
>
{{ student_form.make }}
</div>
<div
style=
"float:left;"
>
{{ student_form.make
(style="list-style:none")
}}
</div>
</div>
<input
type=
"submit"
name=
"submit_button"
value=
"Porovnej"
>
...
...
evalweb/templates/convert.html
View file @
3e7393c3
...
...
@@ -14,12 +14,12 @@
<div
style=
"width:400px; float:right;"
>
<textarea
style=
"width:400px;"
name=
"student_string"
id=
"student_string"
>
{{ student_area }}
</textarea></div>
{{ student_form.hidden_tag() }}
<div
style=
"float:left;"
>
{{ student_form.make }}
</div>
<div
style=
"float:left;"
>
{{ student_form.make
(style="list-style:none")
}}
</div>
</div>
<label>
Převeď na typ
</label><br>
{{ task_form.hidden_tag() }}
{{ task_form.make }}
{{ task_form.make
(style="list-style:none")
}}
<input
type=
"submit"
name=
"submit_button"
value=
"Převeď"
>
</form>
...
...
evalweb/templates/result_compare.html
View file @
3e7393c3
...
...
@@ -13,7 +13,7 @@
{% else %} nesprávné řešení.
{% endif %}
</h2><br>
{% if alphabets != "" %}{{ alphabets }}
<br><br>
{% endif %}
{% if alphabets != "" %}
<b>
{{ alphabets }}
<
/b><
br><br>
{% endif %}
{% if task_solved == "" %}
Odpověď splňuje požadavky kladené na formalismus.
...
...
@@ -57,7 +57,10 @@
<p>
<h3>
Porovnání jazyků
</h3>
<img
style=
"float:left; margin:10px 30px;"
src=
"static/img/{{ img_src }}.png"
alt=
"{{ img_src }}"
><br>
{% if img_src %}
<img
style=
"float:left; margin:10px 30px;"
src=
"static/img/{{ img_src }}.png"
alt=
"{{ img_src }}"
><br>
{% endif %}
{% if not ok and (extra_word_ce or missing_word_ce) %}
{% if extra_word_ce %}
Příklad slova, které je ve studentově řešení a není v zadaném jazyce: {{ extra_word_ce }}
...
...
@@ -81,6 +84,41 @@
{% endif %}
</p>
<div>
{% if langs[0] %}
<table>
<tr>
<th>
Jazyk
</th><th>
Charakteristika
</th><th>
Slovo z jazyka
</th><th>
Automat
</th></tr>
<tr><td>
0
</td><td>
{{ langs[0].sizename }}
</td><td>
{{ langs[0].example }}
</td><td><button
onclick=
"toggleDFA('.dfa_0')"
>
Automat
</button>
<div
class=
"dfa_0"
style=
"display: none;"
>
{{ langs[0].minimal }}
</div></td></tr>
{% if langs[1] %}
<tr><td>
1
</td><td>
{{ langs[1].sizename }}
</td><td>
{{ langs[1].example }}
</td><td><button
onclick=
"toggleDFA('.dfa_1')"
>
Automat
</button>
<div
class=
"dfa_1"
style=
"display: none;"
>
{{ langs[1].minimal }}
</div></td></tr>
{% if langs[2] %}
<tr><td>
2
</td><td>
{{ langs[2].sizename }}
</td><td>
{{ langs[2].example }}
</td><td><button
onclick=
"toggleDFA('.dfa_2')"
>
Automat
</button>
<div
class=
"dfa_2"
style=
"display: none;"
>
{{ langs[2].minimal }}
</div></td></tr>
{% if langs[3] %}
<tr><td>
3
</td><td>
{{ langs[3].sizename }}
</td><td>
{{ langs[3].example }}
</td><td><button
onclick=
"toggleDFA('.dfa_3')"
>
Automat
</button>
<div
class=
"dfa_3"
style=
"display: none;"
>
{{ langs[3].minimal }}
</div></td></tr>
{% endif %}
{% endif %}
{% endif %}
</table>
{% endif %}
</div>
<script>
function
toggleDFA
(
dfa
){
el
=
document
.
querySelector
(
dfa
);
if
(
el
.
style
.
display
==
'
none
'
){
el
.
style
.
display
=
'
block
'
}
else
{
el
.
style
.
display
=
'
none
'
}
}
</script>
<br><br><br><br><br>
<div
style=
"margin:10px 30px;"
>
<h3>
Vygenerovaný řetězec pro odpovědník
</h3>
...
...
evalweb/web_checker.py
View file @
3e7393c3
import
lib.reg
as
reg
from
lib.parsing.parser
import
Parser
,
ParsingError
from
lib.checker
import
transform
,
dfa_transform
,
nfa_transform
,
check_task
,
check_alphabets
from
typing
import
List
,
Tuple
from
enum
import
Enum
import
enum
...
...
@@ -13,7 +14,7 @@ class Size(Enum):
class
Language
:
# contains information about formalism and its language
def
__init__
(
self
,
string
:
str
,
task
:
str
):
def
__init__
(
self
,
string
:
str
,
task
:
str
=
"DFA"
):
self
.
string
=
string
self
.
task
=
task
self
.
dfa
=
None
...
...
@@ -52,7 +53,7 @@ class Language: # contains information about formalism and its language
teacher
=
"NFA"
if
self
.
task
==
"EFA"
else
self
.
task
parser
=
Parser
()
dfa
=
parser
.
dfa_to_str
(
self
.
dfa
.
canonize
())
return
f
"
{
teacher
}
-
{
task
}
-N
:
{
dfa
}
"
return
f
"
{
teacher
}
-
{
task
}
:
{
dfa
}
"
class
WebChecker
:
...
...
@@ -65,7 +66,8 @@ class WebChecker:
self
.
teacher
=
None
self
.
student
=
None
self
.
is_task
=
None
self
.
img_src
=
"disjunction"
self
.
img_src
=
None
self
.
languages
=
[
None
,
None
,
None
,
None
]
# nearly equivalent to dfa_task in fja_checker (for IS ROPOTs)
def
dfa_task
(
self
,
teacher_type
,
teacher_string
,
task
,
student_string
):
...
...
@@ -92,11 +94,13 @@ class WebChecker:
teacher_alpha
=
teacher
.
dfa
.
characters
,
task
=
task
)
if
alphabets
!=
""
:
self
.
alphabets
=
alphabets
return
False
self
.
eq
=
reg
.
DFA
.
is_equivalent
(
student
.
dfa
,
teacher
.
dfa
)
# self.img_src = self.picture(self.eq.inf is None)
self
.
img_src
=
self
.
relation
(
self
.
eq
.
left_counterexample
is
None
and
self
.
eq
.
right_counterexample
is
None
)
if
self
.
task_solved
==
""
and
\
self
.
eq
.
right_counterexample
is
None
and
\
self
.
eq
.
left_counterexample
is
None
:
...
...
@@ -121,13 +125,11 @@ class WebChecker:
dfa
=
dfa_transform
(
self
.
student_string
,
student_type
)
if
self
.
task
==
"DFA"
:
return
parser
.
dfa_to_str
(
dfa
)
return
parser
.
dfa_to_str
(
dfa
.
canonize
()
)
if
self
.
task
==
"TOT"
:
return
parser
.
dfa_to_str
(
dfa
.
total
())
return
parser
.
dfa_to_str
(
dfa
.
total
()
.
canonize
()
)
if
self
.
task
==
"MIN"
:
return
parser
.
dfa_to_str
(
dfa
.
minimize
().
canonize
())
#if canonize: TODO checkbox
# return parser.dfa_to_str(automaton.canonize())
nfa
=
nfa_transform
(
self
.
student_string
,
student_type
)
if
self
.
task
==
"EFA"
:
...
...
@@ -146,28 +148,59 @@ class WebChecker:
except
Exception
as
ex
:
print
(
"Error inside of web checker:"
,
ex
.
args
)
def
relation
(
self
,
eq
:
bool
)
->
str
:
# TODO test
def
relation
(
self
,
eq
:
bool
)
->
str
:
student
=
self
.
student
.
dfa
teacher
=
self
.
teacher
.
dfa
# language 0 on picture: complement of both
self
.
languages
[
0
]
=
self
.
language
((
reg
.
DFA
.
union
(
teacher
,
student
)).
complement
())
if
not
eq
:
if
self
.
eq
.
left_counterexample
is
not
None
:
# extra word
if
self
.
eq
.
lef
t_counterexample
is
not
None
:
# missing word
intersection
=
reg
.
DFA
.
intersection
(
self
.
student
.
dfa
,
self
.
teacher
.
dfa
)
if
self
.
eq
.
righ
t_counterexample
is
not
None
:
# missing word
intersection
=
reg
.
DFA
.
intersection
(
student
,
teacher
)
if
intersection
.
is_empty
():
# disjunction
self
.
languages
[
1
]
=
self
.
teacher
self
.
languages
[
2
]
=
self
.
student
return
"disjunction"
else
:
self
.
languages
[
1
]
=
self
.
language
(
reg
.
DFA
.
subtraction
(
teacher
,
student
))
self
.
languages
[
2
]
=
self
.
language
(
reg
.
DFA
.
subtraction
(
student
,
teacher
))
self
.
languages
[
3
]
=
self
.
language
(
reg
.
DFA
.
intersection
(
teacher
,
student
))
return
"intersection"
else
:
# teacher is subset of student
self
.
languages
[
1
]
=
self
.
teacher
self
.
languages
[
2
]
=
self
.
language
(
reg
.
DFA
.
subtraction
(
student
,
teacher
))
picture
=
"t_in_s"
else
:
# student is subset of teacher
self
.
languages
[
1
]
=
self
.
language
(
reg
.
DFA
.
subtraction
(
teacher
,
student
))
self
.
languages
[
2
]
=
self
.
student
picture
=
"s_in_t"
else
:
print
(
self
.
eq
.
left_counterexample
,
self
.
eq
.
right_counterexample
)
picture
=
"eq"
self
.
languages
[
0
]
=
self
.
language
(
teacher
.
complement
())
self
.
languages
[
1
]
=
self
.
teacher
if
self
.
teacher
.
size
==
Size
.
Empty
or
self
.
student
.
size
==
Size
.
Universal
:
picture
+=
"_empty"
el
if
self
.
teacher
.
size
==
Size
.
Universal
or
self
.
student
.
size
==
Size
.
Universal
:
#
if self.teacher.size == Size.Empty or self.student.size == Size.Universal:
#
picture += "_empty"
if
self
.
teacher
.
size
==
Size
.
Universal
or
self
.
student
.
size
==
Size
.
Universal
:
picture
+=
"_universal"
if
self
.
teacher
.
size
==
Size
.
Universal
:
self
.
languages
.
pop
(
0
)
if
self
.
student
.
size
==
Size
.
Universal
:
self
.
languages
[
0
]
=
self
.
languages
[
2
]
self
.
languages
[
2
]
=
None
return
picture
# name of static image file to show in feedback
def
language
(
self
,
dfa
:
reg
.
DFA
)
->
Language
:
parser
=
Parser
()
return
Language
(
parser
.
dfa_to_str
(
dfa
))
def
DFA_lines
(
self
,
str
):
pass
lib/dfa.py
View file @
3e7393c3
...
...
@@ -158,11 +158,13 @@ class DFA:
# new final
final
:
Set
[
State
]
=
set
()
for
state_1
in
dfa_1
.
final
:
for
state_2
in
dfa_2
.
final
:
for
state_1
in
dfa_1
.
states
:
for
state_2
in
dfa_2
.
states
:
state
=
DFA
.
state_composition
(
state_1
,
state_2
)
if
operation
==
Composition
.
Union
:
if
operation
==
Composition
.
Union
and
\
(
state_1
in
dfa_1
.
final
or
\
state_2
in
dfa_2
.
final
):
final
.
add
(
state
)
elif
operation
==
Composition
.
Intersection
and
\
...
...
@@ -171,6 +173,7 @@ class DFA:
final
.
add
(
state
)
elif
operation
==
Composition
.
Subtraction
and
\
state_1
in
dfa_1
.
final
and
\
state_2
not
in
dfa_2
.
final
:
final
.
add
(
state
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment