changeset 86:0141df465205 extractapp_dev

New: add chinese characters to pinyin
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 30 Apr 2015 10:52:05 +0200
parents 966a36752c34
children fb5049fc5dd7
files controllers/extractapp.php css/taggingtext.css models/extractapp.php views/Extractapp/TaggingText.php views/maintemplate.php views/maintemplate_local.php
diffstat 6 files changed, 162 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/controllers/extractapp.php	Thu Apr 23 17:08:31 2015 +0200
+++ b/controllers/extractapp.php	Thu Apr 30 10:52:05 2015 +0200
@@ -66,11 +66,20 @@
                 $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;   
             case 'SaveFullTextToLGService':
-                $viewmodel->messages['info'] .= "SaveFullTextToLGService! ";
-                $viewmodel->SetInfoFromPreviousPage($this->postdata);
-                $response = $viewmodel->SaveFullTextToLGService($this->postdata);
-                $viewmodel->UpdateInfoResponsedFromLGService($response);    // update file_id, branch_id, user_id
-                $viewmodel->SetTextFromFileId();     
+                global $AT_LOCAL;
+                if ($AT_LOCAL) {
+                    $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) ";
+                    $viewmodel->SetInfoFromPreviousPage($this->postdata);
+                    $response = $viewmodel->SaveFullTextToLGService($this->postdata);
+                    
+                } else {
+
+                    $viewmodel->messages['info'] .= "SaveFullTextToLGService! ";
+                    $viewmodel->SetInfoFromPreviousPage($this->postdata);
+                    $response = $viewmodel->SaveFullTextToLGService($this->postdata);
+                    $viewmodel->UpdateInfoResponsedFromLGService($response);    // update file_id, branch_id, user_id
+                    $viewmodel->SetTextFromFileId();     
+                }
                 $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;
 
--- a/css/taggingtext.css	Thu Apr 23 17:08:31 2015 +0200
+++ b/css/taggingtext.css	Thu Apr 30 10:52:05 2015 +0200
@@ -13,6 +13,23 @@
 .bg-default{
 	background-color: #F4F4F4;
 }
+.btn-xs{
+	height: 25px;
+	width: 60px;
+}
+.btn-sm{
+	height: 35px; 
+	width: 70px;
+}
+.btn-md{
+	height: 35px;
+	width: 110px;
+}
+.btn-lg{
+	height: 35px; 
+	width: 220px;
+}
+
 
 .info-board{
 	margin:10 30 10 30;
--- a/models/extractapp.php	Thu Apr 23 17:08:31 2015 +0200
+++ b/models/extractapp.php	Thu Apr 30 10:52:05 2015 +0200
@@ -76,11 +76,38 @@
         $section_meta = json_decode(file_get_contents($section_meta_url), true);
 
         $b = $section_meta['section']['book'];
-
+        
+        $this->book_name = $b['name'];
+        $this->book_id = $b['id'];
+        /*
         $book_meta = array();
         array_push($book_meta, array($b['id'],$b['name'],$b['level1'],$b['level2'],
                     $b['period'],$b['dynasty'], $b['start_year'], $b['end_year'],$b['line'],
                     $b['volume'],$b['author'], $b['edition'],$b['in_jibengujiku'], $b['admin_type']));    // missing author,year,pagenumber
+        */
+        /*
+        $book_meta = array('id'=>$b['id'],'name'=>$b['name'],'level1'=>$b['level1'],'level2'=>$b['level2'],
+                    'period'=>$b['period'],'dynasty'=>$b['dynasty'],'start_year'=>$b['start_year'], 'end_year'=>$b['end_year'],'line'=>$b['line'],
+                    'volume'=>$b['volume'],'author'=>$b['author'],'edition'=>$b['edition'],
+                    'in_jibengujiku'=>$b['in_jibengujiku'],'admin_type'=>$b['admin_type']);    // missing author,year,pagenumber
+        */
+
+        $book_meta->id = $b['id'];
+        $book_meta->name = $b['name'];
+        $book_meta->level1 = $b['level1'];
+        $book_meta->level2 = $b['level2'];
+        $book_meta->period = $b['period'];
+        $book_meta->dynasty = $b['dynasty'];
+        $book_meta->start_year = $b['start_year'];
+        $book_meta->end_year = $b['end_year'];
+        $book_meta->line = $b['line'];
+        $book_meta->volume = $b['volume'];
+        $book_meta->author = $b['author'];
+        $book_meta->edition = $b['edition'];
+        $book_meta->in_jibengujiku = $b['in_jibengujiku'];
+        $book_meta->admin_type = $b['admin_type'];
+
+
         $this->book_meta = $book_meta;
 
     }
