Created
February 28, 2011 10:42
-
-
Save ozero/847173 to your computer and use it in GitHub Desktop.
add desc from eijirou to words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Zend/Db.php'; | |
require_once 'Zend/Config/Ini.php'; | |
//connect db | |
$db=dbfactory(); | |
$fhf=fopen('./src.txt','r'); | |
$fht=fopen('./ext.txt','w'); | |
$repl=array("/.*?ed$/","/.*?sd$/","/.*?ing$/",); | |
$count=0; | |
while(!feof($fhf)){ | |
$line=strtolower(trim(fgets($fhf))); | |
$line_src=$line; | |
//$line=substr(); | |
$sql="select keyword,trans,pron from kwd where keyword = '{$line}' order by keyword limit 1 offset 0;"; | |
$stmt = $db->query($sql); | |
$tmp=$stmt->fetchAll(PDO::FETCH_ASSOC); | |
//print_r($tmp); | |
if(!isset($tmp[0]['trans'])){ | |
//print "\n301:{$line}\n"; | |
//$line = substr($line,0,-2); | |
$line = preg_replace("/(.*?)s$/","\\1",$line); | |
$line = preg_replace("/(.*?)ed$/","\\1",$line); | |
$line = preg_replace("/(.*?)ing$/","\\1",$line); | |
$sql="select * from kwd where keyword like '{$line}%' order by keyword limit 1 offset 0;"; | |
$stmt = $db->query($sql); | |
$tmp=$stmt->fetchAll(PDO::FETCH_ASSOC); | |
} | |
if(!isset($tmp[0]['trans'])){ | |
print "404:{$line_src}\n"; | |
fwrite($fht,"{$line_src}\n"); | |
}else{ | |
$tmp[0]['trans'] = preg_replace("/[\r|\n]/","",$tmp[0]['trans']); | |
$tmp[0]['pron'] = preg_replace("/[\r|\n]/","",$tmp[0]['pron']); | |
fwrite($fht,"{$line_src}\t{$tmp[0]['pron']} {$tmp[0]['trans']}\n"); | |
} | |
if(($count % 20) == 0 ){print "{$count}\n";} | |
$count++; | |
} | |
function dbfactory(){ | |
$config = new Zend_Config_Ini('./db.ini', 'default'); | |
$db = Zend_Db::factory($config->db); | |
$db->setFetchMode(Zend_Db::FETCH_OBJ); | |
return $db; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment