Mercurial > hg > extraction-interface
comparison develop/models/extractapp.php @ 42:c245d54eab9f extractapp
config lg server url, without port
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Thu, 12 Mar 2015 17:33:30 +0100 |
| parents | 533a6c39c128 |
| children | 3d6b8fb7335d |
comparison
equal
deleted
inserted
replaced
| 41:533a6c39c128 | 42:c245d54eab9f |
|---|---|
| 382 } | 382 } |
| 383 public function SaveFullTextToLGService($_postdata) { | 383 public function SaveFullTextToLGService($_postdata) { |
| 384 // save tagged text (full text) by Jorge's API to lg service | 384 // save tagged text (full text) by Jorge's API to lg service |
| 385 | 385 |
| 386 // -------- | 386 // -------- |
| 387 if ($_postdata['text']){ | 387 if ($_postdata['text']){ |
| 388 $date = date('Y_m_d_H_i_s', time()); | 388 $date = date('Y_m_d_H_i_s', time()); |
| 389 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { | 389 if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) { |
| 390 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); | 390 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt"); |
| 391 //saving in my local machine in developing phrase | 391 //saving in my local machine in developing phrase |
| 392 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); | 392 file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile); |
| 402 $require = preg_replace('/&/u', "&", $require); | 402 $require = preg_replace('/&/u', "&", $require); |
| 403 $require = preg_replace("/○/u", " ", $require); | 403 $require = preg_replace("/○/u", " ", $require); |
| 404 $require = preg_replace("/<br>/u", "\n", $require); | 404 $require = preg_replace("/<br>/u", "\n", $require); |
| 405 //$require = preg_replace("/<br>/u", "\n", $require); | 405 //$require = preg_replace("/<br>/u", "\n", $require); |
| 406 | 406 |
| 407 // TODO: append metadata at the beginning of file | |
| 408 if ($_postdata['branchId'] == 0) { | 407 if ($_postdata['branchId'] == 0) { |
| 409 // -- new branch case | 408 // -- new branch case |
| 410 $require = "<text_content>\n".$require."</text_content>\n"; | 409 $require = "<text_content>\n".$require."</text_content>\n"; |
| 411 } | 410 } |
| 412 $require = $this->AppendMetaData($require); | 411 $require = $this->AppendMetaData($require); |
| 413 | 412 |
| 414 //saving in my local machine in developing phrase | 413 //saving in my local machine in developing phrase |
| 415 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); | 414 //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require); |
| 416 } | 415 } |
| 417 | 416 |
| 418 // ------ | 417 // ------ |
| 419 | 418 |
| 420 | 419 |
| 429 $save_url = $this->save_to_LGService_url; | 428 $save_url = $this->save_to_LGService_url; |
| 430 | 429 |
| 431 } else { | 430 } else { |
| 432 // -- new branch case | 431 // -- new branch case |
| 433 echo "saveNew!"; | 432 echo "saveNew!"; |
| 433 $user_id = "0"; | |
| 434 if ($_postdata['userId']) { | 434 if ($_postdata['userId']) { |
| 435 $user_id = $_postdata['userId']; | 435 $user_id = $_postdata['userId']; |
| 436 } else { | 436 } |
| 437 $user_id = "12"; | 437 |
| 438 } | |
| 439 $postfields = array( | 438 $postfields = array( |
| 440 "text" => $require, | 439 "text" => $require, |
| 441 "sectionId" => $_postdata['sectionId'], | 440 "sectionId" => $_postdata['sectionId'], |
| 442 "userId" => $user_id, | 441 "userId" => $user_id, |
| 443 "label" => $_postdata['label'], | 442 "label" => $_postdata['label'], |
| 1194 return $data; | 1193 return $data; |
| 1195 } | 1194 } |
| 1196 | 1195 |
| 1197 private function ParseMetaData($filename) { | 1196 private function ParseMetaData($filename) { |
| 1198 $text = file_get_contents($filename); | 1197 $text = file_get_contents($filename); |
| 1199 $xml = simplexml_load_string($text) or die("Error: Cannot load from xml string"); | 1198 $xml = simplexml_load_string($text); //or die("Error: Cannot load from xml string"); |
| 1199 if (!$xml) { | |
| 1200 // when file created by section_id, read the plain text from file_get_contents | |
| 1201 return $text; | |
| 1202 } | |
| 1200 | 1203 |
| 1201 $this->topic = (string)$xml->topic; // set topic id | 1204 $this->topic = (string)$xml->topic; // set topic id |
| 1202 | 1205 |
| 1203 // get taglist in file | 1206 // get taglist in file |
| 1204 $taglist_infile = $xml->tagitem; | 1207 $taglist_infile = $xml->tagitem; |
