Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions RequirementsTraceabilityAssignment/sorted_frs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FR2: 0.7272982597351074
FR59: 0.6924091577529907
FR41: 0.658149242401123
FR3: 0.6336919665336609
FR32: 0.6048915386199951
FR9: 0.5977640151977539
FR13: 0.5880354046821594
FR30: 0.5614917278289795
FR6: 0.5527222156524658
FR56: 0.501095712184906
FR35: 0.4926453232765198
FR51: 0.4922177791595459
FR43: 0.4850791394710541
FR27: 0.4834768772125244
FR50: 0.4728085994720459
FR16: 0.4689098000526428
FR23: 0.46860480308532715
FR10: 0.4604903757572174
FR42: 0.4555082321166992
FR47: 0.4390988349914551
FR40: 0.4389651417732239
FR49: 0.43022799491882324
FR54: 0.4262740910053253
FR21: 0.41903120279312134
FR15: 0.40128734707832336
FR28: 0.39869096875190735
FR1: 0.372334361076355
FR7: 0.36662811040878296
FR19: 0.3618888854980469
FR5: 0.36042946577072144
FR14: 0.3450104296207428
FR44: 0.3450104296207428
FR34: 0.3366490602493286
FR33: 0.33334457874298096
FR58: 0.3215200901031494
FR60: 0.28449445962905884
FR24: 0.282522588968277
FR29: 0.27975350618362427
FR31: 0.27687233686447144
FR36: 0.2559022009372711
FR20: 0.25007960200309753
FR18: 0.2497757077217102
FR57: 0.24898050725460052
FR46: 0.23702991008758545
FR45: 0.23629112541675568
FR4: 0.2229391634464264
FR53: 0.21678310632705688
FR52: 0.2120310366153717
FR22: 0.20914143323898315
FR39: 0.20602846145629883
FR17: 0.20446419715881348
FR8: 0.20398864150047302
FR48: 0.2015649676322937
FR26: 0.18092623353004456
FR12: 0.17228464782238007
FR25: 0.16649314761161804
FR11: 0.14829087257385254
FR37: 0.13823707401752472
FR55: 0.13276946544647217
FR38: 0.09154436737298965
63 changes: 62 additions & 1 deletion RequirementsTraceabilityAssignment/traceability_fergujp.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def run_option1(filepath, answerpath):

sim = tfidf_similarity(frs, nfrs)

sort_similarities(frs, sim)

THRESHOLDS_TFIDF = [0.1, 0.1, 0.1]

preds = predict_labels(sim, thresholds=THRESHOLDS_TFIDF)
Expand All @@ -290,6 +292,8 @@ def run_option2(filepath, answerpath):

sim = embedding_similarity(frs, nfrs)

sort_similarities(frs, sim)

THRESHOLDS_EMBEDDING = [0.3, 0.3, 0.3]

preds = predict_labels(sim, thresholds=THRESHOLDS_EMBEDDING)
Expand All @@ -310,7 +314,64 @@ def run_option3(filepath, answerpath):
evaluate(preds, frs, answers)

# ============================================================
# 9. RUN PIPELINE
# 10. OPTIONAL MERGE SORTING OF FRs BASED ON SIMILARITY SCORES
# ============================================================
def sort_similarities(frs, similarities):
"""
Sorts FRs based on max similarity to any NFR
TODO - compared to each NFR separately
"""

fr_sim_pairs = [(fr_id, max(similarities[i])) for i, (fr_id, _) in enumerate(frs)]

# Use manual merge sort instead of sorted()
sorted_pairs = merge_sort(fr_sim_pairs)

# TODO - output as text with the actual FR texts
with open("sorted_frs.txt", "w") as f:
for fr_id, sim in sorted_pairs:
f.write(f"{fr_id}: {sim}\n")

return sorted_pairs

def merge_sort(fr_sim_pairs):
if len(fr_sim_pairs) <= 1:
return fr_sim_pairs

mid = len(fr_sim_pairs) // 2
left = merge_sort(fr_sim_pairs[:mid])
right = merge_sort(fr_sim_pairs[mid:])

return merge(left, right)


def merge(left, right):
result = []
i = 0
j = 0

# Descending order by similarity (index 1)
while i < len(left) and j < len(right):
if left[i][1] >= right[j][1]:
result.append(left[i])
i += 1
else:
result.append(right[j])
j += 1

while i < len(left):
result.append(left[i])
i += 1

while j < len(right):
result.append(right[j])
j += 1

return result


# ============================================================
# 11. RUN PIPELINE
# ============================================================
if __name__ == "__main__":
run_option1(DATAPATH, ANSWERPATH)
Expand Down