# HG changeset patch # User Zoe Hong # Date 1433321340 -7200 # Node ID 61593b0472896e29bd9f0e6c5ece74a7330b72a4 # Parent 966a36752c342f796801a1a49b90c536a8b19cb1# Parent fb5049fc5dd7a9afc78a4279d3c303a379649ca1 merged from extractapp_dev diff -r 966a36752c34 -r 61593b047289 config/config.php --- a/config/config.php Thu Apr 23 17:08:31 2015 +0200 +++ b/config/config.php Wed Jun 03 10:49:00 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 966a36752c34 -r 61593b047289 controllers/extractapp.php --- a/controllers/extractapp.php Thu Apr 23 17:08:31 2015 +0200 +++ b/controllers/extractapp.php Wed Jun 03 10:49:00 2015 +0200 @@ -59,6 +59,8 @@ if (isset($this->postdata['func'])) { $func = $this->postdata['func']; + } else { + $func = ""; } switch ($func) { case 'SaveFullText': @@ -66,11 +68,20 @@ $this->ReturnView($viewmodel->StartTagging(), true); break; case 'SaveFullTextToLGService': - $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; - $viewmodel->SetInfoFromPreviousPage($this->postdata); - $response = $viewmodel->SaveFullTextToLGService($this->postdata); - $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id - $viewmodel->SetTextFromFileId(); + global $AT_LOCAL; + if ($AT_LOCAL) { + $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) "; + $viewmodel->SetInfoFromPreviousPage($this->postdata); + $response = $viewmodel->SaveFullTextToLGService($this->postdata); + + } else { + + $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; + $viewmodel->SetInfoFromPreviousPage($this->postdata); + $response = $viewmodel->SaveFullTextToLGService($this->postdata); + $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id + $viewmodel->SetTextFromFileId(); + } $this->ReturnView($viewmodel->StartTagging(), true); break; diff -r 966a36752c34 -r 61593b047289 css/taggingtext.css --- a/css/taggingtext.css Thu Apr 23 17:08:31 2015 +0200 +++ b/css/taggingtext.css Wed Jun 03 10:49:00 2015 +0200 @@ -1,18 +1,56 @@ .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; +} +.btn-sm{ + height: 35px; + width: 70px; +} +.btn-md{ + height: 35px; + width: 110px; +} +.btn-lg{ + height: 35px; + width: 220px; +} + +*/ +.tool-frame .btn{ + background-color: #F4F4F4; +} + +.btn:hover { + border: 2px solid #A1A1A1; + border-radius: 4px; +} + .info-board{ margin:10 30 10 30; @@ -21,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 { @@ -45,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 966a36752c34 -r 61593b047289 js/taggingtext.js --- a/js/taggingtext.js Thu Apr 23 17:08:31 2015 +0200 +++ b/js/taggingtext.js Wed Jun 03 10:49:00 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 966a36752c34 -r 61593b047289 models/extractapp.php --- a/models/extractapp.php Thu Apr 23 17:08:31 2015 +0200 +++ b/models/extractapp.php Wed Jun 03 10:49:00 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'=>""); @@ -76,11 +78,44 @@ $section_meta = json_decode(file_get_contents($section_meta_url), true); $b = $section_meta['section']['book']; - + + $this->book_name = $b['name']; + $this->book_id = $b['id']; + /* $book_meta = array(); array_push($book_meta, array($b['id'],$b['name'],$b['level1'],$b['level2'], $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'], $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber + */ + /* + $book_meta = array('id'=>$b['id'],'name'=>$b['name'],'level1'=>$b['level1'],'level2'=>$b['level2'], + 'period'=>$b['period'],'dynasty'=>$b['dynasty'],'start_year'=>$b['start_year'], 'end_year'=>$b['end_year'],'line'=>$b['line'], + 'volume'=>$b['volume'],'author'=>$b['author'],'edition'=>$b['edition'], + 'in_jibengujiku'=>$b['in_jibengujiku'],'admin_type'=>$b['admin_type']); // missing author,year,pagenumber + */ + + $book_meta->id = $b['id']; + $book_meta->name = $b['name']; + $book_meta->level1 = $b['level1']; + $book_meta->level2 = $b['level2']; + $book_meta->period = $b['period']; + $book_meta->dynasty = $b['dynasty']; + $book_meta->start_year = $b['start_year']; + $book_meta->end_year = $b['end_year']; + $book_meta->line = $b['line']; + $book_meta->volume = $b['volume']; + $book_meta->author = $b['author']; + $book_meta->edition = $b['edition']; + $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; } @@ -213,7 +248,7 @@ return true; } - + // === for tagging === public function StartTagging() { /** @@ -229,7 +264,7 @@ //$taglistArray = $this->GetTaglistArray(); //for GetTaglistByTopicId: $taglistArray = $this->GetTaglistByTopicId($this->GetTopic()); - + // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not @@ -253,13 +288,16 @@ $data['section_id'] = $section_id; $data['topiclistArray'] = $topiclistArray; $data['default_topic_id'] = $this->GetTopic(); - $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); - $data['topic_name'] = $this->GetTopicName($this->GetTopic()); + $topic_id = $this->GetTopic(); + + $data['topic_tag'] = $this->GetTopicTag($topic_id); + $data['topic_name'] = $this->GetTopicName($topic_id); + $data['topic_tag_ch'] = $this->GetTopicTagName($topic_id); $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, - 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, + 'book_name'=>$this->book_name,'section_name'=>$this->section_name, 'period'=>$this->book_meta->period, 'current_fileId'=>$this->current_fileId); $this->messages['debug'] .= "[Debug] "; @@ -272,6 +310,7 @@ $this->messages['info'] .= ", section id: ". $this->section_id; $this->messages['info'] .= ", branch id: ".$this->branch_id; $this->messages['info'] .= ", file id: ".$this->file_id; + $this->messages['info'] .= ", period: ".$this->book_meta->period; $this->messages['info'] .= "
"; @@ -308,10 +347,9 @@ public function UpdateInfoResponsedFromLGService($response) { /** - * + * */ - if (isset($response["file"])) { $response_file = $response["file"]; } @@ -353,6 +391,29 @@ $text .= "".$this->topic."\n"; // --- book meta data --- $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->place_name."\n"; + $text .= "".$book->x."\n"; + $text .= "".$book->y."\n"; + $text .= "\n"; + + /* foreach ($book as $b) { $text .= "\n"; $text .= "".$b[0]."\n"; @@ -372,6 +433,8 @@ $text .= "\n"; } + */ + // --- section info --- $text .= "
\n"; $text .= "".$this->section_id."\n"; @@ -1086,7 +1149,6 @@ $row = mysql_fetch_assoc($result); $tag = $row['tag']; return $tag; - } private function GetTopicName($topic_id) { $result = $this->GetTopicById($topic_id); @@ -1094,10 +1156,19 @@ //$name = $row['name']; $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']); return $name; + } + private function GetTopicTagName($topic_id) { + $topic_tag = $this->GetTopicTag($topic_id); + $query = "SELECT * FROM `taglist` WHERE tag='".$topic_tag."'"; + $result = mysql_query($query); + $row = mysql_fetch_assoc($result); + return $row['name']; } + + // =========================== // === for manage wordlist === @@ -1290,6 +1361,8 @@ $bookId = $section_info['bookId']; $startPage = $section_info['startPage']; $endPage = $section_info['endPage']; + $this->section_name = $section_info['sectionName']; + $contentString=""; $data_path = $this->GetDataPath(); diff -r 966a36752c34 -r 61593b047289 views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Thu Apr 23 17:08:31 2015 +0200 +++ b/views/Extractapp/TaggingText.php Wed Jun 03 10:49:00 2015 +0200 @@ -40,6 +40,7 @@ $default_topic_id = $viewmodel['default_topic_id']; $topic_name = $viewmodel['topic_name']; // array of names $topic_tag = $viewmodel['topic_tag']; +$topic_tag_ch = $viewmodel['topic_tag_ch']; $info = $viewmodel['info']; $messages = $viewmodel['messages']; @@ -53,7 +54,9 @@ Extraction Interface - + + +