+ -
当前位置:首页 → 问答吧 → 请教高手 急需解决我这个困惑已久的问题 关于 httpd.exe的问题

请教高手 急需解决我这个困惑已久的问题 关于 httpd.exe的问题

时间:2011-12-05

来源:互联网

我写了RMM分词技术的一个类 我在测试的时候 资源管理器里的 httpd.exe的cpu能占到50%以上的资源,哪位高手能帮我解决一下这个问题吗?谢谢了。。。

作者: Mr_sophisticated   发布时间: 2011-12-05

那你得自己看看你的类是怎么写的咯.

作者: PhpNewnew   发布时间: 2011-12-05

<?php
class SplitWord{
var $TagDic = Array();
var $RankDic = Array();
var $SourceStr = '';
var $ResultStr = '';
var $SplitChar = ' ';
var $SplitLen = 4;
var $MaxLen = 7;
var $MinLen = 3; 

  function SplitWord(){
  $this->__construct();
  }
  
  function __construct(){
  $dicfile = dirname(__FILE__)."/ppldic.csv"; 
  $fp = fopen($dicfile,'r');
  while($line = fgets($fp,256)){
  $ws = explode(' ',$line);
  $this->TagDic[$ws[0]] = $ws[1];
  $this->RankDic[strlen($ws[0])][$ws[0]] = $ws[2];
  }
  fclose($fp);
  }
 function Clear(){
  @fclose($this->QuickDic);
  }
  function SetSource($str){
  $this->SourceStr = $this->UpdateStr($str);
  $this->ResultStr = "";
  }
  function NotGBK($str)
  {
  if($str=="") return "";
  if( ord($str[0])>0x80 ) return false;
  else return true;
  }
  function SplitRMM($str=""){
  if($str!="") $this->SetSource($str);
  if($this->SourceStr=="") return "";
  $this->SourceStr = $this->UpdateStr($this->SourceStr);
  $spwords = explode(" ",$this->SourceStr);
  $spLen = count($spwords);
  $spc = $this->SplitChar;
  for($i=($spLen-1);$i>=0;$i--){
  if($spwords[$i]=="") continue;
  if($this->NotGBK($spwords[$i])){
  if(ereg("[^0-9\.\+\-]",$spwords[$i]))
  { $this->ResultStr = $spwords[$i].$spc.$this->ResultStr; }
  else
  {
  $nextword = "";
  @$nextword = substr($this->ResultStr,0,strpos($this->ResultStr,""));
  }
  }
  else
  {
  $c = $spwords[$i][0].$spwords[$i][1];
  $n = hexdec(bin2hex($c));
  if(strlen($spwords[$i]) <= $this->SplitLen)
  {
  }
  else
  { 
  $this->ResultStr = $this->RunRMM($spwords[$i]).$spc.$this->ResultStr;
  }
  }
  }
  return $this->ResultStr;
  }
  function RunRMM($str){
  $spc = $this->SplitChar;
  $spLen = strlen($str);
  $rsStr = "";
  $okWord = "";
  $tmpWord = "";
  $WordArray = Array();
  for($i=($spLen-1);$i>=0;){
  if($i<=$this->MinLen){
  if($i==1){
  $WordArray[] = substr($str,0,2);
  }else
  {
  $w = substr($str,0,$this->MinLen+1);
  if($this->IsWord($w)){
  $WordArray[] = $w;  
  }else{
  $WordArray[] = substr($str,2,2);
  $WordArray[] = substr($str,0,2);
  }
  }
  $i = -1; break;
  }
  if($i>=$this->MaxLen) $maxPos = $this->MaxLen;
  else $maxPos = $i;
  $isMatch = false;
  for($j=$maxPos;$j>=0;$j=$j-2){
  $w = substr($str,$i-$j,$j+1);
  if($this->IsWord($w)){
  $WordArray[] = $w;
  $i = $i-$j-1;
  $isMatch = true;
  break;
  }
  }
  }
  $rsStr = $this->otherword($WordArray);
  $rsStr;
  }
  
function otherword($WordArray){
  $wlen = count($WordArray)-1;
  $rsStr = "";
  $spc = $this->SplitChar;
  for($i=$wlen;$i>=0;$i--)
  {
$rsStr .= $spc.$WordArray[$i]."、";
  }
$rsStr = preg_replace("/^".$spc."/","、",$rsStr);
  return $rsStr;
  }
  
  function IsWord($okWord){
  $slen = strlen($okWord);
  if($slen > $this->MaxLen) return false;
  else return isset($this->RankDic[$slen][$okWord]);
  }
  
  function UpdateStr($str){
  $spc = $this->SplitChar;
  $slen = strlen($str);
  if($slen==0) return '';
  $okstr = '';
  $prechar = 0;
  for($i=0;$i<$slen;$i++){
  if(ord($str[$i]) < 0x81){
  if(ord($str[$i]) < 33){
  if($prechar!=0&&$str[$i]!="\r"&&$str[$i]!="\n") $okstr .= $spc;
  $prechar=0;
  continue; 
  }else if(ereg("[^0-9a-zA-Z@\.%#:/\\&_-]",$str[$i])){
  if($prechar==0){ $okstr .= $str[$i]; $prechar=3;}
  else{ $okstr .= $spc.$str[$i]; $prechar=3;}
  }else{
  if($prechar==2||$prechar==3)
  { $okstr .= $spc.$str[$i]; $prechar=1;}
  else
  { 
  if(ereg("@#%:",$str[$i])){ $okstr .= $str[$i]; $prechar=3; }
  else { $okstr .= $str[$i]; $prechar=1; }
  }
  }
  }
  else{
  if($prechar!=0 && $prechar!=2) $okstr .= $spc;
  if(isset($str[$i+1])){
  $c = $str[$i].$str[$i+1];
   
  $n = hexdec(bin2hex($c));
  if($n<0xA13F && $n > 0xAA40){
  if($prechar!=0) $okstr .= $spc.$c;
  else $okstr .= $c;
  $prechar = 3; 
  }
  else{
  $okstr .= $c;
  $prechar = 2;
  }
  $i++;
  }
  }
  }
  return $okstr;
  }
}
$sp=new SplitWord();
$sp->RunRMM('sfdsf');
?>
这就是那个类

作者: Mr_sophisticated   发布时间: 2011-12-05

相关阅读 更多