Spaces:
Runtime error
Runtime error
Add size and similarity score threshold input
Browse files
app.py
CHANGED
@@ -134,13 +134,13 @@ def extract_elements(tgrl_text):
|
|
134 |
# ************************* Bad Smells Detection *************************
|
135 |
|
136 |
# ########### Long Elements ###########
|
137 |
-
def get_long_elements(elements): # Using RegEx
|
138 |
|
139 |
long_elements = []
|
140 |
|
141 |
for key, value in elements.items():
|
142 |
for i in range(0, len(elements[key])):
|
143 |
-
if len(re. findall(r'\w+', elements[key][i])) >
|
144 |
long_elements.append(elements[key][i])
|
145 |
|
146 |
if long_elements:
|
@@ -332,7 +332,7 @@ def check_task_syntax(tasks):
|
|
332 |
# ############################################
|
333 |
|
334 |
# ########## Similarity ###########
|
335 |
-
def get_similar_elements(elements_per_actor):
|
336 |
|
337 |
# Prepare sentence pair array
|
338 |
sentence_pairs = []
|
@@ -348,7 +348,7 @@ def get_similar_elements(elements_per_actor):
|
|
348 |
|
349 |
similar_elements = []
|
350 |
for index, value in enumerate(sentence_pairs):
|
351 |
-
if semantic_similarity_scores[index] >
|
352 |
similar_elements.append(value)
|
353 |
#semantic_similarity["pair_"+str(index+1)] = [value,semantic_similarity_scores[index]]
|
354 |
|
@@ -497,7 +497,7 @@ def check_contradiction(elements_per_actor):
|
|
497 |
|
498 |
# ************************* User Interface *************************
|
499 |
|
500 |
-
def identify_bad_smells(tgrl_file, selected_bad_smells):
|
501 |
|
502 |
output = ""
|
503 |
|
@@ -506,7 +506,7 @@ def identify_bad_smells(tgrl_file, selected_bad_smells):
|
|
506 |
elements, elements_per_actor, decomposed_elements = extract_elements(tgrl_text)
|
507 |
|
508 |
if 'Size' in selected_bad_smells:
|
509 |
-
output = output + get_long_elements(elements) + "\n\n"
|
510 |
|
511 |
if 'Complexity' in selected_bad_smells:
|
512 |
output = output + get_complex_sentences(elements) + "\n\n"
|
@@ -527,7 +527,7 @@ def identify_bad_smells(tgrl_file, selected_bad_smells):
|
|
527 |
output = output + check_task_syntax(elements['tasks']) + "\n\n"
|
528 |
|
529 |
if 'Similar Elements' in selected_bad_smells:
|
530 |
-
output = output + get_similar_elements(elements_per_actor) + "\n\n"
|
531 |
|
532 |
if 'Spelling Mistakes' in selected_bad_smells:
|
533 |
output = output + check_spelling(elements) + "\n\n"
|
@@ -544,9 +544,11 @@ def identify_bad_smells(tgrl_file, selected_bad_smells):
|
|
544 |
|
545 |
interface = gr.Interface(fn = identify_bad_smells,
|
546 |
inputs = [gr.File(label="TGRL File"),
|
547 |
-
|
548 |
-
label="Which bad smells you want to detect?")
|
549 |
-
|
|
|
|
|
550 |
title = "TGRL Bad Smells Detection",
|
551 |
description = "Upload your .xgrl file and we will find the bad smells for you!",
|
552 |
theme = gr.themes.Soft())
|
|
|
134 |
# ************************* Bad Smells Detection *************************
|
135 |
|
136 |
# ########### Long Elements ###########
|
137 |
+
def get_long_elements(elements, size_threshold): # Using RegEx
|
138 |
|
139 |
long_elements = []
|
140 |
|
141 |
for key, value in elements.items():
|
142 |
for i in range(0, len(elements[key])):
|
143 |
+
if len(re. findall(r'\w+', elements[key][i])) > size_threshold:
|
144 |
long_elements.append(elements[key][i])
|
145 |
|
146 |
if long_elements:
|
|
|
332 |
# ############################################
|
333 |
|
334 |
# ########## Similarity ###########
|
335 |
+
def get_similar_elements(elements_per_actor, similarity_threshold):
|
336 |
|
337 |
# Prepare sentence pair array
|
338 |
sentence_pairs = []
|
|
|
348 |
|
349 |
similar_elements = []
|
350 |
for index, value in enumerate(sentence_pairs):
|
351 |
+
if semantic_similarity_scores[index] > similarity_threshold:
|
352 |
similar_elements.append(value)
|
353 |
#semantic_similarity["pair_"+str(index+1)] = [value,semantic_similarity_scores[index]]
|
354 |
|
|
|
497 |
|
498 |
# ************************* User Interface *************************
|
499 |
|
500 |
+
def identify_bad_smells(tgrl_file, selected_bad_smells, size_threshold, similarity_threshold):
|
501 |
|
502 |
output = ""
|
503 |
|
|
|
506 |
elements, elements_per_actor, decomposed_elements = extract_elements(tgrl_text)
|
507 |
|
508 |
if 'Size' in selected_bad_smells:
|
509 |
+
output = output + get_long_elements(elements, size_threshold) + "\n\n"
|
510 |
|
511 |
if 'Complexity' in selected_bad_smells:
|
512 |
output = output + get_complex_sentences(elements) + "\n\n"
|
|
|
527 |
output = output + check_task_syntax(elements['tasks']) + "\n\n"
|
528 |
|
529 |
if 'Similar Elements' in selected_bad_smells:
|
530 |
+
output = output + get_similar_elements(elements_per_actor, similarity_threshold) + "\n\n"
|
531 |
|
532 |
if 'Spelling Mistakes' in selected_bad_smells:
|
533 |
output = output + check_spelling(elements) + "\n\n"
|
|
|
544 |
|
545 |
interface = gr.Interface(fn = identify_bad_smells,
|
546 |
inputs = [gr.File(label="TGRL File"),
|
547 |
+
gr.CheckboxGroup(["Size", "Complexity", "Punctuations", "Actors Syntax", "Goals Syntax", "Softgoals Syntax", "Tasks Syntax", "Similar Elements", "Spelling Mistakes", "Goal-Subgoal Mismatch", "Contradicting Elements"],
|
548 |
+
label="Which bad smells you want to detect?"),
|
549 |
+
gr.Slider(label= "Size threshold", value = 5, minimum = 2, maximum = 10, step = 1),
|
550 |
+
gr.Slider(label= "Similarity threshold", value = 0.6, minimum = 0, maximum = 1, step = 0.1)],
|
551 |
+
outputs = [gr.Textbox(label= "Detected bad smells:")],
|
552 |
title = "TGRL Bad Smells Detection",
|
553 |
description = "Upload your .xgrl file and we will find the bad smells for you!",
|
554 |
theme = gr.themes.Soft())
|