File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818SEMANTICSCHOLAR_DELAY = 1.0
1919CACHE_DIR = os .path .expanduser ("~/.cache/check-hallucinations" )
2020
21- # Quotes are typographical decoration for title matching. Removing them also
22- # makes BibTeX's TeX-style ``...'' quotes compare equal to straight or curly
23- # quotes returned by external APIs.
24- _TITLE_QUOTE_TRANSLATION = str .maketrans ("" , "" , "`'\" \u2018 \u2019 \u201c \u201d " )
21+ # Quotes are typographical decoration for title matching. Treating them as
22+ # word boundaries makes BibTeX's TeX-style ``...'' quotes compare equal to
23+ # straight or curly quotes, including API metadata missing a space after one.
24+ _TITLE_QUOTE_TRANSLATION = str .maketrans (
25+ {quote : " " for quote in "`'\" \u2018 \u2019 \u201c \u201d " }
26+ )
2527
2628
2729def _api_key ():
@@ -34,7 +36,7 @@ def _strip_diacritics(s):
3436
3537
3638def _normalize_title (title ):
37- return _strip_diacritics (
39+ normalized = _strip_diacritics (
3840 title .lower ()
3941 .strip ()
4042 .translate (_TITLE_QUOTE_TRANSLATION )
@@ -46,8 +48,6 @@ def _normalize_title(title):
4648 .replace ("\\ #" , "#" )
4749 .replace (": " , ". " )
4850 .replace ("," , " " )
49- .replace (" " , " " )
50- .replace (" " , " " )
5151 .replace ("{" , "" )
5252 .replace ("}" , "" )
5353 .replace (" " , " " )
@@ -58,6 +58,7 @@ def _normalize_title(title):
5858 .replace ("-" , " " )
5959 .replace (" ..." , "..." )
6060 )
61+ return " " .join (normalized .split ())
6162
6263
6364def _cache_path (subdir , key ):
Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ def test_latex_quotes_match_semantic_scholar_quotes():
3636 )
3737
3838
39+ def test_quote_preserves_word_boundary_for_missing_api_space ():
40+ bib = "On LLMs' Internal Representation of Code Correctness"
41+ ss = "On LLMs'Internal Representation of Code Correctness"
42+ assert _title_matches (ss , bib )
43+
44+
3945def test_double_dash_vs_single_dash ():
4046 bib = "DeepSeek-Coder: When the large language model meets programming -- the rise of code intelligence"
4147 ss = "DeepSeek-Coder: When the Large Language Model Meets Programming - The Rise of Code Intelligence"
You can’t perform that action at this time.
0 commit comments