Rmm 分词算法代码片段

 更新时间:2016年11月25日 15:58  点击:1662

function SplitRMM($str=""){
   if($str!="") $this->SetSource(trim($str));
   if($this->SourceString=="") return "";
   //对文本进行粗分
   $this->SourceString = $this->ReviseString($this->SourceString);
   //对特定文本进行分离
   $spwords = explode(" ",$this->SourceString);
   $spLen = count($spwords);
   $spc = $this->SplitChar;
   for($i=($spLen-1);$i>=0;$i--){
    if(trim($spwords[$i])=="") continue;
    if($this->NotGBK($spwords[$i])){
     if(ereg("[^0-9.+-]",$spwords[$i]))
     { $this->ResultString = $spwords[$i].$spc.$this->ResultString; }
     else
     {
      $nextword = "";
      @$nextword = substr($this->ResultString,0,strpos($this->ResultString," "));
      if(ereg("^".$this->CommonUnit,$nextword)){
       $this->ResultString = $spwords[$i].$this->ResultString;
      }else{
       $this->ResultString = $spwords[$i].$spc.$this->ResultString;
      }
     }
    }
    else
    {
      $c = $spwords[$i][0].$spwords[$i][1];
      $n = hexdec(bin2hex($c));
      if($c=="《") //书名
      { $this->ResultString = $spwords[$i].$spc.$this->ResultString; }
      else if($n>0xA13F && $n < 0xAA40) //标点符号
      { $this->ResultString = $spwords[$i].$spc.$this->ResultString; }
      else //正常短句
      {
       if(strlen($spwords[$i]) <= $this->SplitLen)
       {
        //如果结束符为特殊分割词,分离处理
        if(ereg($this->EspecialChar."$",$spwords[$i],$regs)){
          $spwords[$i] = ereg_replace($regs[0]."$","",$spwords[$i]).$spc.$regs[0];
        }
        //是否为常用单位
        if(!ereg("^".$this->CommonUnit,$spwords[$i]) || $i==0){
         $this->ResultString = $spwords[$i].$spc.$this->ResultString;
        }else{
         $this->ResultString = $spwords[$i-1].$spwords[$i].$spc.$this->ResultString;
         $i--;
        }
       }
       else
       {
        $this->ResultString = $this->RunRMM($spwords[$i]).$spc.$this->ResultString;
       }
      }
     }
   }
   return $this->ResultString;
  }

  //
  function GetAlabNum($fnum)
  {
   $nums = array("0","1","2","3","4","5","6","7","8","9","+","-","%",".");
   $fnums = "0123456789+-%.";
   for($i=0;$i<count($nums);$i++){
    if($nums[$i]==$fnum) return $fnums[$i];
   }
   return $fnum;
  }

这是一个文件目录移动类,只要在listDir写你的要转移文件的目录名移就可以了,这个文件夹与文件移动类,比较适合采集下载的多文件操作,如要在打包文件里面加说明,等哦。

<?php教程
die();
 class s{
  //var $path ='flash';
  var $htm ='/index.htm';
  var $html='/index.html';
  var $ladir='/111cn.net教程';
  
  public function full_copy( $source, $target )
  {

   if ( is_dir( $source ) && $source != $source.$this->ladir )
   {
    @mkdir( $target );
    $d = dir( $source );
    while ( FALSE !== ( $entry = $d->read() ) )
    {
     if ( $entry == '.' || $entry == '..' )
     {
        continue;
     }
     $Entry = $source . '/' . $entry;
     if ( is_dir( $Entry ) )
     {
      $this->full_copy( $Entry, $target . '/' . $entry );
      continue;
     }
     copy( $Entry, $target . '/' . $entry );
    }
    $d->close();
   }
   else
   {
    copy( $source, $target );
   }
    }
   
    //
   
  public function listDir($dir_path)
  {
   if(is_dir($dir_path)){ 
    if($dir_file=opendir($dir_path)){
     while(($dir_list=readdir($dir_file))!==false)
      {
       if($dir_list!="." && $dir_list!="..")
       {        
        $this->listSunDir($dir_path."/".$dir_list);
        //$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
       }
      }
    }else{
     echo($dir_path);
    }
  }else{
 
   echo($dir_path);
  }
 }
 
 //
 
  public function listSunDir($dir_path)
  {
   if(is_dir($dir_path)){ 
    if($dir_file=opendir($dir_path)){
     while(($dir_list=readdir($dir_file))!==false)
      {
       if($dir_list!="." && $dir_list!="..")
       {
        
        //$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
        
       
        if( '/'.$dir_list == $this->ladir )
        {
         continue;
        }
        else
        {
         echo $dir_path."/".$dir_list,'<br />';
         $this->full_copy($dir_path."/".$dir_list,$dir_path."/".$this->ladir);
         $this->deldir($dir_path."/".$dir_list);
        }
              
        //$this->full_copy($dir_path."/".$dir_list,$dir_path."/".$dir_list.$this->ladir);
       }
      }
    }else{
     echo($dir_path);
    }
  }else{
 
   echo($dir_path);
  }
 }
 
 //
 
 public function checkFile($dir)
 {
  if( is_dir( $dir ) )
  {
   if(is_file( $dir.$htm ) || is_file($dir . $html) )
   {
     continue;
   }
   else
   {
    $this->full_copy( $dir, $target );
   }
  }
 }
 
 // mkdir
 
 function mkdir_r($dirName, $rights=0777)
 {
  $dirs = explode('/', $dirName);
  $dir='';
  foreach ($dirs as $part) {
   $dir.=$part.'/';
   if (!is_dir($dir) && strlen($dir)>0 && !is_file($dirName))
   {
    mkdir($dir, $rights);
    echo "$dirName<br/>";
   }
  }
 }
 
 // delall
 
 function deldir($dir)
 {
  if(is_dir($dir))
  {
   $rdir = $dir;
   if($dirlist = scandir($rdir))
   {
    array_shift($dirlist);
    array_shift($dirlist);
    foreach($dirlist as $d){
     $rd = $rdir.'/'.$d;
     if(isset($d) && is_file($rd)){ 
      unlink($rd);
     }else{
      $this->deldir($rd);
     }
    }  
    rmdir($rdir);
   }else{
    return false;
   }
  }
     return true;
 }  
}

 $s = new s();
 $s->listDir('flash');//要移动目录
