質問編集履歴

1

ソースコードなど

2017/10/06 12:30

投稿

tsrao35
tsrao35

スコア17

test CHANGED
File without changes
test CHANGED
@@ -5,3 +5,91 @@
5
5
  お願いします
6
6
 
7
7
  辞書はmecab-ipadic-2.7.0-20070801です
8
+
9
+ 使っているのはphp,apache,mysql
10
+
11
+ osはwindows10です
12
+
13
+
14
+
15
+ ```php
16
+
17
+ <?php
18
+
19
+
20
+
21
+ require_once 'igp-phpの場所';
22
+
23
+
24
+
25
+ $igo = new Igo("辞書の場所", "UTF-8");
26
+
27
+
28
+
29
+ $str = "文章~";
30
+
31
+ mb_language("japanese");
32
+
33
+ $str=mb_convert_encoding($str,'UTF-8','auto');
34
+
35
+ echo $str.'<br />';
36
+
37
+ $str=preg_replace("/[-_.!~*'();/?:\@&=+$,%#。、 ・]|[\s]/imsu"," ",$str);
38
+
39
+ echo $str.'<br />';
40
+
41
+
42
+
43
+
44
+
45
+ $result_c = $igo->parse($str);
46
+
47
+ print_r($result_c);
48
+
49
+ $noun = "";
50
+
51
+ $count=0;
52
+
53
+ $words = array();
54
+
55
+
56
+
57
+ foreach($result_c as $val){
58
+
59
+ $feature = explode(",", $val->feature);
60
+
61
+ if($feature[0] === "名詞" && !(preg_match("/[\s]/ims",$val->feature))){
62
+
63
+ $noun .= $val->surface;
64
+
65
+ $words[] = $val->surface;
66
+
67
+ $count++;
68
+
69
+ echo $count;
70
+
71
+ } else {
72
+
73
+ if(mb_strlen($noun) && $count!=1 ) $words[] = $noun;
74
+
75
+ $noun = "";
76
+
77
+ $words[] = $val->surface;
78
+
79
+ $count=0;
80
+
81
+ }
82
+
83
+ }
84
+
85
+ if(mb_strlen($noun) && $count!=1) $words[] = $noun;
86
+
87
+ print_r($words);
88
+
89
+
90
+
91
+ ?>
92
+
93
+
94
+
95
+ ```