Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If break at period, it has to be followed by space #61

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/libriheavy/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_params() -> AttributeDict:
"preceding_context_length": 1000,
"timestamp_position": "current",
"silence_length_to_break": 0.45,
"overlap_ratio": 0.45,
"overlap_ratio": 0.5,
"min_duration": 2,
"max_duration": 30,
"expected_duration": (5, 20),
Expand Down
72 changes: 44 additions & 28 deletions textsearch/python/textsearch/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,55 +704,71 @@ def _get_segment_candidates(
# punctuation
prev_punctuation = 0
j = align["ref_pos"] - 1
num_space_behind_period = 0
while j >= 0:
current_token = chr(target_source.binary_text[j])
if is_punctuation(current_token, eos_only=True):
tmp = "".join(
[
chr(x)
for x in target_source.binary_text[
j - period_pattern_length : j + 1
if current_token == ".":
tmp = "".join(
[
chr(x)
for x in target_source.binary_text[
j - period_pattern_length : j + 1
]
]
]
)
if current_token != "." or (
current_token == "."
and period_patterns.search(tmp) is not None
):
)
if (
period_patterns.search(tmp) is not None
and num_space_behind_period >= 1
):
prev_punctuation = punctuation_score
break
else:
break
else:
prev_punctuation = punctuation_score
break
else:
j -= 1
elif current_token == " " or is_punctuation(current_token):
if current_token == " ":
num_space_behind_period += 1
j -= 1
else:
break

succ_punctuation = 0
j = align["ref_pos"] + 1
followed_by_period = False
followed_by_other_eos = False
num_space_behind_period = 0
while j < target_source.binary_text.size:
current_token = chr(target_source.binary_text[j])
if is_punctuation(current_token, eos_only=True):
tmp = "".join(
[
chr(x)
for x in target_source.binary_text[
j - period_pattern_length : j + 1
if current_token == ".":
tmp = "".join(
[
chr(x)
for x in target_source.binary_text[
j - period_pattern_length : j + 1
]
]
]
)
if current_token != "." or (
current_token == "."
and period_patterns.search(tmp) is not None
):
succ_punctuation = punctuation_score
break
)
if period_patterns.search(tmp) is not None:
followed_by_period = True
else:
j += 1
followed_by_other_eos = True
j += 1
elif current_token == " " or is_punctuation(current_token):
if current_token == " ":
num_space_behind_period += 1
j += 1
else:
break
if (
followed_by_period and num_space_behind_period >= 1
) or followed_by_other_eos:
succ_punctuation = punctuation_score
break
else:
break

begin_score = (
prev_silence
Expand Down
Loading