?>

<?
//php教程获取ip的算法
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];
//echo $user_IP;
//===================================
//
// 功能:IP地址获取真实地址函数
// 参数:$ip - IP地址
// 作者:[Discuz!] (C) Comsenz Inc.
//
//===================================
function convertip($ip) {
    //IP数据文件路径,请根据情况自行修改
    $dat_path = 'QQWry.dat';
    //检查IP地址
    if(!ereg("^([0-9]{1,3}.){3}[0-9]{1,3}$", $ip)){
        return 'IP Address Error';
    }
    //打开IP数据文件
    if(!$fd = @fopen($dat_path, 'rb')){
        return 'IP date file not exists or access denied';
    }
    //分解IP进行运算,得出整形数
    $ip = explode('.', $ip);
    $ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];
    //获取IP数据索引开始和结束位置
    $DataBegin = fread($fd, 4);
    $DataEnd = fread($fd, 4);
    $ipbegin = implode('', unpack('L', $DataBegin));
    if($ipbegin < 0) $ipbegin += pow(2, 32);
    $ipend = implode('', unpack('L', $DataEnd));
    if($ipend < 0) $ipend += pow(2, 32);
    $ipAllNum = ($ipend - $ipbegin) / 7 + 1;
    $BeginNum = 0;
    $EndNum = $ipAllNum;
    //使用二分查找法从索引记录中搜索匹配的IP记录
    while($ip1num>$ipNum || $ip2num<$ipNum) {
        $Middle= intval(($EndNum + $BeginNum) / 2);
        //偏移指针到索引位置读取4个字节
        fseek($fd, $ipbegin + 7 * $Middle);
        $ipData1 = fread($fd, 4);
        if(strlen($ipData1) < 4) {
            fclose($fd);
            return 'System Error';
        }
        //提取出来的数据转换成长整形,如果数据是负数则加上2的32次幂
        $ip1num = implode('', unpack('L', $ipData1));
        if($ip1num < 0) $ip1num += pow(2, 32);
        //提取的长整型数大于我们IP地址则修改结束位置进行下一次循环
        if($ip1num > $ipNum) {
            $EndNum = $Middle;
            continue;
        }
        //取完上一个索引后取下一个索引
        $DataSeek = fread($fd, 3);
        if(strlen($DataSeek) < 3) {
            fclose($fd);
            return 'System Error';
        }
        $DataSeek = implode('', unpack('L', $DataSeek.chr(0)));
        fseek($fd, $DataSeek);
        $ipData2 = fread($fd, 4);
        if(strlen($ipData2) < 4) {
            fclose($fd);
            return 'System Error';
        }
        $ip2num = implode('', unpack('L', $ipData2));
        if($ip2num < 0) $ip2num += pow(2, 32);
        //没找到提示未知
        if($ip2num < $ipNum) {
            if($Middle == $BeginNum) {
                fclose($fd);
                return 'Unknown';
            }
            $BeginNum = $Middle;
        }
    }
    //下面的代码读晕了,没读明白,有兴趣的慢慢读
    $ipFlag = fread($fd, 1);
    if($ipFlag == chr(1)) {
        $ipSeek = fread($fd, 3);
        if(strlen($ipSeek) < 3) {
            fclose($fd);
            return 'System Error';
        }
        $ipSeek = implode('', unpack('L', $ipSeek.chr(0)));
        fseek($fd, $ipSeek);
        $ipFlag = fread($fd, 1);
    }
    if($ipFlag == chr(2)) {
        $AddrSeek = fread($fd, 3);
        if(strlen($AddrSeek) < 3) {
            fclose($fd);
            return 'System Error';
        }
        $ipFlag = fread($fd, 1);
        if($ipFlag == chr(2)) {
            $AddrSeek2 = fread($fd, 3);
            if(strlen($AddrSeek2) < 3) {
                fclose($fd);
                return 'System Error';
            }
            $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
            fseek($fd, $AddrSeek2);
        } else {
            fseek($fd, -1, SEEK_CUR);
        }
        while(($char = fread($fd, 1)) != chr(0))
            $ipAddr2 .= $char;
        $AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));
        fseek($fd, $AddrSeek);
        while(($char = fread($fd, 1)) != chr(0))
            $ipAddr1 .= $char;
    } else {
        fseek($fd, -1, SEEK_CUR);
        while(($char = fread($fd, 1)) != chr(0))
            $ipAddr1 .= $char;
        $ipFlag = fread($fd, 1);
        if($ipFlag == chr(2)) {
            $AddrSeek2 = fread($fd, 3);
            if(strlen($AddrSeek2) < 3) {
                fclose($fd);
                return 'System Error';
            }
            $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
            fseek($fd, $AddrSeek2);
        } else {
            fseek($fd, -1, SEEK_CUR);
        }
        while(($char = fread($fd, 1)) != chr(0)){
            $ipAddr2 .= $char;
        }
    }
    fclose($fd);
    //最后做相应的替换操作后返回结果
    if(preg_match('/http/i', $ipAddr2)) {
        $ipAddr2 = '';
    }
    $ipaddr = "$ipAddr1 $ipAddr2";
    $ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr);
    $ipaddr = preg_replace('/^s*/is', '', $ipaddr);
    $ipaddr = preg_replace('/s*$/is', '', $ipaddr);
    if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {
        $ipaddr = 'Unknown';
    }
    return $ipaddr;
}
?>
<script language="javascript教程">
var sf='<?echo convertip($user_IP);?>';
if(sf.indexOf("香港")>=0){
        window.location.href="http://xianggang.111cn.net";
}
else if(sf.indexOf("广东省")>=0){
        window.location.href="http://guangdong.111cn.net";
}
else if(sf.indexOf("北京")>=0){
        window.location.href="http://beijing.111cn.net";
}
else{
        window.location.href="http://www.111cn.net";
}
</script>

