Mercurial > hg > extraction-interface
diff models/extractapp.php @ 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 |
line wrap: on
line diff
--- 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']; }