One of the four signals the framework's conflict-resolution design uses to merge duplicate findings from different tools.
Each tool writes its own message. Without matching, the developer gets the same problem reported twice and has to work out by hand that it's a duplicate.
A and B are the same problem. C is a different one, even though it's in the same file.
TF-IDF gives every word a weight. Words that appear in only some descriptions (hardcoded, connection, blocking) get high weights, and very common words (is, in, the) are removed. Each description becomes a list of word weights, called a vector.
Cosine similarity measures how closely two vectors point the same way: 1.0 = identical wording, 0 = no words in common.
| Pair | Cosine similarity | Result (example threshold 0.7) |
|---|---|---|
| A vs B: same issue | 0.73 | Above threshold → treat as one issue |
| A vs C: different issue | 0.29 | Below threshold → keep separate |
| B vs C: different issue | 0.10 | Below threshold → keep separate |
Text similarity is never used on its own. A and B also point to the same file and line and the same anti-pattern type, so the evidence agrees. The design's resolution rules then decide what is shown:
Result: the developer sees 2 issues (hardcoded connection, synchronous blocking) instead of 3, and the merged issue notes that two tools agree.
# pip install scikit-learn from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity def find_similar_issues(descriptions, threshold=0.7): # Step 1: descriptions -> TF-IDF vectors (common English words removed) vectors = TfidfVectorizer(stop_words="english").fit_transform(descriptions) # Step 2: similarity of every pair scores = cosine_similarity(vectors) # Step 3: pairs above the threshold are candidate duplicates return [(i, j, round(float(scores[i][j]), 2)) for i in range(len(descriptions)) for j in range(i + 1, len(descriptions)) if scores[i][j] >= threshold] findings = [ "Hardcoded database connection detected in UserService", "Database connection string is hardcoded in UserService", "Synchronous blocking operation detected in UserService", ] print(find_similar_issues(findings)) # [(0, 1, 0.73)]
Mahyad Mirzabagheri · MSc Software Engineering, Staffordshire University · Source code on GitHub