Mercurial > hg > extraction-interface
comparison models/extractapp.php @ 94:b0cecc104639 extractapp
new: modified tags can work on tagged text
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Mon, 09 Nov 2015 12:00:24 +0100 |
| parents | 3e11a9c5a672 |
| children | 9a29e9d28ece |
comparison
equal
deleted
inserted
replaced
| 93:a05491461199 | 94:b0cecc104639 |
|---|---|
| 248 return true; | 248 return true; |
| 249 | 249 |
| 250 } | 250 } |
| 251 | 251 |
| 252 // === for tagging === | 252 // === for tagging === |
| 253 private function ReplaceLgTextWithLatestTag() { | |
| 254 // modify $this->lg_text with the latest tags from database | |
| 255 // can do it by getting the tag's id using tag's information in the file, then by the id to get latest tag (in db) | |
| 256 $lg_text = $this->lg_text; | |
| 257 | |
| 258 $taglist_indb = $this->GetTaglistByTopicId($this->GetTopic()); | |
| 259 $taglist_infile = $this->taglist_infile; | |
| 260 | |
| 261 if ($taglist_infile == "") return; | |
| 262 | |
| 263 $count_tag_indb = count($taglist_indb); | |
| 264 | |
| 265 foreach ($taglist_infile as $t1) { | |
| 266 $id = $t1[0]; | |
| 267 $tag = $t1[2]; | |
| 268 $latest_tag = ""; | |
| 269 | |
| 270 $cnt = 0; | |
| 271 foreach ($taglist_indb as $t2) { | |
| 272 if ($t2[0] == $id) { | |
| 273 $latest_tag = $t2[2]; | |
| 274 } | |
| 275 | |
| 276 if ($tag != $t2[2]) { | |
| 277 // not match with this t2 | |
| 278 $cnt += 1; | |
| 279 } else { | |
| 280 break; | |
| 281 } | |
| 282 | |
| 283 } | |
| 284 if ($cnt == $count_tag_indb) { | |
| 285 if ($latest_tag == "") { | |
| 286 // tag has been deleted in the db | |
| 287 // delele the tag in $this->lg_text | |
| 288 //echo "tag been deleted"; | |
| 289 | |
| 290 $lg_text = preg_replace("/<\/".$tag.">/u", "", $lg_text); | |
| 291 $lg_text = preg_replace("/<".$tag.">/u", "", $lg_text); | |
| 292 | |
| 293 } else { | |
| 294 // replace all tags $tag into $latest_tag in $this->lg_text | |
| 295 //echo "replace tag: ".$tag." into ".$latest_tag."<br>"; | |
| 296 $lg_text = preg_replace("/".$tag."/u", $latest_tag, $lg_text); | |
| 297 } | |
| 298 } | |
| 299 } | |
| 300 | |
| 301 | |
| 302 $this->lg_text = $lg_text; | |
| 303 | |
| 304 } | |
| 253 public function StartTagging() { | 305 public function StartTagging() { |
| 254 /** | 306 /** |
| 255 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view. | 307 * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view. |
| 256 * The information contain the text string, taglist array, wordlis array, topic, etc. | 308 * The information contain the text string, taglist array, wordlis array, topic, etc. |
| 257 */ | 309 */ |
| 258 | 310 |
| 259 $section_id = $this->section_id; | 311 $section_id = $this->section_id; |
| 260 $stringInput = $this->lg_text; | 312 |
| 261 | |
| 262 $data = array(); // data array to be passed to view | 313 $data = array(); // data array to be passed to view |
| 263 | 314 |
| 264 //$taglistArray = $this->GetTaglistArray(); | |
| 265 //for GetTaglistByTopicId: | 315 //for GetTaglistByTopicId: |
| 266 $taglistArray = $this->GetTaglistByTopicId($this->GetTopic()); | 316 $taglistArray = $this->GetTaglistByTopicId($this->GetTopic()); |
| 267 | 317 |
| 268 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided | 318 // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided |
| 269 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. | 319 // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. |
| 270 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not | 320 if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not |
| 271 $this->taglist_infile = ""; | 321 $this->taglist_infile = ""; |
| 272 } | 322 |
| 323 } else { | |
| 324 // taglist_infile is out-to-date | |
| 325 // replace all the old tag with new ones in database | |
| 326 // replace old tags for $this->lg_text with the latest tags from db | |
| 327 $this->ReplaceLgTextWithLatestTag(); | |
| 328 | |
| 329 } | |
| 330 $stringInput = $this->lg_text; | |
| 331 | |
| 332 | |
| 273 $data['taglist_infile'] = $this->taglist_infile; // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file | 333 $data['taglist_infile'] = $this->taglist_infile; // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file |
| 274 | |
| 275 | 334 |
| 276 // book_meta | 335 // book_meta |
| 277 $data['book_meta'] = $this->book_meta; | 336 $data['book_meta'] = $this->book_meta; |
| 278 | 337 |
| 279 // topic list | 338 // topic list |
| 422 $text .= "</section>\n"; | 481 $text .= "</section>\n"; |
| 423 | 482 |
| 424 // ---- taglist --- | 483 // ---- taglist --- |
| 425 // $taglist = $this->taglist_infile; | 484 // $taglist = $this->taglist_infile; |
| 426 // obtain the latest taglist from db | 485 // obtain the latest taglist from db |
| 486 // TDOO: possible bug: when taglist is modified by other user, the latest taglist from db of course will be changed. | |
| 487 // As the result, here the taglist we get from db will be inconsistent with the tag in file. | |
| 488 // which means the information in <tagitem> nodes are inconsistent with the text in <text_content> node. | |
| 489 | |
| 427 $taglist = $this->GetTaglistByTopicId($this->GetTopic()); | 490 $taglist = $this->GetTaglistByTopicId($this->GetTopic()); |
| 428 | 491 |
| 429 foreach ($taglist as $tagitem) { | 492 foreach ($taglist as $tagitem) { |
| 430 $text .= "<tagitem>\n"; | 493 $text .= "<tagitem>\n"; |
| 431 $text .= "<id>".$tagitem[0]."</id>\n"; | 494 $text .= "<id>".$tagitem[0]."</id>\n"; |
| 873 | 936 |
| 874 } | 937 } |
| 875 | 938 |
| 876 public function DeleteTag($postdata) { | 939 public function DeleteTag($postdata) { |
| 877 if ($postdata['id']) { | 940 if ($postdata['id']) { |
| 878 $queryInsert = sprintf("DELETE FROM `taglist` WHERE `id` = %s", stripslashes($postdata['id'])); | 941 $tag_id = $postdata['id']; |
| 879 $resultInsert = mysql_query($queryInsert); | 942 |
| 880 } | 943 // delete record in 'taglist' table |
| 881 | 944 $query = sprintf("DELETE FROM `taglist` WHERE `id` = %s", stripslashes($tag_id)); |
| 945 $result = mysql_query($query); | |
| 946 | |
| 947 // delete record in 'topic_tag_relation' table | |
| 948 $topic_id = $postdata['topic_id']; | |
| 949 $query = sprintf("DELETE FROM `topic_tag_relation` WHERE `tag_id` = %s and `topic_id` = %s", stripslashes($tag_id), stripcslashes($topic_id)); | |
| 950 $result = mysql_query($query); | |
| 951 | |
| 952 } | |
| 953 | |
| 882 } | 954 } |
| 883 | 955 |
| 884 // === for config topic === | 956 // === for config topic === |
| 885 public function ConfigTagsInTopic($postdata) { | 957 public function ConfigTagsInTopic($postdata) { |
| 886 /** | 958 /** |
| 972 $data['tag_others'] = $tag_others; | 1044 $data['tag_others'] = $tag_others; |
| 973 | 1045 |
| 974 return $data; | 1046 return $data; |
| 975 } | 1047 } |
| 976 | 1048 |
| 1049 public function CreateNewTopic($_postdata) { | |
| 1050 | |
| 1051 | |
| 1052 } | |
| 977 | 1053 |
| 978 public function UpdateTagsInTopic($_postdata) { | 1054 public function UpdateTagsInTopic($_postdata) { |
| 979 $topic_id = $_postdata['topic_id']; | 1055 $topic_id = $_postdata['topic_id']; |
| 980 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); | 1056 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); |
| 981 | 1057 |
| 1305 if ($book_metaArray) { | 1381 if ($book_metaArray) { |
| 1306 $this->book_meta = $book_metaArray; | 1382 $this->book_meta = $book_metaArray; |
| 1307 } | 1383 } |
| 1308 */ | 1384 */ |
| 1309 // ----- | 1385 // ----- |
| 1310 // TODO: get section_id, section_name from file | 1386 // get section_id, section_name from file |
| 1311 if ($this->section_id == 0 && isset($xml->section)) { | 1387 if ($this->section_id == 0 && isset($xml->section)) { |
| 1312 if ($xml->section) { | 1388 if ($xml->section) { |
| 1313 $this->section_id = (string)$xml->section->id; | 1389 $this->section_id = (string)$xml->section->id; |
| 1314 $this->section_name = (string)$xml->section->name; | 1390 $this->section_name = (string)$xml->section->name; |
| 1315 } | 1391 } |
| 1324 | 1400 |
| 1325 $contentString = (string)($xml->text_content->asXML()); | 1401 $contentString = (string)($xml->text_content->asXML()); |
| 1326 | 1402 |
| 1327 $removed_str = array("<text_content>","</text_content>"); | 1403 $removed_str = array("<text_content>","</text_content>"); |
| 1328 $new_contentString = str_replace($removed_str, "", $contentString); | 1404 $new_contentString = str_replace($removed_str, "", $contentString); |
| 1405 | |
| 1329 | 1406 |
| 1330 return $new_contentString; | 1407 return $new_contentString; |
| 1331 } | 1408 } |
| 1332 | 1409 |
| 1333 | 1410 |
