<commit_before><?php

namespace App\Resource\Model;

use fengqi\Hanzi\Hanzi;
use App\Resource\Model\SubtitleModel as Subtitle;
use App\Resource\Model\ThemeModel as Theme;

class ResourceNameSharp{

    public $rawName;

    public $name;

    public $number = 0;

    public $tag = [];

    public $subtitle;

    public $otherNumber = [];

    public $nameArray = [];

    public $theme = [];

    function __construct(&$name){

        $this->init($name);

    }


    function singleByte(&$name){

        $pattern = array( 

            '０' , '１' , '２' , '３' , '４' , '５' , '６' , '７' , '８' , '９' , 'Ａ' , 'Ｂ' , 'Ｃ' , 'Ｄ' , 'Ｅ' , 
            'Ｆ' , 'Ｇ' , 'Ｈ' , 'Ｉ' , 'Ｊ' , 'Ｋ' , 'Ｌ' , 'Ｍ' , 'Ｎ' , 'Ｏ' , 'Ｐ' , 'Ｑ' , 'Ｒ' , 'Ｓ' , 'Ｔ' , 
            'Ｕ' , 'Ｖ' , 'Ｗ' , 'Ｘ' , 'Ｙ' , 'Ｚ' , 'ａ' , 'ｂ' , 'ｃ' , 'ｄ' , 'ｅ' , 'ｆ' , 'ｇ' , 'ｈ' , 'ｉ' , 
            'ｊ' , 'ｋ' , 'ｌ' , 'ｍ' , 'ｎ' , 'ｏ' , 'ｐ' , 'ｑ' , 'ｒ' , 'ｓ' , 'ｔ' , 'ｕ' , 'ｖ' , 'ｗ' , 'ｘ' , 
            'ｙ' , 'ｚ' , '－' , '　' , '：' , '．' , '，' , '／' , '％' , '＃' , '！' , '＠' , '＆' , '（' , '）' ,
            '＜' , '＞' , '＂' , '＇' , '？' , '［' , '］' , '｛' , '｝' , '＼' , '｜' , '＋' , '＝' , '＿' , '＾' , '￥' , '￣' , '｀','&amp;','×'
        );
 
        $replace = array(

            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 
            'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
            'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 
            'y', 'z', '-', ' ', ':','.', ',', '/', '%', ' #','!', '@', '&', '(', ')',
            '<', '>', '"', '\'','?','[', ']', '{', '}', '\\','|', '+', '=', '_', '^','￥','~', '`','&','x'
        );

        $name = str_replace( $pattern, $replace, $name );

    }

