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