# HG changeset patch # User Zoe Hong # Date 1433256725 -7200 # Node ID fb5049fc5dd7a9afc78a4279d3c303a379649ca1 # Parent 0141df465205e07ab0884a25c1b1c8d0ce537bed New:(1)UI(2)generate simple regex by examples(3)coordinates in book metadata diff -r 0141df465205 -r fb5049fc5dd7 config/config.php --- a/config/config.php Thu Apr 30 10:52:05 2015 +0200 +++ b/config/config.php Tue Jun 02 16:52:05 2015 +0200 @@ -22,17 +22,17 @@ $mysql_server = "localhost"; $mysql_user = "root"; $mysql_password = "admin"; - $server_host = "http://localgazetteers-dev/"; + $server_host = "http://localgazetteers/"; $lgserver_url = $server_host."LGServices/"; } else { // localhost - $mysql_database = "Gazetteers"; + $mysql_database = "Gazetteer"; $mysql_server = "localhost"; $mysql_user = "root"; $mysql_password = "root"; $server_host = "http://localhost:1080/localgazetteers-dev/"; - $lgserver_url = "http://localgazetteers-dev/LGServices/"; + $lgserver_url = "http://localgazetteers/LGServices/"; } $systemNAME = "interface"; diff -r 0141df465205 -r fb5049fc5dd7 controllers/extractapp.php --- a/controllers/extractapp.php Thu Apr 30 10:52:05 2015 +0200 +++ b/controllers/extractapp.php Tue Jun 02 16:52:05 2015 +0200 @@ -59,6 +59,8 @@ if (isset($this->postdata['func'])) { $func = $this->postdata['func']; + } else { + $func = ""; } switch ($func) { case 'SaveFullText': diff -r 0141df465205 -r fb5049fc5dd7 css/taggingtext.css --- a/css/taggingtext.css Thu Apr 30 10:52:05 2015 +0200 +++ b/css/taggingtext.css Tue Jun 02 16:52:05 2015 +0200 @@ -1,18 +1,29 @@ .bg-danger{ background-color: #FFD1D1; + margin: 5 5 5 5; } .bg-warning{ background-color: #FFFF99; + margin: 5 5 5 5; } - +.bg-success{ + background-color: #ADFAAA; + margin: 5 5 5 5; +} .bg-info{ background-color: #E7F3FF; - + margin: 5 5 5 5; } .bg-default{ background-color: #F4F4F4; + margin: 5 5 5 5; } +.bg-white{ + background-color: white; + margin: 5 5 5 5; +} +/* .btn-xs{ height: 25px; width: 60px; @@ -30,6 +41,16 @@ width: 220px; } +*/ +.tool-frame .btn{ + background-color: #F4F4F4; +} + +.btn:hover { + border: 2px solid #A1A1A1; + border-radius: 4px; +} + .info-board{ margin:10 30 10 30; @@ -38,18 +59,32 @@ min-width: 680px; border: 2px solid #A1A1A1; border-radius: 4px; - height:70px; + max-height:70px; overflow:scroll; overflow-x:hidden; } + + #follow-scroll { position:absolute; height:680px; overflow:scroll; margin:0 5 15 5; max-width:280px; - border: 1px solid #A1A1A1; - border-radius: 4px; +} + +.tool-frame{ + background-color: white; + border: 2px solid #A1A1A1; + border-radius: 3px; + padding: 5px; +} +.tool-topic { + background-color: #E7F3FF; + border-radius: 3px; +} +.tool-topic:hover{ + border: 2px solid #E7F3FF; } .popup-frame { @@ -62,26 +97,44 @@ } .popup-regex { - left: -400px; - width: 400px; + left: -450px; + width: 450px; height: 300px; - top: 100px; + top: 120px; z-index: 2; } .popup-loadregex{ left: -300px; width: 300px; - height: 70px; + height: 85px; top: 100px; - z-index: 2; + z-index: 3; } .popup-topic { - left: -200px; - width: 200px; - height: 50px; + left: -250px; + width: 250px; + height: 80px; top: 20px; z-index: 2; } + +.tagItemDivClass { + position:absolute; + background-color: white; + border: 2px solid #A1A1A1; + border-radius: 4px; + padding: 5px; + z-index:5; +} + +.questionMarkClass { + position:absolute; + background-color: white; + border: 2px solid #A1A1A1; + border-radius: 4px; + padding: 5px; + z-index:4; +} diff -r 0141df465205 -r fb5049fc5dd7 js/taggingtext.js --- a/js/taggingtext.js Thu Apr 30 10:52:05 2015 +0200 +++ b/js/taggingtext.js Tue Jun 02 16:52:05 2015 +0200 @@ -238,16 +238,19 @@ function removeTagNewDiv( eventObject, tagName, tagObject ) { + // TODO: nesting tag representaion + saveUndoText(); var newdiv = document.createElement("div"); - newdiv.id = "questionMarkId"; - newdiv.setAttribute("class", "questionMarkClass"); + $(newdiv).id = "questionMarkId"; + $(newdiv).attr("class", "questionMarkClass"); // set z-index to 3 to bring popup tag windwo to front - newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px; z-index:3'; + newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+';'; + newdiv.innerHTML = "Tag: "+tagName+"
Value: "+tagObject.text()+"
"; - var newbutton = $('').mouseup(function (e2) { + var newbutton = $('').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=//g; var replaceText=""; @@ -257,7 +260,7 @@ }); newbutton.appendTo(newdiv); - var newbutton = $('').mouseup(function (e2) { + var newbutton = $('').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=//g; var replaceText=""; @@ -271,7 +274,7 @@ }); newbutton.appendTo(newdiv); - var newbutton = $('').mouseup(function (e2) { + var newbutton = $('').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=//g; var replaceText=""; @@ -293,7 +296,7 @@ }); newbutton.appendTo(newdiv); - var newbutton = $('').mouseup(function (e2) { + var newbutton = $('').mouseup(function (e2) { var textKeep = $(this).parent().parent().html(); var regexText=//g; var replaceText=""; @@ -464,7 +467,14 @@ } function smartRegexNew() { - $('#smartRegexPopUpDiv').css("display", "block"); + + var popup_status = $('#smartRegexPopUpDiv').css("display"); + if (popup_status == "block") { + $('#smartRegexPopUpDiv').css("display", "none"); + } else { + $('#smartRegexPopUpDiv').css("display", "block"); + } + $('#smartRegexPopUpAdd').attr("disabled", false); $('#smartRegexPopUpEdit').attr("disabled", "disabled"); @@ -476,8 +486,6 @@ function replaceSmartClose() { $('#smartRegexShowDiv > span').css("border","1px solid black"); - - $('#smartRegexPopUpDiv').css("display", "none"); $("#smartRegexPopUpSelectWord").val("NULL"); $("#smartRegexPopUpText").val(""); @@ -545,6 +553,7 @@ replaceSmartClose(); } + $(document).on("click", '#smartRegexShowDiv > span', function (e) { @@ -566,6 +575,247 @@ $('#smartRegexPopUpFor').attr("disabled", false); }); +function genRegexWindowOpen(){ + var btn_state = $('#regex_generator').css('display'); + if (btn_state == "block") { + $("#regex_generator").css("display", "none"); + $("#gen_regex_window_open_id").text("Open Gen Regex"); + } else { + $('#regex_generator').css("display", "block"); + $("#gen_regex_window_open_id").text("Close Gen Regex"); + } +} +function genRegexWindowClose(){ + $('#regex_generator').css("display", "none"); +} + +function sharedStart_(array){ + var A= array.concat().sort(), + a1= A[0], a2= A[A.length-1], L= a1.length, i= 0; + while(i longestCommonSubstring){ + longestCommonSubstring = table[i+1][j+1]; + } + } else { + table[i+1][j+1] = 0; + } + } + } + return longestCommonSubstring; +} + +function longestCommonSubstring(s1, s2) { + + var start_idx = 0; + var max_len = 0; + for (var i = 0; i < s1.length; i++) + { + for (var j = 0; j < s2.length; j++) + { + var x = 0; + while (s1.charAt(i + x) == s2.charAt(j + x)) + { + x++; + if ((i + x) >= s1.length || ((j + x) >= s2.length)) + break; + } + if (x > max_len) + { + max_len = x; + start_idx = i; + } + } + } + return s1.substring(start_idx, (start_idx + max_len)); + +} + +function getRegex(_pattern) { + console.log(_pattern[0]); + console.log(_pattern[1]); + var p0 = _pattern[0]; + var p1 = _pattern[1]; + + // TODO: find common pattern + var reg_str = ""; + // _p1 = 測試 + // _p2 = 測一下 + var combined = []; + if (p0.length > p1.length) { + combined = p0; + } else if(p0.length < p1.length) { + combined = p1; + } else { // equal length + // find matching string + var cnt = p0.length; + for (var i = 0; i < cnt; i++) { + if (p1[i].tag != null) { + combined.push({tag:p1[i].tag, txt:"[^○如即而之有<>〈〉【】]{1,"+p1[i].txt.length+"}"}); + } else if (p0[i].tag != null) { + combined.push({tag:p0[i].tag, txt:"[^○如即而之有<>〈〉【】]{1,"+p0[i].txt.length+"}"}); + } else { + // find matching for text in each corresponding position + var texts = [p0[i].txt, p1[i].txt]; + var common = longestCommonSubstring(p0[i].txt, p1[i].txt); + + /* + var reg_for_common = "["; + for (var i = 0; i < common.length; i++) { + common[i]; + reg_for_common += common[i]+"|"; + }; + reg_for_common += "]"; + */ + combined.push({tag:null, txt:common}); + } + }; + } + + for (var i = 0; i < combined.length; i++) { + reg_str += combined[i].txt; + }; + + return reg_str; +} + +var pattern_obj = []; // record pattern array for regex generator. only contain pattern1 and pattern2 + +function genRegexBySelection(tag_item_div, _selection) { + var add_gen_regex_button = document.createElement("button"); + $(add_gen_regex_button).id = "addToGenRegex"; + $(add_gen_regex_button).addClass("btn btn-md"); + $(add_gen_regex_button).click( function(){ + // popup for selected words regex gen + console.log("Debug: "); + console.log(_selection); + + if (_selection.type == "Range") { + // select words, not just click on text + var anchor_node = _selection.anchorNode; + var focus_node = _selection.focusNode; + var sibling_node = anchor_node.nextElementSibling; + + + if (anchor_node && sibling_node && focus_node && container.innerHTML.indexOf( "br" ) == -1) { + // Chrome can work on this. + // Safari does not support some of the member in selection object + // container.innerHTML.indexOf( "br" ) == -1: selection does not contain br. + + var seleted_div = document.createElement("div"); + var seleted_obj = []; // array for selected text as well as its tag if it has any + + if (anchor_node == focus_node ) { + // selected text in plain text + var text_all = anchor_node.textContent; + var text_ = text_all.substring(_selection.anchorOffset, _selection.focusOffset); + $(seleted_div).text(text_); + seleted_obj.push({tag:null, txt:text_}); // push object into array + + } else { + // selected text contain tags + var text_before = anchor_node.textContent.substring(_selection.anchorOffset, anchor_node.length); + var tag_name = sibling_node.nodeName.toLowerCase(); + var tagged_text = sibling_node.textContent; + + var text_after = _selection.focusNode.textContent.substring(0, _selection.focusOffset); + + $(seleted_div).text(text_before+tagged_text+text_after); + seleted_obj.push({tag:null, txt:text_before}); + seleted_obj.push({tag:tag_name, txt:tagged_text}); + seleted_obj.push({tag:null, txt:text_after}); + + + console.log(text_before); + console.log(tag_name); + console.log(tagged_text); + console.log(text_after); + } + + + var generated_regex = ""; + // show generate regex window + $('#regex_generator').css("display", "block"); + $("#gen_regex_window_open_id").text("Close Gen Regex"); + + //var seleted_text = String(_selection).replace(/^\s+|\s+$/g,''); + var pattern1 = $('#regex_pattern1'); + var pattern2 = $('#regex_pattern2'); + if (pattern1.children().length == 0) { + pattern1.append(seleted_div); + pattern_obj.push(seleted_obj); + // pattern1.text(seleted_div.text()); + } else if (pattern2.children().length == 0) { + pattern2.append(seleted_div); + pattern_obj.push(seleted_obj); + //pattern2.text(seleted_div.text()); + generated_regex = getRegex(pattern_obj); + + } else { + // pattern1 and pattern2 are already having text + pattern1.children().remove(); + pattern1.append(pattern2.children()); + + pattern2.children().remove(); + pattern2.append(seleted_div); + + pattern_obj.shift(); + pattern_obj.push(seleted_obj); + + //pattern1.text(pattern2.text()); + //pattern2.text(seleted_div); + generated_regex = getRegex(pattern_obj); + + } + $('#generated_regex').text(generated_regex); + // --- + + $('#regex_generator_error_msg').text(""); + } else { + $('#regex_generator_error_msg').text("Note: Not a valid selection for regex generator."); + } + + $('.tagItemDivClass').remove(); // close the tag window + + } else if (_selection.type == "Caret") { + // TODO: click on tagged text case rather than select + // If do this process, also need to consider between browers since not all of them support + // and also need to modify pop_remove_tag_window + } + }); + + $(add_gen_regex_button).text("Add to Gen Regex"); + tag_item_div.appendChild(add_gen_regex_button); +} + + function smartRegexEmpty() { $('#smartRegexShowDiv').html(""); regex_element_index = 0; @@ -789,7 +1039,12 @@ function smartRegexLoad(topic_id) { $('#load_regex_div').html(""); - $('#load_regex_div').css("display", "block"); + var popup_status = $('#load_regex_div').css("display"); + if (popup_status == "block") { + $('#load_regex_div').css("display", "none"); + } else { + $('#load_regex_div').css("display", "block"); + } var newselect = document.createElement("select"); newselect.id = "loadRegexSelect"; diff -r 0141df465205 -r fb5049fc5dd7 models/extractapp.php --- a/models/extractapp.php Thu Apr 30 10:52:05 2015 +0200 +++ b/models/extractapp.php Tue Jun 02 16:52:05 2015 +0200 @@ -27,7 +27,9 @@ class ExtractappModel extends BaseModel{ protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, - $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; + $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", + $book_meta = "", $book_dynasty = ""; + public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); @@ -107,6 +109,12 @@ $book_meta->in_jibengujiku = $b['in_jibengujiku']; $book_meta->admin_type = $b['admin_type']; + $coordinates = $section_meta['section']['coordinates_books']; + $book_meta->x = $coordinates['x']; + $book_meta->y = $coordinates['y']; + $book_meta->place_name = $coordinates['place_name']; + + $this->book_meta = $book_meta; @@ -385,23 +393,26 @@ $book = $this->book_meta; $text .= "\n"; - $text .= "".$book->id."\n"; - $text .= "".$book->name."\n"; - $text .= "".$book->level1."\n"; - $text .= "".$book->level2."\n"; - $text .= "".$book->period."\n"; - $text .= "".$book->dynasty."\n"; - $text .= "".$book->start_year."\n"; - $text .= "".$book->end_year."\n"; - $text .= "".$book->line."\n"; - $text .= "".$book->volume."\n"; - $text .= "".$book->author."\n"; - $text .= "".$book->edition."\n"; - $text .= "".$book->in_jibengujiku."\n"; - $text .= "".$book->admin_type."\n"; + $text .= "".$book->id."\n"; + $text .= "".$book->name."\n"; + $text .= "".$book->level1."\n"; + $text .= "".$book->level2."\n"; + $text .= "".$book->period."\n"; + $text .= "".$book->dynasty."\n"; + $text .= "".$book->start_year."\n"; + $text .= "".$book->end_year."\n"; + $text .= "".$book->line."\n"; + $text .= "".$book->volume."\n"; + $text .= "".$book->author."\n"; + $text .= "".$book->edition."\n"; + $text .= "".$book->in_jibengujiku."\n"; + $text .= "".$book->admin_type."\n"; + + $text .= "".$book->place_name."\n"; + $text .= "".$book->x."\n"; + $text .= "".$book->y."\n"; $text .= "\n"; - /* foreach ($book as $b) { $text .= "\n"; diff -r 0141df465205 -r fb5049fc5dd7 views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Thu Apr 30 10:52:05 2015 +0200 +++ b/views/Extractapp/TaggingText.php Tue Jun 02 16:52:05 2015 +0200 @@ -216,6 +216,7 @@ }); // --- + //--- for popups --- //run once var el=$('#popups'); @@ -252,7 +253,7 @@ var info = JSON.parse(''); // the first time to this section. without branch_id and file_id if (info['file_id'] == 0) { // or info['branch_id'] == 0, means new file - $( "#saveTextToLGService_id").text( "Create(Save) Branch to LGService" ); + $( "#save_text_to_LGService_id").text( "Create(Save) Branch to LGService" ); } handleFileVersionConflict(); @@ -271,7 +272,7 @@ // TOOD: ask user to modify/decide tags // showing taglist_infile and taglistArray - alert("Warning: taglist is deprecated in the current file."); + //alert("Warning: taglist is deprecated in the current file."); } @@ -290,15 +291,20 @@ container = document.createElement("div"); container.appendChild(selection.getRangeAt(0).cloneContents()); - if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) { + if(selection && (selection_plain = new String(selection).replace(/^\s+|\s+$/g,''))) { try{ var newdiv = document.createElement("div"); - newdiv.id = "tagItemDivId"; - newdiv.setAttribute("class", "tagItemDivClass"); - newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px; z-index:4'; - + //newdiv.id = "tagItemDivId"; + //newdiv.setAttribute("class", "tagItemDivClass"); + $(newdiv).id = "tagItemDivId"; + $(newdiv).addClass("tagItemDivClass"); + newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+';'; //console.log(selection.getRangeAt(0).cloneContents()); if ( container.innerHTML.indexOf( "br" ) != -1 ) { + // when selected words containing tags (i.e. has 'br' in the selected string), + // which means user want to apply Title / or tags all in once at each line + // This may not be the best checking solution, since 'br' also appears between not-tagged words + var newselect = document.createElement("select"); newselect.id = "TitletagType"; //console.log(JSON.parse('')); @@ -319,8 +325,6 @@ } else { newdiv.innerHTML += "
"; } - - newdiv.innerHTML += "
"; /* @@ -340,57 +344,52 @@ newdiv.innerHTML += "
"; } else { // for pop up window on edit-area for tag list - newdiv.innerHTML = "Tagging word: "+String(selection)+"
"; - + // newdiv.innerHTML = "Tagging word: "+String(selection)+"
"; + var tagging_words = document.createElement("div"); + $(tagging_words).addClass("bg-info"); + $(tagging_words).text("Tagging words: " + String(selection_plain)); + + newdiv.appendChild(tagging_words); + + var tagging_tags = document.createElement("div"); + $(tagging_tags).addClass("bg-white"); + $(tagging_tags).text("Tag as: "); + + tagging_tags.innerHTML += "
"; + Tag as:".$taglistValue[1]."\";\n"; - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - - /* - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - */ + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"
\";\n"; break; } } + foreach ( $taglistArray as $taglistValue ) { + if ($taglistValue[2] == $topic_tag) { + // pass + } else if ($taglistValue[2] == "post_time") { + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"
\";\n"; + } else if ($taglistValue[2] == "office") { + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"
\";\n"; + } else { + echo "tagging_tags.innerHTML += \"\";\n"; + echo "tagging_tags.innerHTML += \"
\";\n"; + } + } ?> - newdiv.innerHTML += "
"; - - Tag as:".$taglistValue[1]."(No BR)\";\n"; - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - } else */ - if ($taglistValue[2] == $topic_tag) { - // pass - } else if ($taglistValue[2] == "post_time") { - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - } else if ($taglistValue[2] == "office") { - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - } else { - echo "newdiv.innerHTML += \"\";\n"; - echo "newdiv.innerHTML += \"
\";\n"; - } + newdiv.appendChild(tagging_tags); + // add selected words to generator regex + genRegexBySelection(newdiv, selection); // append button to newdiv and handle the selection words - } - ?> } //$('#tagItemDivId').addClass(); // tagItemDivId is newdiv's id $('body').append(newdiv); - $('#TitletagType').val(lastAddTag); // selected some words, so hide popping up remove-tag-window @@ -405,15 +404,9 @@ pop_remove_tag_window = true; } - - //e.stopPropagation(); - - - }); - // === for exporttable.php === function exportTable( range, container ) { //MsgBox("enter function"); @@ -708,9 +701,13 @@ var t = JSON.parse( '' ); var info = JSON.parse(''); - $('#load_topic_div').html(""); - $('#load_topic_div').css("display", "block"); + var popup_status = $('#load_topic_div').css("display"); + if (popup_status == "block") { + $('#load_topic_div').css("display", "none"); + } else { + $('#load_topic_div').css("display", "block"); + } /* $('#load_topic_div').css("border", "1px solid black"); $('#load_topic_div').css("background-color", "White"); @@ -903,9 +900,22 @@ - -
-
+ + +
@@ -916,6 +926,7 @@
+
@@ -925,6 +936,20 @@
+