Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 21 additions & 3 deletions inc/database_connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,9 @@ function update_japanese_word_count($japid)
$row = fgets($handle, 1024);
$arr = explode("4\t", $row, 2);
if (!empty($arr[1])) {
//TODO Add tests
$cnt = substr_count(
preg_replace('$[^267]\t$u', '', $arr[1]),
preg_replace('$[^2678]\t$u', '', $arr[1]),
"\t"
);
if (empty($cnt)) {
Expand Down Expand Up @@ -790,6 +791,7 @@ function parse_japanese_text($text, $id): ?array
);
$handle = fopen($file_name, 'r');
$mecabed = fread($handle, filesize($file_name));

fclose($handle);
$values = array();
$order = 0;
Expand All @@ -801,6 +803,7 @@ function parse_japanese_text($text, $id): ?array
);
}
$term_type = 0;
$last_node_type = 0;
$count = 0;
$row = array(0, 0, 0, "", 0);
foreach (explode(PHP_EOL, $mecabed) as $line) {
Expand All @@ -817,17 +820,32 @@ function parse_japanese_text($text, $id): ?array
$term = '¶';
}
$term_type = 2;
} else if (in_array($node_type, ['2', '6', '7'])) {
} else if (in_array($node_type, ['2', '6', '7', '8'])) {
$term_type = 0;
} else {
$term_type = 1;
}


$order += (int)(($term_type == 0) && ($last_term_type == 0)) +
(int)!(($term_type == 1) && ($last_term_type == 1));
$row[2] = $order; // TiOrder
$row[3] = convert_string_to_sqlsyntax_notrim_nonull($term); // TiText
$row[4] = $term_type == 0 ? 1 : 0; // TiWordCount
$values[] = "(" . implode(",", $row) . ")";
$values[] = $row;
if($last_node_type == 8 && $node_type == 8)
{
$lastKey = array_key_last($values);
if ($lastKey !== null) {
$values[$lastKey-1][3] = convert_string_to_sqlsyntax_notrim_nonull(str_replace("'", '', $values[$lastKey-1][3]).$term);
}
array_pop($values);
}
$last_node_type = $node_type;

}
foreach ($values as &$value) {
$value = "(" . implode(",", $value) . ")";
}
do_mysqli_query(
"INSERT INTO temptextitems2 (
Expand Down
4 changes: 2 additions & 2 deletions inc/session_utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3695,9 +3695,9 @@ function sentences_containing_word_lc_query($wordlc, $lid): string
if (!feof($handle)) {
$row = fgets($handle, 256);
// Format string removing numbers.
// MeCab tip: 2 = hiragana, 6 = kanji, 7 = katakana
// MeCab tip: 2 = hiragana, 6 = kanji, 7 = katakana, 8 = kazu
$mecab_str = "\t" . preg_replace_callback(
'([267]?)\t[0-9]+$',
'([2678]?)\t[0-9]+$',
function ($matches) {
return isset($matches[1]) ? "\t" : "";
},
Expand Down