@@ -213,7 +240,7 @@
         return true;
        
     }
-
+    
     // === for tagging ===
     public function StartTagging() {
         /**
@@ -229,7 +256,7 @@
         //$taglistArray = $this->GetTaglistArray();
         //for GetTaglistByTopicId: 
         $taglistArray = $this->GetTaglistByTopicId($this->GetTopic());
-        
+
         // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided
         // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file.
         if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) {    // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not
@@ -253,13 +280,16 @@
         $data['section_id'] = $section_id;
         $data['topiclistArray'] = $topiclistArray;
         $data['default_topic_id'] = $this->GetTopic();
-        $data['topic_tag'] = $this->GetTopicTag($this->GetTopic());
-        $data['topic_name'] = $this->GetTopicName($this->GetTopic());
+        $topic_id = $this->GetTopic();
+
+        $data['topic_tag'] = $this->GetTopicTag($topic_id);
+        $data['topic_name'] = $this->GetTopicName($topic_id);
+        $data['topic_tag_ch'] = $this->GetTopicTagName($topic_id);
 
 
         $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id,
                 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 
-                'book_name'=>$this->book_name, 'section_name'=>$this->section_name,
+                'book_name'=>$this->book_name,'section_name'=>$this->section_name, 'period'=>$this->book_meta->period,
                 'current_fileId'=>$this->current_fileId);
 
         $this->messages['debug'] .= "[Debug] ";
@@ -272,6 +302,7 @@
         $this->messages['info'] .= ", section id: ". $this->section_id;
         $this->messages['info'] .= ", branch id: ".$this->branch_id;
         $this->messages['info'] .= ", file id: ".$this->file_id;
+        $this->messages['info'] .= ", period: ".$this->book_meta->period;
         $this->messages['info'] .= "<br>";
 
 
@@ -308,10 +339,9 @@
 
     public function UpdateInfoResponsedFromLGService($response) {
         /**
-         *
+         * 
          */
 
-
         if (isset($response["file"])) {
             $response_file = $response["file"];
         }
@@ -353,6 +383,26 @@
         $text .= "<topic>".$this->topic."</topic>\n";
         // --- book meta data ---
         $book = $this->book_meta;
+       
+        $text .= "<book>\n";
+        $text .= "<id>".$book->id."</id>\n";
+        $text .= "<name>".$book->name."</name>\n";
+        $text .= "<level1>".$book->level1."</level1>\n";
+        $text .= "<level2>".$book->level2."</level2>\n";
+        $text .= "<period>".$book->period."</period>\n";
+        $text .= "<dynasty>".$book->dynasty."</dynasty>\n";
+        $text .= "<start_year>".$book->start_year."</start_year>\n";
+        $text .= "<end_year>".$book->end_year."</end_year>\n";
+        $text .= "<line>".$book->line."</line>\n";
+        $text .= "<volume>".$book->volume."</volume>\n";
+        $text .= "<author>".$book->author."</author>\n";
+        $text .= "<edition>".$book->edition."</edition>\n";
+        $text .= "<in_jibengujiku>".$book->in_jibengujiku."</in_jibengujiku>\n";
+        $text .= "<admin_type>".$book->admin_type."</admin_type>\n";
+        $text .= "</book>\n";
+        
+   
+        /*
         foreach ($book as $b) {
             $text .= "<book>\n";
             $text .= "<id>".$b[0]."</id>\n";
@@ -372,6 +422,8 @@
             $text .= "</book>\n";
             
         }
+        */ 
+
         // --- section info ---
         $text .= "<section>\n";
         $text .= "<id>".$this->section_id."</id>\n";
@@ -1086,7 +1138,6 @@
         $row = mysql_fetch_assoc($result);
         $tag = $row['tag'];
         return $tag;
-
     }
     private function GetTopicName($topic_id) {
         $result = $this->GetTopicById($topic_id);
@@ -1094,10 +1145,19 @@
         //$name = $row['name'];
         $name = array('name_en'=>$row['name_en'], 'name_ch'=>$row['name_ch'], 'name_pinyin'=>$row['name_pinyin']);
         return $name;
+    }
+    private function GetTopicTagName($topic_id) {
+        $topic_tag = $this->GetTopicTag($topic_id);
+        $query = "SELECT * FROM `taglist` WHERE tag='".$topic_tag."'";
+        $result = mysql_query($query);
+        $row = mysql_fetch_assoc($result);
 
+        return $row['name'];
     }
 
 
+
+
     // =========================== 
 
     // === for manage wordlist ===
@@ -1290,6 +1350,8 @@
         $bookId = $section_info['bookId'];
         $startPage = $section_info['startPage'];
         $endPage = $section_info['endPage'];
+        $this->section_name = $section_info['sectionName'];
+
 
         $contentString="";
         $data_path = $this->GetDataPath();
--- a/views/Extractapp/TaggingText.php	Thu Apr 23 17:08:31 2015 +0200
+++ b/views/Extractapp/TaggingText.php	Thu Apr 30 10:52:05 2015 +0200
@@ -40,6 +40,7 @@
 $default_topic_id = $viewmodel['default_topic_id'];
 $topic_name = $viewmodel['topic_name']; // array of names
 $topic_tag = $viewmodel['topic_tag'];
+$topic_tag_ch = $viewmodel['topic_tag_ch'];
 $info = $viewmodel['info']; 
 $messages = $viewmodel['messages'];
 
@@ -53,7 +54,9 @@
 <head>
     <meta charset="UTF-8">
     <title>Extraction Interface</title>
-
+    <meta http-equiv="no-cache">
+    <meta http-equiv="Expires" content="-1">
+    <meta http-equiv="Cache-Control" content="no-cache">
 <style>
 dynasty
 {
@@ -91,6 +94,8 @@
 
 <script type="text/javascript">
 
+var cjst = window.cjst; // for pinyin from cjst.js
+
 // not use this for now
 function _showTagColor(up_to_date) {
     var taglistArray = "";
@@ -335,14 +340,14 @@
                 newdiv.innerHTML += "<button onclick=\"removeTagTitle( range, container )\">Remove</button></br>";
             } else {
      			// for pop up window on edit-area for tag list
-                newdiv.innerHTML = "Tag: "+String(selection)+"<br>";
+                newdiv.innerHTML = "Tagging word: "+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 accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
+                        echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(without new line)</button>\";\n";
                         echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
                         
                         /*
@@ -637,6 +642,7 @@
     var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
 
     // if this is a new branch, ask for label
+    // if (info['branch_id'] == 0) {
     if (info['branch_id'] == 0) {
         //var label = prompt("Please enter your label for this new branch", "section"+info['section_id']);
         var today = new Date();
@@ -651,11 +657,23 @@
             mm='0'+mm
         } 
         today = dd+'.'+mm+'.'+yyyy;
-        var label = prompt("Please enter your label for this new branch", today);
+        var book_name = info['book_name'];
+        var section_name = info['section_name'];
+        var period = info['period'];
+
+        var default_label = "";
+        if (book_name == "" || section_name == "" || period == "") {
+            default_label = today;
+        } else {
+            default_label = book_name+"("+cjst.chineseToPinyin(book_name).join(' ')+")_"+period+ "_"+section_name
+                        + "("+ cjst.chineseToPinyin(section_name).join(' ') + ")_" + today;
+        }
+        
+
+        var label = prompt("Please enter your label for this new branch", default_label);
         while (label == null) {
             alert("You haven't saved your editing.");
             return;
-            // label = prompt("Please enter your label for this new branch (not empty)", "section"+info['section_id']);
         }    
     };
     
@@ -780,6 +798,7 @@
     hiddenField.setAttribute("name", "book_meta");
     var book_metaObj = JSON.parse('<?php echo json_encode($book_meta) ?>');
     book_metaArray = JSON.stringify(book_metaObj);
+
     hiddenField.setAttribute("value", book_metaArray);
     form.appendChild(hiddenField);    
 
@@ -882,6 +901,7 @@
     }
 });
 
+
 </script>
  
 <div id="dialog-form" title="config tags for topic" style="position:fixed; top: 30px; ">
@@ -896,7 +916,7 @@
     <div class="bg-default"> <?php echo $messages['debug']; ?> </div>
 </div>
 
-<table border="1" style="margin:10 30 30 30; width:100%; max-width:1270px">
+<table border="1" style="margin:10 30 30 30; width:100%; max-width:1270px; min-width:680px">
     <tr>
         <td style="padding:0 5 0 5; margin: 0 5 0 5;">
             <div id="editable-area" class="area" style="max-width:980px; min-width:400px"><?php echo $stringInput; ?></div>
@@ -941,58 +961,66 @@
             <div id="follow-scroll">
                 <form action="javascript:void(0);">   
                     <fieldset>
-                        <legend><h5 class="text-success"> Config Topic: </h5></legend>
-                        <div> current topic is: <?php echo $topic_name['name_en']; ?> <br>
+                        <legend><h5 class="text-success"> Topic: </h5></legend>
+                        <div> Current topic is: <br> 
+                            <?php echo $topic_name['name_en']; ?> 
                             (<?php echo $topic_name['name_ch']; ?>, <?php echo $topic_name['name_pinyin']; ?>)
-                            <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn btn-xs btn-default">Change</button>
+                            <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn-xs">Change</button>
                         </div>
-                        <button onclick="configTagsInTopic(<?php echo $default_topic_id;?>)" class="btn btn-sm btn-default" style="">Manage Tags in topic</button></br>
+                        <div>The topic tag is: <?php echo $topic_tag_ch;?>(<?php echo $topic_tag;?>)</div>
                     </fieldset>
 
                     <fieldset>
                         <legend><h5 class="text-success"> Replace By <i><b>Smart Regex</b></i>©: </h5></legend>
                         <div id="smartRegexShowDiv"></div><br>
-                        <button onclick="smartRegexNew()" style="height: 35px; width: 220px">Add Regex Group</button></br>
+                        <!-- <button onclick="smartRegexNew()" class="btn-lg">Add Regex Group</button></br>
+                        -->
+                        <button onclick="smartRegexNew()" class="btn-lg">Search by Patterns (Smart Regex)</button></br>
                         Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br>
-                        <button onclick="replaceSmartRun()" style="height: 35px; width: 100px">Run</button>
-                        <button onclick="replaceSmartRunWithBr()" style="height: 35px; width: 100px">Run(with Br)</button></br>
-                        <button onclick="replaceSmartRunSpace()" style="height: 35px; width: 220px">Run(Allow space between Group)</button></br>
-                        <button onclick="smartRegexSave(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 70px">Save</button>
-                        <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 70px">Load</button>
-                        <button onclick="smartRegexEmpty()" style="height: 35px; width: 70px">Clear</button></br>
+                        <button onclick="replaceSmartRun()" class="btn-sm">Run</button>
+                        <button onclick="replaceSmartRunWithBr()" class="btn-md">Run(in new line)</button></br>
+                        <!-- <button onclick="replaceSmartRunSpace()" class="btn-lg">Run(Allow space between Group)</button></br>
+                        -->
+                        <button onclick="replaceSmartRunSpace()" class="btn-lg">Run(Allow space between block)</button></br>
+                        <button onclick="smartRegexSave(<?php echo $default_topic_id; ?>)" class="btn-sm">Save</button>
+                        <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" class="btn-sm">Load</button>
+                        <button onclick="smartRegexEmpty()" class="btn-sm">Clear</button></br>
                     </fieldset>
                     
                     <fieldset>
                         <legend><h5 class="text-success"> Tag by rule:</h5></legend>
-                        <button onclick="tagNameWithLastName()" style="height: 35px; width: 220px">Tag Word Begin With Surname</button></br>
+                        <button onclick="tagNameWithLastName()" class="btn-lg">Tag Word Begin With Surname</button></br>
                         <button onclick="tagNameWithLastName2()" style="height: 35px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
                         <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>-->
                         <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>-->
-                        <button onclick="Undo()" style="height: 35px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
+                        <button onclick="Undo()" class="btn-lg" id="buttonUndo" disabled="true">Undo</button>
                     </fieldset>
-                
+                                    
+                    <fieldset>
+                        <legend><h5 class="text-success"> Save:</h5></legend>
+                        <button onclick="saveTextToLGService()" id="saveTextToLGService_id" class="btn-lg">Save to LGService</button></br>
+                    </fieldset>
+                                    
                     <fieldset>
                         <legend><h5 class="text-success"> Edit:</h5></legend>
-
-                        <button onclick="saveTextToLGService()" id="saveTextToLGService_id" style="height: 35px; width: 220px">Save to LGService</button></br>
-                    
                         <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
                         <!-- save text in local. replaced by saveTextToLGService, which is also saving on copy in local in development stage -->
                         <!-- 
                         <button onclick="saveText(<?php echo $section_id; ?>)" style="height: 30px; width: 220px">Save the text</button></br>
                         -->
 
-                        <button onclick="editText()" id="editTextId" style="height: 35px; width: 220px">Edit the text</button></br>
+                        <button onclick="editText()" id="editTextId" class="btn-lg">Edit the text</button></br>
                         </br>
-                        <button onclick="window.open('./EditWordlist')" style="height: 35px; width: 220px">Manage Word List</button></br>
-                        <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 220px">Manage Tag List</button></br>
+                        <button onclick="window.open('./EditWordlist')" class="btn-lg">Edit Word List</button></br>
+                        <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" class="btn-lg">Edit Tag List</button></br>
+                        <button onclick="configTagsInTopic(<?php echo $default_topic_id;?>)" class="btn-lg">Select Existing Tags</button></br>
                     </fieldset>
                     
                     <fieldset>
                         <legend><h5 class="text-success"> Export:</h5></legend>
-                        Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br>
-                        <button onclick="exportPage(<?php echo $default_topic_id;?>)" style="height: 35px; width: 220px">Export</button></br>
-                        <button onclick="exportAll(<?php echo $default_topic_id;?>)" style="height: 35px; width: 220px">Export All</button></br>
+                        Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd">
+                        <button onclick="exportPage(<?php echo $default_topic_id;?>)" class="btn-sm">Export</button></br>
+                        <button onclick="exportAll(<?php echo $default_topic_id;?>)" class="btn-lg">Export All</button></br>
                     </fieldset>
                 
                     <fieldset>
--- a/views/maintemplate.php	Thu Apr 23 17:08:31 2015 +0200
+++ b/views/maintemplate.php	Thu Apr 30 10:52:05 2015 +0200
@@ -4,6 +4,7 @@
 <script src="../js/jquery-1.10.2.min.js"></script>
 <script src="../js/jquery-ui.js"></script>
 <script src="../js/taggingtext.js"></script>
+<script src="../js/cjst.js"></script>
 <link href="../css/taggingtext.css" rel="stylesheet">
 
 </head>
--- a/views/maintemplate_local.php	Thu Apr 23 17:08:31 2015 +0200
+++ b/views/maintemplate_local.php	Thu Apr 30 10:52:05 2015 +0200
@@ -4,6 +4,7 @@
 <script src="../../js/jquery-1.10.2.min.js"></script>
 <script src="../../js/jquery-ui.js"></script>
 <script src="../../js/taggingtext.js"></script>
+<script src="../../js/cjst.js"></script>
 <link href="../../css/taggingtext.css" rel="stylesheet">
 
 </head>