    function getRawNumber(&$name){

        $name = preg_replace_callback('/(\d{2,3}-\d{2,3})(完|end)?/i',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);
        
        $name = preg_replace_callback('/#(\d{2,3})/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('/- ?(\d{2,3})/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('/第(\d{2,3})(集|话)/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('#\|(\d{2,3}) ?(end|final)?\|#',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);
        if($this->otherNumber)array_pop($this->otherNumber);
        
    }

    function getTag(&$name){

        $array = [

            '720p','360p','1080p','480p','\d{4}x1080','\d{3,4}x\d{3}','\b(19|20)\d{2}\b',

            '(繁|简)(体|體|中)?','(GB|BIG5)\b','CH(T|S)\b','(内|外)(嵌|挂)(版)?','中日双语','字幕(文件)?\b',

            'MP4\b','MKV\b','IOS\b','RMVB\b',

            '(10|1|4|7|一|四|七|十)月(新番)?',

            'OVA','OAD','MOVIE','HDTV',

            'h264\b','x26\d\b','10-?bit\b','8-?bit\b','ACC\b','AC3\b','FLAC\b','HEVC\b','Main10p\b','VFR\b','Web(Rip)?\b',
            
            'BD-?(RIP|BOX)?\b','DVD(RIP)?\b','TV(RIP)?\b','网盘','第.{1,2}(季|部|卷|章)',

            '320K','v\d\b','s\d\b','PSV\b','pc\b'
        ];


        foreach($array as $a)$name = mb_ereg_replace_callback($a,function($matches){
            $this->tag[] = trim($matches[0]);
            return '|';

        },$name,'i');



        
        $name = preg_replace('# +#',' ',$name);
        $name = preg_replace('#(\|| )+#','|',$name);
        $name = trim( $name );

    }

    function multibyteUnicodeNameOfResource(&$name){

        $name = trim($name);

        if(!$name)return;

        $pieces = explode(' ',$name);


        foreach($pieces as $k=>$p){
            
            if( preg_match('#[^0-9a-z!-]#i',$p)){

                if(strlen($p)>1)$this->nameArray[] = trim($p);

                unset($pieces[$k]);

            }elseif(strlen($p)<2)unset($pieces[$k]);

        }

        $name = implode(' ',$pieces);

        $name = preg_replace('# +#',' ',$name);

        $name = trim( $name );

        
    }
  
    function init(&$name2){
        $name = $name2;

        //未加工的名字
        $name = trim( $name );
        $this->rawName = $name;


        //优化名字
        $this->singleByte($name);

        $name2 = $name;

        $name = preg_replace('# *({|【|「|\[|}|】|」|\]|\+|&| x |附|/|\\|~|:) *#','|',$name);
        $name = preg_replace(['#\(.*?\)|_#'],' ',$name);

        $name = str_replace('★','',$name);
        if(substr_count($name,'.')>2)$name = str_replace('.',' ',$name);
        $name = Hanzi::turn($name, true);

        $name = preg_replace('# +#',' ',$name);
        $name = preg_replace('#(\|| )+#','|',$name);
        $name = trim( $name );<commit_msg>up fix<commit_after><?php

namespace App\Resource\Model;

use fengqi\Hanzi\Hanzi;
use App\Resource\Model\SubtitleModel as Subtitle;
use App\Resource\Model\ThemeModel as Theme;

class ResourceNameSharp{

    public $rawName;

    public $name;

    public $number = 0;

    public $tag = [];

    public $subtitle;

    public $otherNumber = [];

    public $nameArray = [];

    public $theme = [];

    function __construct(&$name){

        $this->init($name);

    }


    function singleByte(&$name){

        $pattern = array( 

            '０' , '１' , '２' , '３' , '４' , '５' , '６' , '７' , '８' , '９' , 'Ａ' , 'Ｂ' , 'Ｃ' , 'Ｄ' , 'Ｅ' , 
            'Ｆ' , 'Ｇ' , 'Ｈ' , 'Ｉ' , 'Ｊ' , 'Ｋ' , 'Ｌ' , 'Ｍ' , 'Ｎ' , 'Ｏ' , 'Ｐ' , 'Ｑ' , 'Ｒ' , 'Ｓ' , 'Ｔ' , 
            'Ｕ' , 'Ｖ' , 'Ｗ' , 'Ｘ' , 'Ｙ' , 'Ｚ' , 'ａ' , 'ｂ' , 'ｃ' , 'ｄ' , 'ｅ' , 'ｆ' , 'ｇ' , 'ｈ' , 'ｉ' , 
            'ｊ' , 'ｋ' , 'ｌ' , 'ｍ' , 'ｎ' , 'ｏ' , 'ｐ' , 'ｑ' , 'ｒ' , 'ｓ' , 'ｔ' , 'ｕ' , 'ｖ' , 'ｗ' , 'ｘ' , 
            'ｙ' , 'ｚ' , '－' , '　' , '：' , '．' , '，' , '／' , '％' , '＃' , '！' , '＠' , '＆' , '（' , '）' ,
            '＜' , '＞' , '＂' , '＇' , '？' , '［' , '］' , '｛' , '｝' , '＼' , '｜' , '＋' , '＝' , '＿' , '＾' , '￥' , '￣' , '｀','&amp;','×'
        );
 
        $replace = array(

            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 
            'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
            'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 
            'y', 'z', '-', ' ', ':','.', ',', '/', '%', ' #','!', '@', '&', '(', ')',
            '<', '>', '"', '\'','?','[', ']', '{', '}', '\\','|', '+', '=', '_', '^','￥','~', '`','&','x'
        );

        $name = str_replace( $pattern, $replace, $name );

    }

    function getRawNumber(&$name){

        $name = preg_replace_callback('/(\d{2,3}-\d{2,3})(完|end)?/i',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);
        
        $name = preg_replace_callback('/#(\d{2,3})/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('/- ?(\d{2,3})/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('/第(\d{2,3})(集|话)/',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);

        $name = preg_replace_callback('#\|(\d{2,3}) ?(end|final)?\|#',function($r){
            $this->otherNumber[] = $this->number = $r[1];
            return '';
        },$name);
        if($this->otherNumber)array_pop($this->otherNumber);
        
    }

    function getTag(&$name){

        $array = [

            '720p','360p','1080p','480p','\d{4}x1080','\d{3,4}x\d{3}','\b(19|20)\d{2}\b',

            '(繁|简)(体|體|中)?','(GB|BIG5)\b','CH(T|S)\b','(内|外)(嵌|挂)(版)?','中日双语','字幕(文件)?\b',

            'MP4\b','MKV\b','IOS\b','RMVB\b',

            '(10|1|4|7|一|四|七|十)月(新番)?',

            'OVA','OAD','MOVIE','HDTV',

            'h264\b','x26\d\b','10-?bit\b','8-?bit\b','ACC\b','AC3\b','FLAC\b','HEVC\b','Main10p\b','VFR\b','Web(Rip)?\b',
            
            'BD-?(RIP|BOX)?\b','DVD(RIP)?\b','TV(RIP)?\b','网盘','第.{1,2}(季|部|卷|章)',

            '320K','v\d\b','s\d\b','PSV\b','pc\b'
        ];


        foreach($array as $a)$name = mb_ereg_replace_callback($a,function($matches){
            $this->tag[] = trim($matches[0]);
            return '|';

        },$name,'i');



        
        $name = preg_replace('# +#',' ',$name);
        $name = preg_replace('# *\| *#','|',$name);
        $name = preg_replace('#\|+#','|',$name);
        $name = trim( $name );

    }

    function multibyteUnicodeNameOfResource(&$name){

        $name = trim($name);

        if(!$name)return;

        $pieces = explode(' ',$name);


        foreach($pieces as $k=>$p){
            
            if( preg_match('#[^0-9a-z!-]#i',$p)){

                if(strlen($p)>1)$this->nameArray[] = trim($p);

                unset($pieces[$k]);

            }elseif(strlen($p)<2)unset($pieces[$k]);

        }

        $name = implode(' ',$pieces);

        $name = preg_replace('# +#',' ',$name);

        $name = trim( $name );

        
    }
  
    function init(&$name2){
        $name = $name2;

        //未加工的名字
        $name = trim( $name );
        $this->rawName = $name;


        //优化名字
        $this->singleByte($name);

        $name2 = $name;

        $name = preg_replace('# *({|【|「|\[|}|】|」|\]|\+|&| x |附|/|\\|~|:) *#','|',$name);
        $name = preg_replace(['#\(.*?\)|_#'],' ',$name);

        $name = str_replace('★','',$name);
        if(substr_count($name,'.')>2)$name = str_replace('.',' ',$name);
        $name = Hanzi::turn($name, true);

        $name = preg_replace('# +#',' ',$name);
        $name = preg_replace('# *\| *#','|',$name);
        $name = preg_replace('#\|+#','|',$name);
        $name = trim( $name );
{'fraction_non_alphanumeric': 0.3213192455811198, 'fraction_numerical': 0.018959217932260294, 'mean_word_length': 2.0107015457788346, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5701110', 'n_tokens_mistral': 4688, 'n_tokens_neox': 4349, 'n_words': 623}