Skip to content

Instantly share code, notes, and snippets.

@naoa
Created December 9, 2013 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoa/7865980 to your computer and use it in GitHub Desktop.
Save naoa/7865980 to your computer and use it in GitHub Desktop.
<?php
$input_file = $argv[1];
if($argc >= 3){
$output_file = $argv[2];
}
else{
$output_file = "";
}
$conv = "./converter-main -i";
$dict = "dict/bccwj4";
$fp = fopen($input_file, 'r');
if($output_file != ""){
$fw = fopen($output_file, 'a+');
}
while (!feof($fp)){
$line = fgets($fp);
$line = str_replace(array("\r\n","\r","\n"),'',$line);
$line_arr = explode(",",$line);
$cmd = 'echo ' . $line_arr[0] . ' | ' . $conv . ' ' . $dict;
$af_str = exec($cmd);
if($af_str != ""){
$af_str = mb_convert_kana($af_str, "C", "UTF-8");
if($output_file != ""){
fwrite($fw,$line_arr[0] . "," . $af_str . "," . $line_arr[1] . "," . "1" . "\n");
}
else{
echo $line_arr[0] . "," . $af_str . "," . $line_arr[1] . "," . "1" . "\n";
}
}
}
fclose($fp);
if($output_file != ""){
fclose($fw);
}
echo "Done.\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment