-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
167 lines (143 loc) · 4.06 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* 实例开始
*/
// 分词结果之回调函数 (param: 分好的词组成的数组)
function words_cb($ar)
{
foreach ($ar as $tmp)
{
if ($tmp == "\n")
{
echo $tmp;
continue;
}
echo $tmp . ' ';
}
flush();
}
// 实例化前的参数指定与读取
$dict = 'dict/dict.xdb'; // 默认采用 xdb (不需其它任何依赖)
$mydata = NULL; // 待切数据
$version = 3; // 采用版本
$autodis = true; // 是否识别名字
$ignore = true; // 是否忽略标点
$sample_text = <<<__EOF__
此处键入关键字
__EOF__;
// 切分数据
if (!isset($_REQUEST['mydata']) || empty($_REQUEST['mydata']))
{
$mydata = $sample_text;
}
else
{
$mydata = & $_REQUEST['mydata'];
if (get_magic_quotes_gpc())
$mydata = stripslashes($mydata);
}
// 清除最后的 \r\n\t
if (!is_null($mydata))
$mydata = trim($mydata);
// 实例化分词对像(mydata非空)
$object = 'PSCWS' . $version;
require (strtolower($object) . '.class.php');
$cws = new $object($dict);
$cws->set_ignore_mark($ignore);
$cws->set_autodis($autodis);
?>
<html>
<head>
<title>Task II 软工项目II实现</title>
<meta http-equiv="Content-type" content="text/html; charset=gbk">
<style type="text/css">
#searchcontrol .gsc-control
{
width: 100%;
}
#searchcontrol .gsc-result-cnblogs .gs-title
{
color:Red;
}
</style>
<script src="https://www.google.com/jsapi?key=ABQIAAAAWUT8aaIj9mtqQa087LjVOhTPB5B7LRDljl2Cr4-JwBNft1mFrRRmR1RoYEUCZCj0dtS2gIc8Al4-VA" type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
google.load("search", "1");
function OnLoad() {
//搜索设置
var options = new google.search.SearcherOptions();
//当搜索结果为空时显示内容
options.setNoResultsString('查询结果为空!');
//搜索控件实例化
var searchControl = new google.search.SearchControl();
//每次显示8个搜索结果(取值范围:1-8)
searchControl.setResultSetSize(3);
//全网搜索
searchControl.addSearcher(new google.search.WebSearch(), options);
//添加视频搜索
searchControl.addSearcher(new google.search.VideoSearch(), options);
//添加新闻搜索
searchControl.addSearcher(new google.search.NewsSearch(), options);
//添加图片搜索
searchControl.addSearcher(new google.search.ImageSearch(), options);
//添加本地地图搜索
var localSearch = new google.search.LocalSearch();
//地图中心标记 测试时可使用“大雁塔”
localSearch.setCenterPoint("西安,钟楼");
searchControl.addSearcher(localSearch, options);
//绘制搜索
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
//执行搜索查询
searchControl.execute("google api");
}
//框架加载完成后调用
google.setOnLoadCallback(OnLoad);
</script>
<style type="text/css">
<!--
td, body { background-color: #efefef; font-family: tahoma; font-size: 14px; }
.demotx { font-size: 12px; width: 100%; height: 100px; }
small { font-size: 12px; }
//-->
</style>
</head>
<body>
<h3>
<font color=red>Task II 软工项目II实现</font>
</h3>
<table width=100% border=0>
<tr>
<form method=post>
<td width=100%>
<strong>请输入文字点击提交尝试分词: </strong> <br />
<textarea name=mydata cols=60 rows=8 class=demotx><?php echo $mydata; ?></textarea>
<input type=submit>
</td>
</form>
</tr>
<tr>
<td><hr /></td>
</tr>
<tr>
<td width=100%>
<strong>分词结果(原文总长度 <?php echo strlen($mydata); ?> 字符) </strong><br />
<textarea cols=60 rows=8 class=demotx readonly style="color:#888888;">
<?php
// 执行切分, 分词结果数组执行 words_cb()
$cws->segment($mydata, 'words_cb');
// 以下显示结果
?>
</textarea>
</td>
</tr>
</table>
<pre>
<?php echo "搜索结果<br/>";?>
</pre>
<div id="searchcontrol">
加载中...
</div>
</body>
</html>