"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(papers): split sentences that run on after a number
Rudy Celeklif4b153dc361b
diff --git a/agent/src/tools/research_papers_tool.py b/agent/src/tools/research_papers_tool.pyindex 28c0d6f3d..b03739ce4 100644--- a/agent/src/tools/research_papers_tool.py+++ b/agent/src/tools/research_papers_tool.py@@ -136,7 +136,8 @@ _PUNCT_FOLD = {# * a period inside an abbreviation ("the U.S. Treasury yield", "J. Smith")# is not a boundary -- splitting there truncates the sentence and detaches a# metric name from its number;-# * a period with no space after it ("... 15 files.The IC engine ...") IS a+# * a period with no space after it ("... 15 files.The IC engine ...",+# "... ratio is 1.5.The sample ...", "... was 12%.The drawdown ...") IS a# boundary; feeds do emit these, and leaving the two sentences glued lets a# number from one corroborate a keyword in the other.# Only abbreviations that essentially never END a sentence are guarded. "et al."@@ -151,7 +152,10 @@ _ABBREV_GUARD = ()_SENTENCE_SPLIT = re.compile(rf"(?<=[.!?]){_ABBREV_GUARD}"- rf"(?:\s+(?=[A-Z(\"$\\])|(?<=[a-z][a-z][.!?])(?=[A-Z][a-z]))"+ rf"(?:\s+(?=[A-Z(\"$\\])"+ rf"|(?<=[a-z][a-z][.!?])(?=[A-Z][a-z])"+ rf"|(?<=\d[.!?])(?=[A-Z][a-z])"+ rf"|(?<=%[.!?])(?=[A-Z][a-z]))")# ---------------------------------------------------------------------------diff --git a/agent/tests/test_research_papers_tool.py b/agent/tests/test_research_papers_tool.pyindex 52bfb8e7c..b83bcdf97 100644--- a/agent/tests/test_research_papers_tool.py+++ b/agent/tests/test_research_papers_tool.py@@ -956,6 +956,30 @@ def test_a_period_with_no_space_after_it_still_splits():assert sentences == ["The run wrote 15 files.", "The IC of 0.06 holds."]+def test_a_period_after_a_number_with_no_space_still_splits():+ # Numeric endings are the same missing-space boundary as "files.The".+ # "Sec. 2" must stay intact; the break is the period after the digit.+ assert rpt._split_sentences(+ "Costs are discussed in Sec. 2.The Sharpe ratio is 1.5."+ ) == ["Costs are discussed in Sec. 2.", "The Sharpe ratio is 1.5."]+ assert rpt._split_sentences(+ "The Sharpe ratio is 1.5.The sample ends in 2019."+ ) == ["The Sharpe ratio is 1.5.", "The sample ends in 2019."]+ assert rpt._split_sentences(+ "Annualized return was 12%.The drawdown stayed small."+ ) == ["Annualized return was 12%.", "The drawdown stayed small."]+++def test_a_numeric_glued_boundary_does_not_widen_the_evidence_quote():+ rows = rpt._extract_performance(rpt._segments(+ "",+ "Costs are discussed in Sec. 2.The Sharpe ratio is 1.5.",+ ))+ sharpe = next(r for r in rows if r["metric"] == "sharpe_ratio")+ assert sharpe["value"] == 1.5+ assert sharpe["evidence"]["quote"] == "The Sharpe ratio is 1.5."++def test_a_glued_boundary_does_not_leak_a_number_into_the_next_claim():rows = rpt._extract_performance(rpt._segments("", "The IC engine processed 15 files.The strategy is simple.")