From b50c9005ea2855163a1e3beb44993d46b6b6b554 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Wed, 15 Oct 2025 14:14:33 -0700 Subject: [PATCH 1/2] find common tags Signed-off-by: Saurabh Misra --- codeflash/result/common_tags.py | 11 +++++++++++ tests/test_common_tags.py | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 codeflash/result/common_tags.py create mode 100644 tests/test_common_tags.py diff --git a/codeflash/result/common_tags.py b/codeflash/result/common_tags.py new file mode 100644 index 000000000..504cb5cd6 --- /dev/null +++ b/codeflash/result/common_tags.py @@ -0,0 +1,11 @@ +from __future__ import annotations + + +def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]: + if not articles: + return set() + + common_tags = articles[0].get("tags", []) + for article in articles[1:]: + common_tags = [tag for tag in common_tags if tag in article.get("tags", [])] + return set(common_tags) diff --git a/tests/test_common_tags.py b/tests/test_common_tags.py new file mode 100644 index 000000000..754261b55 --- /dev/null +++ b/tests/test_common_tags.py @@ -0,0 +1,22 @@ +from codeflash.result.common_tags import find_common_tags + + +def test_common_tags_1() -> None: + articles_1 = [ + {"title": "Article 1", "tags": ["Python", "AI", "ML"]}, + {"title": "Article 2", "tags": ["Python", "Data Science", "AI"]}, + {"title": "Article 3", "tags": ["Python", "AI", "Big Data"]}, + ] + + expected = {"Python", "AI"} + + assert find_common_tags(articles_1) == expected + + articles_2 = [ + {"title": "Article 1", "tags": ["Python", "AI", "ML"]}, + {"title": "Article 2", "tags": ["Python", "Data Science", "AI"]}, + {"title": "Article 3", "tags": ["Python", "AI", "Big Data"]}, + {"title": "Article 4", "tags": ["Python", "AI", "ML"]}, + ] + + assert find_common_tags(articles_2) == expected From 2db26db40de02ed6deee30335894910cffbe7c0b Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Wed, 15 Oct 2025 14:24:47 -0700 Subject: [PATCH 2/2] Update codeflash/result/common_tags.py Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com> --- codeflash/result/common_tags.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/codeflash/result/common_tags.py b/codeflash/result/common_tags.py index 504cb5cd6..fcbb10662 100644 --- a/codeflash/result/common_tags.py +++ b/codeflash/result/common_tags.py @@ -5,7 +5,9 @@ def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]: if not articles: return set() - common_tags = articles[0].get("tags", []) + common_tags = set(articles[0].get("tags", [])) for article in articles[1:]: - common_tags = [tag for tag in common_tags if tag in article.get("tags", [])] - return set(common_tags) + common_tags.intersection_update(article.get("tags", [])) + if not common_tags: + break + return common_tags