Bladeren bron

优化自动查词,计算复合词语法信息

visuddhinanda 3 jaren geleden
bovenliggende
commit
8e740be2c5

+ 1 - 1
app/Http/Controllers/WbwLookupController.php

@@ -78,7 +78,7 @@ class WbwLookupController extends Controller
 						$newBase = array();
 						$parents = $caseman->WordToBase($word);
 						foreach ($parents as $base => $rows) {
-							Log::info("found:{$value['type']}-{$value['grammar']}-{$value['parent']}");
+							Log::info("found:{$base}");
 							array_push($output,$rows);
 						}
 						Log::info("去尾查结束");

+ 1 - 0
public/app/studio/editor.php

@@ -84,6 +84,7 @@ else{$currDevice="computer";}
 	<script src="./js/message.js"></script>
 	<script src="../uwbw/update.js"></script>
 	<script src="../usent/usent.js"></script>
+	<script src="../ucenter/setting.js"></script>
 	<script src="../fileindex/file_info.js"></script>
 
 	<script  src="../channal/channal.js"></script>

+ 224 - 137
public/app/studio/js/editor.js

@@ -319,24 +319,7 @@ function editor_dict_one_dict_done(dictIndex) {
 	}
 }
 
-function menu_dict_match() {
-	g_dict_search_one_pass_done = null;
-	g_dict_search_one_dict_done = null;
-	g_dict_search_all_done = null;
 
-	currMatchingDictNum = 0;
-	g_dictFindParentLevel = 0;
-	g_dictFindAllDone = false;
-	g_dict_search_one_dict_done = editor_dict_one_dict_done;
-	g_dict_search_all_done = editor_dict_all_done;
-	dict_refresh_word_download_list();
-	var arrBuffer = dict_get_search_list();
-	g_CurrDictBuffer = JSON.stringify(arrBuffer);
-	dict_mark_word_list_done();
-	document.getElementById("id_dict_match_inner").innerHTML +=
-		"finding parent level " + g_dictFindParentLevel + " buffer:" + arrBuffer.length + "<br>";
-	editor_dict_match();
-}
 
 function editor_dict_match() {
 	if (currMatchingDictNum < g_dictList.length) {
@@ -3442,7 +3425,7 @@ function add_word_to_tran_win(sMeaning) {
 }
 
 function on_word_mouse_enter() {
-	var wordid = $(this).attr("id");
+	let wordid = $(this).attr("id");
 
 	if (gCurrMoseEnterWordId == wordid) {
 		return;
@@ -3454,12 +3437,16 @@ function on_word_mouse_enter() {
 
 	relation_link_show(_curr_mouse_enter_wordid);
 
-	var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
-	var iIndex = getWordIndex(_curr_mouse_enter_wordid);
+	let xAllWord = gXmlBookDataBody.getElementsByTagName("word");
+	let iIndex = getWordIndex(_curr_mouse_enter_wordid);
 	if (iIndex >= 0) {
-		var paliword = getNodeText(xAllWord[iIndex], "real");
-		//如果内存里有这个词,渲染单词下拉菜单
-		dictFetch([paliword],function(){
+		let paliword = getNodeText(xAllWord[iIndex], "real");
+		let factors = [];
+		if(getNodeText(xAllWord[iIndex], "org") != '?'){
+			factors = getNodeText(xAllWord[iIndex], "org").split('+');
+		}
+		//渲染单词下拉菜单
+		dictFetch([paliword].concat(factors),function(){
 			render_word_menu(_curr_mouse_enter_wordid);
 		})
 
@@ -4239,7 +4226,11 @@ var gCurrWordDivBorder = "none";
 var gWordHeadBarVisible = false;
 var gCurrMoseEnterWordId = "";
 
-
+/**
+ * 渲染单词意思,拆分,语法下拉菜单
+ * @param {string} id 单词id
+ * 
+ */
 function render_word_menu(id) {
 	$("#word_mean").html(render_word_menu_mean(id));
 	$("#word_parts").html(render_word_menu_parts(id));
@@ -4286,12 +4277,11 @@ function render_word_menu_mean(id, target = 0) {
 	}
 	sWord.unshift(word_real);
 
-	output +=
-		"<button style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' onclick='fieldListChanged(\"" +
-		id +
-		'","mean","")\'>' +
-		gLocal.gui.empty1 +
-		"</button>";
+	output += "<button ";
+	output += "style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' ";
+	output += "onclick='fieldListChanged(\"" + id + '","mean","")\'>' ;
+	output += gLocal.gui.empty1 ;
+	output += "</button>";
 	output += '<div class="case_dropdown-org">';
 	for (var iWord in sWord) {
 		var pali = sWord[iWord];
@@ -4452,31 +4442,26 @@ function show_word_menu_mean(id) {
 	}
 }
 
-/*
-渲染单词拆分下拉菜单
-id	单词id
-target	默认渲染目标
-		0:主编辑窗口下拉菜
-		1:编辑窗口下拉菜单
-
-返回值	无
-*/
+/**
+ * 渲染单词拆分下拉菜单
+ * @param {string} id	单词id
+ * @param {string} target	默认渲染目标 0:主编辑窗口下拉菜 1:编辑窗口下拉菜单
+ * @return {void}
+ */
 function render_word_menu_parts(id, target = 0) {
 	let output = "";
 	let wordID = id;
 	output += "<div>";
-	output +=
-		"<button style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' onclick='fieldListChanged(\"" +
-		wordID +
-		'","org","")\'>' +
-		gLocal.gui.empty1 +
-		"</button>";
-	output +=
-		"<button style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' onclick='show_word_map(\"" +
-		wordID +
-		"\")'>" +
-		gLocal.gui.wordmap +
-		"</button>";
+	output += "<button ";
+	output += "style='font-size:100%;display:inline-flex; padding:0.1em 0.5em'";
+	output += "onclick='fieldListChanged(\"" + wordID + '","org","")\'>' ;
+	output += gLocal.gui.empty1 ;
+	output += "</button>";
+	output += "<button ";
+	output += "style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' ";
+	output += "onclick='show_word_map(\"" + wordID + "\")'>" ;
+	output += gLocal.gui.wordmap ;
+	output += "</button>";
 	output += "</div>";
 	let pali = doc_word("#" + id).val("real");
 	let wParent = doc_word("#" + id).val("parent");
@@ -4489,25 +4474,25 @@ function render_word_menu_parts(id, target = 0) {
 	if (target == 1) {
 		arrParts[pali] = 1;
 	}
-	if (mDict[pali]) {
-		for (let iWord in mDict[pali]) {
-			if (mDict[pali][iWord].parts && mDict[pali][iWord].parts != "") {
-				arrParts[mDict[pali][iWord].parts] = 1;
-			}
-			if (mDict[pali][iWord].parent && mDict[pali][iWord].parent != "") {
-				arrParent[mDict[pali][iWord].parent] = 1;
+	if (typeof mDict[pali] !== "undefined") {
+		for (const word of mDict[pali]) {
+			if (!isEmpty(word.factors)) {
+				arrParts[word.factors] = 1;
 			}
+			if (!isEmpty(word.parent)) {
+				arrParent[word.parent] = 1;
+			}			
 		}
 	}
 	//加入base拆分
 	if (mDict[wParent]) {
 		let ending = getAutoEnding(pali, wParent);
-		for (let iWord in mDict[wParent]) {
-			if (mDict[wParent][iWord].parts && mDict[wParent][iWord].parts != "") {
-				arrParts[mDict[wParent][iWord].parts] = 1;
+		for (const word of mDict[wParent]) {
+			if (word.factors && word.factors != "") {
+				arrParts[word.factors] = 1;
 				{
 					for (let end in ending) {
-						arrParts[mDict[wParent][iWord].parts + "+[" + end + "]"] = 1;
+						arrParts[word.factors + "+[" + end + "]"] = 1;
 					}
 				}
 			}
@@ -4534,9 +4519,9 @@ function render_word_menu_parts(id, target = 0) {
 	for (let sParent in arrParent) {
 		if (mDict[sParent]) {
 			let arrParts = new Array();
-			for (let iWord in mDict[sParent]) {
-				if (mDict[sParent][iWord].parts && mDict[sParent][iWord].parts != "") {
-					arrParts[mDict[sParent][iWord].parts] = 1;
+			for (const word of mDict[sParent]) {
+				if (word.factors && word.factors != "") {
+					arrParts[word.factors] = 1;
 				}
 			}
 			if (arrParts.length > 0) {
@@ -4549,9 +4534,12 @@ function render_word_menu_parts(id, target = 0) {
 				output += "</div>";
 
 				output += "<div>";
-				for (let sPart in arrParts) {
-					output +=
-						"<a onclick='fieldListChanged(\"" + wordID + '","org","' + sPart + "\")'>" + sPart + "</a>";
+				for (const sPart in arrParts) {
+					if (Object.hasOwnProperty.call(arrParts, sPart)) {
+						output += "<a onclick='fieldListChanged(\"" + wordID + '","org","' + sPart + "\")'>";
+						output += sPart ;
+						output += "</a>";
+					}
 				}
 				output += "</div>";
 
@@ -4571,42 +4559,28 @@ function show_word_menu_parts(id) {
 		}
 	}
 }
-//渲染单词拆分意思下拉菜单
+
+/**
+ * 渲染单词拆分意思下拉菜单
+ * @param {string} id 单词id
+ * @returns {string} html string
+ */
 function render_word_menu_partmean(id) {
-	var wordID = id;
-	var sHtml = "";
-	var pali = doc_word("#" + id).val("real");
-	var sOrg = doc_word("#" + id).val("org");
-	var listFactorForFactorMean = sOrg.split("+");
-	var currDefualtFM = "";
-	for (iFactor in listFactorForFactorMean) {
-		currDefualtFM += findFirstMeanInDict(listFactorForFactorMean[iFactor]) + "+"; //拆分元素加号分隔
-	}
-	currDefualtFM = currDefualtFM.replace(/"  "/g, " ");
-	currDefualtFM = currDefualtFM.replace(/"+ "/g, "+");
-	currDefualtFM = currDefualtFM.replace(/" +"/g, "+");
-	currDefualtFM = currDefualtFM.substring(0, currDefualtFM.length - 1); //去掉尾部的加号 kosalla
-
-	if (currDefualtFM.slice(-1, -2) == "+") {
-		currDefualtFM = currDefualtFM.substring(0, currDefualtFM.length - 1);
-	}
-
-	sHtml +=
-		"<button style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' onclick='fieldListChanged(\"" +
-		wordID +
-		'","om","")\'>' +
-		gLocal.gui.empty1 +
-		"</button>";
-	sHtml +=
-		"<a onclick='fieldListChanged(\"" +
-		wordID +
-		'","om","[a]' +
-		currDefualtFM +
-		"\")'>[" +
-		gLocal.gui.auto +
-		"]" +
-		currDefualtFM +
-		"</a>";
+	let wordID = id;
+	let sHtml = "";
+	let pali = doc_word("#" + id).val("real");
+	let sOrg = doc_word("#" + id).val("org");
+	let currDefualtFM = getAutoFactorMeaning(sOrg);
+	
+	sHtml += "<button ";
+	sHtml += "style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' ";
+	sHtml += "onclick='fieldListChanged(\"" + wordID + '","om","")\'>' ;
+	sHtml += gLocal.gui.empty1 ;
+	sHtml += "</button>";
+	sHtml += "<a onclick='fieldListChanged(\"" + wordID + '","om","[a]' + currDefualtFM + "\")'>";
+	sHtml += "[" + gLocal.gui.auto + "]" ;
+	sHtml += currDefualtFM ;
+	sHtml += "</a>";
 
 	var arrPartMean = new Array();
 	if (mDict[pali]) {
@@ -5054,11 +5028,16 @@ function win_close(id) {
 	document.getElementById(id).style.display = "none";
 }
 
-//利用下拉菜单修改单词信息
-
+/**
+ * 利用下拉菜单修改单词信息
+ * @param {string} inWordId 单词id
+ * @param {string} inField 要修改的字段名
+ * @param {string} inChangeTo 改为某个值
+ * @param {string} sParent 
+ */
 function fieldListChanged(inWordId, inField, inChangeTo, sParent = null) {
-	var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
-	var wordIndex = getWordIndex(inWordId);
+	let xAllWord = gXmlBookDataBody.getElementsByTagName("word");
+	let wordIndex = getWordIndex(inWordId);
 	let arr_id_word = inWordId.split("-");
 	let book = arr_id_word[0].slice(1);
 	let paragraph = arr_id_word[1];
@@ -5079,6 +5058,14 @@ function fieldListChanged(inWordId, inField, inChangeTo, sParent = null) {
 	user_wbw_push_word(inWordId);
 	user_wbw_commit();
 
+	//新的拆分查字典
+	if(inField == "org"){
+		let parts = inChangeTo.split('+');
+		dictFetch(parts,function(){
+			render_word_menu(inWordId);
+		})
+	}
+
 	//准备消息数据
 	let d = new Date();
 	let msg_doc_id;
@@ -5240,17 +5227,18 @@ function set_tran_show_mode(set, obj) {
 var _para_list = new Array();
 
 function menu_dict_match1() {
-	var book;
-	var para = new Array();
+	let book;
+	let para = new Array();
 	xBlock = gXmlBookDataBody.getElementsByTagName("block");
-	for (var iBlock = 0; iBlock < xBlock.length; iBlock++) {
-		xmlParInfo = xBlock[iBlock].getElementsByTagName("info")[0];
-		xmlParData = xBlock[iBlock].getElementsByTagName("data")[0];
+	for (const block of xBlock) {
+		xmlParInfo = block.getElementsByTagName("info")[0];
+		xmlParData = block.getElementsByTagName("data")[0];
 		book = getNodeText(xmlParInfo, "book");
 		paragraph = getNodeText(xmlParInfo, "paragraph");
 
-		para[book + "-" + paragraph] = { book: book, para: paragraph };
+		para[book + "-" + paragraph] = { book: book, para: paragraph };		
 	}
+
 	_para_list = new Array();
 	for (var i in para) {
 		_para_list.push(para[i]);
@@ -5340,7 +5328,18 @@ function auto_match_wbw(para_index) {
 	);
 }
 
-function MatchWord(){
+function isEmpty(val){
+	if(typeof val == "undefined" || val == null || val ==""){
+		return true;
+	}else{
+		return false;
+	}
+}
+/**
+ * 自动填充单词
+ * @param {string} word 需要自动填充的单词
+ */
+function FillAllWord(word=''){
 	let counter = 0;
 	let xAllWord = gXmlBookDataBody.getElementsByTagName("word");
 	for (let x = 0; x < xAllWord.length; x++) {
@@ -5351,40 +5350,128 @@ function MatchWord(){
 		}
 		let wid = getNodeText(xAllWord[x], "id");
 		let real = getNodeText(xAllWord[x], "real");
+		if(word !== ''){
+			if(word !== real){
+				continue;
+			}
+		}
 		let aid = wid.split("-");
 		let book = aid[0].substr(1);
 		let para = aid[1];
 		let num = aid[2];
 		if (mDict.hasOwnProperty(real)) {
+			setNodeText(xAllWord[x], "parent", "");			
+			console.log('setNodeAttr',setNodeAttr(xAllWord[x], "type",'status',0)) ;
+			setNodeAttr(xAllWord[x], "gramma",'status',0);
+			setNodeAttr(xAllWord[x], "case",'status',0);
+			setNodeAttr(xAllWord[x], "parent",'status',0);
+			setNodeAttr(xAllWord[x], "mean",'status',0);
+			setNodeAttr(xAllWord[x], "org",'status',0);
+			setNodeAttr(xAllWord[x], "om",'status',0);
+
 			for (const iterator of mDict[real]) {
-				   if (iterator.type) {
-					   setNodeText(xAllWord[x], "type", iterator.type);
-				   }
-				   if (iterator.gramma) {
-					   setNodeText(xAllWord[x], "gramma", iterator.gramma);
-				   }
-				   setNodeText(xAllWord[x], "case", iterator.type + "#" + iterator.gramma);
-				   if (iterator.mean) {
-					   setNodeText(xAllWord[x], "mean", iterator.mean);
-				   }
-				   if (iterator.parent) {
-					   setNodeText(xAllWord[x], "parent", iterator.parent);
-				   }
-				   if (iterator.parts) {
-					   setNodeText(xAllWord[x], "org", iterator.parts);
-				   }
-				   if (iterator.partmean) {
-					   setNodeText(xAllWord[x], "om", iterator.partmean);
-				   }
-				   setNodeText(xAllWord[x], "status", "3");
+				if (getNodeAttr(xAllWord[x], "type",'status') == '0' && !isEmpty(iterator.type)) {
+					setNodeText(xAllWord[x], "type", iterator.type);
+					setNodeAttr(xAllWord[x], "type",'status',3);
+					console.log('type:',iterator.type);
+
+					if (!isEmpty(iterator.grammar)) {
+						setNodeText(xAllWord[x], "gramma", iterator.grammar);
+						setNodeAttr(xAllWord[x], "gramma",'status',3);
+					}
+					setNodeText(xAllWord[x], "case", iterator.type + "#" + iterator.grammar);
+					setNodeAttr(xAllWord[x], "case",'status',3);
+					if (!isEmpty(iterator.parent)) {
+						setNodeText(xAllWord[x], "parent", iterator.parent);
+						setNodeAttr(xAllWord[x], "parent",'status',3);
+					}
+				}
+
+				if (getNodeAttr(xAllWord[x], "parent",'status') == '0' && !isEmpty(iterator.parent)) {
+					setNodeText(xAllWord[x], "parent", iterator.parent);
+					setNodeAttr(xAllWord[x], "parent",'status',3);
+					console.log('parent:',iterator.parent);
+
+				}
+
+				if (getNodeAttr(xAllWord[x], "mean",'status') == '0' && !isEmpty(iterator.mean)) {
+					setNodeText(xAllWord[x], "mean", iterator.mean);
+					setNodeAttr(xAllWord[x], "mean",'status',3);
+					console.log('mean:',iterator.mean);
+
+				}
+
+				if (getNodeAttr(xAllWord[x], "org",'status') == '0' && !isEmpty(iterator.factors)) {
+					setNodeText(xAllWord[x], "org", iterator.factors);
+					setNodeAttr(xAllWord[x], "org",'status',3);
+					console.log('org:',iterator.factors);
+				}
+				if (getNodeAttr(xAllWord[x], "om",'status') == '0' && !isEmpty(iterator.factormean)) {
+					setNodeText(xAllWord[x], "om", iterator.factormean);
+					setNodeAttr(xAllWord[x], "om",'status',3);
+				}
 				   counter++;
-				   modifyWordDetailByWordId(wid);
-				   user_wbw_push_word(wid);				
 			}
+			setNodeText(xAllWord[x], "status", "3");
+			//查看是否有没匹配上的项目
+			let parts = getNodeText(xAllWord[x], "org").split('+');
+			if(getNodeText(xAllWord[x], "type") == '.cp.'){
+				//复合词,猜测parent 和语法信息
+				if(parts.length>0){
+					let endOfParts = parts[parts.length-1];//末尾的一个单词
+					if(!isEmpty(endOfParts)){
+						if (mDict.hasOwnProperty(endOfParts) && mDict[endOfParts].length>0) {
+							setNodeText(xAllWord[x], "type", mDict[endOfParts][0].type);
+							setNodeText(xAllWord[x], "gramma", mDict[endOfParts][0].grammar);
+							setNodeText(xAllWord[x], "case", mDict[endOfParts][0].type + "#" + mDict[endOfParts][0].grammar);
+							setNodeAttr(xAllWord[x], "case",'status',3);
+							if(isEmpty(getNodeAttr(xAllWord[x], "parent"))){
+								inline_dict_auto_case(real);
+								for (const iterator of mDict[real]) {
+									if(iterator.type == mDict[endOfParts][0].type && 
+									   iterator.grammar == mDict[endOfParts][0].grammar){
+										setNodeText(xAllWord[x], "parent", iterator.parent);
+										setNodeAttr(xAllWord[x], "parent",'status',3);
+										break;
+									}
+								}
+							}	
+						}
+					}
+				}
+			}
+			let fm = "";
+			if(isEmpty(getNodeAttr(xAllWord[x], "om"))){
+				//根据拆分,自动给出拆分意思
+				fm = getAutoFactorMeaning(getNodeText(xAllWord[x], "org"));
+				setNodeText(xAllWord[x], "om", fm);
+				setNodeAttr(xAllWord[x], "om",'status',3);
+			}
+			if(isEmpty(getNodeAttr(xAllWord[x], "mean"))){
+				//根据拆分,自动给出整体意思
+				setNodeText(xAllWord[x], "mean", fm.replace(/\+/g,' '));
+				setNodeAttr(xAllWord[x], "mean",'status',3);
+			}
+			console.log('auto fill:'+real);
+			outputFilder('type:',getNodeText(xAllWord[x], "type"));
+			outputFilder('gramma:',getNodeText(xAllWord[x], "gramma"));
+			outputFilder('parent:',getNodeText(xAllWord[x], "parent"));
+			outputFilder('mean:',getNodeText(xAllWord[x], "mean"));
+			outputFilder('org:',getNodeText(xAllWord[x], "org"));
+			outputFilder('om:',getNodeText(xAllWord[x], "om"));
 
-
+			modifyWordDetailByWordId(wid);
+			user_wbw_push_word(wid);	
 		}
+	}
+}
 
+
+function outputFilder(filder,value){
+	if(isEmpty(value)){
+		console.log("%c"+filder+"empty" ,"color:red;");
+	}else{
+		console.log(filder,value);
 	}
 }
 

+ 18 - 6
public/app/studio/js/render.js

@@ -4184,6 +4184,11 @@ function render_word_mean_menu2(spell) {
 	return output;
 }
 
+/**
+ * 渲染单词意思下拉菜单
+ * @param {xmlnode} xElement 单词xml节点
+ * @returns 
+ */
 function render_word_mean_menu(xElement) {
 	var wMean = getNodeText(xElement, "mean");
 	var wReal = getNodeText(xElement, "real");
@@ -4199,12 +4204,13 @@ function render_word_mean_menu(xElement) {
 	output += renderMeaning;
 	output += "</p>";
 	output += '<div class="case_dropdown-content">';
-	output +=
-		"<button style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' onclick='fieldListChanged(\"" +
-		wId +
-		'","mean","")\'>' +
-		gLocal.gui.empty1 +
-		'</button><div class="case_dropdown-org">';
+	output += "<button ";
+	output += "style='font-size:100%;display:inline-flex; padding:0.1em 0.5em' ";
+	output += "onclick='fieldListChanged(\"" + wId + '","mean","")\'>' ;
+	output +=  gLocal.gui.empty1 ;
+	output += '</button>';
+	
+	output += '<div class="case_dropdown-org">';
 
 	var sWord = new Array(wReal);
 	sWord = sWord.concat(render_get_word_parent_list(wReal));
@@ -4275,6 +4281,11 @@ function render_word_mean_menu(xElement) {
 	return output;
 }
 
+/**
+ * 获取单词意思列表
+ * @param {string} sWord 
+ * @returns 
+ */
 function render_get_word_mean_list(sWord) {
 	var wReal = sWord;
 
@@ -4282,6 +4293,7 @@ function render_get_word_mean_list(sWord) {
 
 	for (var x in g_DictWordList) {
 		if (g_DictWordList[x].Pali == wReal || g_DictWordList[x].Real == wReal) {
+			//用用户设置的语言过滤结果
 			if (dict_language_enable.indexOf(g_DictWordList[x].Language) >= 0) {
 				if (
 					g_DictWordList[x].Mean != "" &&

+ 242 - 63
public/app/studio/js/wbw_dict.js

@@ -1,63 +1,100 @@
 //var ApiWbwLookup = "./dict_find_one.php";
 var ApiWbwLookup = "/api/v2/wbwlookup";
 
+/**
+ * 
+ * @param {array} words 要查询的单词数组
+ * @param {function} callback 
+ */
 function dictFetch(words,callback=null){
-	if (mDict[words]) {
+
+	//将单词加入查询队列
+	//0 已经查询完,1,正在查询 2,等待查询
+	for (const word of words) {
+		if (!isEmpty(word) && (typeof mDictQueue[word] == "undefined" || typeof mDict[word] == "undefined" )) {
+			mDictQueue[word] = 2;
+		}
+	}
+
+	for (const word in mDictQueue) {
+		if (Object.hasOwnProperty.call(mDictQueue, word)) {
+			//上次的查询尚未完成,退出
+			if(mDictQueue[word] == 1) return;
+		}
+	}
+
+	let wq = new Array();
+	for (const word in mDictQueue) {
+		if (Object.hasOwnProperty.call(mDictQueue, word)) {
+			//上次的查询尚未完成,退出
+			if(mDictQueue[word] == 2){
+				wq.push(word);
+				mDictQueue[word] = 1;
+			}
+		}
+	}
+
+	if (wq.length==0) {
+		//队列为空,没有要查询的词。
 		if(callback){
 			callback();
 		}
 	} else {
-		//如果内存里没有这个词,查字典
-		if (!mDictQueue[words]) {
-			//查询队列里没有,加入队列
-			if (gCurrLookupWord != words) {
-				mDictQueue[words] = 1;
-				gCurrLookupWord = words;
-				$.ajax({
-					type: "GET",
-					url: ApiWbwLookup,
-					dataType: "json",
-					data: {
-						word:words,
-					},
-				}).done(function (data) {
-					if(data.ok){
-						inline_dict_parse(data.data.rows);
-						if(callback){
-							callback();
-						}					
-					}else{
-						alert(data.message);
+		console.log('lookup',wq);
+		//查询队列不为空,查字典
+		gCurrLookupWord = words[0];
+		$.ajax({
+			type: "GET",
+			url: ApiWbwLookup,
+			dataType: "json",
+			data: {
+				word:wq.join(),
+			},
+		}).done(function (data) {
+			if(data.ok){
+				for (const word in mDictQueue) {
+					if (Object.hasOwnProperty.call(mDictQueue, word)) {
+						//设置正在查询的为已经查询过的
+						if(mDictQueue[word] == 1){
+							mDictQueue[word] = 0;
+						}
 					}
+				}
+				inline_dict_parse(data.data.rows);
+				if(callback){
+					callback();
+				}					
+			}else{
+				alert(data.message);
+			}
 
-				}).fail(function(jqXHR, textStatus, errorThrown){
-					ntf_show(textStatus);
-					switch (textStatus) {
-						case "timeout":
-							break;
-						case "error":
-							switch (jqXHR.status) {
-								case 404:
-									break;
-								case 500:
-									break;				
-								default:
-									break;
-							}
-							break;
-						case "abort":
-							break;
-						case "parsererror":			
-							console.log("parsererror",jqXHR.responseText);
+		}).fail(function(jqXHR, textStatus, errorThrown){
+			ntf_show(textStatus);
+			switch (textStatus) {
+				case "timeout":
+					break;
+				case "error":
+					switch (jqXHR.status) {
+						case 404:
 							break;
+						case 500:
+							break;				
 						default:
 							break;
 					}
-					
-				});
-
+					break;
+				case "abort":
+					break;
+				case "parsererror":			
+					console.log("parsererror",jqXHR.responseText);
+					break;
+				default:
+					break;
 			}
-		}
+			
+		});
+
+
 	}
 }
 
@@ -89,27 +126,15 @@ function load_my_formula() {
 
 //解析字典数据
 function inline_dict_parse(data) {
-	/*
-	if (data == "") {
-		return;
-	}
-	
-	try {
-		var worddata = JSON.parse(data);
-	} catch (e) {
-		console.error(e + " data:" + data);
-		return;
-	}
-	*/
 	let worddata = data;
 	if (worddata.length > 0) {
 		//如果有数据 解析查询数据
 		let spell = new Array();
 		for (const iterator of worddata) {
-			if (mDict[iterator.pali]) {
-				spell[iterator.pali] = 1;
+			if (mDict[iterator.word]) {
+				spell[iterator.word] = 1;
 			} else {
-				spell[iterator.pali] = 0;
+				spell[iterator.word] = 0;
 			}
 		}
 		for (const key in spell) {
@@ -122,9 +147,9 @@ function inline_dict_parse(data) {
 		}
 
 		for (const iterator of worddata) {
-			if (spell[iterator.pali] == 0) {
-				mDict[iterator.pali].push(iterator);
-				mDictQueue[iterator.pali] = 0;
+			if (spell[iterator.word] == 0) {
+				mDict[iterator.word].push(iterator);
+				mDictQueue[iterator.word] = 0;
 			}
 		}
 		let currWordParent = new Array();
@@ -235,3 +260,157 @@ function lookupNewWord(param,callback){
 	);
 }
 
+/**
+ * 根据拆分,自动给出拆分意思
+ * @param {string} factors 
+ * @returns 
+ */
+function getAutoFactorMeaning(factors){
+	let fm = new Array();
+	for (const part of factors.split('+')) {
+		fm.push($.trim(findFirstPartMeanInDict(part))); 
+	}
+	return fm.join('+');
+}
+
+
+//自动查词典
+var _para_list = new Array();
+
+function AutoLookup() {
+	let book;
+	let para = new Array();
+	xBlock = gXmlBookDataBody.getElementsByTagName("block");
+	for (const block of xBlock) {
+		xmlParInfo = block.getElementsByTagName("info")[0];
+		xmlParData = block.getElementsByTagName("data")[0];
+		book = getNodeText(xmlParInfo, "book");
+		paragraph = getNodeText(xmlParInfo, "paragraph");
+		
+		let xWord = block.getElementsByTagName("word");
+		let words = [];
+		for (const word of xWord) {
+			let real = getNodeText(word,'real');
+			let type = getNodeText(word,'type');
+			if(real != '' && type != '.ctl.'){
+				words.push(real);
+			}
+		}
+		//不查询重复的段落
+		para[book + "-" + paragraph] = { book: book, para: paragraph,word:words };
+	}
+
+	_para_list = new Array();
+	for (const key in para) {
+		if (Object.hasOwnProperty.call(para, key)) {
+			const element = para[key];
+			_para_list.push(element);
+		}
+	}
+
+	if (_para_list.length > 0) {
+		auto_lookup_wbw(0);
+	}
+}
+
+//自动查词典
+function auto_lookup_wbw(para_index) {
+	dictFetch(_para_list[para_index].word,function(){
+		FillAllWord();
+
+		//计算查字典的进度
+		let precent = (para_index * 100) / (_para_list.length - 1);
+		ntf_show(
+			gLocal.gui.auto_fill +
+				_para_list[para_index].book +
+				"-" +
+				_para_list[para_index].para +
+				"-" +
+				precent.toFixed(1) +
+				"%" +
+				gLocal.gui.finished
+		);
+		//查询下一个段落
+		para_index++;
+		if (para_index < _para_list.length) {
+			auto_lookup_wbw(para_index);
+		}
+	});
+	return;
+	$.get(
+		"./dict_find_auto.php",
+		{
+			book: _para_list[para_index].book,
+			para: _para_list[para_index].para,
+		},
+		function (data, status) {
+			if (data.length > 0) {
+				var dict_data = new Array();
+				try {
+					dict_data = JSON.parse(data);
+				} catch (error) {
+					ntf_show("Error:" + error + "<br>" + data);
+				}
+				var counter = 0;
+				var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
+				for (var x = 0; x < xAllWord.length; x++) {
+					let wordStatus = getNodeText(xAllWord[x], "status");
+					if (parseInt(wordStatus) > 3) {
+						//忽略已经被用户修改的词
+						continue;
+					}
+					let wid = getNodeText(xAllWord[x], "id");
+					let aid = wid.split("-");
+					let book = aid[0].substr(1);
+					let para = aid[1];
+					let num = aid[2];
+					for (var i = 0; i < dict_data.length; i++) {
+						if (dict_data[i].book == book && dict_data[i].paragraph == para && dict_data[i].num == num) {
+							if (dict_data[i].type) {
+								setNodeText(xAllWord[x], "type", dict_data[i].type);
+							}
+							if (dict_data[i].gramma) {
+								setNodeText(xAllWord[x], "gramma", dict_data[i].gramma);
+							}
+							setNodeText(xAllWord[x], "case", dict_data[i].type + "#" + dict_data[i].gramma);
+							if (dict_data[i].mean) {
+								setNodeText(xAllWord[x], "mean", dict_data[i].mean);
+							}
+							if (dict_data[i].parent) {
+								setNodeText(xAllWord[x], "parent", dict_data[i].parent);
+							}
+							if (dict_data[i].parts) {
+								setNodeText(xAllWord[x], "org", dict_data[i].parts);
+							}
+							if (dict_data[i].partmean) {
+								setNodeText(xAllWord[x], "om", dict_data[i].partmean);
+							}
+							setNodeText(xAllWord[x], "status", "3");
+							counter++;
+							modifyWordDetailByWordId(wid);
+							user_wbw_push_word(wid);
+							break;
+						}
+					}
+				}
+				user_wbw_commit();
+			}
+			//计算查字典的进度
+			var precent = (para_index * 100) / (_para_list.length - 1);
+			ntf_show(
+				gLocal.gui.auto_fill +
+					_para_list[para_index].book +
+					"-" +
+					_para_list[para_index].para +
+					"-" +
+					precent.toFixed(1) +
+					"%" +
+					gLocal.gui.finished
+			);
+			para_index++;
+			if (para_index < _para_list.length) {
+				auto_match_wbw(para_index);
+			}
+		}
+	);
+}

+ 49 - 23
public/app/studio/js/xml.js

@@ -82,14 +82,14 @@ function getNodeAttr(inNode, subTagName, attr) {
 }
 
 function setNodeAttr(inNode, subTagName, attr, strValue) {
-	if (!inNode || !strValue || !attr || attr == "") {
+	if ( inNode == null || subTagName === "" || attr === "") {
 		return;
 	}
 	let mValue = strValue.toString();
 	try {
 		if (inNode.getElementsByTagName(subTagName).length == 0) {
-			var newNode = gXmlBookData.createElement(subTagName);
-			var textnode = gXmlBookData.createTextNode(" ");
+			let newNode = gXmlBookData.createElement(subTagName);
+			let textnode = gXmlBookData.createTextNode(" ");
 			newNode.appendChild(textnode);
 			inNode.appendChild(newNode);
 		}
@@ -99,7 +99,7 @@ function setNodeAttr(inNode, subTagName, attr, strValue) {
 			newatt = gXmlBookData.createAttribute(attr);
 			newatt.nodeValue = mValue;
 			inNode.getElementsByTagName(subTagName)[0].setAttributeNode(newatt);
-			return mValue;
+			return true;
 		}
 	} catch (error) {
 		console.error(error);
@@ -153,38 +153,64 @@ function findFirstPartInDict(inWord) {
 	}
 	return output;
 }
-function findFirstPartMeanInDict(inWord) {
-	var output = "?";
-	var pali = com_getPaliReal(inWord);
+
+
+
+function LangInclude(lang,testLang){
+	if(lang.length>0){
+		return lang.includes(testLang);
+	}else{
+		return true;
+	}
+}
+
+
+/**
+ * 查找某单词的意思
+ * @param {string} inWord 要查找的单词拼写
+ * @returns 
+ */
+function findFirstMeanInDict(inWord) {
+	let output = "?";
+	let pali = com_getPaliReal(inWord);
 	if (mDict[pali]) {
-		for (var iWord in mDict[pali]) {
-			if (dict_language_enable.indexOf(mDict[pali][iWord].language) >= 0) {
-				if (mDict[pali][iWord].partmean) {
-					if (mDict[pali][iWord].partmean.length > 0) {
-						return mDict[pali][iWord].partmean;
-					}
+		for (const iterator of mDict[pali]) {
+			//if(dict_language_enable.indexOf(mDict[pali][iWord].language)>=0)
+			{
+				if (!isEmpty(iterator.mean)) {
+					return iterator.mean.split("$")[0];
 				}
 			}
 		}
 	}
 	return output;
 }
-function findFirstMeanInDict(inWord) {
-	var output = "?";
-	var pali = com_getPaliReal(inWord);
+/**
+ * 查找某单词在复合词中的意思
+ * @param {string} inWord 要查找的单词拼写
+ * @returns 
+ */
+function findFirstPartMeanInDict(inWord) {
+	let pali = com_getPaliReal(inWord);
 	if (mDict[pali]) {
-		for (var iWord in mDict[pali]) {
-			//if(dict_language_enable.indexOf(mDict[pali][iWord].language)>=0)
+		for (const iterator of mDict[pali]) {
+			if(LangInclude(setting['dict.lang'],iterator.language))
 			{
-				if (mDict[pali][iWord].mean) {
-					if (mDict[pali][iWord].mean.length > 0) {
-						return mDict[pali][iWord].mean.split("$")[0];
-					}
+				if (iterator.type == ".part." && !isEmpty(iterator.mean)) {
+					return iterator.mean.split("$")[0];
+				}
+			}
+		}
+		for (const iterator of mDict[pali]) {
+			if(LangInclude(setting['dict.lang'],iterator.language))
+			{
+				if (!isEmpty(iterator.mean)) {
+					return iterator.mean.split("$")[0];
 				}
 			}
 		}
 	}
-	return output;
+	return "?";
 }
 
 function findAllMeanInDict(inWord, limit) {

+ 4 - 2
public/app/ucenter/setting.js

@@ -1,9 +1,11 @@
 var setting;
-$(document).load(function () {
+$(document).ready(function () {
 	$.post("../ucenter/get_setting.php", {}, function (data, status) {
 		try {
 			setting = JSON.parse(data);
-		} catch (e) {}
+		} catch (e) {
+			console.error(e.message);
+		}
 	});
 });
 function setting_head_render(file) {

+ 1 - 0
public/dicttext/cm/sys_wbw/sys_wbw.csv

@@ -0,0 +1 @@
+id,word,type,grammar,parent,meaning,note,factors,factor_meaning,status,confidence,strlen,source,language

+ 15 - 0
public/dicttext/cm/sys_wbw/sys_wbw.ini

@@ -0,0 +1,15 @@
+[meta]
+dictname = "system wbw"
+shortname = "社区"
+description = "由用户贡献词条的社区字典"
+src_lang = "pa"
+dest_lang = "cm"
+isbn = ""
+publisher = "pcds"
+year = 2018
+url = ""
+author = ""
+uuid = "ef620a93-a55d-4756-89c5-e188ab009e45"
+rows = 0
+[cols]
+status = 3