Mercurial > hg > extraction-interface
comparison models/extractapp.php @ 81:f1f849d31272 extractapp
book_id as string
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Thu, 23 Apr 2015 14:58:27 +0200 |
| parents | e6e213b26454 |
| children | 23b6bd897777 |
comparison
equal
deleted
inserted
replaced
| 80:c15f53afd7a5 | 81:f1f849d31272 |
|---|---|
| 1 <?php | 1 <?php |
| 2 /* | |
| 3 * extractapp.php | |
| 4 * This file is part of Extraction-interface. | |
| 5 * | |
| 6 * Extraction-interface is free software: you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation, either version 3 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * Extraction-interface is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. | |
| 18 */ | |
| 2 /** | 19 /** |
| 3 * ExtractappModel is extended from the BaseModel. | 20 * ExtractappModel class is extended from the BaseModel class. |
| 4 * This is where we implement the functions/models that related to extraction-interface. | 21 * This is where we implement the functions/models to prepare data that been sent to views. |
| 22 * ExtractappModel is notified by Extractapp controller when there has been a change in its state, | |
| 23 * and produces the output/data to the corresponding view in "views/Extractapp/". | |
| 24 * | |
| 5 */ | 25 */ |
| 6 | 26 |
| 7 class ExtractappModel extends BaseModel{ | 27 class ExtractappModel extends BaseModel{ |
| 8 | 28 |
| 9 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, | 29 protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, |
| 10 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; | 30 $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; |
| 11 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); | 31 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); |
| 12 | 32 |
| 13 | 33 |
| 14 public function GetTextFromFileId() { // remove $_postdata as input | 34 public function SetTextFromFileId() { // remove $_postdata as input |
| 35 /** | |
| 36 * Get text content from LGService by $this->file_id. | |
| 37 * After preprocessing the text string (replace space to circle symbol, link for page number, etc), | |
| 38 * set $this->lg_text to the processed text gotten from LGService. | |
| 39 */ | |
| 40 | |
| 15 /* | 41 /* |
| 16 $this->file_id = $_postdata['fileId']; | 42 $this->file_id = $_postdata['fileId']; |
| 17 $branch_id = $_postdata['branchId']; | 43 $branch_id = $_postdata['branchId']; |
| 18 $section_id = $_postdata['sectionId']; | 44 $section_id = $_postdata['sectionId']; |
| 19 | 45 |
| 57 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber | 83 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber |
| 58 $this->book_meta = $book_meta; | 84 $this->book_meta = $book_meta; |
| 59 | 85 |
| 60 } | 86 } |
| 61 | 87 |
| 62 public function GetTextFromSectionId() { // remove $_postdata as input | 88 public function SetTextFromSectionId() { // remove $_postdata as input |
| 89 /** | |
| 90 * Get text content from LGService by $this->section_id. | |
| 91 * After preprocessing the text string (replace space to circle symbol, link for page number, etc), | |
| 92 * set $this->lg_text to the processed text gotten from LGService. | |
| 93 */ | |
| 94 | |
| 63 /* | 95 /* |
| 64 $section_id = $_postdata['sectionId']; | 96 $section_id = $_postdata['sectionId']; |
| 65 $this->section_id = $section_id; | 97 $this->section_id = $section_id; |
| 66 $this->user_id = $_postdata['userId']; | 98 $this->user_id = $_postdata['userId']; |
| 67 | 99 |
| 85 | 117 |
| 86 $this->lg_text = $lg_text; | 118 $this->lg_text = $lg_text; |
| 87 } | 119 } |
| 88 | 120 |
| 89 // This is only used on localhost | 121 // This is only used on localhost |
| 90 public function GetTextFromLocal($_id){ | 122 public function SetTextFromLocal($_id){ |
| 91 $this->section_id = $_id; | 123 $this->section_id = $_id; |
| 92 //$this->branch_id = 1; // local test sets branch_id to 1 | 124 //$this->branch_id = 1; // local test sets branch_id to 1 |
| 93 $this->messages['debug'] .= "[Debug] from my local"."<br>"; | 125 $this->messages['debug'] .= "[Debug] from my local"."<br>"; |
| 94 $this->lg_text = $this->GetSectionContent(); | 126 $this->lg_text = $this->GetSectionContent(); |
| 95 } | 127 } |
| 96 | 128 |
| 97 | 129 |
| 98 public function GetInfoFromPreviousPage($_postdata) { | 130 public function SetInfoFromPreviousPage($_postdata) { |
| 131 /** | |
| 132 * Get information from post data passsed by the previous page, and set variables in $this. | |
| 133 * The previous page could be: | |
| 134 * | |
| 135 * (1) LGService: the first time user enters Extraction-interface, which should linked from LGService. | |
| 136 * | |
| 137 * (2) Extraction-interface itself: changing topic then continue to tag, saving text to LGService, reload the text from LGService. | |
| 138 * | |
| 139 */ | |
| 99 | 140 |
| 100 if (isset($_postdata['fileId'])) { | 141 if (isset($_postdata['fileId'])) { |
| 101 $this->file_id = $_postdata['fileId']; | 142 $this->file_id = $_postdata['fileId']; |
| 102 } | 143 } |
| 103 if (isset($_postdata['sectionId'])) { | 144 if (isset($_postdata['sectionId'])) { |
| 120 } | 161 } |
| 121 if (isset($_postdata['bookName'])) { | 162 if (isset($_postdata['bookName'])) { |
| 122 $this->book_name = $_postdata['bookName']; | 163 $this->book_name = $_postdata['bookName']; |
| 123 } | 164 } |
| 124 if (isset($_postdata['bookId'])) { | 165 if (isset($_postdata['bookId'])) { |
| 125 $this->book_id = $_postdata['bookId']; | 166 $book_id = $_postdata['bookId']; |
| 167 if ($book_id < 10000) { | |
| 168 $book_id = '0'.(string)$book_id; | |
| 169 } else if ($book_id < 1000) { | |
| 170 $book_id = '00'.(string)$book_id; | |
| 171 } | |
| 172 | |
| 173 $this->book_id = (string)$book_id; | |
| 174 | |
| 126 } | 175 } |
| 127 if (isset($_postdata['currentFileId'])) { | 176 if (isset($_postdata['currentFileId'])) { |
| 128 $this->current_fileId = $_postdata['currentFileId']; | 177 $this->current_fileId = $_postdata['currentFileId']; |
| 129 } | 178 } |
| 130 if (isset($_postdata['taglistArray'])) { | 179 if (isset($_postdata['taglistArray'])) { |
| 173 | 222 |
| 174 } | 223 } |
| 175 | 224 |
| 176 // === for tagging === | 225 // === for tagging === |
| 177 public function StartTagging() { | 226 public function StartTagging() { |
| 227 /** | |
| 228 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view. | |
| 229 * The information contain the text string, taglist array, wordlis array, topic, etc. | |
| 230 */ | |
| 178 | 231 |
| 179 $section_id = $this->section_id; | 232 $section_id = $this->section_id; |
| 180 $stringInput = $this->lg_text; | 233 $stringInput = $this->lg_text; |
| 181 | 234 |
| 182 $data = array(); // data array to be passed to view | 235 $data = array(); // data array to be passed to view |
| 235 return $data; | 288 return $data; |
| 236 | 289 |
| 237 } | 290 } |
| 238 | 291 |
| 239 public function SaveFullText($postdata) { | 292 public function SaveFullText($postdata) { |
| 293 // locally | |
| 240 if ($postdata['text']){ | 294 if ($postdata['text']){ |
| 241 $date = date('Y_m_d_H_i_s', time()); | 295 $date = date('Y_m_d_H_i_s', time()); |
| 242 if ( file_exists("data/parsing_files/".$postdata['filename'].".txt") ) { | 296 if ( file_exists("data/parsing_files/".$postdata['filename'].".txt") ) { |
| 243 $oldFile = file_get_contents("data/parsing_files/".$postdata['filename'].".txt"); | 297 $oldFile = file_get_contents("data/parsing_files/".$postdata['filename'].".txt"); |
| 244 file_put_contents("data/parsing_files/".$postdata['filename']."_".$date.".txt", $oldFile); | 298 file_put_contents("data/parsing_files/".$postdata['filename']."_".$date.".txt", $oldFile); |
| 259 } | 313 } |
| 260 | 314 |
| 261 } | 315 } |
| 262 | 316 |
| 263 public function UpdateInfoResponsedFromLGService($response) { | 317 public function UpdateInfoResponsedFromLGService($response) { |
| 264 | 318 /** |
| 319 * | |
| 320 */ | |
| 321 | |
| 322 | |
| 265 if (isset($response["file"])) { | 323 if (isset($response["file"])) { |
| 266 $response_file = $response["file"]; | 324 $response_file = $response["file"]; |
| 267 } | 325 } |
| 268 if (isset($response["branch"])) { | 326 if (isset($response["branch"])) { |
| 269 $response_branch = $response["branch"]; | 327 $response_branch = $response["branch"]; |
| 349 | 407 |
| 350 return $text; | 408 return $text; |
| 351 } | 409 } |
| 352 | 410 |
| 353 public function SaveFullTextToLGService($_postdata) { | 411 public function SaveFullTextToLGService($_postdata) { |
| 354 // save tagged text (full text) by Jorge's API to lg service | 412 /** |
| 413 * It saves the full tagged text string in postdata to LGService. | |
| 414 * The responses returned by LGService will later be handled in | |
| 415 */ | |
| 416 | |
| 355 // -------- | 417 // -------- |
| 356 global $AT_LOCAL; | 418 global $AT_LOCAL; |
| 357 | 419 |
| 358 if ($_postdata['text']){ | 420 if ($_postdata['text']){ |
| 359 $date = date('Y_m_d_H_i_s', time()); | 421 $date = date('Y_m_d_H_i_s', time()); |
| 1225 return $new_contentString; | 1287 return $new_contentString; |
| 1226 } | 1288 } |
| 1227 | 1289 |
| 1228 | 1290 |
| 1229 private function GetSectionContent() { | 1291 private function GetSectionContent() { |
| 1230 /** This is only been called by GetTextFromLocal(). | 1292 /** This is only been called by SetTextFromLocal(). |
| 1231 */ | 1293 */ |
| 1232 | 1294 |
| 1233 $section_id = $this->GetSectionId(); | 1295 $section_id = $this->GetSectionId(); |
| 1234 $section_info = $this->GetSectionInfo(); | 1296 $section_info = $this->GetSectionInfo(); |
| 1235 | 1297 |
