mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 23:09:47 +08:00
Merge commit '3b750ec003b8c8e3da011ae18aede591b9d84457' into codex/validate-reviewed-integration
This commit is contained in:
20
CONTRIBUTORS.md
Normal file
20
CONTRIBUTORS.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Contributors
|
||||
|
||||
Thank you to everyone who contributes code, fixes, tests, translations, documentation, and feedback to DeepTutor. Git history preserves original authors and coauthors; the [GitHub contributors page](https://github.com/HKUDS/DeepTutor/graphs/contributors) also records contributions to the default branch.
|
||||
|
||||
## Contributions integrated into dev after v1.7.0
|
||||
|
||||
This list acknowledges contributions on the development branch before the next release reaches the default branch. It supplements the project's existing contributor history.
|
||||
|
||||
- [@0x-IHRR](https://github.com/0x-IHRR) — [#2128](https://github.com/HKUDS/DeepTutor/pull/2128).
|
||||
- [@amartinawi](https://github.com/amartinawi) — [#2169](https://github.com/HKUDS/DeepTutor/pull/2169).
|
||||
- [@bercedev](https://github.com/bercedev) — [#2167](https://github.com/HKUDS/DeepTutor/pull/2167).
|
||||
- [@Eapp1e](https://github.com/Eapp1e) — [#2197](https://github.com/HKUDS/DeepTutor/pull/2197), [#2215](https://github.com/HKUDS/DeepTutor/pull/2215).
|
||||
- [@Frank-zhu2000](https://github.com/Frank-zhu2000) — [#2127](https://github.com/HKUDS/DeepTutor/pull/2127).
|
||||
- [@hydraxman](https://github.com/hydraxman) — [#2131](https://github.com/HKUDS/DeepTutor/pull/2131).
|
||||
- [@kevin9327](https://github.com/kevin9327) — [#2225](https://github.com/HKUDS/DeepTutor/pull/2225).
|
||||
- [@KKandLL-Forever](https://github.com/KKandLL-Forever) — [#2149](https://github.com/HKUDS/DeepTutor/pull/2149).
|
||||
- [@Rimcat-JA](https://github.com/Rimcat-JA) — [#2232](https://github.com/HKUDS/DeepTutor/pull/2232).
|
||||
- [@rudycelekli](https://github.com/rudycelekli) — [#2198](https://github.com/HKUDS/DeepTutor/pull/2198), [#2199](https://github.com/HKUDS/DeepTutor/pull/2199), [#2200](https://github.com/HKUDS/DeepTutor/pull/2200), [#2226](https://github.com/HKUDS/DeepTutor/pull/2226), [#2227](https://github.com/HKUDS/DeepTutor/pull/2227), [#2228](https://github.com/HKUDS/DeepTutor/pull/2228), [#2233](https://github.com/HKUDS/DeepTutor/pull/2233), [#2234](https://github.com/HKUDS/DeepTutor/pull/2234), [#2235](https://github.com/HKUDS/DeepTutor/pull/2235), [#2236](https://github.com/HKUDS/DeepTutor/pull/2236), [#2237](https://github.com/HKUDS/DeepTutor/pull/2237), [#2238](https://github.com/HKUDS/DeepTutor/pull/2238), [#2239](https://github.com/HKUDS/DeepTutor/pull/2239), [#2240](https://github.com/HKUDS/DeepTutor/pull/2240).
|
||||
- [@sriv144](https://github.com/sriv144) — [#2153](https://github.com/HKUDS/DeepTutor/pull/2153).
|
||||
- [@x-labb](https://github.com/x-labb) — [#2219](https://github.com/HKUDS/DeepTutor/pull/2219).
|
||||
@@ -1279,6 +1279,8 @@ We want DeepTutor to keep iterating and improving — and ultimately to become a
|
||||
|
||||
We hope DeepTutor becomes a gift for the community. 🎁
|
||||
|
||||
See the [development-branch contributor list](CONTRIBUTORS.md) for recently integrated contributions.
|
||||
|
||||
<a href="https://github.com/HKUDS/DeepTutor/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=HKUDS/DeepTutor&max=999" alt="Contributors" />
|
||||
</a>
|
||||
|
||||
@@ -21,9 +21,9 @@ Boundary = Literal["paragraph", "sentence"]
|
||||
|
||||
# Paragraph boundary: one or more blank lines.
|
||||
_PARA_BOUNDARY = re.compile(r"\n\s*\n+")
|
||||
# Sentence boundary: terminal punctuation followed by space/newline.
|
||||
# Covers ASCII (.!?) and CJK (。!?).
|
||||
_SENT_BOUNDARY = re.compile(r"[.!?。!?](?:[\")»」』]+)?(?=\s|$)")
|
||||
# ASCII sentence punctuation needs whitespace/end-of-text (not e.g. a decimal point).
|
||||
# CJK sentences commonly follow 。!? immediately, without intervening whitespace.
|
||||
_SENT_BOUNDARY = re.compile(r'[.!?][")»」』]*(?=\s|$)|[。!?][")»」』]*')
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
@@ -74,6 +74,61 @@ def test_sentence_boundary_used_when_configured() -> None:
|
||||
assert chunk.text[-1].isspace() or chunk.text.rstrip()[-1] in ".!?"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("punctuation", ["。", "!", "?"])
|
||||
@pytest.mark.parametrize("closing_quote", ["", "」", "』", '"'])
|
||||
def test_cjk_sentences_without_spaces_end_at_boundaries(
|
||||
punctuation: str, closing_quote: str
|
||||
) -> None:
|
||||
sentences = [
|
||||
f"学习数学需要练习{punctuation}{closing_quote}",
|
||||
f"理解概念也很重要{punctuation}{closing_quote}",
|
||||
f"每天复习能够巩固知识{punctuation}{closing_quote}",
|
||||
]
|
||||
text = "".join(sentences)
|
||||
chunks = chunk_with_boundary(
|
||||
text,
|
||||
budget=4,
|
||||
overlap_ratio=0.0,
|
||||
min_chunk_chars=1,
|
||||
max_chunk_chars=14,
|
||||
boundary="sentence",
|
||||
)
|
||||
assert [chunk.text for chunk in chunks] == sentences
|
||||
assert "".join(chunk.text for chunk in chunks) == text
|
||||
assert all(chunk.end - chunk.start <= 14 for chunk in chunks)
|
||||
|
||||
|
||||
def test_cjk_sentence_boundaries_with_default_chunk_sizes() -> None:
|
||||
text = "学习数学需要练习。理解概念也很重要。每天复习能够巩固知识。" * 5000
|
||||
chunks = chunk_with_boundary(
|
||||
text,
|
||||
budget=20,
|
||||
overlap_ratio=0.1,
|
||||
min_chunk_chars=1000,
|
||||
max_chunk_chars=64000,
|
||||
boundary="sentence",
|
||||
)
|
||||
assert all(chunk.text.endswith("。") for chunk in chunks)
|
||||
assert chunks[0].start == 0
|
||||
assert chunks[-1].end == len(text)
|
||||
assert all(chunk.end - chunk.start <= 64000 for chunk in chunks)
|
||||
assert all(left.end >= right.start for left, right in zip(chunks, chunks[1:]))
|
||||
|
||||
|
||||
def test_ascii_period_inside_number_is_not_a_sentence_boundary() -> None:
|
||||
text = "Value is 3.14. Next sentence."
|
||||
chunks = chunk_with_boundary(
|
||||
text,
|
||||
budget=4,
|
||||
overlap_ratio=0.0,
|
||||
min_chunk_chars=1,
|
||||
max_chunk_chars=20,
|
||||
boundary="sentence",
|
||||
)
|
||||
assert chunks[0].text == "Value is 3.14."
|
||||
assert "".join(chunk.text for chunk in chunks) == text
|
||||
|
||||
|
||||
def test_budget_caps_chunk_count() -> None:
|
||||
text = ("paragraph body. " * 20 + "\n\n") * 30 # ~ 10k chars
|
||||
chunks = chunk_with_boundary(
|
||||
|
||||
Reference in New Issue
Block a user