# HG changeset patch # User Zoe Hong diff -r 4b3da4802998 -r 8347776a44fc develop/data/parsing_files/1.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/develop/data/parsing_files/1.txt Sun Mar 08 22:28:21 2015 +0100 @@ -0,0 +1,49 @@ + + + 2 + + 南陵縣志 + qwer + 1999 + 333 + + + + 2 + 人名 + person + rgb(8, 148, 255) + + + 29 + 入仕時間 + entry_time + rgb(174, 179, 39) + + + 31 + 物產名稱 + product_name + rgb(227, 63, 227) + + + + + 【102】 契本工課鈔肆貫 +物産 按淳属嚴郡爲 +〈古揚州之境〉而其物産之見於經 者曰陽鳥攸居而已曰篠簜既敷而已曰厥草惟 夭厥木惟喬而已固今日諸郡縣之所同而非止 嚴陵属縣爲然也謹擇其有資於民生服食噐用 +者載焉 +〈糓〉〈糓〉 秔 +〈糓〉有 +〈糓〉早稻 +〈糓〉晚稻 +〈糓〉紅稻 +〈糓〉白稻 + +〈糯〉〈糯〉有 +〈糯〉秋糯 +〈糯〉晩糯 + + + + \ No newline at end of file diff -r 4b3da4802998 -r 8347776a44fc develop/models/extractapp.php --- a/develop/models/extractapp.php Fri Mar 06 17:56:48 2015 +0100 +++ b/develop/models/extractapp.php Sun Mar 08 22:28:21 2015 +0100 @@ -8,7 +8,8 @@ return array("Index Value 1", "Value 2", "Value 3"); } - protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; + protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, + $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0, $taglist_infile = "", $book_meta = ""; public $messages = ""; private function Initialize($_urlvalues) { @@ -193,26 +194,49 @@ */ + private function Taglist_infileUpToDate($taglistArray) { + // compare $this->taglist_infile is the same as $taglistArray + $taglist_infile = $this->taglist_infile; + if (count($taglist_infile) != count($taglistArray)) { + return false; + } + foreach ($taglistArray as $row_indb) { + foreach ($taglist_infile as $row) { + //$taglistArray: array( $row['id'], $row['name'], $row['tag'], $row['color'] ) + if ($row[0] == $row_indb[0] && $row[1] == $row_indb[1] && $row[2] == $row_indb[2] && $row[3] == $row_indb[3]) { + + } else { + return false; + } + } + } + return true; + } // === for tagging === public function StartTagging() { - // $this->Initialize($urlvalues); - $section_id = $this->section_id; $stringInput = $this->lg_text; - + + $data = array(); // data array to be passed to view //$taglistArray = $this->GetTaglistArray(); //for GetTaglistByTopicID: $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); + + // TODO: check if taglist_infile is up-to-date + if ( !$this->Taglist_infileUpToDate($taglistArray)) { + $data['taglist_infile'] = $this->taglist_infile; + } + + // topic list $topiclistArray = $this->GetTopiclistArray(); $wordlistArray = $this->GetWordlistArray(); - $data = array(); $data['stringInput'] = $stringInput; $data['taglistArray'] = $taglistArray; $data['wordlistArray'] = $wordlistArray; @@ -1119,6 +1143,31 @@ return $data; } + private function ParseMetaData($filename) { + $text = file_get_contents($filename); + $xml = simplexml_load_string($text) or die("Error: Cannot load from xml string"); + + $this->topic = $xml->topic; // set topic id + + // get taglist in file + $taglist_infile = $xml->taglist; + $taglistArray = array(); + foreach ($taglist_infile as $row) { + array_push($taglistArray, array((string)$row->id, (string)$row->name, (string)$row->tag, (string)$row->color)); + } + $this->taglist_infile = $taglistArray; + + // TODO: get meta data of book + $this->book_meta = $xml->book; + + // echo $taglist->name.", ".$taglist->tag."," .$taglist->color; + // --- detect if the taglist set is up-to-date or not --- + + + $contentString = $xml->text_content->asXML(); + + return $contentString; + } private function GetSectionContent() { $section_id = $this->GetSectionId(); $section_info = $this->GetSectionInfo(); @@ -1130,8 +1179,10 @@ $contentString=""; $data_path = $this->GetDataPath(); if ( file_exists($data_path."parsing_files/".$section_id.".txt") ) { - $contentString=file_get_contents($data_path."parsing_files/".$section_id.".txt"); - $stringInput = $contentString; + $filename = $data_path."parsing_files/".$section_id.".txt"; + // --- parsing meta data + $stringInput = $this->ParseMetaData($filename); + // ---- // if the text is from file system $stringInput = preg_replace("/ /u", "○", $stringInput); diff -r 4b3da4802998 -r 8347776a44fc develop/views/Extractapp/TaggingText.php --- a/develop/views/Extractapp/TaggingText.php Fri Mar 06 17:56:48 2015 +0100 +++ b/develop/views/Extractapp/TaggingText.php Sun Mar 08 22:28:21 2015 +0100 @@ -11,6 +11,7 @@ $info = $viewmodel['info']; $messages = $viewmodel['messages']; +$taglist_infile = $viewmodel['taglist_infile']; ?> @@ -61,7 +62,7 @@ if (_GET['id']) { var info = JSON.parse(''); - var redirectUrl = "http://localhost:1080/localmonographs/develop/Extractapp/TaggingText"; + var redirectUrl = "http://localhost:1080/extraction-interface/develop/Extractapp/TaggingText"; var section_id = info['section_id']; var form = $('
' + @@ -71,6 +72,18 @@ $(form).submit(); } // ==== +// --- check if taglist in file is up-to-date --- +var check_taglist = JSON.parse(''); +if (check_taglist) { + // TODO: pop up to ask if load the latest taglist + var retVal = confirm("The tag list in the file is not up-to-date. \nDo you want to load file with new tag list?"); + if( retVal == true ){ + + alert("Load with new tag list."); + }else{ + alert("You are using the old version of tag list."); + } +}