Mercurial > hg > extraction-interface
comparison develop/models/extractapp.php @ 24:b55f5d3564c4
add some regular expressions and wordlist for topic ??
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Fri, 27 Feb 2015 16:35:59 +0100 |
| parents | a879f6b9d166 |
| children | 4b6d2d7e706e |
comparison
equal
deleted
inserted
replaced
| 23:a879f6b9d166 | 24:b55f5d3564c4 |
|---|---|
| 200 $response_file = $response["file"]; | 200 $response_file = $response["file"]; |
| 201 $response_branch = $response["branch"]; | 201 $response_branch = $response["branch"]; |
| 202 | 202 |
| 203 $this->file_id = (string)$response_file["id"]; | 203 $this->file_id = (string)$response_file["id"]; |
| 204 $this->branch_id = (string)$response_branch["id"]; | 204 $this->branch_id = (string)$response_branch["id"]; |
| 205 | 205 |
| 206 $this->messages .= "file_id: ".$this->file_id."<br>"; | 206 //$this->messages .= "file_id: ".$this->file_id."<br>"; |
| 207 $this->messages .= "branch_id: ".$this->branch_id."<br>"; | 207 //$this->messages .= "branch_id: ".$this->branch_id."<br>"; |
| 208 | 208 |
| 209 } | 209 } |
| 210 public function SaveFullTextToLGService($_postdata) { | 210 public function SaveFullTextToLGService($_postdata) { |
| 211 // save tagged text (full text) by Jorge's API to lg service | 211 // save tagged text (full text) by Jorge's API to lg service |
| 212 | 212 |
| 595 | 595 |
| 596 } | 596 } |
| 597 | 597 |
| 598 // === for config topic === | 598 // === for config topic === |
| 599 public function ConfigTagsInTopic($postdata) { | 599 public function ConfigTagsInTopic($postdata) { |
| 600 | 600 $topic = $postdata['topic']; |
| 601 $result = $this->GetTopicByID($topic); | |
| 602 $row = mysql_fetch_assoc($result); | |
| 603 $topic_name = $row['name']; | |
| 604 | |
| 605 /* | |
| 601 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; | 606 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; |
| 602 $result = mysql_query($query); | 607 $result = mysql_query($query); |
| 603 if (!$result) { | 608 if (!$result) { |
| 604 return json_encode("Failed during selecting/joining taglist and topic_tag_relation table."); | 609 return json_encode("Failed during selecting/joining taglist and topic_tag_relation table."); |
| 605 } | 610 } |
| 606 $taglistArray = array(); | 611 $taglistArray = array(); |
| 607 while ($row = mysql_fetch_assoc($result)) { | 612 while ($row = mysql_fetch_assoc($result)) { |
| 608 array_push($taglistArray, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); | 613 array_push($taglistArray, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); |
| 609 } | 614 } |
| 610 | 615 */ |
| 611 $topic = $postdata['topic']; | |
| 612 $result = $this->GetTopicByID($topic); | |
| 613 $row = mysql_fetch_assoc($result); | |
| 614 $topic_name = $row['name']; | |
| 615 | |
| 616 $data = array(); | |
| 617 $data['taglistArray'] = $taglistArray; | |
| 618 $data['topic'] = $topic; | |
| 619 $data['topic_name'] = $topic_name; | |
| 620 | |
| 621 | |
| 622 | |
| 623 | 616 |
| 624 // ------ | 617 // ------ |
| 625 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; | 618 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; |
| 626 $result = mysql_query($query); | 619 $result = mysql_query($query); |
| 627 if (!$result) { | 620 if (!$result) { |
| 637 } else { | 630 } else { |
| 638 array_push($tag_tmp_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); | 631 array_push($tag_tmp_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); |
| 639 } | 632 } |
| 640 } | 633 } |
| 641 | 634 |
| 642 // check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags | 635 // --- check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags |
| 643 $num_others = count($tag_tmp_others); | 636 $num_others = count($tag_tmp_others); |
| 644 for ($i=0; $i < $num_others; $i++) { | 637 for ($i=0; $i < $num_others; $i++) { |
| 645 $cnt = 0; | 638 $cnt = 0; |
| 646 for ($j=$i+1; $j < $num_others; $j++) { | 639 for ($j=$i+1; $j < $num_others; $j++) { |
| 647 if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) { | 640 if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) { |
| 654 $row = $tag_tmp_others[$i]; | 647 $row = $tag_tmp_others[$i]; |
| 655 array_push($tag_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); | 648 array_push($tag_others, array('id'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id']) ); |
| 656 } | 649 } |
| 657 } | 650 } |
| 658 | 651 |
| 659 // remove duplicated tags in tag_others that is duplicated with tags in tag_intopic | 652 // --- remove duplicated tags in tag_others that is duplicated with tags in tag_intopic |
| 660 $tag_tmp_others = $tag_others; | 653 $tag_tmp_others = $tag_others; |
| 661 $tag_others = array(); | 654 $tag_others = array(); |
| 662 | 655 |
| 663 foreach ($tag_tmp_others as $tmp) { | 656 foreach ($tag_tmp_others as $tmp) { |
| 664 $cnt = 0; | 657 $cnt = 0; |
| 673 // not appear in $tag_intopic | 666 // not appear in $tag_intopic |
| 674 array_push($tag_others, $tmp); | 667 array_push($tag_others, $tmp); |
| 675 } | 668 } |
| 676 } | 669 } |
| 677 | 670 |
| 671 // ----- | |
| 672 | |
| 673 | |
| 674 $data = array(); | |
| 675 //$data['taglistArray'] = $taglistArray; | |
| 676 $data['topic'] = $topic; | |
| 677 $data['topic_name'] = $topic_name; | |
| 678 | 678 |
| 679 $data['tag_intopic'] = $tag_intopic; | 679 $data['tag_intopic'] = $tag_intopic; |
| 680 $data['tag_others'] = $tag_others; | 680 $data['tag_others'] = $tag_others; |
| 681 | 681 |
| 682 return $data; | 682 return $data; |
| 886 $date = date('Y_m_d_H_i_s', time()); | 886 $date = date('Y_m_d_H_i_s', time()); |
| 887 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { | 887 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { |
| 888 $filename = "data/wordlist/".$postdata['filename']."_".$date.".txt"; | 888 $filename = "data/wordlist/".$postdata['filename']."_".$date.".txt"; |
| 889 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt"); | 889 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt"); |
| 890 file_put_contents($filename, $oldFile); | 890 file_put_contents($filename, $oldFile); |
| 891 } else { | 891 } |
| 892 /*else { | |
| 892 $filename = "data/wordlist/".$postdata['filename'].".txt"; | 893 $filename = "data/wordlist/".$postdata['filename'].".txt"; |
| 893 } | 894 } |
| 895 */ | |
| 894 | 896 |
| 895 | 897 |
| 896 if (get_magic_quotes_gpc()) { | 898 if (get_magic_quotes_gpc()) { |
| 897 $require = stripslashes($postdata['text']); | 899 $require = stripslashes($postdata['text']); |
| 898 } else { | 900 } else { |
| 899 $require = $postdata['text']; | 901 $require = $postdata['text']; |
| 900 } | 902 } |
| 901 | 903 |
| 902 $require = preg_replace("/<br>/u", "<br>", $require); | 904 $require = preg_replace("/<br>/u", "<br>", $require); |
| 903 file_put_contents($filename, $require); | 905 file_put_contents("data/wordlist/".$postdata['filename'].".txt", $require); |
| 904 } | 906 } |
| 905 /* | 907 /* |
| 906 if ($postdata['text']){ | 908 if ($postdata['text']){ |
| 907 $date = date('Y_m_d_H_i_s', time()); | 909 $date = date('Y_m_d_H_i_s', time()); |
| 908 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { | 910 if ( file_exists("data/wordlist/".$postdata['filename'].".txt") ) { |
| 1038 | 1040 |
| 1039 private function GetWordlistArray() { | 1041 private function GetWordlistArray() { |
| 1040 $wordlistArray=""; | 1042 $wordlistArray=""; |
| 1041 $result = $this->GetWordlist(); | 1043 $result = $this->GetWordlist(); |
| 1042 while ($row = mysql_fetch_assoc($result)) { | 1044 while ($row = mysql_fetch_assoc($result)) { |
| 1043 $listString = file_get_contents("wordlist/".$row['id'].".txt"); | 1045 $listString = file_get_contents("data/wordlist/".$row['id'].".txt"); |
| 1044 $listString = preg_replace("/<div>/u", "\n", $listString); | 1046 $listString = preg_replace("/<div>/u", "\n", $listString); |
| 1045 $listString = preg_replace("/<\/div>/u", "", $listString); | 1047 $listString = preg_replace("/<\/div>/u", "", $listString); |
| 1046 $listString = preg_replace("/<span(.*?)>/u", "", $listString); | 1048 $listString = preg_replace("/<span(.*?)>/u", "", $listString); |
| 1047 $listString = preg_replace("/<\/span>/u", "", $listString); | 1049 $listString = preg_replace("/<\/span>/u", "", $listString); |
| 1048 //$listString = preg_replace("/\n/u", "|", $listString); | 1050 //$listString = preg_replace("/\n/u", "|", $listString); |
