Mercurial > hg > extraction-interface
changeset 11:3d6fba07bfbd
implemented for topic tag. tagging with topic tag (main tag) indicating each row when export to html.
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 11 Feb 2015 12:33:59 +0100 |
parents | 54a235d43694 |
children | e82ca7375e93 |
files | develop/classes/basemodel.php develop/controllers/extractapp.php develop/data/parsing_files/10078.txt develop/js/taggingtext.js develop/models/extractapp.php develop/views/Extractapp/taggingtext.php |
diffstat | 6 files changed, 103 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/develop/classes/basemodel.php Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/classes/basemodel.php Wed Feb 11 12:33:59 2015 +0100 @@ -98,6 +98,14 @@ return $result; } + protected function GetTopicByID($topic_id) { + $query = sprintf("SELECT * FROM `topics` WHERE id=\"%s\"", $topic_id); + $result = mysql_query($query); + if (!$result) { + return json_encode("Failed during selecting topics table."); + } + return $result; + } }
--- a/develop/controllers/extractapp.php Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/controllers/extractapp.php Wed Feb 11 12:33:59 2015 +0100 @@ -18,6 +18,7 @@ if ($this->postdata['topic']) { $viewmodel->SetTopic($this->postdata['topic']); } + // TODO: get the _post data from Jorge's service $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); break; } @@ -66,7 +67,17 @@ } - + protected function ConfigTagsInTopic() { + $viewmodel = new ExtractappModel(); + switch ($this->postdata['func']) { + case '': + + break; + default: + $this->ReturnView($viewmodel->ConfigTagsInTopic($this->urlvalues,$this->postdata), false); + break; + } + } protected function TestAction() { $viewmodel = new ExtractappModel();
--- a/develop/data/parsing_files/10078.txt Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/data/parsing_files/10078.txt Wed Feb 11 12:33:59 2015 +0100 @@ -1,4 +1,7 @@ -【829】南陵縣志卷十七 職官志 秦改封建為郡縣縣置令或長 漢<jiguan>縣置令或長一</jiguan><null>人</null> 縣萬户為令秩工石至六百石減 萬户為長秩五百石至三百石掌 治民顯善勸義禁姦罰惡理訟平賊恤 □時務秋冬集課上計於所屬郡國 <jiguan>丞一</jiguan><null>人</null> 貳 漢制 丞<jiguan>尉縣多以本部</jiguan><null>人</null>為之秩四百 石至二百石丞署文書典知倉獄 <jiguan>主簿一</jiguan><null>人</null> 佐 令 長自調 用 <jiguan>尉大縣二</jiguan><null>人</null><jiguan>餘一</jiguan><null>人</null> 圭捕盜賊 察姦宄 諸曹椽史有秩三 老 掌教 化 +【829】南陵縣志卷十七 職官志 秦改封建為郡縣縣置令或長 漢<jiguan>縣置令或長一</jiguan><null>人</null> 縣萬户為令秩工石至六百石減 +〈萬户為長秩五百石至三百石掌〉 治民 +<object>顯善勸</object>義禁姦罰惡理訟平賊恤 □時<place>務秋</place>冬集課上計於所屬郡國 <jiguan>丞一</jiguan><null>人</null> 貳 漢制 丞<jiguan>尉縣多以本部</jiguan><null>人</null>為之 +<object>秩</object>四百 石至二百石丞署文書典知倉獄 <place>主簿一人</place> 佐 令 <species>長自調</species> 用 <jiguan>尉大縣二</jiguan><null>人</null><jiguan>餘一</jiguan><null>人</null> 圭捕盜賊 察姦宄 諸曹椽史有秩三 老 掌教 化 游徼 循禁 姦盜 嗇夫 主知民情 平其差品 鄕佐 主收 賦稅 亭長 主 捕 盜 賊 里魁 掌察一里善 惡 並幕屬 吳官制書闕無考縣令佐貳大率多沿漢制 【830】晉縣大者置令小者置長縣佐有主簿 省 丞 錄事史記室 史門下書佐幹游徼議生循行功曹史廷椽户曹法 曹金倉賊曹椽兵曹賊捕椽等員又縣五百户以上 置一鄕 三千以上二鄕五千 以上三鄕萬置四鄕 <jiguan>鄕置嗇夫一</jiguan><null>人</null>縣率百 <jiguan>户置里吏一</jiguan><null>人</null><jiguan>户千置校官一</jiguan><null>人</null> 南北朝宋縣大者為令小為長有簿有尉 尉大縣 <jiguan>二</jiguan><null>人</null> 鄕有 鄕佐 五家為伍有伍長二伍為什有什長十什 為里有里魁十里為亭有亭長十亭為鄕 三老 有秩<jiguan>嗇夫游徼各一</jiguan><null>人</null>齊梁陳略同 隋縣為令或長其下為丞簿尉 煬帝時嘗改 尉為縣正 廢鄕官 開 皇 初經部授 <post_time>十五</post_time><post_time>年</post_time>罷 【831】<jiguan>唐上縣令一</jiguan><null>人</null><jiguan>丞一人主簿一</jiguan><null>人</null><jiguan>縣尉二</jiguan><null>人</null><jiguan>餘縣一</jiguan><null>人</null> 自令以下並以縣上中下分品 武德初改尉曰正尋復稱尉 司户佐司法佐各一 人 貞觀初縣置 錄事後省 經學<jiguan>博士助教各一</jiguan><null>人</null> 宋<jiguan>縣置知縣事一</jiguan><null>人</null> 初用京朝官以重民社之寄其後 參用幕職及試銜官而令選猥下 天聖中詔為舉法以重令選慶歷紹興屢嚴其制乾 道<post_time>二</post_time><post_time>年</post_time>御筆非兩任縣令不除察御史而其職始 重 <jiguan>丞一人主簿一</jiguan><null>人</null><jiguan>尉大邑二</jiguan><null>人</null><jiguan>餘一</jiguan><null>人</null> 宋初無丞 天聖中始 於赤縣置丞小 邑以簿兼之 鎭砦官無定員 元<jiguan>縣達魯花赤一</jiguan><null>人</null><jiguan>尹一人丞一</jiguan><null>人</null><jiguan>簿一</jiguan><null>人</null>尉典史各 <jiguan>一人教諭一</jiguan><null>人</null> 書院有 山長 <jiguan>訓導一</jiguan><null>人</null> 按元史百官志 無訓導官未詳 巡 檢稅務使無定<jiguan>員又有直學一</jiguan><null>人</null> 見學 宮碑
--- a/develop/js/taggingtext.js Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/js/taggingtext.js Wed Feb 11 12:33:59 2015 +0100 @@ -361,6 +361,13 @@ range.insertNode(newdiv); var newdiv = document.createElement("br"); range.insertNode(newdiv); + } else if (tag=="object2") { + var newdiv = document.createElement("object"); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + } else { var newdiv = document.createElement(tag); newdiv.innerHTML = stringSelection; @@ -707,7 +714,7 @@ } } -function exportAll(section_id) { +function exportAll(section_id, topic_id) { var el = document.getElementById("editable-area"); var str="" + el.innerHTML; var form = document.createElement("form"); @@ -721,11 +728,18 @@ hiddenField.setAttribute("value", str); form.appendChild(hiddenField); + var hiddenField2 = document.createElement("input"); + hiddenField2.setAttribute("name", "topic"); + hiddenField2.setAttribute("value", topic_id); + form.appendChild(hiddenField2); + console.log(topic_id); + + /* var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "sectionid"); hiddenField.setAttribute("value", section_id); form.appendChild(hiddenField); - + */ if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { document.body.appendChild(form);
--- a/develop/models/extractapp.php Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/models/extractapp.php Wed Feb 11 12:33:59 2015 +0100 @@ -13,6 +13,7 @@ private function Initialize($_urlvalues) { $this->SetSectionId($_urlvalues); + } // === for tagging === @@ -42,6 +43,7 @@ $data['section_id'] = $section_id; $data['topiclistArray'] = $topiclistArray; $data['default_topic_id'] = $this->GetTopic(); + $data['topic_tag'] = $this->GetTopicTag($this->GetTopic()); return $data; @@ -76,8 +78,8 @@ public function ExportTable($urlvalues, $postdata) { $this->Initialize($urlvalues); $content = $postdata['content']; + $topic = $postdata['topic']; - // outputTableArray: $section_id = $this->GetSectionId(); @@ -91,8 +93,10 @@ $outputTableArray = array(); - $taglistArray = $this->GetTaglistArray(); + //$taglistArray = $this->GetTaglistArray(); + $taglistArray = $this->GetTaglistByTopicID($topic); + $outputTableArray[0]=array(); $outputTableArray[0][0]=array(); $outputTableArray[0][1]=array(); @@ -151,11 +155,29 @@ $value = preg_replace("/</u", "<", $value); $outputTableArray[$count]["full"] = $value; } + /* + echo "<br>"."DEBUG: outputTableArray:"."<br>"; + var_dump($outputTableArray); + */ foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { - if ( !isset($arrayValue[0]["person"]) ) { - unset($outputTableArray[$arrayIndex]); + // output each row which the topic tag + // e.g. the original version is for 'person' + + // TODO: choose topic tag based on the topic + // for person topic + if ($topic == 1) { + if ( !isset($arrayValue[0]["person"]) ) { + unset($outputTableArray[$arrayIndex]); + } + } else if ($topic == 2) { + + // for object topic + if ( !isset($arrayValue[0]["object"]) ) { // only the record with the tag of 'object' will become a row + unset($outputTableArray[$arrayIndex]); + } } + } @@ -240,7 +262,9 @@ } // === for config topic === - + public function ConfigTagsInTopic($urlvalues, $postdata) { + + } private function GetTaglistByTopicID($topic_id) { $taglistArray = array(); @@ -284,11 +308,20 @@ $topiclistArray = array(); $result = $this->GetTopiclist(); while ($row = mysql_fetch_assoc($result)) { - array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'])); + array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'],'tag'=>$row['tag'])); } return $topiclistArray; } + + private function GetTopicTag($topic_id) { + $result = $this->GetTopicByID($topic_id); + $row = mysql_fetch_assoc($result); + $tag = $row['tag']; + return $tag; + + } + // =========================== // === for manage wordlist === @@ -469,7 +502,6 @@ } return $taglistArray; - } private function GetWordlistArray() {
--- a/develop/views/Extractapp/taggingtext.php Tue Feb 10 16:20:29 2015 +0100 +++ b/develop/views/Extractapp/taggingtext.php Wed Feb 11 12:33:59 2015 +0100 @@ -6,6 +6,7 @@ $section_id = $viewmodel['section_id']; $topiclistArray = $viewmodel['topiclistArray']; $default_topic_id = $viewmodel['default_topic_id']; +$topic_tag = $viewmodel['topic_tag']; ?> @@ -141,15 +142,31 @@ // for pop up window on edit-area for tag list newdiv.innerHTML = "Tag: "+String(selection)+"<br>"; + <?php + foreach ( $taglistArray as $taglistValue ) { + if ($taglistValue[2] == $topic_tag) { + echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">[TopicTag]Tag as:".$taglistValue[1]."(necessary for this topic!)</button>\";\n"; + echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n"; + echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; + break; + } + } + ?> + newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>"; <?php - foreach ( $taglistArray as $taglistValue ) { - if ( $taglistValue[2] == "person") { + + foreach ( $taglistArray as $taglistValue ) { + /* + if ( $taglistValue[2] == "person") { echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n"; echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; - } else if ($taglistValue[2] == "post_time") { + } else */ + if ($taglistValue[2] == $topic_tag) { + // pass + } else if ($taglistValue[2] == "post_time") { echo "newdiv.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; } else if ($taglistValue[2] == "office") { @@ -158,7 +175,8 @@ } else { echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; - } + } + } ?> } @@ -348,7 +366,7 @@ </div> <form action="javascript:void(0);"> <button onclick="chooseTopic(<?php echo $section_id;?>, <?php echo $default_topic_id; ?>)">Choose Topic</button> - + <button onclick="window.open('../ConfigTagsInTopic/<?php echo $section_id;?>')" style="height: 30px; width: 220px">Config Tag List For Topic</button></br> <fieldset> <legend>Replace By <i><b>Smart Regex</b></i>©:</legend> <div id="smartRegexShowDiv"></div><br> @@ -384,7 +402,7 @@ <legend>Export:</legend> Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br> <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br> - <button onclick="exportAll(<?php echo $section_id;?>)" style="height: 30px; width: 220px">Export All</button></br> + <button onclick="exportAll(<?php echo $section_id;?>,<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export All</button></br> </fieldset> <fieldset>