Mercurial > hg > extraction-interface
changeset 78:960ba96efce1 extractapp
Update: click to popup remove-tag-window; select to popup tag-window
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 20 Apr 2015 15:44:54 +0200 |
parents | 97c1e5102a22 |
children | e6e213b26454 |
files | classes/basemodel.php config/config.php controllers/extractapp.php models/extractapp.php views/Extractapp/ExportTable.php views/Extractapp/TaggingText.php |
diffstat | 6 files changed, 125 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/classes/basemodel.php Thu Apr 16 14:53:22 2015 +0200 +++ b/classes/basemodel.php Mon Apr 20 15:44:54 2015 +0200 @@ -70,7 +70,7 @@ return $result; } - protected function GetSectionsByID($section_id) { + protected function GetSectionsById($section_id) { $query = sprintf("SELECT * FROM `sections_index` WHERE `id`=\"%s\"", $section_id); $result = mysql_query($query); if (!$result){ @@ -89,7 +89,7 @@ return $result; } - protected function GetBooksByID($bookId) { + protected function GetBooksById($bookId) { $query = sprintf("SELECT * FROM `books` WHERE id=\"%s\"", $bookId); $result = mysql_query($query); if (!$result) { @@ -98,7 +98,7 @@ return $result; } - protected function GetTopiclist() { + protected function GetTopicList() { $query = sprintf("SELECT * FROM `topics`"); $result = mysql_query($query); if (!$result) { @@ -107,7 +107,7 @@ return $result; } - protected function GetTopicByID($topic_id) { + protected function GetTopicById($topic_id) { $query = sprintf("SELECT * FROM `topics` WHERE id=\"%s\"", $topic_id); $result = mysql_query($query); if (!$result) {
--- a/config/config.php Thu Apr 16 14:53:22 2015 +0200 +++ b/config/config.php Mon Apr 20 15:44:54 2015 +0200 @@ -6,9 +6,9 @@ public function Configuration() { /** - * Configuration for the system. - * If it runs with LGService, set $AT_LOCAL to be true; - * otherwise (runs on localhost), set it to be false. + * Configuration for the system. + * If it runs with LGService, set $AT_LOCAL to be true; + * otherwise (runs on localhost), set it to be false. */ global $AT_LOCAL, $mysql_database, $mysql_server, $mysql_user, $mysql_password, $server_host, $lgserver_url,
--- a/controllers/extractapp.php Thu Apr 16 14:53:22 2015 +0200 +++ b/controllers/extractapp.php Mon Apr 20 15:44:54 2015 +0200 @@ -1,17 +1,15 @@ <?php /** - * Extractapp is extended from the BaseController. - * This is where we handle the processes for every action. - * - * For example, there are five actions in Extractapp, tagging text, exporting a table, - * editing the wordlist, and configurating tags in one topic. -**/ + * Extractapp is extended from the BaseController. + * This is where we handle the processes for every action. + * + * For example, there are five actions in Extractapp, tagging text, exporting a table, + * editing the wordlist, and configurating tags in one topic. +*/ class Extractapp extends BaseController { - protected function Index() { - $viewmodel = new ExtractappModel(); - $this->ReturnView($viewmodel->Index(), true); - } + + protected $viewmodel; @@ -22,19 +20,19 @@ protected function TaggingText() { /** - * TaggingText action in Extractapp handles the taging related actions, for example, - * tagging itself, saving tag results, loading and saving regular expression for tagging. - * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself. - * - * From LGService, the postdata contains essential information about the file/section of local gazetteers data. - * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService. - * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case) - * - * From extraction-interface itself, it contains the information from previous page. - * This happens when user choosing another topic in the extraction-interface, - * the page need to retrieve related information from database for the topic. - * (ContinueTagging case) - */ + * TaggingText action in Extractapp handles the taging related actions, for example, + * tagging itself, saving tag results, loading and saving regular expression for tagging. + * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself. + * + * From LGService, the postdata contains essential information about the file/section of local gazetteers data. + * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService. + * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case) + * + * From extraction-interface itself, it contains the information from previous page. + * This happens when user choosing another topic in the extraction-interface, + * the page need to retrieve related information from database for the topic. + * (ContinueTagging case) + */ $viewmodel = $this->viewmodel; @@ -50,16 +48,16 @@ $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; $viewmodel->GetInfoFromPreviousPage($this->postdata); $response = $viewmodel->SaveFullTextToLGService($this->postdata); - $viewmodel->UpdateInfoByResponseFromLGService($response); // update file_id, branch_id, user_id + $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id $viewmodel->GetTextFromFileId(); $this->ReturnView($viewmodel->StartTagging(), true); break; case 'SmartRegexLoad': - $viewmodel->SmartRegexLoad($this->postdata['topic_id']); + $viewmodel->LoadSmartRegex($this->postdata['topic_id']); break; case 'SmartRegexSave': - $viewmodel->SmartRegexSave($this->postdata); + $viewmodel->SaveSmartRegex($this->postdata); break; case 'ReloadText': $viewmodel->messages['info'] .= "Reload the latest text "; @@ -87,7 +85,7 @@ if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) { // --- Existing branch case --- $viewmodel->GetInfoFromPreviousPage($this->postdata); - $viewmodel->SetBookMetaDataBySectionId(); + $viewmodel->SetBookMetadataBySectionId(); // get text by fileId, from LGService $viewmodel->GetTextFromFileId(); } @@ -95,18 +93,18 @@ } else if ($this->postdata['sectionId'] != 0 && $this->postdata['userId'] != 0) { // --- New branch case --- $viewmodel->GetInfoFromPreviousPage($this->postdata); - $viewmodel->SetBookMetaDataBySectionId(); + $viewmodel->SetBookMetadataBySectionId(); // get text by sectionId from LGService $viewmodel->GetTextFromSectionId(); } else if ($this->postdata['sectionId'] != 0) { $viewmodel->GetTextFromLocal($this->postdata['sectionId']); - $viewmodel->SetBookMetaDataBySectionId(); + $viewmodel->SetBookMetadataBySectionId(); } else if (is_numeric($this->urlvalues['id'])) { // get text from local file system (for development stage only) $viewmodel->GetTextFromLocal($this->urlvalues['id']); - $viewmodel->SetBookMetaDataBySectionId(); + $viewmodel->SetBookMetadataBySectionId(); $this->ReturnView_localtest($viewmodel->StartTagging(), true); break; @@ -126,8 +124,8 @@ protected function ExportTable() { /** - * ExportTable action returns "./views/Extractapp/ExportTable.php" view. - */ + * ExportTable action returns "./views/Extractapp/ExportTable.php" view. + */ $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { @@ -150,9 +148,9 @@ protected function EditWordlist() { /** - * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, - * It adds or saves wordlist based on the 'func' variable in postdata. - */ + * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, + * It adds or saves wordlist based on the 'func' variable in postdata. + */ $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { @@ -174,9 +172,9 @@ protected function EditTaglist() { /** - * EditTaglist action returns "./views/Extractapp/EditTaglist.php" view. - * It adds, saves or delete tag in the current topic. - */ + * EditTaglist action returns "./views/Extractapp/EditTaglist.php" view. + * It adds, saves or delete tag in the current topic. + */ $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) { @@ -201,9 +199,9 @@ protected function ConfigTagsInTopic() { /** - * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view. - * It shows or updates the tags-in-topic relation. - */ + * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view. + * It shows or updates the tags-in-topic relation. + */ $viewmodel = $this->viewmodel; if (isset($this->postdata['func'])) {
--- a/models/extractapp.php Thu Apr 16 14:53:22 2015 +0200 +++ b/models/extractapp.php Mon Apr 20 15:44:54 2015 +0200 @@ -43,7 +43,7 @@ } - public function SetBookMetaDataBySectionId() { + public function SetBookMetadataBySectionId() { // get book_meta from $$this->get_section_metadata_by_sectionId_url $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; @@ -182,8 +182,8 @@ $data = array(); // data array to be passed to view //$taglistArray = $this->GetTaglistArray(); - //for GetTaglistByTopicID: - $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); + //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. @@ -260,7 +260,7 @@ } - public function UpdateInfoByResponseFromLGService($response) { + public function UpdateInfoResponsedFromLGService($response) { if (isset($response["file"])) { $response_file = $response["file"]; @@ -296,7 +296,7 @@ } // This is only called by SaveFullTextToLGService() - private function AppendMetaData($text_content) { + private function AppendMetadata($text_content) { $text = '<?xml version="1.0" encoding="UTF-8"?>'; $text .= "\n<text>\n"; // --- topic --- @@ -331,7 +331,7 @@ // ---- taglist --- // $taglist = $this->taglist_infile; // obtain the latest taglist from db - $taglist = $this->GetTaglistByTopicID($this->GetTopic()); + $taglist = $this->GetTaglistByTopicId($this->GetTopic()); foreach ($taglist as $tagitem) { $text .= "<tagitem>\n"; @@ -349,6 +349,7 @@ return $text; } + public function SaveFullTextToLGService($_postdata) { // save tagged text (full text) by Jorge's API to lg service // -------- @@ -385,7 +386,7 @@ } */ - $require = $this->AppendMetaData($require); + $require = $this->AppendMetadata($require); //saving in my local machine in developing phrase if ($AT_LOCAL) { @@ -454,7 +455,7 @@ } // --- for regex ---- - public function GetRegexFilenameById($topic_id) { + private function GetRegexFilenameById($topic_id) { $query = sprintf("SELECT regex_filename FROM `topic_regex_relation` WHERE topic_id=\"%s\"", $topic_id); $result = mysql_query($query); if (!$result) { @@ -468,7 +469,7 @@ return $filenames; } - public function SmartRegexLoad($topic_id) { + public function LoadSmartRegex($topic_id) { // Load regex file based on current topic. Only shows the regex in this topic -- $filenames = $this->GetRegexFilenameById($topic_id); @@ -492,7 +493,7 @@ } - public function SmartRegexSave($_postdata) { + public function SaveSmartRegex($_postdata) { if ($_postdata['text']){ // --- update topic_regex_relation table --- @@ -559,9 +560,11 @@ $outputTableArray[0]["page"] = "頁數"; $outputTableArray[0]["full"] = "全文"; + // id, name, tag, color in _taglistArray foreach ( $_taglistArray as $tagValue ) { - $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $_content); - $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $_content); + $tag_name = $tagValue[2]; // $tagValue[2] is tag_name + $content = preg_replace("/<\/".$tag_name.">○*<".$tag_name.">/u", "", $_content); + $content = preg_replace("/<".$tag_name.">[ ]*<\/".$tag_name.">/u", "", $_content); } $contentLineArray = explode( "<br>", $content ); @@ -573,30 +576,34 @@ $recordString = $value; $otherString = $recordString; //echo $recordString."<br>\n"; + // find hyper link in pattern with <a>...</a> if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) { $pageNow = $matches[2]; } foreach ( $_taglistArray as $tagValue ) { - if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) { + $tag_name = $tagValue[2]; // $tagValue[2] is tag_name + + if ( preg_match_all("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", $recordString, $matches, PREG_SET_ORDER) ) { foreach ( $matches as $matchesValue ) { $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]); + if ( preg_match_all("/〈(.*?)〉/u", $matchesValue[1], $matches2, PREG_SET_ORDER) ) { foreach ( $matches2 as $matches2Value ) { - if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { - $outputTableArray[$count][0][$tagValue[2]] .= ";".$matches2Value[1]; + if ( isset($outputTableArray[$count][0][$tag_name]) ) { + $outputTableArray[$count][0][$tag_name] .= ";".$matches2Value[1]; } else { - $outputTableArray[$count][0][$tagValue[2]] = $matches2Value[1]; + $outputTableArray[$count][0][$tag_name] = $matches2Value[1]; } } } else { - if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { - $outputTableArray[$count][0][$tagValue[2]] .= ";".$matchesValue[1]; + if ( isset($outputTableArray[$count][0][$tag_name]) ) { + $outputTableArray[$count][0][$tag_name] .= ";".$matchesValue[1]; } else { - $outputTableArray[$count][0][$tagValue[2]] = $matchesValue[1]; + $outputTableArray[$count][0][$tag_name] = $matchesValue[1]; } } } - $otherString = preg_replace("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", " ", $otherString); + $otherString = preg_replace("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", " ", $otherString); } } $otherString = preg_replace("/○/u", "", $otherString); @@ -645,7 +652,7 @@ $bookName = $postdata['bookName']; //$taglistArray = $this->GetTaglistArray(); - $taglistArray = $this->GetTaglistByTopicID($topic); + $taglistArray = $this->GetTaglistByTopicId($topic); } // ===== @@ -683,7 +690,7 @@ $topic_id = $_postdata['topic_id']; - $result = $this->GetTaglistByTopicID($topic_id); + $result = $this->GetTaglistByTopicId($topic_id); $taglistArray = array(); @@ -784,7 +791,7 @@ */ $topic = $postdata['topic']; - $result = $this->GetTopicByID($topic); + $result = $this->GetTopicById($topic); $row = mysql_fetch_assoc($result); $topic_name_en = $row['name_en']; $topic_name_ch = $row['name_ch']; @@ -971,7 +978,7 @@ } - private function GetTaglistByTopicID($topic_id) { + private function GetTaglistByTopicId($topic_id) { $taglistArray = array(); // select taglist ids from topic_tag_relation table $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id); @@ -1005,13 +1012,13 @@ $this->topic = $topic; } - public function GetTopic() { + private function GetTopic() { return $this->topic; } private function GetTopiclistArray() { $topiclistArray = array(); - $result = $this->GetTopiclist(); + $result = $this->GetTopicList(); while ($row = mysql_fetch_assoc($result)) { //array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'],'tag'=>$row['tag'])); array_push($topiclistArray, array('id'=>$row['id'],'tag'=>$row['tag'],'name_en'=>$row['name_en'],'name_ch'=>$row['name_ch'],'name_pinyin'=>$row['name_pinyin'],)); @@ -1021,14 +1028,14 @@ private function GetTopicTag($topic_id) { - $result = $this->GetTopicByID($topic_id); + $result = $this->GetTopicById($topic_id); $row = mysql_fetch_assoc($result); $tag = $row['tag']; return $tag; } private function GetTopicName($topic_id) { - $result = $this->GetTopicByID($topic_id); + $result = $this->GetTopicById($topic_id); $row = mysql_fetch_assoc($result); //$name = $row['name']; $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']); @@ -1121,8 +1128,8 @@ // ======================================= - - public function sortFunction($a,$b) { + + private function sortFunction($a,$b) { return strlen($b)-strlen($a); } @@ -1141,7 +1148,7 @@ return $section_id; } - $result = $this->GetSectionsByID($section_id); + $result = $this->GetSectionsById($section_id); while ($row = mysql_fetch_assoc($result)) { @@ -1267,7 +1274,7 @@ /* // get book_meta from books table in db on localhost $book_meta = array(); - $books_result = $this->GetBooksByID($bookId); + $books_result = $this->GetBooksById($bookId); while ($row = mysql_fetch_assoc($books_result)) { array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'],(string)$row['dynasty'])); // use 'start_year' as year, 'line' is pagenumber @@ -1323,8 +1330,8 @@ } - protected function GetBooksInfo($bookId) { - $result = $this->GetSectionsByID($bookId); + private function GetBooksInfo($bookId) { + $result = $this->GetSectionsById($bookId); while ($row = mysql_fetch_assoc($result)) { $bookName = $row['name']; }
--- a/views/Extractapp/ExportTable.php Thu Apr 16 14:53:22 2015 +0200 +++ b/views/Extractapp/ExportTable.php Mon Apr 20 15:44:54 2015 +0200 @@ -1,7 +1,7 @@ <?php /*! \file -* This is the view for ExportTable. -* It shows a html table with each row as a topic object and each column as a tag/attribute. + * This is the view for ExportTable. + * It shows a html table with each row as a topic object and each column as a tag/attribute. */ // --- initialize ---
--- a/views/Extractapp/TaggingText.php Thu Apr 16 14:53:22 2015 +0200 +++ b/views/Extractapp/TaggingText.php Mon Apr 20 15:44:54 2015 +0200 @@ -1,9 +1,9 @@ <?php /*! \file -* This is the view for TaggingText. -* It shows the extraction-interface application itself. -* It contains the tagging area and toolbox on the right side. -* + * This is the view for TaggingText. + * It shows the extraction-interface application itself. + * It contains the tagging area and toolbox on the right side. + * */ // --- initialize config file and input text --- @@ -92,7 +92,7 @@ function reloadText() { /** - * Reload the text when there is a new version of this branch. + * Reload the text when there is a new version of this branch. */ // confirm to reload var r = confirm("Are you sure you want to load the latest version (in a new tab)?"); @@ -134,6 +134,28 @@ } +// on click on tagged words, call removeTagNewDiv() for the popup window +// popup-window overlapping issue +var pop_remove_tag_window = true; +var taglistArray = JSON.parse('<?php echo json_encode($taglistArray) ?>'); +for (var i = 0; i < taglistArray.length; i++) { + var taglistValue = taglistArray[i]; + + $(document).on("click", taglistValue[2], function (e) { + if ($("#editTextId").html() != "Edit the text") return 0; + var tagName = $(this).prop("tagName").toLowerCase(); + /* + if ($(this).prop("tagName").toLowerCase() != taglistValue[2]) { + return 0; + } + */ + if (pop_remove_tag_window) { + removeTagNewDiv( e, tagName , $(this)); + }; + }); +}; + +/* <?php foreach ( $taglistArray as $taglistValue ) { echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n"; @@ -143,6 +165,7 @@ echo "});\n"; } ?> +*/ $(document).ready(function(){ @@ -225,7 +248,6 @@ }); $(document).on("mouseup", '#editable-area', function (e) { - $('.questionMarkClass').remove(); $('.tagItemDivClass').remove(); @@ -244,7 +266,6 @@ 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'; - //console.log(selection.getRangeAt(0).cloneContents()); if ( container.innerHTML.indexOf( "br" ) != -1 ) { var newselect = document.createElement("select"); @@ -341,8 +362,16 @@ $('#TitletagType').val(lastAddTag); + // selected some words, so hide popping up remove-tag-window + pop_remove_tag_window = false; // questionMarkID + + } else { + // without selecting any word, so pop up remove-tag-window + pop_remove_tag_window = true; } + + //e.stopPropagation();