Skip to content

Commit

Permalink
When generating line level annotation, also check whether last word i…
Browse files Browse the repository at this point in the history
…n line starts before line ends
  • Loading branch information
f90 committed Jun 2, 2022
1 parent adcfda5 commit 8db3813
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion generate_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@
line_start = None
for word_idx, (word, time) in enumerate(zip(words, annotation)):
curr_line += word + " "
word_start = float(time["word_start"])
if line_start is None:
# Starting a new line - set line start to the start of the word
line_start = float(time["word_start"])
line_start = word_start

if not math.isnan(float(time["line_end"])):
# A line ends here - write it, using the line_end column
line_end = float(time["line_end"])
if line_end < line_start:
pass
# Check if line starts before it ends
assert line_end > line_start, (
f"Found line in {annotation_path} with line end "
f"{line_end} before line start {line_start}!"
)

# Check if last word starts before line ends
assert word_start < line_end, (
f"Found line in {annotation_path} with last word start at {word_start} "
f"before line end {line_end}"
)

out_file.write(f"{str(line_start)},{line_end},{curr_line.strip()}\n")

curr_line = ""
Expand Down

0 comments on commit 8db3813

Please sign in to comment.