فهرست منبع

术语字符串调用错误 相似句子增加起始id

visuddhinanda 5 سال پیش
والد
کامیت
7059774b35
4فایلهای تغییر یافته به همراه185 افزوده شده و 109 حذف شده
  1. 2 2
      app/doc/load_channal_para.php
  2. 19 4
      app/pali_sent/sim_sent.php
  3. 146 94
      app/term/note.js
  4. 18 9
      app/term/term.css

+ 2 - 2
app/doc/load_channal_para.php

@@ -61,8 +61,8 @@ else{
 					echo "<paragraph>{$para}</paragraph>";
 					echo "<level>100</level>";
 					echo "<title></title>";
-					echo "<album_id>{$block->channal}</album_id>";
-					echo "<album_guid>{$block->channal}</album_guid>";
+					echo "<album_id></album_id>";
+					echo "<album_guid></album_guid>";
 					echo "<author>{$FetchBlock["owner"]}</author>";
 					echo "<language>{$FetchBlock["lang"]}</language>";
 					echo "<version>1</version>";

+ 19 - 4
app/pali_sent/sim_sent.php

@@ -5,6 +5,10 @@ require_once "../public/_pdo.php";
 
 global $PDO;
 PDO_Connect("sqlite:"._FILE_DB_PALI_SENTENCE_);
+PDO_Execute("PRAGMA synchronous = OFF");
+PDO_Execute("PRAGMA journal_mode = WAL");
+PDO_Execute("PRAGMA foreign_keys = ON");
+PDO_Execute("PRAGMA busy_timeout = 5000");
 
 
 // 输入一个句子,输出整个句子的单词 array
@@ -115,16 +119,21 @@ function insert_similar_sent_list_into_sqlite($current_id, $text_list) {
 }
 
 // 预计算,存入数据库
-function similar_sent_matrix($begin,$end) {
+function similar_sent_matrix($begin,$end,$begin_id=0) {
 	// 按照 count = 18, 8, ..., 255 依次获得查询结果 (i-3,i+3)
 	//          count = 17,16,...,7                                       (i-2,i+2)
-	for ($current_count=$begin; $current_count <$end ; $current_count++) { 
+	for ($current_count=$begin; $current_count <=$end ; $current_count++) { 
 		print("单词数:".$current_count."\n");
 		$current_query = "select id,text from pali_sent where count=".$current_count;
 		$Current = PDO_FetchAll($current_query);
 		if (count($Current)) {
 			foreach($Current as $current_row) {
 				$current_id = $current_row['id'];
+				if($begin_id>0 && $current_count==$begin){
+					if($current_id<$begin_id){
+						continue;
+					}
+				}
 				$current_sent = $current_row['text'];
 				$current_words = words_of_sentence($current_sent);
 				
@@ -215,18 +224,24 @@ function sents_similar_to_id($id) {
 //$id = $argv[1];
 //sents_similar_to_id($id);
 
-	if ($argc != 3){
+	if ($argc < 3){
 		echo "无效的参数 ";
 		exit;
 	}
 	$from = (int)$argv[1];
 	$to =(int)$argv[2];
+	if ($argc > 3){
+		$from_id = (int)$argv[3];
+	}
+	else{
+		$from_id = 0;
+	}
 	if($from<4){
 		$from = 4;
 	}
 	if($to>255){
 		$to = 255;
 	}
-	similar_sent_matrix($from,$to);
+	similar_sent_matrix($from,$to,$from_id);
 	echo "\n all done";
 ?>

+ 146 - 94
app/term/note.js

@@ -463,96 +463,12 @@ function note_json_html(in_json) {
 
 	output += "<div class='palitext'>" + in_json.palitext + "</div>";
 
-	//output += "<div class='translation_div'>";
+	output += "<div id='translation_div'>";
 	for (const iterator of in_json.translation) {
-		output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
-		//译文工具按钮开始
-		output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
-		output +=
-			"<div class='icon_expand' style='width: 0.8em;height: 0.8em;min-width: 0.8em;min-height: 0.8em;transition: transform 0.5s ease;'></div>";
-		//译文工具栏开始
-		output += "<div class='tran_text_tool_bar'>";
-		output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
-		output +=
-			" onclick=\"note_edit_sentence('" +
-			in_json.book +
-			"' ,'" +
-			in_json.para +
-			"' ,'" +
-			in_json.begin +
-			"' ,'" +
-			in_json.end +
-			"' ,'" +
-			iterator.channal +
-			"')\"";
-		output +=
-			">" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
-		output += gLocal.gui.edit + "</li>";
-		output += "<li class = 'tip_buttom' ";
-		output += " onclick=\"history_show('" + iterator.id + "')\"";
-		output +=
-			">" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
-		output += gLocal.gui.timeline + "</li>";
-		output +=
-			"<li class = 'tip_buttom'>" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
-		output += gLocal.gui.copy + "</li></div>";
-
-		output +=
-			"<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
-		output += gLocal.gui.like + "</li>";
-		output +=
-			"<li class = 'tip_buttom'>" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
-		output += gLocal.gui.comment + "</li>";
-		output +=
-			"<li class = 'tip_buttom'>" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
-		output += gLocal.gui.digest + "</li></div>";
-		output +=
-			"<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
-			'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
-		output += gLocal.gui.share_to + "</li>";
-		output += "</div></div>";
-		//译文工具栏结束
-		output += "</div>";
-		//译文工具按钮结束
-		//译文正文开始
-		output +=
-			"<div class='text' id='tran_text_" +
-			in_json.book +
-			"_" +
-			in_json.para +
-			"_" +
-			in_json.begin +
-			"_" +
-			in_json.end +
-			"_" +
-			iterator.channal +
-			"'>";
-		if (iterator.text == "") {
-			output +=
-				"<span style='color:var(--border-line-color);'>" +
-				iterator.channalinfo.name +
-				"-" +
-				iterator.channalinfo.lang +
-				"</span>";
-		} else {
-			//note_init处理句子链接 marked不处理
-			//output += marked(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
-			output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
-		}
-		output += "</div>";
-		//译文正文结束
-
-		output += "</div>";
-		//单个channal译文框结束
+		output += render_one_sent_tran(in_json.book, in_json.para, in_json.begin, in_json.end, iterator);
 	}
 	//所选全部译文结束
-	//output += "</div>";
+	output += "</div>";
 	//未选择的其他译文开始
 	output += "<div class='other_tran_div' sent='";
 	output += in_json.book + "-" + in_json.para + "-" + in_json.begin + "-" + in_json.end;
@@ -574,8 +490,9 @@ function note_json_html(in_json) {
 	output += "begin='" + in_json.begin + "' ";
 	output += "end='" + in_json.end + "' ";
 	output += " >";
-
-	//output += "<div class='more_tran icon_expand'></div>";
+	output += "<div class='icon_add' onclick='add_new_tran_button_click(this)'></div>";
+	output += "<div class='tran_text_tool_bar'>";
+	output += "</div>";
 	output += "</div>";
 	//新增译文按钮结束
 	//出处路径开始
@@ -595,6 +512,140 @@ function note_json_html(in_json) {
 	return output;
 }
 
+function render_one_sent_tran(book, para, begin, end, iterator) {
+	let output = "";
+	output += "<div class='tran' lang='" + iterator.lang + "' style='display:flex;'>";
+	//译文工具按钮开始
+	output += "<div class='tran_text_tool_botton' onclick='tool_bar_show(this)'>";
+	output +=
+		"<div class='icon_expand' style='width: 0.8em;height: 0.8em;min-width: 0.8em;min-height: 0.8em;transition: transform 0.5s ease;'></div>";
+	//译文工具栏开始
+	output += "<div class='tran_text_tool_bar'>";
+	output += "<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom' ";
+	output +=
+		" onclick=\"note_edit_sentence('" +
+		book +
+		"' ,'" +
+		para +
+		"' ,'" +
+		begin +
+		"' ,'" +
+		end +
+		"' ,'" +
+		iterator.channal +
+		"')\"";
+	output +=
+		">" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_mode_edit"></use></svg>';
+	output += gLocal.gui.edit + "</li>";
+	output += "<li class = 'tip_buttom' ";
+	output += " onclick=\"history_show('" + iterator.id + "')\"";
+	output +=
+		">" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#recent_scan"></use></svg>';
+	output += gLocal.gui.timeline + "</li>";
+	output +=
+		"<li class = 'tip_buttom'>" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#copy"></use></svg>';
+	output += gLocal.gui.copy + "</li></div>";
+
+	output +=
+		"<div style='border-right: solid 1px;margin: 0.3em 0;'><li class = 'tip_buttom'>" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#like"></use></svg>';
+	output += gLocal.gui.like + "</li>";
+	output +=
+		"<li class = 'tip_buttom'>" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#comment"></use></svg>';
+	output += gLocal.gui.comment + "</li>";
+	output +=
+		"<li class = 'tip_buttom'>" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#ic_shopping_cart"></use></svg>';
+	output += gLocal.gui.digest + "</li></div>";
+	output +=
+		"<div style='margin: 0.3em 0;'><li class = 'tip_buttom'>" +
+		'<svg class="icon" ><use xlink="http://www.w3.org/1999/xlink" href="../studio/svg/icon.svg#share_to"></use></svg>';
+	output += gLocal.gui.share_to + "</li>";
+	output += "</div></div>";
+	//译文工具栏结束
+	output += "</div>";
+	//译文工具按钮结束
+	//译文正文开始
+	output +=
+		"<div class='text' id='tran_text_" +
+		book +
+		"_" +
+		para +
+		"_" +
+		begin +
+		"_" +
+		end +
+		"_" +
+		iterator.channal +
+		"'>";
+	if (iterator.text == "") {
+		output +=
+			"<span style='color:var(--border-line-color);'>" +
+			iterator.channalinfo.name +
+			"-" +
+			iterator.channalinfo.lang +
+			"</span>";
+	} else {
+		//note_init处理句子链接 marked不处理
+		//output += marked(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
+		output += note_init(term_std_str_to_tran(iterator.text, iterator.channal, iterator.editor, iterator.lang));
+	}
+	output += "</div>";
+	//译文正文结束
+
+	output += "</div>";
+	//单个channal译文框结束
+	return output;
+}
+function add_new_tran_button_click(obj) {
+	let html = "<ul>";
+	for (const iterator of _my_channal) {
+		if (_channal.indexOf(iterator.id) < 0) {
+			html += '<li onclick="';
+			html +=
+				"new_sentence('" +
+				$(obj).parent().attr("book") +
+				"' ,'" +
+				$(obj).parent().attr("para") +
+				"' ,'" +
+				$(obj).parent().attr("begin") +
+				"' ,'" +
+				$(obj).parent().attr("end") +
+				"' ,'" +
+				iterator.id +
+				"')";
+			html += '">' + iterator.name + "</li>";
+		}
+	}
+	html += "</ul>";
+	$(obj).parent().children(".tran_text_tool_bar").first().html(html);
+	$(obj).parent().children(".tran_text_tool_bar").first().show();
+	$(obj).parent().show();
+}
+
+function new_sentence(book, para, begin, end, channel) {
+	let newsent = { id: "", text: "", lang: "", channal: channel };
+
+	for (let iterator of _arrData) {
+		if (iterator.book == book && iterator.para == para && iterator.begin == begin && iterator.end == end) {
+			let found = false;
+			for (const tran of iterator.translation) {
+				if (tran.channal == channel) {
+					found = true;
+					break;
+				}
+			}
+			if (!found) {
+				iterator.translation.push(newsent);
+			}
+		}
+	}
+	note_edit_sentence(book, para, begin, end, channel);
+}
 function set_more_button_display() {
 	$(".other_tran_div").each(function () {
 		const sentid = $(this).attr("sent").split("-");
@@ -698,15 +749,15 @@ function note_edit_sentence(book, para, begin, end, channal) {
 						"<textarea id='edit_dialog_text' sent_id='" +
 						tran.id +
 						"' book='" +
-						iterator.book +
+						book +
 						"' para='" +
-						iterator.para +
+						para +
 						"' begin='" +
-						iterator.begin +
+						begin +
 						"' end='" +
-						iterator.end +
+						end +
 						"' channal='" +
-						tran.channal +
+						channal +
 						"' style='width:100%;min-height:260px;'>" +
 						tran.text +
 						"</textarea>";
@@ -717,6 +768,7 @@ function note_edit_sentence(book, para, begin, end, channal) {
 			}
 		}
 	}
+
 	alert("未找到句子");
 }
 

+ 18 - 9
app/term/term.css

@@ -184,7 +184,8 @@ note > .tran > .text {
 	min-width: 0.8em;
 	min-height: 0.8em;
 }
-note > .tran .tran_text_tool_bar {
+note > .tran .tran_text_tool_bar,
+.tran_text_tool_bar {
 	padding: 0 0.1em;
 	position: absolute;
 	display: none;
@@ -202,7 +203,8 @@ note > .tran .tran_text_tool_bar {
 note > .tran:lang(my) .tran_text_tool_bar {
 	margin-top: -2.5em;
 }
-note > .tran .tran_text_tool_bar::after {
+note > .tran .tran_text_tool_bar::after,
+.tran .tran_text_tool_bar::after {
 	content: " ";
 	position: absolute;
 	left: 1.4em;
@@ -349,27 +351,34 @@ note > .bottm_tool_button {
 note:hover > .bottm_tool_button {
 	display: block;
 }
-note:hover .add_new {
+.add_new {
 	display: inline-block;
 	position: absolute;
+	min-width: 1.4vw;
+	display: none;
 }
-.tool_bar > .more_tran {
+note:hover .add_new {
 	display: inline-block;
-	margin-right: 5px;
-	transform: rotate(-90deg);
-	transition: all 0.2s ease;
+	position: absolute;
 }
 .icon_add {
-	width: auto;
+	width: 1.5vw;
 	min-width: 1.4vw;
 	height: 1.5vw;
 	cursor: pointer;
 	background: url(add.svg);
 	background-repeat: no-repeat;
 	background-size: contain;
-	display: none;
+
 	margin-bottom: -0.7em;
 }
+.tool_bar > .more_tran {
+	display: inline-block;
+	margin-right: 5px;
+	transform: rotate(-90deg);
+	transition: all 0.2s ease;
+}
+
 .icon_expand {
 	width: auto;
 	min-width: 14px;