<?php
require ('resize_img.php');
//how to use the class:
//makes a simple thumbnail of an image of 100x100 and saves the image then outputs it.
$imgresize = new resize_img();

$imgresize->sizelimit_x = 100;
$imgresize->sizelimit_y = 100;
$imgresize->keep_proportions = true;
$imgresize->output = 'PNG';

if( $imgresize->resize_image( 'C:/xampp/htdocs/wannabe/image_bin/public/treeshadows_001.gif' ) === false )
{
  echo 'ERROR!';
}
else
{
  $imgresize->save_resizedimage( 'C:/xampp/htdocs/wannabe/image_bin/public/thumbnails/', 'treeshadows_001' );
  $imgresize->output_resizedimage();
}

$imgresize->destroy_resizedimage();

?>

// resize_img.php文件

<?php

/**
 * by Daniel M. Story <admin@danstory.com>
 */

class resize_img
{
  var $image_path = '';
  //holds the image path
  var $sizelimit_x = 250;
  //the limit of the image width
  var $sizelimit_y = 250;
  //the limit of the image height
  var $image_resource = '';
  //holds the image resource
  var $keep_proportions = true;
  //if true it keeps教程 the image proportions when resized
  var $resized_resource = '';
  //holds the resized image resource
  var $hasGD = false;
  var $output = 'SAME';
  //can be JPG, GIF, PNG, or SAME (same will save as old type)
 
  function resize_img()
  {
    if( function_exists('gd_info') ){ $this->hasGD = true; } 
  }
 
