å®éãã¿ã¹ã¯ã¯ããã»ã©çãããããŸãããåæ§ã®æ©èœãããã¹ããšãã£ã¿ãŒãPuntoSwitcherããŒããŒãã¹ã€ãããããã³æ©æ¢°ç¿»èš³ã·ã¹ãã ã«ãããæ å ±æ€çŽ¢ã·ã¹ãã ã¯ãã¡ããã®ããšããã®ãããªæ©èœãæ±ããããŠããŸãã ã¡ãªã¿ã«ããã®ãããªåé¡ãçºçããã®ã¯ãç¹æ®ãªæ€çŽ¢ãšã³ãžã³ãšããã¹ãåé¡åãäœæãããšããã³ã³ããã¹ãã§ããã PHPãã©ãããã©ãŒã ã®ç¬èªã®ããã°ã©ã ã§ãã®æ©äŒãååŸããåæã«ãµãŒãããŒãã£ã®ãµãŒãã¹ã䜿çšããªãããšãå¿ èŠã§ãã-GoogleèšèªAPIã«ã¯WebãµãŒãã¹ã®åœ¢åŒã§åæ§ã®æ©äŒããããŸãïŒ ããã°ã§ãã®ãµãŒãã¹ãæ¢ã«æ€èšããŸãã ïŒãããªã¢ãŒãã§å®è¡ãããç¹ã«ãèšèªèªèã®ããã»ã¹ã¯å€§å¹ ã«é ããŠå®è¡ãããæ¬è³ªçã«éåæã§ãã ããã«ãããã»ã¹ãå®å šã«å¶åŸ¡ããæè»ã«æ§æã§ããããã«ãããã£ãã®ã§ãããããã¯ãµãŒãããŒãã£ã®ãµãŒãã¹ã«ã¯å«ãŸããŠããŸããã ãããã£ãŠãç§ã¯èªåã§ãããèããŠå®è£ ããå¿ èŠããããŸããããçµæãããªãã®æ³šæã«ç€ºããŸãã
ãŸããå°ãã®çè«ã èšèªã®èªå決å®ã®ããã»ã¹ã¯äžæ£ç¢ºã§ãããååãšããŠç¢ºççã§ãããšããã«èšããªããã°ãªããŸããã ã€ãŸããçµæã¯åžžã«ç¢ºçã§äžããããŸããç¹ã«ãã¹ãã«ãéåžžã«äŒŒãŠããããŸãã¯åãã¢ã«ãã¡ãããã§ããããããç°ãªãèšèªã®å Žåã¯ããã§ãã ããã«ã調æ»å¯Ÿè±¡ã®ããã¹ãã®è¡ã®é·ãã«ãäŸåããŸãã調æ»ã®ããã®è³æãå°ãªãã»ã©ããã®ãããªå®çŸ©ã¯ããå°é£ãŸãã¯äžå¯èœã«ãããªããŸãã å®éãçµ±èšæ å ±ã®å Žåã¯ããã©ã¡ãŒã¿ãŒãèšç®ããããã®ãã£ãŒã«ãã倧ããããå¿ èŠããããŸããçãè¡ã§ã¯ãç¹ã«åãã¢ã«ãã¡ãããã«åºã¥ãèšèªãåæããå Žåãèå¥ã«ååãªè³æãååŸã§ããŸããã ãã®ãããªããã¹ãã§ã¯ãäžæã®æåã¯åã«çºçããªãå Žåããããå¥ã®èšèªã®åèªãšããŠå®çŸ©ãããŸãã ãããã£ãŠã䜿çšãããã¢ã«ãã¡ãããã®åææ¹æ³ã®æåã®å¶éã¯ãããã¹ãã®é·ãã§ããããã倧ããã»ã©ãåæã®ç²ŸåºŠãé«ããªããŸãã äŸãæããŸããããã rappel ããšããèšèã§ãã ããã¯äœèªã§ããïŒ è±èªã§ïŒ ããã¯ãããŒãã§éãããããšãæå³ããŸãã ããããåãèšèã¯ãã€ãèªã§ãïŒ ãããŠãããã¯ãïŒçªç¶ã®ïŒçæ°ãæãã®çºäœããæå³ããŸãã
ãã®æ¹æ³ã«ã¯2ã€ã®çš®é¡ããããŸãã ãã¢ã«ãã¡ãããã®äœ¿çšçãã®äœ¿çšäŸã§ã¯ãããã¹ãã§äœ¿çšãããŠããã¢ã«ãã¡ãããã®äžæã®æåæ°ã®èšç®ãšãç·éã®ïŒ ã®èšç®ã䜿çšããŸãã 2çªç®ã¯ãã¢ã«ãã¡ããããšäžèŽããããã¹ãã®æåæ°ãå€æŽããŸãããäžéšã®æåã¯ç°ãªãã¢ã«ãã¡ãããã«åé¡ãããäž¡æ¹ã®èšèªã«ã«ãŠã³ããããå¯èœæ§ããããŸãã
2çªç®ã®æ¹æ³ã¯ãèšèªã®ææ³ã«åºæãŸãã¯å žåçãªäžé£ã®æåïŒããšãã°ãè±èªã®èšäºããã·ã¢èªã®æåãbãããã³ãeãããŸãã¯ãŠã¯ã©ã€ãèªã®ãÑãïŒã䜿çšããŠããã¹ãã®ã¢ã€ãã³ãã£ãã£ã確ç«ããäºåã«åœ¢æãããã«ãŒã«ã®äœ¿çšã«åºã¥ããŠããŸãã ãã®ãããªN-gramã®ã«ãŒã«ã¯èšèªåŠè ãéçºã§ããããã¹ãã®èšèªãè¿ éãã€æ£ç¢ºã«æ±ºå®ã§ããŸãããä¿èšŒãããçµæã¯åŸãããŸããã æåã«äœæããå¿ èŠããããŸããã€ãŸããèšèªã®åªããèœåããããããŸããŸãªèšèªã«åºæã®ç¹æ§ã·ãŒã±ã³ã¹ã¯ããã»ã©å€ããããŸããã ãã ããã©ã®èšèªãå®çŸ©ããå¿ èŠãããããäºåã«ç¥ã£ãŠããå Žåã¯ããã¹ãŠã®èšèªã䜿çšããå Žåãããåºæã®çµã¿åãããããå€ãååšããå¯èœæ§ããããŸãã ãã·ã¢èªãšè±èªãããªãå Žåããã€ãèªãšè±èªã®ãã¢ãããæããã«ãã®ãããªæåã®çµã¿åãããå€ããããŸãã
ãŸããããã¹ãã«ç°ãªãã¢ã«ãã¡ãããã®åèªãæ··åšããŠããå Žåã«ã€ããŠãæ€èšããå¿ èŠããããŸãã ããšãã°ãäŒç€Ÿã補åã®ååã¯ãå ã®èšèªãã»ãšãã©ã®å Žåã¯è±èªã§èšè¿°ã§ããŸãããæå šäœã¯ãã·ã¢èªã§äœæãããŸãã ããã§ã¯ãã¢ã«ãã¡ãããã«å±ããæåã®ç·æ°ãèšç®ãããªãã·ã§ã³ã®ã¿ã圹ç«ã¡ã誰ãããå€ãã®æåã«åºã¥ããŠæ±ºå®ãäžãããšãã§ããŸãã å°æ¥ã®ããŒãžã§ã³ã§ã¯ãã©ã€ãã©ãªã¯ãã®ãããªãªãã·ã§ã³ãèªèããæååã§èŠã€ãã£ãèšèªã®é åãçºè¡ã§ããããã«ãªããæååã§æãæåæ°ãå€ãã¡ã€ã³èšèªã®ã¿ã衚瀺ããããã«ãªããŸãã
ç§ã®ã©ã€ãã©ãªã§ã¯ãäž¡æ¹ã®ã¢ãããŒããšãã¹ãŠã®å¯èœãªãªãã·ã§ã³ã䜿çšããããšã«ããŸãããããã«ãããä»»æã®ã¢ãããŒããŸãã¯äž¡æ¹ã®çµã¿åããã䜿çšããããã«ã¢ã«ãŽãªãºã ãæè»ã«æ§æã§ããŸãã æè¡çã«ã¯ãã©ã€ãã©ãªã¯éåžžã«åçŽã§ã-1ã€ã®ã¯ã©ã¹ãäœæ¥ã®ãã©ã¡ãŒã¿ãŒãæå®ããããã€ãã®ã¡ãœãããšããããã£ã 圌ã¯ãœãŒã¹ã³ãŒãã®è¡ããšã«ã³ã¡ã³ãããã®ã§ãããã§ã¯å®è£ ã®å®å šãªèª¬æã¯ãããæ©èœã®ã¿ã«çŠç¹ãåœãŠãŸãã
ã©ã€ãã©ãªã¯UTF-8ã§ãšã³ã³ãŒããããããã¹ãã§åäœãããããmb_stringsã¢ãžã¥ãŒã«ãå¿ èŠã§ãããŸããçµæã®æååãæšæºåœ¢åŒã«å€æãããã©ã³ã¹ã³ãŒããè©Šã¿ãŠãäœåãªæåãåé€ããŠé·ãããã§ãã¯ããŸãã æå°ããã¹ããµã€ãºã¯50æåãæ倧ããã¹ããµã€ãºã¯1680ã§ããããã¯ã1ã€ã®æšæºA4ããŒãžãšã»ãŒåãã§ãã
ããŸããŸãªæ€åºãªãã·ã§ã³ãèšå®ã§ããŸãã ã©ã€ãã©ãªã¯ãããã¹ãã®åèšéãŸãã¯åã¢ã«ãã¡ãããã§äœ¿çšãããŠããæåã®å²åã確èªããªãããã¢ã«ãã¡ãããã®åæã䜿çšã§ããŸãã 決å®ã®ãããå€ãèšå®ãããŸããããã©ã«ãã§ã¯75ïŒ ã§ãïŒèšç®ã«å¿ããŠãã¢ã«ãã¡ãããã®æåã®75ïŒ ããããã¹ãã§ãã®èšèªã®æåã®ç·æ°ã75ïŒ ãè¶ ããŸãïŒã ãã¥ãŒãªã¹ãã£ãã¯ã«ãŒã«ã䜿çšããŠçµæãæ確ã«ããããšãã§ããŸãããåªå é äœã調æŽã§ããŸã-ã«ãŒã«ãçµ±èšã«åŸã£ãŠåæã®çµæã確èªããªãå Žåãã«ãŒã«ã®çµæãèæ ®ããããçµ±èšãä¿¡é Œããå¿ èŠããããŸãã ç¹ã«å€§éã®ããã¹ããŸãã¯å€æ°ã®èšèªã§äœæ¥ãé«éåããã«ã¯ãã«ãŒã«ã®ã¿ã䜿çšã§ããŸããéåžžã¯ãã¢ã«ãã¡ãããã®æåãããã¯ããã«å°ãããªããŸãã ã¡ãªã¿ã«ãã«ãŒã«ã®äœ¿çšãèšå®å¯èœã§ã-çµæãååŸããã«ã¯ãã«ãŒã«ã®1ã€ãšã®äžèŽãšããŠäœ¿çšããããåãèšèªã®ãã¹ãŠã®ã«ãŒã«ãšã®äžèŽãèŠæ±ã§ããŸãããããã¯é·ãããã¹ãã«ã®ã¿é©çšãããåžžã«ãšã©ãŒã®å¯èœæ§ããããŸãã
ã©ã€ãã©ãªã¯ãæ€åºåŸãŸãã¯falseãè¿ããŸããããã¯ãã©ã€ãã©ãªãå€å¥ã§ããªããã䜿çšãããŠããèšèªãããŒã¿ããŒã¹ã«ãªãããšãæå³ããŸãã æåãããšã2æåã®èšèªã³ãŒãïŒäŸïŒãenãããruãããŸãã¯ãuaãïŒãããã³è¿œå æ å ±-èšèªã®ãã«ããŒã ãããã³ããŒãã¹ãšããŠãŠã£ãããã£ã¢ã®èšèªã«é¢ããèšäºãžã®ãªã³ã¯ãå«ãé åãååŸããŸãã orgïŒãã¡ãããåãèšèªã§ïŒã
ãããŸã§ã®ãšãããã©ã€ãã©ãªã®æåã®ããŒãžã§ã³ã¯ãè±èªããã·ã¢èªããŠã¯ã©ã€ãèªã®3ã€ã®èšèªã®ã¿ã§åäœããŸãããèšèªãæäœããããã®ã¢ã«ãã¡ããããšã«ãŒã«ãè¿œå ããããšã劚ãããã®ã¯ãããŸããã
æåŸã«ãé床ã«ã€ããŠã®1ã€ã®çºèšã æéã®ãªãã·ã§ã³ã¯ã«ãŒã«ã®ã¿ã䜿çšããããšã§ããããã¯åžžã«æåãããã«ãŒã«ã®æ°ãå°ãªããã©ã€ãã©ãªå ã§çãã«ãŒãã䜿çšããããã§ãã ç¹ã«ãããŒã¿ããŒã¹å ã§æ€çŽ¢ããããã¹ããé·ããªããèšèªãå€ããªãã»ã©ãã«ãŒã«ã®ã¿ã®ãªãã·ã§ã³ãéããªããŸãã ãããã£ãŠãæé©åã®ããã«ã¯ãäºåã«èšèªã»ãããå¶éããäžèŠãªèšèªãåé€ããããšããå§ãããŸããããã«ããããµã€ã¯ã«æ°ãå€§å¹ ã«åæžãããã¢ã«ãŽãªãºã ãé«éã«å®è¡ãããŸãã ã·ã¹ãã ã§UTF-8ãšã³ã³ãŒãã£ã³ã°ã«å€æãããã¢ã«ãŽãªãºã å€æãããæååã®ã¿ãã¢ã«ãŽãªãºã ã®å ¥åã«éãããããšã確å®ãªå Žåã¯ãæååã®ãã§ãã¯ãšãã³ãŒããåé€ããããšãã§ããŸãã
ãããžã§ã¯ãã®å ¬åŒãµã€ã ïŒ http : //code.google.com/p/phplangautodetect/
ã©ã€ã»ã³ã¹ ïŒ GNU General Public License v3
äœæè ïŒAlexander LozovyukïŒaleks_raidenãaleks.raiden @ gmail.comïŒ
èšèª/ãã©ãããã©ãŒã ïŒPHP 5ïŒmb_stringsã¢ãžã¥ãŒã«ãå¿ èŠïŒ
ãã£ã¹ããªãã¥ãŒã·ã§ã³ã«ã¯ãå®éšçšã®æãã·ã³ãã«ãªã¹ã¯ãªãããå«ãŸããŠããŸã ã ææ°ã®ãªã³ã©ã€ã³ããŒãžã§ã³ã¯ãã¡ãã§ãã
以äžã¯ãäžèšã®ã¢ã«ãŽãªãºã ã®å®è£ ã«é¢ããã³ã¡ã³ããšèŠè§£ãå«ããœãŒã¹ã³ãŒãã§ãã
- Lang_Auto_Detect ã¯ã©ã¹
- {
- //äž»ãªå€æ°
- //ãµããŒããããŠããèšèªã®ãªã¹ã
- public $ lang = ArrayïŒ 'en' => arrayïŒ 'English' ã 'http://en.wikipedia.org/wiki/English_language' ïŒã
- 'ru' =>é åïŒ 'ãã·ã¢èª' ã 'http://en.wikipedia.org/wiki/%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0 ïŒ B9_ïŒ D1ïŒ 8FïŒ D0ïŒ B7ïŒ D1ïŒ 8BïŒ D0ïŒ BA ' ïŒã
- 'ua' =>é åïŒ 'ãŠã¯ã©ã€ã' ã 'http://uk.wikipedia.org/wiki/%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1 ïŒ 81ïŒ D1ïŒ 8CïŒ D0ïŒ BAïŒ D0ïŒ B0_ïŒ D0ïŒ BCïŒ D0ïŒ BEïŒ D0ïŒ B2ïŒ D0ïŒ B0 ' ïŒ
- ïŒ;
- //æ床ã®ãããå€ãå®çŸ©ããèšèªã«äœïŒ ã®æåãå¿ èŠã
- public $ detect_range = 75;
- //å€èšèªããã¥ã¡ã³ããåŠçãã䜿çšãããèšèªã®é åãè¿ããã©ãã
- public $ detect_multi_lang = false ; //ãŸã å®è£ ãããŠããŸãã
- //ãã¹ãŠã®çµæãšç¢ºçãè¿ããŸã
- public $ return_all_results = false ; //å®éã®äœ¿çšã§ã¯ãç¡å¹ã«ããæ¹ãè¯ã
- //ã«ãŒã«ãšäŸå€ã®è¿œå ã·ã¹ãã ã䜿çšããŸã
- public $ use_rules = false ;
- //ã«ãŒã«ã®ã¿ãé©çšããŸãïŒã¯ããã«é«éã§ãããçµæã¯å°ãªããããã¹ããå€ãã»ã©ä¿¡é Œæ§ãé«ããªããŸãïŒ
- public $ use_rules_only = false ;
- //çµ±èšãããã«ãŒã«ã®åªå 床-
- public $ use_rules_priory = true ; // true-çµ±èšã«é¢ããèŠåãfalse-èŠåã«é¢ããçµ±èš
- //æåã®ã«ãŒã«ãŸãã¯æ倧äžèŽã®ã¿ãæ€çŽ¢ããŸããïŒ
- public $ match_all_rules = false ; // 1ã€ã ã= else
- //ã¢ã«ãã¡ãããã®ïŒ ãŸãã¯åã¢ã«ãã¡ãããã®æåã®ç·æ°ã䜿çšããŸã
- public $ use_str_len_per_lang = true ; // true-åªå 床ãããããã¹ãã®å šé·ãã¢ã«ãã¡ãããã®æåã®ïŒ ããã䜿çšããfalse-ãã®é
- //æ€åºã®ããã®æå°æååé·
- public $ min_str_len_detect = 50;
- //éåžžã®ããã©ãŒãã³ã¹ã確ä¿ããããã«ãæ¯èŒããæåã®æ倧é·ãæå®ããŸã
- public $ max_str_len_detect = 1680; //
- //å éšã®éå€æ°-å®çŸ©ã§äœ¿çšãããã¢ã«ãã¡ãããã®è¡š
- private $ _langs = arrayïŒ
- 'en' =>é åïŒ '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 ' ïŒã
- 'ru' =>é åïŒ 'a' ã 'b' ã 'c' ã 'd' ã 'd' ã 'e' ã 'e' ã 'w' ã 's' ã 'and' ã 'i' ã ãkã ã ãlã ã ãmã ã ãnã ã ãoã ã ãpã ã ãpã ã ãsã ã ãtã ã ãyã ã ãfã ã ãxã ã ã c ' ã ' h ' ã ' w ' ã ' u ' ã ' b ' ã ' s ' ã ' b ' ã ' e ' ã ' u ' ã ' i ' ïŒã
- 'ua' =>é åïŒ 'a' ã 'b' ã 'c' ã 'd' ã 'Ò' ã 'd' ã 'e' ã 'Ñ' ã 'w' ã 's' ã 'and' ã ãÑã ã ãÑã ã ãyã ã ãkã ã ãlã ã ãmã ã ãnã ã ãoã ã ãpã ã ãrã ã ãsã ã ãtã ã ã y ' ã ' f ' ã ' x ' ã ' c ' ã ' h ' ã ' w ' ã ' u ' ã ' b ' ã ' u ' ã ' i ' ïŒ
- ïŒ;
- //ã«ãŒã«ãä¿åããŸã
- //ã«ãŒã«ã¯æåãŸãã¯è¡ã§ããããã®ååšïŒãããããŸãã¯ãã¹ãŠïŒã¯èªåçã«ããã¹ãã®èå¥ã䌎ããŸã
- private $ _lang_rules = arrayïŒ
- 'en' =>é åïŒ 'th' ã 'ir' ïŒã
- 'ru' =>é åïŒ '' ã '' ïŒã
- 'ua' =>é åïŒ 'Ñ' ã 'Ñ' ïŒ
- ïŒ;
- //ã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒ
- ãããªã㯠é¢æ° __constructïŒïŒ
- {
- trueã è¿ã ãŸã ã
- }
- //ä¿åããå ¥åæååãæºåããŸã
- ãã©ã€ããŒã é¢æ° _prepare_strïŒ$ tmp_str = null ïŒ
- {
- if ïŒ$ tmp_str == null ïŒ falseã è¿ã ãŸã ; //äœãæž¡ãããªãå ŽåãçµäºããŸã
- $ tmp_str = trimïŒ$ tmp_strïŒ;
- $ tmp_encoding = mb_detect_encodingïŒ$ tmp_strïŒ;
- if ïŒmb_strlenïŒ$ tmp_strã$ tmp_encodingïŒ> $ this-> max_str_len_detectïŒ
- {
- //ããã©ãŒãã³ã¹ã®ããã«ãããã¹ãã®é·ããããªãã³ã°ããŸã
- $ tmp_str = mb_substrïŒ$ tmp_strã0ã$ this-> max_str_len_detectã$ tmp_encodingïŒ;
- }
- ä»ã«
- if ïŒmb_strlenïŒ$ tmp_strã$ tmp_encodingïŒ<= $ this-> min_str_len_detectïŒ false ;
- //ãšã³ã³ãŒããå€æããŸã
- $ tmp_str = mb_convert_encodingïŒ$ tmp_strã 'UTF-8' ã$ tmp_encodingïŒ;
- //ãã¹ãŠãå°æåã«ãã£ã¹ãããŸã
- $ tmp_str = mb_strtolowerïŒ$ tmp_strã 'UTF-8' ïŒ;
- return $ tmp_str;
- }
- //ã«ãŒã«ã«åŸã£ãŠèšèªã決å®ããæ©èœ
- //ã«ãŒã«ã¯èšèªãæ確ã«æ±ºå®ããŸãããçç¥ã§ããŸã:)
- ãã©ã€ããŒã é¢æ° _detect_from_rulesïŒ$ tmp_str = null ïŒ
- {
- if ïŒ$ tmp_str == null ïŒ falseã è¿ã ãŸã ; //äœãæž¡ãããªãå ŽåãçµäºããŸã
- if ïŒïŒis_arrayïŒ$ this-> _ lang_rulesïŒïŒ return false ;
- //ãã¹ãŠã®ã«ãŒã«ãå埩åŠçããŸã
- foreach ïŒ$ this-> _ lang_rules as $ lang_code => $ lang_rulesïŒ
- {
- $ tmp_freq = 0;
- foreach ïŒ$èŠåãšããŠã® $ lang_rulesïŒ
- {
- $ tmp_term = mb_substr_countïŒ$ tmp_strã$ã«ãŒã«ïŒ;
- if ïŒ$ tmp_term> 1ïŒ //ã€ãŸããæååå ã®æåã1å以äž
- {
- $ tmp_freq ++; //ãã®è¡ã«ããèšèªæåã®ã«ãŠã³ã¿ãŒãå¢ãããŸã
- }
- //ä»ç¢ºèªãã
- if ïŒ$ this-> match_all_rules === true ïŒ
- {
- //ãã¹ãŠã®ã«ãŒã«ãäžèŽããå¿ èŠããããŸã
- if ïŒ$ tmp_freq == countïŒ$ lang_rulesïŒïŒ return $ lang_code;
- }
- ä»ã«
- {
- // 1ã€ã§ååã§ã
- if ïŒ$ tmp_freq> 0ïŒ return $ lang_code;
- }
- }
- }
- falseã è¿ã ãŸã ã
- }
- //ããŒãã«èšèªå®çŸ©é¢æ°
- ãã©ã€ããŒã é¢æ° _detect_from_tablesïŒ$ tmp_str = null ïŒ
- {
- if ïŒ$ tmp_str == null ïŒ falseã è¿ã ãŸã ; //äœãæž¡ãããªãå ŽåãçµäºããŸã
- //æ¯èŒããåã«æååãåŠçããå¿ èŠããããŸã
- //ãã¹ãŠã®èšèªãå埩åŠçããåèšèªã®ç¢ºçã決å®ããŸã
- $ lang_res = arrayïŒïŒ;
- foreach ïŒ$ this-> lang as $ lang_code => $ lang_nameïŒ
- {
- $ lang_res [$ lang_code] = 0; //ããã©ã«ã0ãã€ãŸããã®èšèªã§ã¯ãªã
- $ tmp_freq = 0; //çŸåšã®èšèªã®æåã®é »åºŠ
- $ full_lang_symbols = 0; //ãã®èšèªã®åèšæåæ°
- //æååã®é·ãã¯ä»»æã§ãããã¢ã«ãã¡ãããã¯åãã§ãããããã¢ã«ãã¡ãããã®åŸªç°
- $ cur_lang = $ this-> _ langs [$ lang_code];
- foreach ïŒ$ cur_lang ãšã㊠$ l_itemïŒ
- {
- //æååå ã®æåã®åºçŸåæ°ã確èªããŸã
- $ tmp_term = mb_substr_countïŒ$ tmp_strã$ l_itemïŒ;
- if ïŒ$ tmp_term> 1ïŒ //ã€ãŸããæååå ã®æåã1å以äž
- {
- $ tmp_freq ++; //ãã®è¡ã«ããèšèªæåã®ã«ãŠã³ã¿ãŒãå¢ãããŸã
- $ full_lang_symbols + = $ tmp_term;
- }
- }
- if ïŒ$ this-> use_str_len_per_lang === true ïŒ
- {
- //åèšæåæ°ã䜿çšããŸã
- $ lang_res [$ lang_code] = $ full_lang_symbols;
- }
- ä»ã«
- //ã¢ã«ãã¡ãããã®ãã¹ãŠã®æåã®å²åãèšç®ããŸã
- $ lang_res [$ lang_code] = ceilïŒïŒ100 / countïŒ$ cur_langïŒïŒ* $ tmp_freqïŒ;
- }
- //ããã§ã¯ãäœãèµ·ãã£ãã®ãèŠãŠã¿ãŸããã
- arsortïŒ$ lang_resãSORT_NUMERICïŒ; //èšèªã®æåã®èŠçŽ ã§é åããœãŒãããŸã
- if ïŒ$ this-> return_all_results == true ïŒ
- {
- return lang_res; //ãã¹ãŠã®çµæãè¿ãå Žå-æ»ããããã§ãªãå Žåã¯æè¯ãéžæãã
- }
- ä»ã«
- {
- //æå®ãããããå€ãã倧ããå Žåã¯èšèªã³ãŒããè¿ããããã§ãªãå Žåã¯nullïŒã€ãŸããèšèªã³ãŒããç¹å®ã§ããªãïŒ
- $ key = keyïŒ$ lang_resïŒ;
- if ïŒ$ lang_res [$ key]> = $ this-> detect_rangeïŒ
- $ããŒãè¿ããŸãã
- ä»ã«
- falseã è¿ã ãŸã ã
- }
- }
- //èšèªã決å®ããããã®äžè¬çãªæ©èœ
- ãããªã㯠é¢æ° lang_detectïŒ$ tmp_str = null ïŒ
- {
- if ïŒ$ tmp_str == null ïŒ falseã è¿ã ãŸã ; //äœãæž¡ãããªãå ŽåãçµäºããŸã
- $ tmp_str = $ this-> _ prepare_strïŒ$ tmp_strïŒ;
- if ïŒ$ tmp_str === false ïŒ return false ;
- //ããŒãã«ã®åã«ã«ãŒã«ãé©çšããå Žå
- if ïŒ$ this-> use_rules_only === true ïŒ
- {
- $ res = $ this-> _ detect_from_rulesïŒ$ tmp_strïŒ;
- return arrayïŒ$ resã$ this-> lang [$ res]ïŒ;
- }
- ä»ã«
- {
- //ããŒãã«ã䜿çšããå Žåãçµæã«å¿ããŠå®å šãªã¬ã€ã¢ãŠããååŸã§ããªãããããªãã«ããŸã
- $ this-> return_all_results = false ;
- $ res = $ this-> _ detect_from_tablesïŒ$ tmp_strïŒ;
- if ïŒ$ tmp_str === false ïŒ return false ;
- if ïŒ$ this-> use_rules === true ïŒ
- {
- $ res_rules = $ this-> _ detect_from_rulesïŒ$ tmp_strïŒ;
- //ã«ãŒã«ã®åªå 床èšå®ãšçµ±èšããé²ã¿ãŸã
- if ïŒ$ this-> use_rules_priory === true ïŒ
- {
- //ã«ãŒã«ã¯çµ±èšãããéèŠã§ã
- return arrayïŒ$ res_rulesã$ this-> lang [$ res_rules]ïŒ;
- }
- ä»ã«
- {
- return arrayïŒ$ resã$ this-> lang [$ res]ïŒ;
- }
- }
- ä»ã«
- return arrayïŒ$ resã$ this-> lang [$ res]ïŒ;
- }
- }
- }
PSãã¡ãããã³ãŒãã¯å®å šã§ãããšäž»åŒµããŠããŸãããããããããããã¯ãŒã¯ã«ã¯ããã®æ©èœã®å®è£ ãæ¢ã«ãããŸãããç§ã¯çºèŠããŠããŸããã ããç¥ãããŠããå®è£ ãç¥ã£ãŠãããªããã³ã¡ã³ãã§æããŠãã ããã å ã®èšäºã¯ç§ã®ããã°ã«æ²èŒãããŠããŸãã