Skip to content

Commit 7d80ea6

Browse files
monperrusclaude
andcommitted
Accept titles with high word-level Jaccard similarity (>=0.85)
Handles cases like bib "real-GitHub issues" vs SS "Real-World GitHub Issues" where splitting on hyphens makes all bib words a subset of the SS title. Adds _title_word_jaccard helper and a test case for this pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eeffc25 commit 7d80ea6

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

check_hallucinations/main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import hashlib
88
import json
99
import os
10+
import re
1011
import time
1112
import unicodedata
1213

@@ -45,6 +46,14 @@ def _normalize_title(title):
4546
)
4647

4748

49+
def _title_word_jaccard(a, b):
50+
wa = set(re.split(r'[-\s?!,.:;]+', a.lower())) - {""}
51+
wb = set(re.split(r'[-\s?!,.:;]+', b.lower())) - {""}
52+
if not wa or not wb:
53+
return 0.0
54+
return len(wa & wb) / len(wa | wb)
55+
56+
4857
def _cache_path(subdir, key):
4958
digest = hashlib.sha256(key.encode("utf-8")).hexdigest()
5059
path = os.path.join(CACHE_DIR, subdir)
@@ -109,7 +118,8 @@ def get_url_from_title(title):
109118
if not result or "paperId" not in result:
110119
raise SemanticScholarNotFound("No data found for title: " + title)
111120
ss_main = _normalize_title(result["title"].split(":")[0])
112-
if _normalize_title(result["title"]) == _normalize_title(title) or ss_main == _normalize_title(title):
121+
similar_enough = _title_word_jaccard(result["title"], title) >= 0.85
122+
if _normalize_title(result["title"]) == _normalize_title(title) or ss_main == _normalize_title(title) or similar_enough:
113123
data = _get_paper_info(result["paperId"])
114124
if "externalIds" in data:
115125
if "DOI" in data["externalIds"]:

test_normalize.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from check_hallucinations.main import _normalize_title
1+
from check_hallucinations.main import _normalize_title, _title_word_jaccard
22

33

44
def test_colon_vs_period_subtitle():
@@ -18,3 +18,11 @@ def test_diacritics():
1818

1919
def test_curly_braces():
2020
assert _normalize_title("{Foo} Bar") == _normalize_title("Foo Bar")
21+
22+
23+
def test_word_jaccard_hyphen_split():
24+
# bib: "real-GitHub" splits as "real"+"github"; SS has "Real-World GitHub"
25+
# all bib words are in SS → Jaccard 0.9
26+
bib = "SWE-bench: Can language models resolve real-GitHub issues?"
27+
ss = "SWE-bench: Can Language Models Resolve Real-World GitHub Issues?"
28+
assert _title_word_jaccard(bib, ss) >= 0.85

0 commit comments

Comments
 (0)