← All presentation pages

Semantic Similarity: spotting the same issue described in different words

One of the four signals the framework's conflict-resolution design uses to merge duplicate findings from different tools.

Where this fits: the dissertation (Section 4.3.3) designs a correlation algorithm with four signals: location, anti-pattern type, semantic similarity of the descriptions, and timing (found in the same run). The prototype uses simplified tool concepts, so this page explains how the semantic step works using a small, real example. All scores below were calculated with scikit-learn, not estimated.

1. The problem: one issue, several reports

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.

Finding A: SonarQube concept"Hardcoded database connection detected in UserService"UserService.java · line 4
Finding B: ArchUnit concept"Database connection string is hardcoded in UserService"UserService.java · line 4
Finding C: SonarQube concept"Synchronous blocking operation detected in UserService"UserService.java · line 7

A and B are the same problem. C is a different one, even though it's in the same file.

2. How the matching works

Step 1: Turn each description into numbers (TF-IDF)

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.

Step 2: Compare the vectors (cosine similarity)

Cosine similarity measures how closely two vectors point the same way: 1.0 = identical wording, 0 = no words in common.

PairCosine similarityResult (example threshold 0.7)
A vs B: same issue0.73Above threshold → treat as one issue
A vs C: different issue0.29Below threshold → keep separate
B vs C: different issue0.10Below threshold → keep separate

Step 3: Combine it with the other signals

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.

3. Python code (runs as shown)

# 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)]

4. Strengths and limits

✅ Works well when…

Tools use overlapping words for the same problem ("hardcoded", "connection"). It's fast, needs no training data, and is easy to explain.

⚠️ Struggles when…

Tools use synonyms with no words in common. For example, "Excessive coupling between services" vs "Services are tightly interconnected" scores only 0.19. That's why location and pattern type are also used, and why embedding-based NLP (a machine-learning model) is listed as future work.

Mahyad Mirzabagheri · MSc Software Engineering, Staffordshire University · Source code on GitHub