  function resize_image( $image_path )
  {
    if( $this->hasGD === false ){ return false; }
    //no GD installed on the server!
   
    list($img_width, $img_height, $img_type, $img_attr) = @getimagesize( $image_path );
    //this is going to get the image width, height, and format
   
    if( ( $img_width != 0 ) || ( $img_width != 0 ) )
    //make sure it was loaded correctly
    {
      switch( $img_type )
      {
        case 1:
          //GIF
          $this->image_resource = @imagecreatefromgif( $image_path );
          if( $this->output == 'SAME' ){ $this->output = 'GIF'; }
          break;
        case 2:
          //JPG
          $this->image_resource = @imagecreatefromjpeg( $image_path );
          if( $this->output == 'SAME' ){ $this->output = 'JPG'; }
          break; 
        case 3:
          //PNG
          $this->image_resource = @imagecreatefrompng( $image_path );
          if( $this->output == 'SAME' ){ $this->output = 'PNG'; }
      }
      if( $this->image_resource === '' ){ return false; }
      //it wasn't able to load the image
    }
    else{ return false; }
    //something happened!
   
    if( $this->keep_proportions === true )
    {
      if( ($img_width-$this->sizelimit_x) > ($img_height-$this->sizelimit_y) )
      {
      //if the width of the img is greater than the size limit we scale by width
        $scalex = ( $this->sizelimit_x / $img_width );
        $scaley = $scalex;
      }
      else
      //if the height of the img is greater than the size limit we scale by height
      {
        $scalex = ( $this->sizelimit_y / $img_height );
        $scaley = $scalex;
      }

    }
    else
    {
      $scalex = ( $this->sizelimit_x / $img_width );
      $scaley = ( $this->sizelimit_y / $img_height );
      //just make the image fit the image size limit
     
      if( $scalex > 1 ){ $scalex = 1; }
      if( $scaley > 1 ){ $scaley = 1; }
      //don't make it so it streches the image
    }
   
    $new_width = $img_width * $scalex;
    $new_height = $img_height * $scaley;
   
    $this->resized_resource = @imagecreatetruecolor( $new_width, $new_height );
    //creates an image resource, with the width and height of the size limits (or new resized proportion )
   
    if( function_exists( 'imageantialias' )){ @imageantialias( $this->resized_resource, true ); }
    //helps in the quality of the image being resized
   
    @imagecopyresampled( $this->resized_resource, $this->image_resource, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height );
    //resize the iamge onto the resized resource
   
    @imagedestroy( $this->image_resource );
    //destory old image resource
   
    return true;
  }
 
  function save_resizedimage( $path, $name )
  {
    switch( strtoupper($this->output) )
    {
      case 'GIF':
        //GIF
        @imagegif( $this->resized_resource, $path . $name . '.gif' );
        break;
      case 'JPG':
        //JPG
        @imagejpeg( $this->resized_resource, $path . $name . '.jpg' );
        break; 
      case 'PNG':
        //PNG
        @imagepng( $this->resized_resource, $path . $name . '.png' );
    }
  }
 
  function output_resizedimage()
  {
    $the_time = time();
    header('Last-Modified: ' . date( 'D, d M Y H:i:s', $the_time ) . ' GMT');
    header('Cache-Control: public');
   
    switch( strtoupper($this->output) )
    {
      case 'GIF':
        //GIF
        header('Content-type: image/gif');
        @imagegif( $this->resized_resource );
        break;
      case 'JPG':
        //JPG
        header('Content-type: image/jpg');
        @imagejpeg( $this->resized_resource );
        break; 
      case 'PNG':
        //PNG
        header('Content-type: image/png');
        @imagepng( $this->resized_resource );
    }
  }
 
  function destroy_resizedimage()
  {
    @imagedestroy( $this->resized_resource );
    @imagedestroy( $this->image_resource );
  }

}

?>

[!--infotagslink--]

相关文章

  • C#几种排序算法

    作者:Sabine 【导读】本文介绍了C#的四种排序算法:冒泡排序、选择排序、插入排序和希尔排序  冒泡排序 using System; namespace BubbleSorter { public class Bubb...2020-06-25
  • 经典实例讲解C#递归算法

    这篇文章主要用实例讲解C#递归算法的概念以及用法,文中代码非常详细,帮助大家更好的参考和学习,感兴趣的朋友可以了解下...2020-06-25
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • php怎么用拼音 简单的php中文转拼音的实现代码

    小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
  • php导出csv格式数据并将数字转换成文本的思路以及代码分享

    php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
  • 几种延迟加载JS代码的方法加快网页的访问速度

    本文介绍了如何延迟javascript代码的加载,加快网页的访问速度。 当一个网站有很多js代码要加载,js代码放置的位置在一定程度上将会影像网页的加载速度,为了让我们的网页加载速度更快,本文总结了一下几个注意点...2013-10-13
  • C#中实现任意List的全组合算法代码

    这篇文章主要是介绍了.net C# 实现任意List的全组合算法实现代码,需要的朋友可以参考下...2020-06-25