ほとんどタイトルで書いてある通りでphpでigo-phpを使っているのですが
文章をparseで分けた際に半角スペースが識別されていないみたなので識別する方法を知りたいです
お願いします
辞書はmecab-ipadic-2.7.0-20070801です
使っているのはphp,apache,mysql
osはwindows10です
php
1<?php 2 3require_once 'igp-phpの場所'; 4 5$igo = new Igo("辞書の場所", "UTF-8"); 6 7$str = "文章~"; 8mb_language("japanese"); 9$str=mb_convert_encoding($str,'UTF-8','auto'); 10echo $str.'<br />'; 11$str=preg_replace("/[-_.!~*'();/?:\@&=+$,%#。、 ・]|[\s]/imsu"," ",$str); 12echo $str.'<br />'; 13 14 15$result_c = $igo->parse($str); 16print_r($result_c); 17$noun = ""; 18$count=0; 19$words = array(); 20 21foreach($result_c as $val){ 22 $feature = explode(",", $val->feature); 23if($feature[0] === "名詞" && !(preg_match("/[\s]/ims",$val->feature))){ 24 $noun .= $val->surface; 25 $words[] = $val->surface; 26 $count++; 27 echo $count; 28 } else { 29 if(mb_strlen($noun) && $count!=1 ) $words[] = $noun; 30 $noun = ""; 31 $words[] = $val->surface; 32 $count=0; 33 } 34} 35if(mb_strlen($noun) && $count!=1) $words[] = $noun; 36print_r($words); 37 38?> 39
あなたの回答
tips
プレビュー