Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions inc/database_connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function update_japanese_word_count($japid) {

// STEP 1: write the useful info to a file
$db_to_mecab = tempnam(sys_get_temp_dir(), "{$tbpref}db_to_mecab");
$mecab_args = ' -F %m%t\\t -U %m%t\\t -E \\n ';
$mecab_args = ' -F %m%t\\t -U %m%t\\t -E ""';
$mecab = get_mecab_path($mecab_args);

$sql = "SELECT WoID, WoTextLC FROM {$tbpref}words
Expand Down Expand Up @@ -745,7 +745,7 @@ function parse_japanese_text($text, $id)

$file_name = tempnam(sys_get_temp_dir(), $tbpref . "tmpti");
// We use the format "word num num" for all nodes
$mecab_args = " -F %m\\t%t\\t%h\\n -U %m\\t%t\\t%h\\n -E EOS\\t3\\t7\\n";
$mecab_args = " -F %m\\t%t\\t%h\\n -U %m\\t%t\\t%h\\n -E ''";
$mecab_args .= " -o $file_name ";
$mecab = get_mecab_path($mecab_args);

Expand Down Expand Up @@ -773,17 +773,22 @@ function parse_japanese_text($text, $id)
$id>0 ?
"(SELECT ifnull(max(`SeID`)+1,1) FROM `{$tbpref}sentences`)"
: 1
) . ", @count:=0,@last_term_type:=0;"
) . ", @count:=0,@last_term_type:=0, @at_sentence_end:=false, @inside_quote:=0;"
);

$sql =
"LOAD DATA LOCAL INFILE " . convert_string_to_sqlsyntax($file_name) . "
INTO TABLE {$tbpref}temptextitems2
FIELDS TERMINATED BY '\\t'
LINES TERMINATED BY '" . PHP_EOL . "'
(@term, @node_type, @third)
SET
TiSeID = IF(@term_type=2 OR (@term='EOS' AND @third='7'), @sid:=@sid+1,@sid),
TiSeID = CASE
WHEN (@inside_quote = 0 AND @term IN ('「', '【', '『', '〝')) THEN @sid:=@sid+(@inside_quote := @inside_quote + 1)*(@at_sentence_end := false)
WHEN (@inside_quote > 0 AND @term IN ('】', '」', '』', '〟')) THEN @sid:=@sid+(@inside_quote := @inside_quote - 1)*(@at_sentence_end := false)
WHEN (@inside_quote = 0 AND @at_sentence_end = true AND (@node_type != 3 OR @term IN ('「', '」', '【', '】', '、', ',', '…', '‥', '『', '』', '〝', '〟', ':', '――'))) THEN @sid:=@sid+1+(@at_sentence_end := false)
WHEN (@inside_quote = 0 AND @node_type = 3 AND @term NOT IN ('「', '」', '【', '】', '、', ',', '…', '‥', '『', '』', '〝', '〟', ':', '――')) THEN @sid:=@sid*(@at_sentence_end := true)
ELSE @sid
END,
TiCount = (@count:= @count + CHAR_LENGTH(@term)) + 1 - CHAR_LENGTH(@term),
TiOrder = IF(
CASE
Expand Down