前面两个类 readDic.class.php将单个文件下的词库以【单词=>翻译】的格式,返回
readDir.class.php同样把每个路径下的文件以数组的格式返回
而groupDicName.class.php则解析分类名
这个类则负责一一对应的将每一个单词存储到对应的redis缓存的对应hash表里,这样讲生成26*NUM ,大约100个哈希表
<?php
require_once "readDic.class.php";
require_once "readDir.class.php";
require_once "storeWord.class.php";
require_once "groupDicName.class.php";
class Server
{
private $redis=null;
private $groupName=null;
public function __construct($dir)
{
$this->groupName=new GroupDicName();
$this->redis=new StoreWord();
$this->parseDic($dir);
}
public function getDir($path)
{
$dir=new Dir($path);
return $dir->getFileList();
}
public function parseDic($dir)
{
$path=$this->getDir($dir);
foreach ($path as $wordZone => $dir)
{
foreach ($dir as $dicPath)
{
$oxf=new Oxford($dicPath);
$res=$oxf->oxf();
$gname=$this->groupName->formatName($dicPath);
$this->groupName->setIndex($dicPath);
$this->redis->setWord($gname, $res);
echo str_repeat(" ", 2048);
echo '单词库入库: '. $dicPath. "<br />";
sleep(2);
}
echo '<font color="red">'.$wordZone.'分类存储完毕</font><br />';
}
echo'<font color="blue">所有分类存储完毕</font><br />';
}
}
set_time_limit(1000);
ob_implicit_flush(true);
$ser=new Server('E:\CodeEdit\php\ciba\TXT格式的牛津电子词典\牛津电子词典');
?>