Spaces:
Sleeping
Sleeping
Bug fix
Browse files
app.py
CHANGED
@@ -68,103 +68,98 @@ def parse_tgrl(file_obj):
|
|
68 |
|
69 |
return tgrl_text
|
70 |
|
71 |
-
def
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
corresponding_actor =
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
elements_per_actor[corresponding_actor] = []
|
114 |
-
elements_per_actor[corresponding_actor].append(task)
|
115 |
-
|
116 |
-
# get decomposed elements
|
117 |
-
|
118 |
-
new_tgrl_text = tgrl_text
|
119 |
-
decomposed_elements = {}
|
120 |
-
|
121 |
-
main_elements_1 = re.findall("\w+(?=\s+decomposedBy)", new_tgrl_text)
|
122 |
-
|
123 |
-
for main_element in main_elements_1:
|
124 |
sub_element_1 = (re.findall(main_element+"\s*(?: decomposedBy )([A-Za-z\s]*)", new_tgrl_text)[0])
|
125 |
sub_element_1 = sub_element_1.replace(" ", "")
|
126 |
sub_element_2 = (re.findall(main_element+"\s*(?: decomposedBy )"+ sub_element_1 +",\s*([A-Za-z\s]*)", new_tgrl_text)[0])
|
127 |
new_tgrl_text = new_tgrl_text.replace(main_element+" decomposedBy "+sub_element_1+", "+sub_element_2+";", '')
|
128 |
decomposed_elements[main_element] = [sub_element_1, sub_element_2]
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
new_key = re.findall("(?:"+key+"\s*{\s*name\s=\s\")([A-Za-z\s]*)", tgrl_text)[0]
|
136 |
new_values = []
|
137 |
-
|
138 |
for element in decomposed_elements[key]:
|
139 |
new_value = re.findall("(?:"+element+"\s*{\s*name\s=\s\")([A-Za-z\s;.,!?:-]*)", tgrl_text)[0]
|
140 |
new_values.append(new_value)
|
141 |
-
|
142 |
new_decomposed_elements[new_key] = new_values
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
sub_element_1 = (re.findall(main_element+"(?: contributesTo )([A-Za-z\s]*)", new_tgrl_text)[0])
|
152 |
sub_element_1 = sub_element_1.replace(" ", "")
|
153 |
contribution = (re.findall(main_element+"(?: contributesTo )"+ sub_element_1 +"\s{(-*[0-9A-Za-z]*)", new_tgrl_text)[0])
|
154 |
new_tgrl_text = new_tgrl_text.replace(main_element+" contributesTo "+sub_element_1, '')
|
155 |
contributing_elements.append([main_element, sub_element_1, contribution])
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
corresponding_actor_1 = tgrl_text.rfind('actor', 0, tgrl_text.index(" "+element[0]))
|
160 |
corresponding_actor_1 = re.split(' |{', tgrl_text[corresponding_actor_1:])[1]
|
161 |
if corresponding_actor_1 not in contributing_elements_IDs_per_actor:
|
162 |
contributing_elements_IDs_per_actor[corresponding_actor_1] = []
|
163 |
contributing_elements_IDs_per_actor[corresponding_actor_1].append(element)
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
contributing_elements = []
|
169 |
for elements in contributing_elements_IDs_per_actor[key]:
|
170 |
element_name_1 = re.findall("(?:"+elements[0]+"\s*{\s*name\s=\s\")([A-Za-z\s;.,!?:-]*)", tgrl_text)[0]
|
@@ -172,13 +167,41 @@ def extract_elements(tgrl_text):
|
|
172 |
contributing_elements.append([element_name_1, element_name_2, elements[2]])
|
173 |
contributing_elements_per_actor[key] = contributing_elements
|
174 |
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
-
|
178 |
|
179 |
-
# ************************* Bad Smells Detection *************************
|
180 |
|
181 |
-
# ########### Long Elements ###########
|
182 |
def get_long_elements(elements, size_threshold): # Using RegEx
|
183 |
|
184 |
long_elements = []
|
@@ -750,7 +773,6 @@ def detect_bad_smells(tgrl_file, selected_bad_smells, size_threshold, similarity
|
|
750 |
all_elements, elements_per_actor, decomposed_elements, contributing_elements = extract_elements(tgrl_text)
|
751 |
|
752 |
if 'Lengthy element' in selected_bad_smells:
|
753 |
-
print(output)
|
754 |
result = get_long_elements(all_elements, size_threshold)
|
755 |
if result != "":
|
756 |
output = output + result + "\n\n"
|
|
|
68 |
|
69 |
return tgrl_text
|
70 |
|
71 |
+
def get_elements_per_actor(all_elements, tgrl_text):
|
72 |
|
73 |
+
# Output format : elements_per_actor =
|
74 |
+
# {"actor_1": ["element_1", "element_2"],
|
75 |
+
# "actor_2": ["element_1", "element_2", "element_3"]}
|
76 |
+
|
77 |
+
elements_per_actor = {}
|
78 |
+
|
79 |
+
for goal in all_elements["goals"]:
|
80 |
+
corresponding_actor = tgrl_text.rfind('actor', 0, tgrl_text.index(goal))
|
81 |
+
corresponding_actor = re.split(' |{', tgrl_text[corresponding_actor:])[1]
|
82 |
+
if corresponding_actor not in elements_per_actor:
|
83 |
+
elements_per_actor[corresponding_actor] = []
|
84 |
+
elements_per_actor[corresponding_actor].append(goal)
|
85 |
+
|
86 |
+
for softGoal in all_elements["softGoals"]:
|
87 |
+
corresponding_actor = tgrl_text.rfind('actor', 0, tgrl_text.index(softGoal))
|
88 |
+
corresponding_actor = re.split(' |{', tgrl_text[corresponding_actor:])[1]
|
89 |
+
if corresponding_actor not in elements_per_actor:
|
90 |
+
elements_per_actor[corresponding_actor] = []
|
91 |
+
elements_per_actor[corresponding_actor].append(softGoal)
|
92 |
+
|
93 |
+
for task in all_elements["tasks"]:
|
94 |
+
corresponding_actor = tgrl_text.rfind('actor', 0, tgrl_text.index(task))
|
95 |
+
corresponding_actor = re.split(' |{', tgrl_text[corresponding_actor:])[1]
|
96 |
+
if corresponding_actor not in elements_per_actor:
|
97 |
+
elements_per_actor[corresponding_actor] = []
|
98 |
+
elements_per_actor[corresponding_actor].append(task)
|
99 |
+
|
100 |
+
return elements_per_actor
|
101 |
+
|
102 |
+
def get_decomposed_elements(tgrl_text):
|
103 |
+
|
104 |
+
# Output format : decomposed_elements =
|
105 |
+
# {"main_element_1": ["sub_element_1", "sub_element_1"]}
|
106 |
+
|
107 |
+
new_tgrl_text = tgrl_text
|
108 |
+
decomposed_elements = {}
|
109 |
+
|
110 |
+
main_elements_1 = re.findall("\w+(?=\s+decomposedBy)", new_tgrl_text)
|
111 |
+
|
112 |
+
for main_element in main_elements_1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
sub_element_1 = (re.findall(main_element+"\s*(?: decomposedBy )([A-Za-z\s]*)", new_tgrl_text)[0])
|
114 |
sub_element_1 = sub_element_1.replace(" ", "")
|
115 |
sub_element_2 = (re.findall(main_element+"\s*(?: decomposedBy )"+ sub_element_1 +",\s*([A-Za-z\s]*)", new_tgrl_text)[0])
|
116 |
new_tgrl_text = new_tgrl_text.replace(main_element+" decomposedBy "+sub_element_1+", "+sub_element_2+";", '')
|
117 |
decomposed_elements[main_element] = [sub_element_1, sub_element_2]
|
118 |
+
|
119 |
+
# Replace elements IDs with names
|
120 |
+
new_decomposed_elements = {}
|
121 |
+
|
122 |
+
for key, _ in decomposed_elements.items():
|
123 |
+
|
124 |
new_key = re.findall("(?:"+key+"\s*{\s*name\s=\s\")([A-Za-z\s]*)", tgrl_text)[0]
|
125 |
new_values = []
|
126 |
+
|
127 |
for element in decomposed_elements[key]:
|
128 |
new_value = re.findall("(?:"+element+"\s*{\s*name\s=\s\")([A-Za-z\s;.,!?:-]*)", tgrl_text)[0]
|
129 |
new_values.append(new_value)
|
130 |
+
|
131 |
new_decomposed_elements[new_key] = new_values
|
132 |
|
133 |
+
return new_decomposed_elements
|
134 |
+
|
135 |
+
def get_contributing_elements(tgrl_text):
|
136 |
+
|
137 |
+
# Output format : contributing_elements_per_actor =
|
138 |
+
# {"actor_1": [["element_1", "element_2", "contribution_value"], ["element_1", "element_3", "contribution_value"]],
|
139 |
+
# "actor_2": [["element_1", "element_2", "contribution_value"]]}
|
140 |
+
|
141 |
+
new_tgrl_text = tgrl_text
|
142 |
+
contributing_elements = []
|
143 |
+
|
144 |
+
main_elements_1 = re.findall("\w+(?=\s+contributesTo)", new_tgrl_text)
|
145 |
+
for main_element in main_elements_1:
|
146 |
sub_element_1 = (re.findall(main_element+"(?: contributesTo )([A-Za-z\s]*)", new_tgrl_text)[0])
|
147 |
sub_element_1 = sub_element_1.replace(" ", "")
|
148 |
contribution = (re.findall(main_element+"(?: contributesTo )"+ sub_element_1 +"\s{(-*[0-9A-Za-z]*)", new_tgrl_text)[0])
|
149 |
new_tgrl_text = new_tgrl_text.replace(main_element+" contributesTo "+sub_element_1, '')
|
150 |
contributing_elements.append([main_element, sub_element_1, contribution])
|
151 |
+
|
152 |
+
contributing_elements_IDs_per_actor = {}
|
153 |
+
for element in contributing_elements:
|
154 |
corresponding_actor_1 = tgrl_text.rfind('actor', 0, tgrl_text.index(" "+element[0]))
|
155 |
corresponding_actor_1 = re.split(' |{', tgrl_text[corresponding_actor_1:])[1]
|
156 |
if corresponding_actor_1 not in contributing_elements_IDs_per_actor:
|
157 |
contributing_elements_IDs_per_actor[corresponding_actor_1] = []
|
158 |
contributing_elements_IDs_per_actor[corresponding_actor_1].append(element)
|
159 |
+
|
160 |
+
# Replace elements IDs with names
|
161 |
+
contributing_elements_per_actor = {}
|
162 |
+
for key, values in contributing_elements_IDs_per_actor.items():
|
163 |
contributing_elements = []
|
164 |
for elements in contributing_elements_IDs_per_actor[key]:
|
165 |
element_name_1 = re.findall("(?:"+elements[0]+"\s*{\s*name\s=\s\")([A-Za-z\s;.,!?:-]*)", tgrl_text)[0]
|
|
|
167 |
contributing_elements.append([element_name_1, element_name_2, elements[2]])
|
168 |
contributing_elements_per_actor[key] = contributing_elements
|
169 |
|
170 |
+
return contributing_elements_per_actor
|
171 |
+
|
172 |
+
def extract_elements(tgrl_text):
|
173 |
+
|
174 |
+
# Extract actors
|
175 |
+
actors = re.findall("(?:.*?actor\s\S+\s?{\s?name\s?=\s?\")([A-Za-z\s;.,!?:-]*)(?:\")", tgrl_text)
|
176 |
+
# Extract goals
|
177 |
+
goals = re.findall("(?:.*?goal\s\S+\s?{\s?name\s?=\s?\")([A-Za-z\s;.,!?:-]*)(?:\")", tgrl_text)
|
178 |
+
# Extract softGoals
|
179 |
+
softGoals = re.findall("(?:.*?softGoal\s\S+\s?{\s?name\s?=\s?\")([A-Za-z\s;.,!?:-]*)(?:\")", tgrl_text)
|
180 |
+
# Extract tasks
|
181 |
+
tasks = re.findall("(?:.*?task\s\S+\s?{\s?name\s?=\s?\")([A-Za-z\s;.,!?:-]*)(?:\")", tgrl_text)
|
182 |
+
# Extract resources
|
183 |
+
resources = re.findall("(?:.*?resource\s\S+\s?{\s?name\s?=\s?\")([A-Za-z\s;.,!?:-]*)(?:\")", tgrl_text)
|
184 |
+
|
185 |
+
all_elements = {
|
186 |
+
"actors": actors,
|
187 |
+
"goals": goals,
|
188 |
+
"softGoals": softGoals,
|
189 |
+
"tasks": tasks,
|
190 |
+
"resources": resources
|
191 |
+
}
|
192 |
+
|
193 |
+
####### get elements per actor #######
|
194 |
+
elements_per_actor = get_elements_per_actor(all_elements, tgrl_text)
|
195 |
+
|
196 |
+
####### get decomposed elements #######
|
197 |
+
decomposed_elements = get_decomposed_elements(tgrl_text)
|
198 |
+
|
199 |
+
####### get contributing elements #######
|
200 |
+
contributing_elements_per_actor = get_contributing_elements(tgrl_text)
|
201 |
|
202 |
+
return all_elements, elements_per_actor, decomposed_elements, contributing_elements_per_actor
|
203 |
|
|
|
204 |
|
|
|
205 |
def get_long_elements(elements, size_threshold): # Using RegEx
|
206 |
|
207 |
long_elements = []
|
|
|
773 |
all_elements, elements_per_actor, decomposed_elements, contributing_elements = extract_elements(tgrl_text)
|
774 |
|
775 |
if 'Lengthy element' in selected_bad_smells:
|
|
|
776 |
result = get_long_elements(all_elements, size_threshold)
|
777 |
if result != "":
|
778 |
output = output + result + "\n\n"
|