@@ -4143,13 +4143,11 @@ function getScriptDirectionTag($lid): string
41434143 *
41444144 * @return string[][] Append text and values to insert to the database
41454145 *
4146- * @since 2.5.0-fork Function added.
4147- *
41484146 * @global string $tbpref Table name prefix
41494147 *
41504148 * @psalm-return list{array<int, string>, list{0?: string,...}}
41514149 */
4152- function insert_expression_from_mecab ($ text , $ lid , $ wid , $ len ): array
4150+ function insertMecabExpression ($ text , $ lid , $ wid , $ len ): array
41534151{
41544152 global $ tbpref ;
41554153
@@ -4183,6 +4181,9 @@ function insert_expression_from_mecab($text, $lid, $wid, $len): array
41834181 $ sqlarray = array ();
41844182 // For each sentence in database containing $text
41854183 while ($ record = mysqli_fetch_assoc ($ res )) {
4184+ if (!array_key_exists ((int ) $ record ['SeTxID ' ], $ mwords )) {
4185+ $ mwords [(int ) $ record ['SeTxID ' ]] = array ();
4186+ }
41864187 $ sent = trim ((string ) $ record ['SeText ' ]);
41874188 $ fp = fopen ($ db_to_mecab , 'w ' );
41884189 fwrite ($ fp , $ sent . "\n" );
@@ -4213,9 +4214,9 @@ function insert_expression_from_mecab($text, $lid, $wid, $len): array
42134214 $ sqlarray [] = "( $ wid, $ lid, {$ record ['SeTxID ' ]}, {$ record ['SeID ' ]},
42144215 $ pos, $ len, " . convert_string_to_sqlsyntax_notrim_nonull ($ text ) . ") " ;
42154216 if (getSettingZeroOrOne ('showallwords ' , 1 )) {
4216- $ mwords [$ pos ] = " $ len  " ;
4217+ $ mwords [( int ) $ record [ ' SeTxID ' ]][ $ pos ] = " $ len  " ;
42174218 } else {
4218- $ mwords [$ pos ] = $ text ;
4219+ $ mwords [( int ) $ record [ ' SeTxID ' ]][ $ pos ] = $ text ;
42194220 }
42204221 $ seek = mb_strpos ($ parsed_sentence , $ parsed_text , $ seek + 1 );
42214222 }
@@ -4227,6 +4228,33 @@ function insert_expression_from_mecab($text, $lid, $wid, $len): array
42274228 return array ($ mwords , $ sqlarray );
42284229}
42294230
4231+ /**
4232+ * Insert an expression to the database using MeCab.
4233+ *
4234+ * @param string $text Text to insert
4235+ * @param string|int $lid Language ID
4236+ * @param string|int $wid Word ID
4237+ * @param int $len Number of words in the expression
4238+ *
4239+ * @return string[][] Append text and values to insert to the database
4240+ *
4241+ * @since 2.5.0-fork Function added.
4242+ *
4243+ * @deprecated Since 2.10.0 Use insertMecabExpression
4244+ *
4245+ * @global string $tbpref Table name prefix
4246+ *
4247+ * @psalm-return list{array<int, string>, list{0?: string,...}}
4248+ */
4249+ function insert_expression_from_mecab ($ text , $ lid , $ wid , $ len ): array
4250+ {
4251+ list ($ mwords , $ sqlarr ) = insertMecabExpression ($ text , $ lid , $ wid , $ len );
4252+ $ flat_mwords = array_reduce ($ mwords , function ($ carry , $ item ) {
4253+ return $ carry + $ item ;
4254+ }, []);
4255+ return array ($ flat_mwords , array (), $ sqlarr );
4256+ }
4257+
42304258/**
42314259 * Insert an expression to the database using MeCab.
42324260 *
@@ -4242,7 +4270,7 @@ function insert_expression_from_mecab($text, $lid, $wid, $len): array
42424270 * $mode is unnused, data are always returned.
42434271 * The second return argument is always empty array.
42444272 *
4245- * @deprecated Use insert_expression_from_mecab instead.
4273+ * @deprecated Use insertMecabExpression instead.
42464274 *
42474275 * @global string $tbpref Table name prefix
42484276 *
@@ -4266,7 +4294,7 @@ function insertExpressionFromMeCab($textlc, $lid, $wid, $len, $mode): array
42664294 *
42674295 * @global string $tbpref Table name prefix
42684296 */
4269- function standardInsertMultiWord ($ textlc , $ lid , $ wid , $ len ): array
4297+ function insertStandardExpression ($ textlc , $ lid , $ wid , $ len ): array
42704298{
42714299 global $ tbpref ;
42724300 $ mwords = array ();
@@ -4372,13 +4400,13 @@ function standardInsertMultiWord($textlc, $lid, $wid, $len): array
43724400 * @since 2.5.0-fork Mode is unnused and data are always added to the output.
43734401 * @since 2.5.2-fork Fixed multi-words insertion for languages using no space.
43744402 *
4375- * @deprecated Since 2.10.0-fork, use standardInsertMultiWord
4403+ * @deprecated Since 2.10.0-fork, use insertStandardExpression
43764404 *
43774405 * @psalm-return list{array<int, null|string>, array<never, never>, list{0?: string,...}}
43784406 */
43794407function insert_standard_expression ($ textlc , $ lid , $ wid , $ len , $ mode ): array
43804408{
4381- list ($ mwords , $ sqlarr ) = standardInsertMultiWord ($ textlc , $ lid , $ wid , $ len );
4409+ list ($ mwords , $ sqlarr ) = insertStandardExpression ($ textlc , $ lid , $ wid , $ len );
43824410 $ flat_mwords = array_reduce ($ mwords , function ($ carry , $ item ) {
43834411 return $ carry + $ item ;
43844412 }, []);
@@ -4525,29 +4553,31 @@ function newMultiWordInteractable($hex, $multiwords, $wid, $len): void
45254553
45264554 ?>
45274555<script type="text/javascript">
4528- let term = <?php echo json_encode ($ attrs ); ?> ;
4556+ (function () {
4557+ let term = <?php echo json_encode ($ attrs ); ?> ;
45294558
4530- const multiWords = <?php echo json_encode ($ multiwords ); ?> ;
4559+ const multiWords = <?php echo json_encode ($ multiwords ); ?> ;
45314560
4532- let title = '';
4533- if (window.parent.LWT_DATA.settings.jQuery_tooltip) {
4534- title = make_tooltip(
4535- multiWords[window.parent.LWT_DATA.text.id][0], term.data_trans,
4536- term.data_rom, parseInt(term.data_status, 10)
4561+ let title = '';
4562+ if (window.parent.LWT_DATA.settings.jQuery_tooltip) {
4563+ title = make_tooltip(
4564+ multiWords[window.parent.LWT_DATA.text.id][0], term.data_trans,
4565+ term.data_rom, parseInt(term.data_status, 10)
4566+ );
4567+ }
4568+ term['title'] = title;
4569+ let attrs = "";
4570+ Object.entries(term).forEach(([k, v]) => attrs += " " + k + '="' + v + '"');
4571+ // keys(term).map((k) => k + '="' + term[k] + '"').join(" ");
4572+
4573+ newExpressionInteractable(
4574+ multiWords[window.parent.LWT_DATA.text.id],
4575+ attrs,
4576+ term.data_code,
4577+ <?php echo json_encode ($ hex ); ?> ,
4578+ <?php echo json_encode ($ showAll ); ?>
45374579 );
4538- }
4539- term['title'] = title;
4540- let attrs = "";
4541- Object.entries(term).forEach(([k, v]) => attrs += " " + k + '="' + v + '"');
4542- // keys(term).map((k) => k + '="' + term[k] + '"').join(" ");
4543-
4544- newExpressionInteractable(
4545- multiWords[window.parent.LWT_DATA.text.id],
4546- attrs,
4547- term.data_code,
4548- <?php echo json_encode ($ hex ); ?> ,
4549- <?php echo json_encode ($ showAll ); ?>
4550- );
4580+ })()
45514581 </script>
45524582 <?php
45534583 flush ();
@@ -4583,11 +4613,11 @@ function insertExpressions($textlc, $lid, $wid, $len, $mode): null|string
45834613 * Should separate the two
45844614 */
45854615 if ('MECAB ' == strtoupper (trim ($ regexp ))) {
4586- list ($ appendtext , $ sqlarr ) = insert_expression_from_mecab (
4616+ list ($ appendtext , $ sqlarr ) = insertMecabExpression (
45874617 $ textlc , $ lid , $ wid , $ len
45884618 );
45894619 } else {
4590- list ($ appendtext , $ sqlarr ) = standardInsertMultiWord (
4620+ list ($ appendtext , $ sqlarr ) = insertStandardExpression (
45914621 $ textlc , $ lid , $ wid , $ len
45924622 );
45934623 }
0 commit comments