<commit_before><?php

namespace Captioning\Format;

use Captioning\File;

class WebvttFile extends File
{
    const TIMECODE_PATTERN = '#^([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}) ?(.*)$#';

    protected $regions = array();

    public function parse()
    {
        $fileContentArray = $this->getFileContentAsArray();

        $parsing_errors = array();

        $case = 'header';
        $i = 1;
        while (($line = $this->getNextValueFromArray($fileContentArray)) !== false) {
            // checking header
            if ('header' === $case) {
                if (trim($line) == 'WEBVTT') {
                    $case = 'region';
                    continue;
                }
                $parsing_errors[] = 'Missing "WEBVTT" at the beginning of the file';
            }

            if ($case !== 'header') {

                if ('region' === $case) {
                    // parsing regions
                    if (strpos($line,'Region:') === 0) {
                        $this->addRegion(WebvttRegion::parseFromString($line));
                    } else if (trim($line) === '') {
                        $case = 'body';
                    }
                    continue;
                } else if ($case === 'body') {
                    // parsing notes
                    if (strpos($line, 'NOTE') === 0) {
                        $note = '';
                        if (trim($line) !== 'NOTE') {
                            $note = trim(ltrim($line, 'NOTE '));
                        }
                        $note .= $this->lineEnding;
                        // note continues until there is a blank line
                        while (trim($line = trim($this->getNextValueFromArray($fileContentArray))) !== '') {
                            $note .= $line.$this->lineEnding;
                            $i++;
                        }
                        continue;
                    }

                    // parsing cues
                    $id_match = !strstr($line, '-->') && trim($line) != '';
                    $matches = array();
                    $timecode_match = preg_match(self::TIMECODE_PATTERN, $line, $matches);
                    if ($id_match || $timecode_match) {
                        $id       = null;
                        $start    = null;
                        $stop     = null;
                        $settings = null;<commit_msg>Fix spacing<commit_after><?php

namespace Captioning\Format;

use Captioning\File;

class WebvttFile extends File
{
    const TIMECODE_PATTERN = '#^([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}) ?(.*)$#';

    protected $regions = array();

    public function parse()
    {
        $fileContentArray = $this->getFileContentAsArray();

        $parsing_errors = array();

        $case = 'header';
        $i = 1;
        while (($line = $this->getNextValueFromArray($fileContentArray)) !== false) {
            // checking header
            if ('header' === $case) {
                if (trim($line) == 'WEBVTT') {
                    $case = 'region';
                    continue;
                }
                $parsing_errors[] = 'Missing "WEBVTT" at the beginning of the file';
            }

            if ($case !== 'header') {

                if ('region' === $case) {
                    // parsing regions
                    if (strpos($line, 'Region:') === 0) {
                        $this->addRegion(WebvttRegion::parseFromString($line));
                    } else if (trim($line) === '') {
                        $case = 'body';
                    }
                    continue;
                } else if ($case === 'body') {
                    // parsing notes
                    if (strpos($line, 'NOTE') === 0) {
                        $note = '';
                        if (trim($line) !== 'NOTE') {
                            $note = trim(ltrim($line, 'NOTE '));
                        }
                        $note .= $this->lineEnding;
                        // note continues until there is a blank line
                        while (trim($line = trim($this->getNextValueFromArray($fileContentArray))) !== '') {
                            $note .= $line.$this->lineEnding;
                            $i++;
                        }
                        continue;
                    }

                    // parsing cues
                    $id_match = !strstr($line, '-->') && trim($line) != '';
                    $matches = array();
                    $timecode_match = preg_match(self::TIMECODE_PATTERN, $line, $matches);
                    if ($id_match || $timecode_match) {
                        $id       = null;
                        $start    = null;
                        $stop     = null;
                        $settings = null;
{'fraction_non_alphanumeric': 0.15526802218114602, 'fraction_numerical': 0.011090573012939002, 'mean_word_length': 1.1000431220353601, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7642685', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1231, 'n_words': 251}