";
#先查原词
echo "
";
$dict_list_a = [];
//社区字典开始
echo lookup_user($word);
//社区字典结束
echo lookup_term($word);
PDO_Connect("" . _FILE_DB_REF_);
//直接查询
$query = "SELECT dict.id, dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN "._TABLE_DICT_REF_NAME_." as info ON dict.dict_id = info.id where word = ? limit 100";
$Fetch = PDO_FetchAll($query, array($word));
$iFetch = count($Fetch);
echo "直接查询{$iFetch}
";
$count_return += $iFetch;
if ($iFetch > 0) {
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["mean"];
$dictid = $Fetch[$i]["dict_id"];
$dict_list[$dictid] = $Fetch[$i]["shortname"];
$dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
$outXml = "";
$outXml = $outXml . "
";
$outXml = $outXml . "
" . $Fetch[$i]["shortname"] . "
";
$mean = GrmAbbr($mean,$dictid);
$outXml = $outXml . "
" . $mean . "
";
$outXml = $outXml . "
";
echo $outXml;
}
}
//去格位除尾查
echo "去格位除尾查
";
$newWord = array();
for ($row = 0; $row < count($case); $row++) {
$len = mb_strlen($case[$row][1], "UTF-8");
$end = mb_substr($word, 0 - $len, null, "UTF-8");
if ($end == $case[$row][1]) {
$base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
if ($base != $word) {
$thiscase = "";
$arrCase = explode('$', $case[$row][2]);
foreach ($arrCase as $value) {
$caseid = "grammar_" . str_replace('.', '', $value);
$thiscase .= "$value";
}
if (isset($newWord[$base])) {
$newWord[$base] .= "
" . $thiscase;
} else {
$newWord[$base] = $thiscase;
}
}
}
}
$base_list = array();
if (count($newWord) > 0) {
foreach ($newWord as $x => $x_value) {
$titleHas = false;
$userDictStr = lookup_user($x);
$termDictStr = lookup_term($x);
if(!empty($userDictStr) || !empty($termDictStr)){
echo "";
$titleHas = true;
}
//$query = "SELECT dict.dict_id,dict.mean,dn.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN "._TABLE_DICT_REF_NAME_." as dn ON dict.dict_id = dn.id where word = ? limit 30";
$Fetch = PDO_FetchAll($query, array($x));
$iFetch = count($Fetch);
$count_return += $iFetch;
if ($iFetch > 0) {
$base_list[] = $x;
$dict_list_a[] = array("word_$x", $x);
if(!$titleHas){
echo "";
}
//语法信息
foreach ($_local->grammastr as $gr) {
$x_value = str_replace($gr->id, $gr->value, $x_value);
}
echo "" . $x_value . "
";
echo $userDictStr;
echo $termDictStr;
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["mean"];
$dictid = $Fetch[$i]["dict_id"];
$dict_list[$dictid] = $Fetch[$i]["shortname"];
$dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
RenderWordDiv($dictid,$Fetch[$i]["shortname"],$Fetch[$i]["id"],$x,$mean);
}
}
}
}
//去除尾查结束
//去分词除尾查
echo "去分词除尾查
";
$arrBase = array();
if (count($newWord) > 0) {
foreach ($newWord as $base => $grammar){
for ($row = 0; $row < count($p_ending); $row++) {
$len = mb_strlen($p_ending[$row][1], "UTF-8");
$end = mb_substr($base, 0 - $len, null, "UTF-8");
if ($end == $p_ending[$row][1]) {
$newbase = mb_substr($base, 0, mb_strlen($base, "UTF-8") - $len, "UTF-8") . $p_ending[$row][0];
if ($newbase != $base) {
$thiscase = "";
$arrCase = explode('$', $p_ending[$row][2]);
foreach ($arrCase as $value) {
$caseid = "grammar_" . str_replace('.', '', $value);
$thiscase .= "$value";
}
if (isset($arrBase[$newbase])) {
$arrBase[$newbase]['grammar'] .= "
" . $thiscase;
} else {
$arrBase[$newbase]['grammar'] = $thiscase;
$arrBase[$newbase]['parent'] = $base;
}
}
}
}
}
$base_list = array();
if (count($arrBase) > 0) {
foreach ($arrBase as $x => $x_value) {
$query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN "._TABLE_DICT_REF_NAME_." as info ON dict.dict_id = info.id where word = ? limit 30";
$Fetch = PDO_FetchAll($query, array($x));
$iFetch = count($Fetch);
$count_return += $iFetch;
if ($iFetch > 0) {
$base_list[] = $x;
$dict_list_a[] = array("word_$x", $x);
echo "";
echo "{$x}➡{$x_value["parent"]}➡{$word}
";
//替换为本地语法信息
foreach ($_local->grammastr as $gr) {
$x_value['grammar'] = str_replace($gr->id, $gr->value, $x_value['grammar']);
}
echo "" . $x_value['grammar'] . "
";
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["mean"];
$dictid = $Fetch[$i]["dict_id"];
$dict_list[$dictid] = $Fetch[$i]["shortname"];
$dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
echo "";
echo "
";
echo "
" . $Fetch[$i]["shortname"] . "
";
$mean = GrmAbbr($mean,$dictid);
echo "
" . $mean . "
";
echo "
";
}
}
}
}
}
//去除尾查结束
echo "";
echo "{$_local->gui->find_about}{$word} {$_local->gui->total}
{$count_return}{$_local->gui->result} ";
if(count($base_list)>0){
echo "找到可能的拼写: ";
foreach ($base_list as $key => $value) {
# code...
echo "
{$value} ";
}
}
echo "
查询内文";
echo "
";
echo "";
//查连读词
/*
if ($count_return < 2) {
echo "Junction
";
$newWord = array();
for ($row = 0; $row < count($un); $row++) {
$len = mb_strlen($un[$row][1], "UTF-8");
$end = mb_substr($word, 0 - $len, null, "UTF-8");
if ($end == $un[$row][1]) {
$base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $un[$row][0];
$arr_un = explode("+", $base);
foreach ($arr_un as $oneword) {
echo "$oneword + ";
}
echo "
";
}
}
}
*/
//拆复合词
echo "";
//查内容
if ($count_return < 4) {
$word1 = $org_word;
$wordInMean = "%$org_word%";
echo "包含 $org_word 的:
";
$query = "SELECT dict.dict_id,dict.word,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN "._TABLE_DICT_REF_NAME_." as info ON dict.dict_id = info.id where mean like ? limit 30";
$Fetch = PDO_FetchAll($query, array($wordInMean));
$iFetch = count($Fetch);
$count_return += $iFetch;
if ($iFetch > 0) {
for ($i = 0; $i < $iFetch; $i++) {
$mean = $Fetch[$i]["mean"];
$pos = mb_stripos($mean, $word, 0, "UTF-8");
if ($pos) {
if ($pos > 20) {
$start = $pos - 20;
} else {
$start = 0;
}
$newmean = mb_substr($mean, $start, 100, "UTF-8");
} else {
$newmean = $mean;
}
$pos = mb_stripos($newmean, $word1, 0, "UTF-8");
$head = mb_substr($newmean, 0, $pos, "UTF-8");
$mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
$end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
$heigh_light_mean = "$head$mid$end";
echo "";
echo "
";
echo "
" . $Fetch[$i]["shortname"] . "
";
echo "
" . $heigh_light_mean . "
";
echo "
";
echo "
";
}
}
}
else{
}
echo "";
foreach ($dict_list_a as $x_value) {
if (substr($x_value[0], 0, 4) == "word") {
echo "
";
} else {
echo "
";
}
}
echo "
";
$arrWords = countWordInPali($word, true);
$weight = 0;
foreach ($arrWords as $oneword) {
$weight += $oneword["count"] * $oneword["len"];
}
//echo "
{$_local->gui->word_weight}:$weight {$_local->gui->characters}
";
//echo "
{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}
";
$right_word_list .= "
{$_local->gui->word_weight}:$weight {$_local->gui->characters}
";
$right_word_list .= "
{$_local->gui->real_declension}:" . count($arrWords) . " {$_local->gui->forms}
";
foreach ($arrWords as $oneword) {
if ($oneword["bold"] > 0) {
//echo "
{$oneword["word"]} {$oneword["count"]} {$_local->gui->times}
";
$right_word_list .= "
{$oneword["word"]} {$oneword["count"]} {$_local->gui->times}
";
} else {
//echo "
{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}
";
$right_word_list .= "
{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}
";
}
}
echo "
";
echo "
";
echo "";
//参考字典查询结束
//用户词典编辑窗口
echo "";
echo "
";
echo $right_word_list;
echo "
";
//查用户词典结束
PrefLog();
function lookup_user($word){
global $dict_list;
global $redis;
global $_local;
global $PDO;
global $count_return;
$output ="";
$Fetch=array();
if($redis){
$rediskey = Redis["prefix"]."dict/user";
$wordData = $redis->hGet($rediskey,$word);
if($wordData){
if(!empty($wordData)){
$arrWord = json_decode($wordData,true);
foreach ($arrWord as $one) {
# code...
$Fetch[] = array("id"=>$one[0],
"pali"=>$one[1],
"type"=>$one[2],
"grammar"=>$one[3],
"parent"=>$one[4],
"mean"=>$one[5],
"note"=>$one[6],
"factors"=>$one[7],
"factormean"=>$one[8],
"status"=>$one[9],
"confidence"=>$one[10],
"creator_id"=>$one[11],
"source"=>$one[12],
"lang"=>$one[13],
);
}
}
}
else{
# 没找到就不找了
}
}
else
{
PDO_Connect(_FILE_DB_WBW_,_DB_USERNAME_,_DB_PASSWORD_);
$query = "SELECT * from " . _TABLE_DICT_WBW_ . " where word = ? and source='_SYS_USER_WBW_' limit 100";
$Fetch = PDO_FetchAll($query, array($word));
}
$iFetch = count($Fetch);
if ($iFetch > 0) {
$count_return++;
$userlist = array();
foreach ($Fetch as $value) {
if (isset($userlist[$value["creator_id"]])) {
$userlist[$value["creator_id"]] += 1;
} else {
$userlist[$value["creator_id"]] = 1;
}
$userwordcase = $value["type"] . "#" . $value["grammar"];
$parent = $value["parent"];
if(empty($parent)){
$parent = "_null_";
}
if (isset($userdict["{$parent}"])) {
$userdict["{$parent}"]["mean"] .= "$". $value["mean"] ;
$userdict["{$parent}"]["factors"] .= "@". $value["factors"];
$userdict["{$parent}"]["case"] .= "@".$userwordcase;
} else {
$userdict["{$parent}"]["mean"] = $value["mean"];
$userdict["{$parent}"]["factors"] = $value["factors"];
$userdict["{$parent}"]["case"] = $userwordcase;
}
}
$output .= "";
$output .= "
{$_local->gui->com_dict}
";
$dict_list_a[] = array("net", $_local->gui->com_dict);
foreach ($userdict as $key => $value) {
#语法信息查重
$thiscase = array();
$strCase = "";
$arrCase = explode("@",$value["case"]);
foreach ($arrCase as $case) {
# code...
$thiscase[$case] = 1;
}
foreach ($thiscase as $case => $casevalue) {
# code...
$strCase .=$case . "; ";
}
#语法信息替换为本地字符串
foreach ($_local->grammastr as $gr) {
$strCase = str_replace($gr->id, $gr->value, $strCase);
}
#拆分查重复
$thispart = array();
$strPart = "";
$arrPart = explode("@",$value["factors"]);
foreach ($arrPart as $part) {
# code...
$thispart[$part] = 1;
}
foreach ($thispart as $part => $partvalue) {
# code...
$strPart .=$part . "; ";
}
#意思查重复
$thismean = array();
$strMean = "";
$arrMean = explode("$",$value["mean"]);
foreach ($arrMean as $mean) {
# code...
$thismean[$mean] = 1;
}
foreach ($thismean as $mean => $meanvalue) {
# code...
$strMean .=$mean . "; ";
}
$output .= "
{$_local->gui->gramma}:{$strCase}
";
if($key!=="_null_"){
$output .= "
";
}
$output .= "
{$_local->gui->g_mean}:{$strMean}
";
$output .= "
{$_local->gui->factor}:{$strPart}
";
}
$output .= "
{$_local->gui->contributor}:";
$userinfo = new UserInfo();
foreach ($userlist as $key => $value) {
$user = $userinfo->getName($key);
$output .= $user["nickname"] . " ";
}
$output .= "
";
$output .= "
";
}
return $output;
}
function lookup_term($word){
global $dict_list;
global $redis;
global $_local;
global $PDO;
global $count_return;
$output ="";
$Fetch=array();
if($redis){
$wordData = $redis->hGet("dict://term",$word);
if($wordData){
if(!empty($wordData)){
$arrWord = json_decode($wordData,true);
foreach ($arrWord as $one) {
# code...
$Fetch[] = array("id"=>$one[0],
"pali"=>$one[1],
"type"=>$one[2],
"gramma"=>$one[3],
"parent"=>$one[4],
"mean"=>$one[5],
"note"=>$one[6],
"factors"=>$one[7],
"factormean"=>$one[8],
"status"=>$one[9],
"confidence"=>$one[10],
"creator"=>$one[11],
"dict_name"=>$one[12],
"lang"=>$one[13],
);
}
}
}
else{
# 没找到就不找了
}
}
else{
exit;
#TODO 查询term 表
PDO_Connect(_FILE_DB_WBW_,_DB_USERNAME_,_DB_PASSWORD_);
$query = "SELECT * from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
$Fetch = PDO_FetchAll($query, array($word));
}
$iFetch = count($Fetch);
$count_return += $iFetch;
if ($iFetch > 0) {
$userlist = array();
foreach ($Fetch as $value) {
if (isset($userlist[$value["creator"]])) {
$userlist[$value["creator"]] += 1;
} else {
$userlist[$value["creator"]] = 1;
}
$userwordcase = $value["type"] . "#" . $value["gramma"];
if (isset($userdict["{$userwordcase}"])) {
$userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
$userdict["{$userwordcase}"]["factors"] .= $value["factors"];
} else {
$userdict["{$userwordcase}"]["mean"] = $value["mean"];
$userdict["{$userwordcase}"]["factors"] = $value["factors"];
}
}
$output .= "";
$output .= "
{$_local->gui->wiki_term}
";
$dict_list_a[] = array("net", $_local->gui->wiki_term);
foreach ($userdict as $key => $value) {
$output .= "
{$key}:{$value["mean"]}
";
}
$output .= "
{$_local->gui->contributor}:";
$userinfo = new UserInfo();
foreach ($userlist as $key => $value) {
$user = $userinfo->getName($key);
$output .= $user["nickname"] . " ";
}
$output .= "
";
$output .= "
";
}
return $output;
}
function GrmAbbr($input,$dictid){
$mean = $input;
foreach (GRM_ABBR as $key => $value) {
# code...
if($value["dictid"]==$dictid && strpos($input,$value["abbr"]."") == false){
$mean = str_ireplace($value["abbr"],"{$value["abbr"]}",$mean);
}
}
return $mean;
}
function RenderWordDiv($dictId,$dictName,$refWordId,$word,$meaning){
echo "";
echo "
";
echo "
" . $dictName . "
";
$mean = GrmAbbr($meaning,$dictId);
echo "
" . $mean . "
";
/*
echo "
";
*/
echo "
";
}
function RenderUserDictEdit($word,$dictId,$refWordId){
global $_local;
//用户词典编辑窗口
echo "