Browse Source

Merge branch 'master' of https://github.com/iapt-platform/mint

visuddhinanda 4 years ago
parent
commit
73ca4220d3

+ 6 - 2
app/dict/grm_abbr.php

@@ -63,11 +63,14 @@ define("GRM_ABBR",[
 	["dictid"=>19,"abbr"=>"aor.","replace"=>"aor"],
 	["dictid"=>19,"abbr"=>"caus.","replace"=>"caus"],
 	["dictid"=>19,"abbr"=>"fut.","replace"=>"fut"],
-	["dictid"=>19,"abbr"=>"grd.","replace"=>"fpp"],	
+	["dictid"=>19,"abbr"=>"grd.","replace"=>"fpp"],
 	["dictid"=>1,"abbr"=>"pron.","replace"=>"pron"],
 	["dictid"=>1,"abbr"=>"pref.","replace"=>"pref"],
-	["dictid"=>1,"abbr"=>"grd.","replace"=>"fpp"],	
+	["dictid"=>1,"abbr"=>"grd.","replace"=>"fpp"],
 	["dictid"=>1,"abbr"=>"caus.","replace"=>"caus"],
+	["dictid"=>1,"abbr"=>"fut.","replace"=>"fut"],
+	["dictid"=>1,"abbr"=>"num.","replace"=>"num"],
+	["dictid"=>1,"abbr"=>"num.","replace"=>"num"],
 	["dictid"=>1,"abbr"=>"fut.","replace"=>"fut"],
 	["dictid"=>1,"abbr"=>"imper.","replace"=>"imp"],	
 	["dictid"=>1,"abbr"=>"caus.","replace"=>"caus"],
@@ -175,6 +178,7 @@ define("GRM_ABBR",[
 	["dictid"=>3,"abbr"=>"[m.]","replace"=>"m"],
 	["dictid"=>3,"abbr"=>"[f.]","replace"=>"f"],
 	["dictid"=>3,"abbr"=>"[n.]","replace"=>"nt"],
+	["dictid"=>3,"abbr"=>"f.","replace"=>"f"],
 	["dictid"=>3,"abbr"=>"[a.]","replace"=>"adj"],
 	["dictid"=>6,"abbr"=>"imper.","replace"=>"imp"],
 	["dictid"=>6,"abbr"=>"denom.","replace"=>"denom"],

+ 66 - 1
app/fts/README.md

@@ -56,6 +56,58 @@ php -d memory_limit=1024M pali.syn.php
 
 将会在当前目录下生成 pali.syn 文件
 
+**注意 01**
+
+变更 pali.syn 词形转换词典后,有两种方式使其生效(任选其一):
+
+1. 在当前会话 (session) 内执行下面语句:
+
+关于使用下面语句的原因,请参见:[PostgreSQL / Dictionaries / Simple Dictionary - Caution ("dummy" update)](https://www.postgresql.org/docs/14/textsearch-dictionaries.html#TEXTSEARCH-SIMPLE-DICTIONARY)
+
+```sql
+-- dummy update
+ALTER TEXT SEARCH DICTIONARY pali_stem (
+    SYNONYMS = pali
+);
+```
+
+2. 断开当前会话 (session),重新连接。
+
+**注意 02**
+
+在 pali.syn 内添加词形转换时,请向文件末尾添加,实际测试发现在文件头部添加并未生效。
+
+**注意 03**
+
+更新 pali.syn 这个变更涉及到所有三藏文本中的词形转换,所以需要手动重建全文检索索引。
+
+两种方式(任选其一):
+
+1. 你知道改变更会影响哪些记录(比如先进行搜索得出结果)
+
+```sql
+-- dummy update
+UPDATE fts SET content = content,
+               bold_single = bold_single,
+               bold_double = bold_double,
+               bold_multiple = bold_multiple
+               WHERE paragraph = 37 AND book = 'p180';
+```
+
+请将 paragraph 和 book 替换为目标值。
+
+2. 这是一个普遍的变更,会影响到很多记录
+
+```sql
+-- dummy update
+UPDATE fts SET content = content,
+               bold_single = bold_single,
+               bold_double = bold_double,
+               bold_multiple = bold_multiple;
+```
+
+移除掉 WHERE 条件,将会触发所有记录重新建立索引,会花上很长时间,执行之前请三思。
+
 #### pali.stop 停用词词典
 
 请熟悉巴利语的贤者依据巴利文法编辑 [pali.stop](./pali.stop) 文件,
@@ -136,7 +188,7 @@ done
 
 数据插入时会同步创建索引,耗时较久,请耐心等待。
 
-### 查询数据:
+### 使用 SQL 查询数据:
 
 权重设置:
 
@@ -758,3 +810,16 @@ SELECT
 	</tr>
 </table>
 </details>
+
+### 使用 PHP 查询数据:
+
+可参考 [example.php](./example.php
+),在当前目录下执行:
+
+```bash
+php -d memory_limit=1024M -S 127.0.0.1:8000
+```
+
+即可通过浏览器测试效果:
+
+![Example](./example.png "Example Screenshot")

+ 103 - 0
app/fts/example.php

@@ -0,0 +1,103 @@
+<html>
+  <head>
+    <title>Pali Full Text Search Example @ PostgreSQL</title>
+    <style>
+     * {
+         font-family: "Noto Sans", "Noto Sans SC", "Noto Sans TC", "Padauk", "ATaiThamKHNewV3-Normal", Arial, Verdana;
+     }
+     td {
+         border-right-style: solid;
+         border-top-style: solid;
+     }
+     table {
+         border-style: solid;
+     }
+     table span {
+         background-color: yellow;
+         font-size: 1.2em;
+     }
+     th {
+         font-weight: bold;
+     }
+     input[name="q"] {
+         width: 70%;
+     }
+    </style>
+  </head>
+  
+  <body>
+    <?php
+    if ($_SERVER["REQUEST_METHOD"] == "POST") {
+      // collect value of input field
+      $q = $_POST['q'];
+    }
+    ?>
+    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
+      Name: <input type="text" name="q" value="<?php echo $q ?>">
+      <input type="submit">
+    </form>
+    <?php
+    if (empty($q)) {
+      echo "Query is empty";
+    } else {
+      // Connecting, selecting database
+      $dbconn = pg_connect("host=localhost dbname=pali user=postgres password=123456")
+      or die('Could not connect: ' . pg_last_error());
+
+      // Performing SQL query
+      $query = "SELECT
+                 ts_rank('{0.1, 0.2, 0.4, 1}',
+                     full_text_search_weighted,
+                     websearch_to_tsquery('pali', '$q')) +
+                 ts_rank('{0.1, 0.2, 0.4, 1}',
+                     full_text_search_weighted_unaccent,
+                     websearch_to_tsquery('pali_unaccent', '$q'))
+                 AS rank,
+                 ts_headline('simple', content,
+                              websearch_to_tsquery('simple', '$q'),
+                              'StartSel = <span>, StopSel = </span>')
+                 AS highlight,
+                 *
+                 FROM fts
+                 WHERE
+                     full_text_search_weighted
+                     @@ websearch_to_tsquery('pali', '$q') OR
+                     full_text_search_weighted_unaccent
+                     @@ websearch_to_tsquery('pali_unaccent', '$q')
+                 ORDER BY rank DESC
+                 LIMIT 20;";
+      $result = pg_query($query) or die('Query failed: ' . pg_last_error());
+
+      // Printing results in HTML
+      echo "<table>\n";
+      echo "<tr>
+                 <th>rank</th>
+                 <th>highlight</th>
+                 <th>paragraph</th>
+                 <th>book</th>
+                 <th>wid</th>
+                 <th>bold_single</th>
+                 <th>bold_double</th>
+                 <th>bold_multiple</th>
+                 <th>content</th>
+                 <th>TSVECTOR</th>
+                 <th>TSVECTOR (unaccent)</th>
+              </tr>";
+      while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
+        echo "\t<tr>\n";
+        foreach ($line as $col_value) {
+          echo "\t\t<td><div class='cell'>$col_value</div></td>\n";
+        }
+        echo "\t</tr>\n";
+      }
+      echo "</table>\n";
+
+      // Free resultset
+      pg_free_result($result);
+
+      // Closing connection
+      pg_close($dbconn);
+    }
+    ?>
+  </body>
+</html>

BIN
app/fts/example.png


+ 3 - 2
app/fts/fts.sql

@@ -32,6 +32,7 @@ CREATE TEXT SEARCH DICTIONARY pali_stopwords (
 );
 
 -- 修改全文检索配置 pali 使用我们创建的字典
+
 ALTER TEXT SEARCH CONFIGURATION pali
     ADD MAPPING FOR asciiword, word, hword_part, hword_asciipart
     WITH pali_stem, pali_stopwords;
@@ -75,7 +76,7 @@ CREATE INDEX full_text_search_weighted__unaccent_idx
 
 -- 创建查询函数
 
-CREATE OR REPLACE FUNCTION query_pali(query_str TEXT) 
+CREATE OR REPLACE FUNCTION query_pali(query_str TEXT)
   RETURNS TABLE(
           rank NUMERIC,
           paragraph INTEGER,
@@ -85,7 +86,7 @@ CREATE OR REPLACE FUNCTION query_pali(query_str TEXT)
           bold_multiple TEXT,
           content TEXT,
           full_text_search_weighted TSVECTOR,
-          full_text_search_weighted_unaccent TSVECTOR) 
+          full_text_search_weighted_unaccent TSVECTOR)
 AS $$
     SELECT
     ts_rank('{0.1, 0.2, 0.4, 1}',

+ 1 - 3
app/path.sample.php

@@ -1,6 +1,4 @@
 <?php
-require_once __DIR__."/config.php";
-
 # 目录
 define("_DIR_APPDATA_", __DIR__ . "/../tmp/appdata");
 
@@ -342,4 +340,4 @@ define("_FILE_DB_USER_STATISTICS_", "sqlite:" . __DIR__ . "/../tmp/user/statisti
 define("_FILE_DB_USER_RBAC_",  __DIR__ . "/../tmp/user/rbac.db3");
 
 # 全文搜索
-define("_TABLE_FTS_", "fts_texts");
+define("_TABLE_FTS_", "fts_texts");

+ 8 - 4
app/pcdl/css/style.css

@@ -2282,13 +2282,17 @@ th {
 	border-collapse: collapse;
 }
 
-.frame_table td,
-th {
-	border: 1px solid #fff;
+.frame_table td,th {
+	border: 1px solid #000;
 	font-size: 100%;
 	vertical-align: baseline;
 }
-
+.frame_table thead{
+	background: burlywood;
+}
+.frame_table tbody{
+	background: antiquewhite;
+}
 #id_wizard_palicannon_index_filelist p {
 	margin: 0;
 }

+ 1 - 1
app/public/lang/en.json

@@ -2226,7 +2226,7 @@
 	"language": {
 		"en": "English",
 		"si": "Sinhalese",
-		"my": "Brummese",
+		"my": "Brumese",
 		"zh": "Chinese",
 		"zh_cn": "Simple Chinese",
 		"zh_tw": "Traditional Chinese",

+ 7 - 0
app/studio/css/style.css

@@ -4088,6 +4088,13 @@ border-bottom: 2px solid red;
 	/*overflow-y: auto;
     max-height: 35vh;*/
 	display: none;
+	/*margin-top: calc(-1em - 29px);*/
+	margin-top: -20px;
+
+}
+.trans_sent_edit{
+	height: auto;
+	min-height: unset;
 }
 
 .search_pali_text_prev {

+ 7 - 3
app/studio/editor.php

@@ -148,17 +148,21 @@ else{$currDevice="computer";}
 		padding: 0.5em 0.5em 0.1em 0.5em;
 		padding-top:0;
 	}
-	.translate_sent_head_content{
-		max-height: 17em;
+	.translate_sent_head{
+		height: 17em;
 		overflow-y: scroll;
 	}
 	.translate_sent_head_content .readonly{
 		border-color: #d1d1d1;
-		background-color: #f1f1f1;		
+		background-color: #f1f1f1;
 	}
 	.trans_text_content{
 		color: unset;
 	}
+	.trans_text_content p{
+		margin-block-start: 0.3em;
+		margin-block-end: 0;
+	}
 	.trans_text_info{
 		font-size: 80%;
 		border-top: 1px solid gray;

+ 1 - 0
app/studio/js/common.js

@@ -632,6 +632,7 @@ function tab_click(panalId, tabid, callback = null, parm = null) {
 		}
 	}
 	guide_init();
+	$(".translate_sent_head").each(function(){$(this).height($(this).parent()[0].scrollHeight+"px")})
 }
 
 /*

+ 1 - 1
app/studio/js/editor.js

@@ -3147,7 +3147,7 @@ function showModifyWin(sWordId) {
 		$("#input_om").val(sOm);
 		$("#input_case").val(sCase);
 
-		if (sParentGrammar != "" || sParent2 != "") {
+		if (sParentGrammar != "" || sParent2 != "" || sParent2 != " ") {
 			document.getElementById("edit_detail_prt_prt").style.display = "block";
 			document.getElementById("svg_parent2").style.transform = "rotate(90deg)";
 		} else {

+ 38 - 4
app/studio/js/render.js

@@ -598,6 +598,7 @@ function updateTranslationPreview(blockId, obj) {
 	}
 	$("#tran_pre_" + blockId).html(out);
 	term_updata_translation();
+	$(obj).css({'height': 'auto'}).height($(obj)[0].scrollHeight+"px");
 }
 
 function getSuperTranslateModifyString(inString, par_num, par_guid, language) {
@@ -1392,12 +1393,19 @@ function renderWordParBlockInner(elementBlock) {
 				next_pali_Case = next_case_array[next_case_array.length - 1];
 			}
 		}
-		if (next_pali_spell == "(") {
+		if (next_pali_spell == "(" || wPali == "(") {
 			Note_Mark = 1;
-		} else if (pre_pali_spell == ")" && Note_Mark == 1) {
+		} else if ((pre_pali_spell == ")" || wPali == ")") && Note_Mark == 1) {
 			Note_Mark = 0;
 		} else {
 		}
+		/*
+		if (next_pali_spell == "[" || curr_pali_spell == "[") {
+			Note_Mark2 = 1;
+		} else if ((pre_pali_spell == "]" || curr_pali_spell == "]") && Note_Mark2 == 1) {
+			Note_Mark2 = 0;
+		} else {
+		}*/
 
 		if (wEnter == 1) {
 			//句子末尾
@@ -1468,7 +1476,7 @@ function renderWordParBlockInner(elementBlock) {
 				//逐句翻译块内容结束
 				output += "<div class='translate_sent_foot'>";
 				output += "</div>";
-				output += "</div>";
+				//output += "</div>";
 				//逐句翻译块结束
 
 				output += "</div>"; //逐句块结束
@@ -2061,7 +2069,33 @@ function sent_edit_click(book, para, begin, end, channal) {
 	)
 		.parent()
 		.show();
-}
+		$(
+			".trans_sent_edit[book='" +
+				book +
+				"'][para='" +
+				para +
+				"'][begin='" +
+				begin +
+				"'][end='" +
+				end +
+				"'][channal='" +
+				channal +
+				"']"
+		).css({'height': 'auto'}).height($(
+			".trans_sent_edit[book='" +
+				book +
+				"'][para='" +
+				para +
+				"'][begin='" +
+				begin +
+				"'][end='" +
+				end +
+				"'][channal='" +
+				channal +
+				"']"
+		)[0].scrollHeight+"px");
+
+	}
 function magic_sentence_cut() {
 	var all_sent_array = document.getElementsByClassName("sent_wbw");
 	for (i_magic = 0; i_magic < all_sent_array.length; i_magic++) {

+ 16 - 8
app/studio/plugin/system_layout/module_function.js

@@ -133,6 +133,8 @@ function layout_wbw_auto_cut() {
 			var splited = getNodeText(xmlParInfo, "splited");
 			if (splited != 1) {
 				var Note_Mark = 0;
+				var Note_Mark1 = 0;
+				var Note_Mark2 = 0;
 				var sent_gramma_i = 0;
 				var word_length_count = 0;
 				var sent_num = 0;
@@ -152,7 +154,7 @@ function layout_wbw_auto_cut() {
 						wType = wCase.split("#")[0];
 					}
 					word_length_count += wPali.length;
-
+					
 					if (iWord >= 1) {
 						var pre_pali_spell = getNodeText(allWord[iWord - 1], "pali");
 						var pre_pali_type = getNodeText(allWord[iWord - 1], "type");
@@ -179,13 +181,19 @@ function layout_wbw_auto_cut() {
 							next_pali_Case = next_case_array[next_case_array.length - 1];
 						}
 					}
-					if (next_pali_spell == "(") {
-						Note_Mark = 1;
-					} else if (pre_pali_spell == ")" && Note_Mark == 1) {
-						Note_Mark = 0;
+					if (next_pali_spell == "(" || wPali == "(") {
+						Note_Mark1 = 1;
+					} else if ((pre_pali_spell == ")" || wPali == ")") && Note_Mark1 == 1) {
+						Note_Mark1 = 0;
 					} else {
 					}
-
+					if (next_pali_spell == "[" || wPali == "[") {
+						Note_Mark2 = 1;
+					} else if ((pre_pali_spell == "]" || wPali == "]") && Note_Mark2 == 1) {
+						Note_Mark2 = 0;
+					} else {
+					}
+					Note_Mark = Note_Mark1 + Note_Mark2
 					var isEndOfSen = false;
 					if (
 						wPali == "." &&
@@ -195,7 +203,7 @@ function layout_wbw_auto_cut() {
 						Note_Mark == 0
 					) {
 						//以.結尾且非註釋
-						if (next_pali_spell != "(") {
+						if (next_pali_spell != "(" && next_pali_spell != "[") {
 							isEndOfSen = true;
 						}
 					} else if (
@@ -212,7 +220,7 @@ function layout_wbw_auto_cut() {
 					} else if (allWord.length >= iWord + 2 && iWord != allWord.length - 1 && Note_Mark == 0) {
 						//以!或?或;結尾
 						if (/*wPali=="!" || */ wPali == ";" || wPali == "?") {
-							if (next_pali_spell != "(") {
+							if (next_pali_spell != "(" && next_pali_spell != "[") {
 								isEndOfSen = true;
 							}
 						}