<commit_before><?php

namespace App\Bird\Parser;

use App\Bird\Parser;
use DateTime;

class Routes extends Parser
{
    public function __contrust( $data ) {
        parent::__contrust($data);
        return $this;
    }

    public function parse() {
        $routes  = [];
        $r       = [];
        $matches = [];

        foreach( preg_split("/((\r?\n)|(\r\n?))/",  $this->data() ) as $line ) {

            // first line is BIRD version
            if( substr( $line, 0, 4 ) == 'BIRD' ) {
                continue;
            }

            if( substr( $line, 0, 17 ) == 'Access restricted' ) {
                continue;
            }

            // should always be starting with a route definition
            if( $r == [] && preg_match( "/^\s+.*$/", $line ) ) {
                continue;
            }

            if( preg_match( "/^([0-9a-f\.\:\/]+)\s+via\s+([0-9a-f\.\:]+)\s+on\s+(\w+)\s+\[(\w+)\s+([0-9\-\:]+(?:\s[0-9\-\:]+){0,1})(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$/", $line, $matches ) ) {
                // 192.168.127.12/21      via 192.168.127.12 on eth1   [pb_0127_as42227 2016-10-09] * (100) [AS42227i]
                // 2a02:2078::/32 via fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b on ens160 [pb_as43760_vli226_ipv6 2016-10-13 from 2001:7f8:18:210::8] (100) [AS47720i]
                // 172.16.17.32/30    via 192.168.3.11 on eth1 [pb_core_rl01 2016-10-19 from 192.168.3.11] * (100/65559) [?]
                // 172.16.31.10/21      via 172.16.31.10 on eth1 [pb_0136_as61194 2016-03-12] * (100) [AS61194i]

                // this is the start of a route definition - so store the previous one if it exists:
                if( $r !== [] ) {
                    $routes[] = $r;
                    $r = [];
                }
                $this->mainRouteDetail( $matches, $r );
            }
            else if( preg_match( "/^\s+via\s+([0-9a-f\.\:]+)\s+on\s+(\w+)\s+\[(\w+)\s+([0-9\-\:]+(?:\s[0-9\-\:]+){0,1})(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$/", $line, $matches ) ) {
                // second entry for previous route
                if( $r == [] ) {
                    // something's not right:
                    continue;
                } else {
                    $routes[]     = $r;
                    $network      = $r['network'];
                    $r            = [];
                    
                    // rearrange $matches to have the same positions as above
                    $regMatch = array_shift($matches);
                    array_unshift( $matches, $network );
                    array_unshift( $matches, $regMatch );
                }
                $this->mainRouteDetail( $matches, $r );
            }
            else if( preg_match( "/^\s+Type:\s+(.*)\s*$/", $line, $matches ) ) {
                // 	Type: BGP unicast univ
                $r['type'] = explode(' ', trim($matches[1]) );
            }
            else if( preg_match( "/^\s+BGP.origin:\s+(\w+)\s*$/", $line, $matches ) ) {<commit_msg>[BF] Loser parsing for interface names<commit_after><?php

namespace App\Bird\Parser;

use App\Bird\Parser;
use DateTime;

class Routes extends Parser
{
    public function __contrust( $data ) {
        parent::__contrust($data);
        return $this;
    }

    public function parse() {
        $routes  = [];
        $r       = [];
        $matches = [];

        foreach( preg_split("/((\r?\n)|(\r\n?))/",  $this->data() ) as $line ) {

            // first line is BIRD version
            if( substr( $line, 0, 4 ) == 'BIRD' ) {
                continue;
            }

            if( substr( $line, 0, 17 ) == 'Access restricted' ) {
                continue;
            }

            // should always be starting with a route definition
            if( $r == [] && preg_match( "/^\s+.*$/", $line ) ) {
                continue;
            }

            if( preg_match( "/^([0-9a-f\.\:\/]+)\s+via\s+([0-9a-f\.\:]+)\s+on\s+([a-zA-Z0-9_\.\-\/]+)\s+\[(\w+)\s+([0-9\-\:]+(?:\s[0-9\-\:]+){0,1})(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$/", $line, $matches ) ) {
                // 192.168.127.12/21      via 192.168.127.12 on eth1   [pb_0127_as42227 2016-10-09] * (100) [AS42227i]
                // 2a02:2078::/32 via fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b on ens160 [pb_as43760_vli226_ipv6 2016-10-13 from fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b] (100) [AS47720i]
                // 172.16.17.32/30    via 192.168.3.11 on eth1 [pb_core_rl01 2016-10-19 from 192.168.3.11] * (100/65559) [?]
                // 172.16.31.10/21      via 172.16.31.10 on eth1 [pb_0136_as61194 2016-03-12] * (100) [AS61194i]
                //  192.168.127.12/24    via 192.168.127.12 on eth0.99 [pb_0065_as63528 2018-07-01] * (100) [AS63528i]

                // this is the start of a route definition - so store the previous one if it exists:
                if( $r !== [] ) {
                    $routes[] = $r;
                    $r = [];
                }
                $this->mainRouteDetail( $matches, $r );
            }
            else if( preg_match( "/^\s+via\s+([0-9a-f\.\:]+)\s+on\s+([a-zA-Z0-9_\.\-\/]+)\s+\[(\w+)\s+([0-9\-\:]+(?:\s[0-9\-\:]+){0,1})(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$/", $line, $matches ) ) {
                // second entry for previous route
                if( $r == [] ) {
                    // something's not right:
                    continue;
                } else {
                    $routes[]     = $r;
                    $network      = $r['network'];
                    $r            = [];
                    
                    // rearrange $matches to have the same positions as above
                    $regMatch = array_shift($matches);
                    array_unshift( $matches, $network );
                    array_unshift( $matches, $regMatch );
                }
                $this->mainRouteDetail( $matches, $r );
            }
            else if( preg_match( "/^\s+Type:\s+(.*)\s*$/", $line, $matches ) ) {
                // 	Type: BGP unicast univ
                $r['type'] = explode(' ', trim($matches[1]) );
            }
            else if( preg_match( "/^\s+BGP.origin:\s+(\w+)\s*$/", $line, $matches ) ) {
{'fraction_non_alphanumeric': 0.2208366219415943, 'fraction_numerical': 0.08950276243093923, 'mean_word_length': 1.399091253313139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 16, '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': '2980699', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2270, 'n_words': 400}