Mercurial > hg > extraction-interface
comparison models/extractapp.php @ 88:61593b047289 extractapp
merged from extractapp_dev
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 03 Jun 2015 10:49:00 +0200 |
parents | fb5049fc5dd7 |
children | e681d693240e |
comparison
equal
deleted
inserted
replaced
85:966a36752c34 | 88:61593b047289 |
---|---|
25 */ | 25 */ |
26 | 26 |
27 class ExtractappModel extends BaseModel{ | 27 class ExtractappModel extends BaseModel{ |
28 | 28 |
29 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, |
30 $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 = "", |
31 $book_meta = "", $book_dynasty = ""; | |
32 | |
31 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); | 33 public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); |
32 | 34 |
33 | 35 |
34 public function SetTextFromFileId() { // remove $_postdata as input | 36 public function SetTextFromFileId() { // remove $_postdata as input |
35 /** | 37 /** |
74 // get book_meta from $$this->get_section_metadata_by_sectionId_url | 76 // get book_meta from $$this->get_section_metadata_by_sectionId_url |
75 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; | 77 $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; |
76 $section_meta = json_decode(file_get_contents($section_meta_url), true); | 78 $section_meta = json_decode(file_get_contents($section_meta_url), true); |
77 | 79 |
78 $b = $section_meta['section']['book']; | 80 $b = $section_meta['section']['book']; |
79 | 81 |
82 $this->book_name = $b['name']; | |
83 $this->book_id = $b['id']; | |
84 /* | |
80 $book_meta = array(); | 85 $book_meta = array(); |
81 array_push($book_meta, array($b['id'],$b['name'],$b['level1'],$b['level2'], | 86 array_push($book_meta, array($b['id'],$b['name'],$b['level1'],$b['level2'], |
82 $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'], | 87 $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'], |
83 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber | 88 $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type'])); // missing author,year,pagenumber |
89 */ | |
90 /* | |
91 $book_meta = array('id'=>$b['id'],'name'=>$b['name'],'level1'=>$b['level1'],'level2'=>$b['level2'], | |
92 'period'=>$b['period'],'dynasty'=>$b['dynasty'],'start_year'=>$b['start_year'], 'end_year'=>$b['end_year'],'line'=>$b['line'], | |
93 'volume'=>$b['volume'],'author'=>$b['author'],'edition'=>$b['edition'], | |
94 'in_jibengujiku'=>$b['in_jibengujiku'],'admin_type'=>$b['admin_type']); // missing author,year,pagenumber | |
95 */ | |
96 | |
97 $book_meta->id = $b['id']; | |
98 $book_meta->name = $b['name']; | |
99 $book_meta->level1 = $b['level1']; | |
100 $book_meta->level2 = $b['level2']; | |
101 $book_meta->period = $b['period']; | |
102 $book_meta->dynasty = $b['dynasty']; | |
103 $book_meta->start_year = $b['start_year']; | |
104 $book_meta->end_year = $b['end_year']; | |
105 $book_meta->line = $b['line']; | |
106 $book_meta->volume = $b['volume']; | |
107 $book_meta->author = $b['author']; | |
108 $book_meta->edition = $b['edition']; | |
109 $book_meta->in_jibengujiku = $b['in_jibengujiku']; | |
110 $book_meta->admin_type = $b['admin_type']; | |
111 | |
112 $coordinates = $section_meta['section']['coordinates_books']; | |
113 $book_meta->x = $coordinates['x']; | |
114 $book_meta->y = $coordinates['y']; | |
115 $book_meta->place_name = $coordinates['place_name']; | |
116 | |
117 | |
118 | |
84 $this->book_meta = $book_meta; | 119 $this->book_meta = $book_meta; |
85 | 120 |
86 } | 121 } |
87 | 122 |
88 public function SetTextFromSectionId() { // remove $_postdata as input | 123 public function SetTextFromSectionId() { // remove $_postdata as input |
211 } | 246 } |
212 } | 247 } |
213 return true; | 248 return true; |
214 | 249 |
215 } | 250 } |
216 | 251 |
217 // === for tagging === | 252 // === for tagging === |
218 public function StartTagging() { | 253 public function StartTagging() { |
219 /** | 254 /** |
220 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view. | 255 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view. |
221 * The information contain the text string, taglist array, wordlis array, topic, etc. | 256 * The information contain the text string, taglist array, wordlis array, topic, etc. |
227 $data = array(); // data array to be passed to view | 262 $data = array(); // data array to be passed to view |
228 | 263 |
229 //$taglistArray = $this->GetTaglistArray(); | 264 //$taglistArray = $this->GetTaglistArray(); |
230 //for GetTaglistByTopicId: | 265 //for GetTaglistByTopicId: |
231 $taglistArray = $this->GetTaglistByTopicId($this->GetTopic()); | 266 $taglistArray = $this->GetTaglistByTopicId($this->GetTopic()); |
232 | 267 |
233 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided | 268 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided |
234 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. | 269 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. |
235 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not | 270 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not |
236 $this->taglist_infile = ""; | 271 $this->taglist_infile = ""; |
237 } | 272 } |
251 $data['taglistArray'] = $taglistArray; | 286 $data['taglistArray'] = $taglistArray; |
252 $data['wordlistArray'] = $wordlistArray; | 287 $data['wordlistArray'] = $wordlistArray; |
253 $data['section_id'] = $section_id; | 288 $data['section_id'] = $section_id; |
254 $data['topiclistArray'] = $topiclistArray; | 289 $data['topiclistArray'] = $topiclistArray; |
255 $data['default_topic_id'] = $this->GetTopic(); | 290 $data['default_topic_id'] = $this->GetTopic(); |
256 $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); | 291 $topic_id = $this->GetTopic(); |
257 $data['topic_name'] = $this->GetTopicName($this->GetTopic()); | 292 |
293 $data['topic_tag'] = $this->GetTopicTag($topic_id); | |
294 $data['topic_name'] = $this->GetTopicName($topic_id); | |
295 $data['topic_tag_ch'] = $this->GetTopicTagName($topic_id); | |
258 | 296 |
259 | 297 |
260 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, | 298 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, |
261 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, | 299 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, |
262 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, | 300 'book_name'=>$this->book_name,'section_name'=>$this->section_name, 'period'=>$this->book_meta->period, |
263 'current_fileId'=>$this->current_fileId); | 301 'current_fileId'=>$this->current_fileId); |
264 | 302 |
265 $this->messages['debug'] .= "[Debug] "; | 303 $this->messages['debug'] .= "[Debug] "; |
266 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; | 304 $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id; |
267 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; | 305 $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic; |
270 | 308 |
271 $this->messages['info'] .= "[Info] book name: ".$this->book_name; | 309 $this->messages['info'] .= "[Info] book name: ".$this->book_name; |
272 $this->messages['info'] .= ", section id: ". $this->section_id; | 310 $this->messages['info'] .= ", section id: ". $this->section_id; |
273 $this->messages['info'] .= ", branch id: ".$this->branch_id; | 311 $this->messages['info'] .= ", branch id: ".$this->branch_id; |
274 $this->messages['info'] .= ", file id: ".$this->file_id; | 312 $this->messages['info'] .= ", file id: ".$this->file_id; |
313 $this->messages['info'] .= ", period: ".$this->book_meta->period; | |
275 $this->messages['info'] .= "<br>"; | 314 $this->messages['info'] .= "<br>"; |
276 | 315 |
277 | 316 |
278 $data['messages'] = $this->messages; | 317 $data['messages'] = $this->messages; |
279 | 318 |
306 | 345 |
307 } | 346 } |
308 | 347 |
309 public function UpdateInfoResponsedFromLGService($response) { | 348 public function UpdateInfoResponsedFromLGService($response) { |
310 /** | 349 /** |
311 * | 350 * |
312 */ | 351 */ |
313 | |
314 | 352 |
315 if (isset($response["file"])) { | 353 if (isset($response["file"])) { |
316 $response_file = $response["file"]; | 354 $response_file = $response["file"]; |
317 } | 355 } |
318 if (isset($response["branch"])) { | 356 if (isset($response["branch"])) { |
351 $text .= "\n<text>\n"; | 389 $text .= "\n<text>\n"; |
352 // --- topic --- | 390 // --- topic --- |
353 $text .= "<topic>".$this->topic."</topic>\n"; | 391 $text .= "<topic>".$this->topic."</topic>\n"; |
354 // --- book meta data --- | 392 // --- book meta data --- |
355 $book = $this->book_meta; | 393 $book = $this->book_meta; |
394 | |
395 $text .= "<book>\n"; | |
396 $text .= "<id>".$book->id."</id>\n"; | |
397 $text .= "<name>".$book->name."</name>\n"; | |
398 $text .= "<level1>".$book->level1."</level1>\n"; | |
399 $text .= "<level2>".$book->level2."</level2>\n"; | |
400 $text .= "<period>".$book->period."</period>\n"; | |
401 $text .= "<dynasty>".$book->dynasty."</dynasty>\n"; | |
402 $text .= "<start_year>".$book->start_year."</start_year>\n"; | |
403 $text .= "<end_year>".$book->end_year."</end_year>\n"; | |
404 $text .= "<line>".$book->line."</line>\n"; | |
405 $text .= "<volume>".$book->volume."</volume>\n"; | |
406 $text .= "<author>".$book->author."</author>\n"; | |
407 $text .= "<edition>".$book->edition."</edition>\n"; | |
408 $text .= "<in_jibengujiku>".$book->in_jibengujiku."</in_jibengujiku>\n"; | |
409 $text .= "<admin_type>".$book->admin_type."</admin_type>\n"; | |
410 | |
411 $text .= "<place_name>".$book->place_name."</place_name>\n"; | |
412 $text .= "<x>".$book->x."</x>\n"; | |
413 $text .= "<y>".$book->y."</y>\n"; | |
414 $text .= "</book>\n"; | |
415 | |
416 /* | |
356 foreach ($book as $b) { | 417 foreach ($book as $b) { |
357 $text .= "<book>\n"; | 418 $text .= "<book>\n"; |
358 $text .= "<id>".$b[0]."</id>\n"; | 419 $text .= "<id>".$b[0]."</id>\n"; |
359 $text .= "<name>".$b[1]."</name>\n"; | 420 $text .= "<name>".$b[1]."</name>\n"; |
360 $text .= "<level1>".$b[2]."</level1>\n"; | 421 $text .= "<level1>".$b[2]."</level1>\n"; |
370 $text .= "<in_jibengujiku>".$b[12]."</in_jibengujiku>\n"; | 431 $text .= "<in_jibengujiku>".$b[12]."</in_jibengujiku>\n"; |
371 $text .= "<admin_type>".$b[13]."</admin_type>\n"; | 432 $text .= "<admin_type>".$b[13]."</admin_type>\n"; |
372 $text .= "</book>\n"; | 433 $text .= "</book>\n"; |
373 | 434 |
374 } | 435 } |
436 */ | |
437 | |
375 // --- section info --- | 438 // --- section info --- |
376 $text .= "<section>\n"; | 439 $text .= "<section>\n"; |
377 $text .= "<id>".$this->section_id."</id>\n"; | 440 $text .= "<id>".$this->section_id."</id>\n"; |
378 $text .= "<name>".$this->section_name."</name>\n"; | 441 $text .= "<name>".$this->section_name."</name>\n"; |
379 $text .= "</section>\n"; | 442 $text .= "</section>\n"; |
1084 private function GetTopicTag($topic_id) { | 1147 private function GetTopicTag($topic_id) { |
1085 $result = $this->GetTopicById($topic_id); | 1148 $result = $this->GetTopicById($topic_id); |
1086 $row = mysql_fetch_assoc($result); | 1149 $row = mysql_fetch_assoc($result); |
1087 $tag = $row['tag']; | 1150 $tag = $row['tag']; |
1088 return $tag; | 1151 return $tag; |
1089 | |
1090 } | 1152 } |
1091 private function GetTopicName($topic_id) { | 1153 private function GetTopicName($topic_id) { |
1092 $result = $this->GetTopicById($topic_id); | 1154 $result = $this->GetTopicById($topic_id); |
1093 $row = mysql_fetch_assoc($result); | 1155 $row = mysql_fetch_assoc($result); |
1094 //$name = $row['name']; | 1156 //$name = $row['name']; |
1095 $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']); | 1157 $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']); |
1096 return $name; | 1158 return $name; |
1097 | 1159 } |
1098 } | 1160 private function GetTopicTagName($topic_id) { |
1161 $topic_tag = $this->GetTopicTag($topic_id); | |
1162 $query = "SELECT * FROM `taglist` WHERE tag='".$topic_tag."'"; | |
1163 $result = mysql_query($query); | |
1164 $row = mysql_fetch_assoc($result); | |
1165 | |
1166 return $row['name']; | |
1167 } | |
1168 | |
1169 | |
1099 | 1170 |
1100 | 1171 |
1101 // =========================== | 1172 // =========================== |
1102 | 1173 |
1103 // === for manage wordlist === | 1174 // === for manage wordlist === |
1288 $section_info = $this->GetSectionInfo(); | 1359 $section_info = $this->GetSectionInfo(); |
1289 | 1360 |
1290 $bookId = $section_info['bookId']; | 1361 $bookId = $section_info['bookId']; |
1291 $startPage = $section_info['startPage']; | 1362 $startPage = $section_info['startPage']; |
1292 $endPage = $section_info['endPage']; | 1363 $endPage = $section_info['endPage']; |
1364 $this->section_name = $section_info['sectionName']; | |
1365 | |
1293 | 1366 |
1294 $contentString=""; | 1367 $contentString=""; |
1295 $data_path = $this->GetDataPath(); | 1368 $data_path = $this->GetDataPath(); |
1296 if ( file_exists($data_path."parsing_files/".$section_id.".txt") ) { | 1369 if ( file_exists($data_path."parsing_files/".$section_id.".txt") ) { |
1297 $filename = $data_path."parsing_files/".$section_id.".txt"; | 1370 $filename = $data_path."parsing_files/".$section_id.".txt"; |