Skip to content

Add option to remove time codes in text #32

Description

@rosanna-smith

Similar to this step in the original CA notebook:

Remove any time codes
This step will search for any timecodes in formats like (~0:33) and (~10:00).

before = df["text"].copy()

df["text"] = df["text"].str.replace(r'^\([\~0-9][\~0-9:\.]*\) ', '', regex=True)
df["text"] = df["text"].str.replace(r' \([\~0-9][\~0-9:\.]*\) ', ' ', regex=True)
df["text"] = df["text"].str.replace(r' \([\~0-9][\~0-9:\.]*\)$', ' ', regex=True)
df["text"] = df["text"].str.replace(r'^\([\~0-9][\~0-9:\.]*\)', '', regex=True)
df["text"] = df["text"].str.replace(r'\([\~0-9][\~0-9:\.]*\)', ' ', regex=True)
df["text"] = df["text"].str.replace(r'\([\~0-9][\~0-9:\.]*\)$', ' ', regex=True)

with open("timecodes_log.txt", "w", encoding="utf-8") as log:
    for i, (b, a) in enumerate(zip(before, df["text"])):
        if b != a:
            log.write("CHANGED:\n")
            log.write(str(b) + "\n")
            log.write("→\n")
            log.write(str(a) + "\n")
            log.write("-" * 40 + "\n")

Another format of time stamps to optionally remove are on a separate line, e.g.

06:11-06:13

If we want to keep the time codes, we could also add an option to put this in a separate column in the csv output.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions