Ejemplo n.º 1
0
 protected function get_feature(Annotation $annotation)
 {
     $feature = $annotation->get_scopes()->get_anchor_speech();
     return $feature;
 }
Ejemplo n.º 2
0
 function anchor_speech()
 {
     $url = 'http://www.plurk.com/p/67k6st#response-1739920625';
     $text1 = '[CODING D17] 晚上睡覺時天氣、室溫、冷氣、電扇、被子的厚度與蓋的方法,組合起來就可以預測隔天會不會一整天過敏。但我還沒有明顯地分辨出他們的關聯。';
     $text2 = '變項太多,這回歸的組合也不知道要排到什麼時候orz';
     $note = '「西瓜牛奶去冰的話可能沒有滿杯喔」由於店員這樣說,所以我改口跟他說不用去冰好了……結果還是一樣沒有滿杯orz';
     $email = '*****@*****.**';
     $scope1 = $this->annotation_scope->create_scope(3, 20, $text1, $url);
     $scope2 = $this->annotation_scope->create_scope(26, 40, $text2, $url);
     $scope_coll = new Annotation_scope_collection();
     $scope_coll->add_scope($scope1);
     $scope_coll->add_scope($scope2);
     $user = $this->user->create_user($url, $email);
     $annotation = $this->annotation->create_annotation($user, $scope_coll);
     $annotation_cache = get_cache($annotation, 'annotation_id', $annotation->get_id());
     if (isset($annotation_cache)) {
         //如果有開啟cache才跑這幾項
         $this->unit->run($annotation_cache, $annotation, '測試取出cache');
         $this->unit->run($annotation->get_scopes()->get_anchor_speech(), $annotation_cache->get_scopes()->get_anchor_speech(), '$annotation跟$annotation_cache的get_scopes應該要是一樣的');
     }
     $scope_coll2 = $annotation->get_scopes();
     $annotation->update();
     $id = $annotation->get_id();
     $annotation2 = new Annotation($id);
     $scope_coll3 = $annotation2->get_scopes();
     $this->unit->run($scope_coll3->length(), $scope_coll2->length(), '取出$annotation2之後,測試scopes的id是否相同?');
     $this->unit->run($scope_coll3->get_anchor_speech(), $scope_coll2->get_anchor_speech(), '取出$annotation2之後,測試scopes的get_anchor_speech()');
     $this->unit->run(count($scope_coll2->get_anchor_speech()) > 0, TRUE, 'count($scope_coll2->get_anchor_speech()) > 0');
     $this->unit->run(count($scope_coll3->get_anchor_speech()) > 0, TRUE, 'count($scope_coll3->get_anchor_speech()) > 0');
     unit_test_report($this, __METHOD__);
 }
Ejemplo n.º 3
0
    function scope_consensus()
    {
        $title = __FUNCTION__;
        $this->_display_header($title);
        // ---------
        $social_function = array(0 => 0, 1 => 68.41493131999999, 2 => 82.31058928, 3 => 89.40518387, 4 => 91.31036774, 5 => 92.55095258999999, 7 => 94.7275144, 8 => 97.06468764, 9 => 1);
        /*$sentence_index = array(0,142,199,256,314,402,473,530,663,667,790,932,1035,1193,1255,1340,1419,1444,1463,1503,1564,1636,1664,1689,1716,1742,1871,1921,1989,2019,2108,2217,2295,2422,2557,2718,2791,2916,3032,3079,3146,3197,3213,3226,3239,3266,3313,3411,3604,3640,3854,3922,3980,4068,4082,4201,4285,4387,4497,4500,4526,4590,4653,4679,4727,4764,4796,4803,4812,4820,4829,4836,4845,4858,4893,4903,4913,4961,4969,5017,5044,5052,5120,5148,5156,5210,5279,5307,5316,5333,5384,5433,5529,5563,5595,5674,5718,5789,5854,5920,5955,5985,6027,6055,6090,6165,6238,6432,6520,6535,6553,6608,6639,6796,6836,7042,7046,7086,7104,7144,7246,7284,7292,7328,7361,7419,7427,7485,7564,7572,7607,7637,7724,7732,7821,7903,7969,7988,8065,8074,8166,8198,8233,8276,8368,8396,8549,8618,8648,8684,8743,8823,8857,8891,8920,8997,9025,9107,9118,9139,9153,9178,9187,9189,9199,9208,9211,9218,9247,9267,9275,9280,9283,9286,9290,9292,9299,9306,9313,9319,9334,9337,9350,9355,9358,9362,9370,9382,9385,9392,9401,9404,9408,9415,9421,9427,9439,9448,9451,9455,9462,9468,9495,9499,9505,9508,9511,9515,9529,9536,9557,9561,9568,9575,9582,9588,9598,9612,9615,9684,9736,9900,18,74,76,682,686,695,1266,1509,1748,2570,2805,3331,3422,3663,3737,3766,3774,4091,5226,5241,5324,5339,5443,5798,6180,6258,6289,6308,6319,6353,6654,6846,6893,6929,6970,6974,7158,7159,7166,7171,7207,7827,8280,9111,9617,9688,9711,9746,9762,9796,9816,9851,9873,9909);
          sort($sentence_index);
          echo '$sentence_index = array(';
          foreach ($sentence_index AS $s)
          {
              echo $s.',';
          }
          echo ');<br />';
           * 
           */
        $sentence_index = array(0, 18, 74, 76, 142, 199, 256, 314, 402, 473, 530, 663, 667, 682, 686, 695, 790, 932, 1035, 1193, 1255, 1266, 1340, 1419, 1444, 1463, 1503, 1509, 1564, 1636, 1664, 1689, 1716, 1742, 1748, 1871, 1921, 1989, 2019, 2108, 2217, 2295, 2422, 2557, 2570, 2718, 2791, 2805, 2916, 3032, 3079, 3146, 3197, 3213, 3226, 3239, 3266, 3313, 3331, 3411, 3422, 3604, 3640, 3663, 3737, 3766, 3774, 3854, 3922, 3980, 4068, 4082, 4091, 4201, 4285, 4387, 4497, 4500, 4526, 4590, 4653, 4679, 4727, 4764, 4796, 4803, 4812, 4820, 4829, 4836, 4845, 4858, 4893, 4903, 4913, 4961, 4969, 5017, 5044, 5052, 5120, 5148, 5156, 5210, 5226, 5241, 5279, 5307, 5316, 5324, 5333, 5339, 5384, 5433, 5443, 5529, 5563, 5595, 5674, 5718, 5789, 5798, 5854, 5920, 5955, 5985, 6027, 6055, 6090, 6165, 6180, 6238, 6258, 6289, 6308, 6319, 6353, 6432, 6520, 6535, 6553, 6608, 6639, 6654, 6796, 6836, 6846, 6893, 6929, 6970, 6974, 7042, 7046, 7086, 7104, 7144, 7158, 7159, 7166, 7171, 7207, 7246, 7284, 7292, 7328, 7361, 7419, 7427, 7485, 7564, 7572, 7607, 7637, 7724, 7732, 7821, 7827, 7903, 7969, 7988, 8065, 8074, 8166, 8198, 8233, 8276, 8280, 8368, 8396, 8549, 8618, 8648, 8684, 8743, 8823, 8857, 8891, 8920, 8997, 9025, 9107, 9111, 9118, 9139, 9153, 9178, 9187, 9189, 9199, 9208, 9211, 9218, 9247, 9267, 9275, 9280, 9283, 9286, 9290, 9292, 9299, 9306, 9313, 9319, 9334, 9337, 9350, 9355, 9358, 9362, 9370, 9382, 9385, 9392, 9401, 9404, 9408, 9415, 9421, 9427, 9439, 9448, 9451, 9455, 9462, 9468, 9495, 9499, 9505, 9508, 9511, 9515, 9529, 9536, 9557, 9561, 9568, 9575, 9582, 9588, 9598, 9612, 9615, 9617, 9684, 9688, 9711, 9736, 9746, 9762, 9796, 9816, 9851, 9873, 9900, 9909);
        $this->load->library('search/Search_annotation_user_collection');
        $this->load->library('search/Search_annotation_id_collection');
        $query = $this->db->select('"user".user_id, email, annotation.annotation_id, score')->from('annotation
, "user", webpage2annotation, score')->where('annotation.user_id = "user".user_id
AND webpage2annotation.annotation_id = annotation.annotation_id
AND webpage_id = ' . $this->obs_webpage_id . '
AND annotation.topic_id IS NULL
AND annotation.deleted IS FALSE
AND annotation.create_timestamp > \'' . $this->obs_date_from . '\'
AND annotation.create_timestamp < \'' . $this->obs_date_to . '\'
AND score.annotation_id = annotation.annotation_id
AND score.score_type_id = 1')->where('email ' . $this->in_email)->order_by('email')->get();
        $consensus_count = array();
        $annotation_count = array();
        $consensus_max = array();
        $consensus_min = array();
        $total_count = 0;
        $total_annotation_count = 0;
        $total_max = 0;
        $total_min = NULL;
        $freq_count = array();
        $freq_total = 0;
        $comp_count = array();
        $comp_total = 0;
        $thead = array('受試者', '閱讀理解分數', '閱讀理解分數高低分組_1低_2高', '標註編號', '標註範圍共識', '專家調查', '加權社群行為', '範圍位置', '以句為單位的共識次數');
        $tbody = array();
        foreach ($query->result_array() as $row) {
            $email = $row['email'];
            $annotation_id = intval($row['annotation_id']);
            $annotation = new Annotation($annotation_id);
            $count = $annotation->get_consensus_count();
            /**
             * 來計算以句子為單位的共識
             * @author Pudding Chen 20121228
             */
            //取得標註的位置
            $scopes = $annotation->get_scopes();
            foreach ($scopes as $scope) {
                $from_index = intval($scope->get_from_index());
                $to_index = intval($scope->get_to_index());
            }
            //擴張標註的位置
            $sentence_from_index = null;
            $sentence_to_index = null;
            $last_s_index = 0;
            //if ($from_index != 1)
            //    continue;
            foreach ($sentence_index as $s => $s_index) {
                //先判斷句子開頭
                if (is_null($sentence_from_index)) {
                    if ($from_index == 0) {
                        $sentence_from_index = 0;
                    } else {
                        if ($from_index < $s_index) {
                            $sentence_from_index = $last_s_index;
                        }
                    }
                }
                if ($to_index < $s_index) {
                    //echo $to_index.'-'.$s_index.'!<br />';
                    //{
                    //$set_next_s_index = true;
                    //$sentence_to_index = $last_s_index;
                    $sentence_to_index = $s_index;
                    break;
                    //}
                }
                //echo '['.$s.":".$from_index.'-'.$to_index.'-'.$s_index.'-'.$last_s_index.'|'.$sentence_from_index.'-'.$sentence_to_index.'?'.($sentence_from_index == null).'-'.($to_index < $s_index).']<br />';
                $last_s_index = $s_index;
            }
            //找完了,範圍是
            //$sentense_from_index
            //$sentense_to_index
            //建立搜尋範圍
            $s = new Annotation_scope();
            //$s->set_index($sentence_from_index, $sentence_to_index);
            $s->set_index($from_index, $to_index);
            $s->set_webpage($this->obs_webpage_id);
            $sentence_search_scope = new Annotation_scope_collection();
            $sentence_search_scope->add_scope($s);
            //echo $sentence_search_scope->length().'-'.$this->obs_webpage_id.'|';
            $sentence_consensus_count = '--';
            //if ($from_index == 1)
            //{
            $search = new Search_annotation_user_collection();
            //只算人頭
            $search->set_check_authorize(false);
            $search->set_limit(NULL);
            $search->set_overlap_scope($sentence_search_scope);
            $search->set_exclude_annotation($annotation_id);
            $search->set_exclude_user($annotation->get_user());
            $search->set_target_newer_create($this->obs_epoch_from);
            $search->set_target_older_create($this->obs_epoch_to);
            $search->set_target_topic(true);
            $sentence_consensus_count = $search->length();
            /*
                            $this->unit->run($search->length()
                            , 0
                            , '測試搜尋 '. $annotation_id . ': '. $sentence_from_index.'-'.$from_index.'-'.$to_index.'-'.$sentence_to_index);
            */
            /*
                        }
                        else
                        {
                            //continue;
                        }*/
            if (isset($consensus_count[$email]) == false) {
                $consensus_count[$email] = 0;
                $annotation_count[$email] = 0;
                $consensus_max[$email] = 0;
                $consensus_min[$email] = $count;
            }
            $annotation_count[$email]++;
            $consensus_count[$email] += $count;
            if ($count > $consensus_max[$email]) {
                $consensus_max[$email] = $count;
            }
            if ($count < $consensus_min[$email]) {
                $consensus_min[$email] = $count;
            }
            $total_annotation_count++;
            $total_count += $count;
            if ($count > $total_max) {
                $total_max = $count;
            }
            if ($total_min == NULL || $count < $total_min) {
                $total_min = $count;
            }
            //次數與加權次數
            if (isset($comp_count[$count]) == FALSE) {
                $freq_count[$count] = 0;
                $comp_count[$count] = 0;
            }
            $freq_count[$count]++;
            $comp_count[$count] += $this->obs_mix_score[$email];
            $freq_total++;
            $comp_total += $this->obs_mix_score[$email];
            $tbody[] = array($email . '(' . $row['user_id'] . ')', $this->obs_mix_score[$email], $this->obs_group[$email], $annotation_id, $count, $row['score'], $social_function[$count], $sentence_from_index . '-' . $from_index . '-' . $to_index . '-' . $sentence_to_index, $sentence_consensus_count);
        }
        //unit_test_report($this);
        $this->_display_body('標註與標註範圍共識列表', $thead, $tbody);
        // ----------------------------
        $thead = array('標註範圍共識人數', '次數', '次數百分比_除以' . $freq_total . '', '累加次數', '累加次數百分比_除以' . $freq_total . '', '加權次數', '加權次數百分比_除以' . $comp_total . '', '累加加權次數', '累加加權次數百分比_除以' . $comp_total . '');
        $freq_plus = 0;
        $comp_plus = 0;
        ksort($freq_count);
        $tbody = array();
        foreach ($freq_count as $consensus => $freq) {
            $comp_freq = $comp_count[$consensus];
            $tbody[] = array($consensus, $freq, $freq / $freq_total * 100, $freq_plus, $freq_plus / $freq_total * 100, $comp_freq, $comp_freq / $comp_total * 100, $comp_plus, $comp_plus / $comp_total * 100);
            $freq_plus += $freq;
            $comp_plus += $comp_freq;
        }
        $this->_display_body('標註範圍共識次數分配表', $thead, $tbody);
        $this->_display_hr();
        return;
        // ----------------------------
        $thead = array('使用者', '標註次數', '共識次數累積質', '共識次數平均值', '共識次數最大值', '共識次數最小值');
        $tbody = array();
        foreach ($this->obs_email as $email) {
            $a_count = 0;
            if (isset($annotation_count[$email])) {
                $a_count = $annotation_count[$email];
            }
            $c_count = 0;
            if (isset($consensus_count[$email])) {
                $c_count = $consensus_count[$email];
            }
            $max = 0;
            if (isset($consensus_max[$email])) {
                $max = $consensus_max[$email];
            }
            $min = 0;
            if (isset($consensus_min[$email])) {
                $min = $consensus_min[$email];
            }
            $tbody[] = array($email, $a_count, $c_count, $c_count / $a_count, $max, $min);
        }
        $tbody[] = array('整體', $total_annotation_count, $total_count, $total_count / $total_annotation_count, $total_max, $total_min);
        $this->_display_body('標註範圍共識統計(以受試者為單位)', $thead, $tbody);
        // ------------------------------------------------------
        //select from_index, to_index
        //from annotation join annotation2scope using (annotation_id)
        //, scope
        //, webpage2annotation
        //where webpage2annotation.webpage_id = 1142
        //and scope.scope_id = annotation2scope.scope_id
        //and webpage2annotation.annotation_id = annotation.annotation_id
        //order by from_index
        $query = $this->db->select('from_index, to_index')->from('annotation join annotation2scope using (annotation_id)
, scope
, webpage2annotation
, "user"')->where('webpage2annotation.webpage_id = ' . $this->obs_webpage_id . '
and scope.scope_id = annotation2scope.scope_id
and webpage2annotation.annotation_id = annotation.annotation_id
AND annotation.topic_id IS NULL
AND annotation.deleted IS FALSE
and "user".user_id = annotation.user_id
AND annotation.create_timestamp > \'' . $this->obs_date_from . '\'
AND annotation.create_timestamp < \'' . $this->obs_date_to . '\'')->where('email ' . $this->in_email)->get();
        $scope_count = array();
        $paragraph_count = array();
        $annotation_count = 0;
        foreach ($query->result_array() as $row) {
            $annotation_count++;
            $from_index = intval($row['from_index']);
            $to_index = intval($row['to_index']);
            for ($i = $from_index; $i < $to_index + 1; $i++) {
                if (isset($scope_count[$i]) == false) {
                    $scope_count[$i] = 0;
                }
                $scope_count[$i]++;
            }
            foreach ($this->paragraph_scope as $para_id => $para_scope) {
                if ($this->in_scope($para_scope, $from_index, $to_index)) {
                    if (isset($paragraph_count[$para_id]) == FALSE) {
                        $paragraph_count[$para_id] = 0;
                    }
                    $paragraph_count[$para_id]++;
                    break;
                } else {
                    if ($this->from_in_scope($para_scope, $from_index, $to_index) || $this->at_scope($para_scope, $from_index, $to_index)) {
                        if (isset($paragraph_count[$para_id]) == FALSE) {
                            $paragraph_count[$para_id] = 0;
                        }
                        $paragraph_count[$para_id]++;
                    } else {
                        if ($this->to_in_scope($para_scope, $from_index, $to_index)) {
                            if (isset($paragraph_count[$para_id]) == FALSE) {
                                $paragraph_count[$para_id] = 0;
                            }
                            $paragraph_count[$para_id]++;
                            break;
                        }
                    }
                }
            }
        }
        $consensus_count = array();
        foreach ($scope_count as $index => $count) {
            if (isset($consensus_count[$count]) == false) {
                $consensus_count[$count] = 0;
            }
            $consensus_count[$count]++;
        }
        //幫排序
        krsort($consensus_count);
        $title1 = '標註範圍共識次數分配表';
        $thead = array('共識次數', '文字長度', '累積文字長度', '佔文章比率', '累積佔文章比率');
        $tbody = array();
        $accumulate_length = 0;
        $accumulate_rate = 0;
        foreach ($consensus_count as $count => $length) {
            $accumulate_length = $accumulate_length + $length;
            $accumulate_rate = $accumulate_rate + $length / $this->text_length;
            $tbody[] = array($count, $length, $accumulate_length, $length / $this->text_length, $accumulate_rate);
        }
        $tbody[] = array(0, $this->text_length - $accumulate_length, $this->text_length, 1 - $accumulate_rate, 1);
        $this->_display_body($title1, $thead, $tbody);
        // -------------------------------------
        $title2 = '標註段落分配表';
        $thead = array('段落編號', '段落標題', '標註次數', '比率');
        $tbody = array();
        foreach ($this->paragraph_scope as $para_id => $para_scope) {
            $count = 0;
            if (isset($paragraph_count[$para_id])) {
                $count = $paragraph_count[$para_id];
            }
            $tbody[] = array($para_scope[2], $para_scope[3], $count, $count / $annotation_count);
        }
        $this->_display_body($title2, $thead, $tbody);
        $this->_display_footer();
    }
Ejemplo n.º 4
0
 /**
  * annotation_thread
  * @param type  $annotation_id
  */
 public function annotation_thread($annotation_id)
 {
     //載入libary
     $this->load->library('kals_resource/Webpage');
     $this->load->library('kals_resource/Annotation');
     $this->load->library('scope/Scope_anchor_text');
     $this->load->library('search/Search_annotation_collection');
     // 語系
     $this->lang->load('kals_web_apps');
     // 接收-送回應值
     // 用post接收textarea的值:array
     $data = array();
     if (isset($_POST["note_text"])) {
         $note_massage = $_POST["note_text"];
         $data["note_massage"] = $note_massage;
     }
     // radio-type
     if (isset($_POST["annotation_type"])) {
         $anno_type = $_POST["annotation_type"];
         $data['pop_type'] = $anno_type;
     }
     $annotation_self_id = $annotation_id;
     // check topic id
     $is_topic_id = NULL;
     if (isset($annotation_id)) {
         $topic_array = $this->db->query("SELECT topic_id\n                                   FROM annotation\n                                   WHERE annotation_id ='" . $annotation_id . "'");
         foreach ($topic_array->result_array() as $row) {
             $is_topic_id = $row['topic_id'];
         }
     }
     if ($is_topic_id !== NULL) {
         //is respond id
         $annotation_id = $is_topic_id;
     }
     //echo 'annotation_id ='.$annotation_id.'/';
     //echo 'topic_id = '.$is_topic_id.'/';
     // $login_test = $this->session->userdata('logged_in');
     //echo 'loggin = '.$login_test.'/';
     // $annotation_id
     $annotation = new Annotation($annotation_id);
     $annotation_id = $annotation->get_id();
     $log_topic_id = $annotation_id;
     $anchor_text = $annotation->get_anchor_text();
     $user = $annotation->get_user()->get_name();
     $user_id = $annotation->get_user()->get_id();
     $type = $annotation->get_type()->get_name();
     $css_type = $annotation->get_type()->get_type_id();
     $note = $annotation->get_note();
     $timestamp = $annotation->get_update_timestamp();
     //$log_user_id = $this->session->userdata('user_id');
     //echo $this->session->userdata('user_id').'??';
     //echo $this->session->userdata('logged_in').'??';
     $login_user = get_context_user();
     $log_user_id = NULL;
     $logged_id = FALSE;
     if (isset($login_user)) {
         $log_user_id = $login_user->get_id();
         $logged_id = TRUE;
     }
     // 如果有回應值才要做新增的動作
     if (isset($note_massage) && isset($anno_type)) {
         // 開始新增標註回應
         //先將權限設成管理者
         set_ignore_authorize(true);
         //取得參考網址(全文網址)資料($url)跟現在登入(session)的user
         //$user_now = $this->session->userdata('user_id');
         $user_now = get_context_user();
         //建立範圍(使用topic_id取得)
         $scope_coll = $annotation->get_scopes();
         //開始建立回應標註
         $new_res_annotation = $annotation->create_annotation($user_now, $scope_coll);
         $type_id = $anno_type;
         //設定標註細節
         //echo 'set annotation detail ->';
         //type
         if (isset($type_id)) {
             $new_res_annotation->set_type($type_id);
         } else {
             echo 'no type_id';
         }
         set_ignore_authorize(true);
         //note
         if (isset($note_massage) && $note_massage !== '') {
             $new_res_annotation->set_note($note_massage);
         } else {
             echo 'no note_msg';
         }
         //標註錨點範圍的特徵(feature location)
         $feature_location = $annotation->get_feature_location();
         if (isset($feature_location)) {
             $new_res_annotation->set_feature_location($feature_location);
         } else {
             echo 'no feature_location';
         }
         //設定respond_topic_id
         $topic_id = $annotation_id;
         if (isset($topic_id)) {
             $new_res_annotation->set_respond_to_topic($topic_id);
         } else {
             echo 'no topic id';
         }
         //設定policy
         //echo 'start set policy';
         $policy_type = 1;
         /*$this->load->library('policy/Authorize_manager');
                      $ACTION_ANNOTATION_READ = 5;
                      $auth->set_resource($annotation);
         
                      if (is_array($share_user_coll)){
                         foreach ($share_user_coll AS $share_user)
                         {
                           //在這邊為該$annotation設定policy readable
                             $auth->policy_add_actor($ACTION_ANNOTATION_READ, $share_user);
                         }
                       }
                      else{
                         //清除該$annotation的policy
                         $auth->policy_remove_actor($ACTION_ANNOTATION_READ);
                      }*/
         //回傳標註
         $new_res_annotation->update();
         set_ignore_authorize(false);
         // 寫入DB(若note不為空才寫入)
         if (isset($note_massage) && $note_massage !== '') {
             context_complete();
         }
     }
     //log區-mobile瀏覽討論-action = 41
     $action = 41;
     // data: topic_id
     $log_webpage = $annotation->get_append_to_webpages();
     $log_webpage_id = $log_webpage[0]->get_id();
     $array_data = array('target_topic' => FALSE, 'topic_id' => $log_topic_id, 'order_by' => 'create', 'show_total_count' => TRUE);
     kals_mobile_log($this->db, $log_webpage_id, $action, array('memo' => $array_data, 'user_id' => $log_user_id));
     context_complete();
     //寫入db
     $data['log_webpage_id'] = $log_webpage_id;
     // type
     if ($type != 'annotation.type.custom') {
         $type_show = $this->lang->line("web_apps." . $type);
         $type_name = $type_show;
     }
     // css-type
     switch ($css_type) {
         case 1:
             $css_type = 'importance';
             break;
         case 2:
             $css_type = 'concept';
             break;
         case 3:
             $css_type = 'confusion';
             break;
         case 4:
             $css_type = 'question';
             break;
         case 5:
             $css_type = 'example';
             break;
         case 6:
             $css_type = 'summary';
             break;
         case 7:
             $css_type = 'other';
             break;
         case 8:
             $css_type = 'custom';
             break;
         default:
             $css_type = 'importance';
             break;
     }
     // annotation_respones
     $respond_collection = $annotation->get_topic_respond_coll();
     $respond_json = array();
     foreach ($respond_collection as $respond_annotation) {
         $json = array();
         $json["annotation_id"] = $respond_annotation->get_id();
         $json["user"] = $respond_annotation->get_user()->get_name();
         $css_res_type = $respond_annotation->get_type()->get_type_id();
         $res_type = $respond_annotation->get_type()->get_name();
         if ($res_type != 'annotation.type.custom') {
             $res_type_show = $this->lang->line("web_apps." . $res_type);
             $res_type = $res_type_show;
         } else {
             $res_type_show = $this->lang->line("web_apps." . 'annotation.type.other');
             $res_type = $res_type_show;
         }
         switch ($css_res_type) {
             case 1:
                 $css_res_type = 'importance';
                 break;
             case 2:
                 $css_res_type = 'concept';
                 break;
             case 3:
                 $css_res_type = 'confusion';
                 break;
             case 4:
                 $css_res_type = 'question';
                 break;
             case 5:
                 $css_res_type = 'example';
                 break;
             case 6:
                 $css_res_type = 'summary';
                 break;
             case 7:
                 $css_res_type = 'other';
                 break;
             case 8:
                 $css_res_type = 'custom';
                 break;
             default:
                 $css_res_type = 'importance';
                 break;
         }
         $json["css_type"] = $css_res_type;
         $json["type"] = $res_type;
         $json["note"] = $respond_annotation->get_note();
         $sub_res_timestamp = $respond_annotation->get_update_timestamp();
         $json["timestamp"] = substr($sub_res_timestamp, 0, 10);
         $respond_json[] = $json;
     }
     //$respond_json[0]['user'];
     // 詳見全文url:Webpage -> get_url()
     $webpage = $annotation->get_append_to_webpages();
     $webpage_id = $webpage[0]->get_id();
     //$webpage_id = 1573;
     $mobile_webpage = new Webpage($webpage_id);
     $url = $mobile_webpage->get_url();
     $data['webpage_url'] = $url;
     $data['webpage_id'] = $webpage_id;
     $data['webpage'] = $webpage;
     // send data -annotation topic
     $data["annotataion_id"] = $annotation_id;
     $data["annotation_self_id"] = $annotation_self_id;
     $data["anchor_text"] = $anchor_text;
     $data["user"] = $user;
     $data["type"] = $type;
     $data["type_name"] = $type_name;
     $data["css_type"] = $css_type;
     $data["note"] = $note;
     $sub_timestamp = substr($timestamp, 0, 10);
     $data["timestamp"] = $sub_timestamp;
     $data["respond_json"] = $respond_json;
     $this->load->view('mobile/mobile_views_header');
     $this->load->view('mobile/annotation_thread_view', $data);
     $this->load->view('mobile/mobile_views_footer');
 }
Ejemplo n.º 5
0
 /**
  * 輸出Annotation的資料
  * @param Annotation $annotation
  * @return string
  */
 private function _print_annotation_table($annotation, &$last_scope)
 {
     $annotation_id = $annotation->get_id();
     $text = '<a name="annotation_' . $annotation_id . '" id="annotation_' . $annotation_id . '"></a><table class="annotation_table"  cellspacing="0" cellpadding="0"><tbody>';
     $scope_collection = $annotation->get_scopes();
     $scope = $scope_collection->get_item(0);
     $from_index = $scope->get_from_index();
     $to_index = $scope->get_to_index();
     if (is_null($last_scope) or !($last_scope[0] == $from_index and $last_scope[1] == $to_index)) {
         $last_scope = array($from_index, $to_index);
         $scope_length = $annotation->get_scope_length();
         $from_to = $from_index;
         if ($from_index != $to_index) {
             $from_to .= '-' . $to_index;
         }
         $anchor_text = $annotation->get_anchor_text();
         $speech = $annotation->get_anchor_speech();
         $speech_list = '';
         foreach ($speech as $s) {
             if ($speech_list != '') {
                 $speech_list .= ', ';
             }
             $speech_list .= $s;
         }
         if ($speech_list == '') {
             $speech_list = '(剖析失敗)';
         }
         //位置
         $location = $annotation->get_feature_location();
         $location_list = '';
         foreach ($location as $l) {
             if ($location_list != '') {
                 $location_list .= ', ';
             }
             $name = '其他';
             $l = intval($l);
             if ($l == 4) {
                 $name = '結尾';
             } else {
                 if ($l == 0) {
                     $name = '開頭';
                 } else {
                     if ($l == 1) {
                         $name = '接近開頭';
                     } else {
                         if ($l == 3) {
                             $name = '接近結尾';
                         } else {
                             if ($l == 5) {
                                 $name = '只有一句';
                             } else {
                                 if ($l == 2) {
                                     $name = '三句中間一句';
                                 }
                             }
                         }
                     }
                 }
             }
             $location_list .= $name . '(' . $l . ')';
         }
         if ($location_list == '') {
             $location_list = '其他';
         }
         $text .= '<tr> <td> <table class="anchor_row" border="1" cellpadding="0" cellspacing="0"><tbody>' . '<tr><th>範圍</th><td>' . $from_to . ' (' . $scope_length . '字)</td><th>詞性(' . count($speech) . ')</th><td>' . $speech_list . '</td><th>位置</th><td>' . $location_list . '</td></tr>' . '<tr><th>錨點文字</th><td colspan="5">' . $anchor_text . '</td></tr>' . '</tbody></table> </td> </tr>';
     }
     //第一列
     //
     // email 發表日期 修改日期 被喜愛 被共識 被回應 編號
     $email = $annotation->get_user()->get_email();
     $print_email = substr($email, 0, 8);
     $print_email = '<a href="' . site_url('/admin_apps/exp201012annotation/email_list/' . $this->_find_email_key($email)) . '">' . $print_email . '</a>';
     //類別
     $type_name = $annotation->get_type()->get_name();
     $type_name_lang = $this->lang->line('web_apps.' . $type_name);
     $type_name_classname = substr($type_name, strrpos($type_name, '.') + 1);
     $create_timestamp = $annotation->get_create_timestamp();
     //2010-12-08 23:17:10.984+08
     //01234567890123456789
     $create_timestamp = $this->_trim_timestamp($create_timestamp);
     $update_timestamp = $annotation->get_update_timestamp();
     $update_timestamp = $this->_trim_timestamp($update_timestamp);
     $liked_count = $annotation->get_like_count();
     $consensus_count = $annotation->get_consensus_count();
     $topic_respond_count = $annotation->get_topic_respond_coll()->length();
     $text .= '<tr> <td> <table class="row" border="1" cellpadding="0" cellspacing="0"><tbody><tr>' . '<th class="email">' . $print_email . '</th>' . '<th class="type ' . $type_name_classname . '">' . $type_name_lang . '</th>' . '<th>建立日期:</th><td class="date">' . $create_timestamp . '</td>' . '<th>修改日期:</th><td class="date">' . $update_timestamp . '</td>' . '<td class="annotation_id">#' . $annotation_id . '</td>' . '</tr></tbody></table> </td> </tr>';
     //第二列
     //  標註類別 位置 分數 建議的ID 推薦的ID 接受建議間隔
     //分數
     $score = $annotation->get_score(0)->get_score();
     //是否有建議?顯示建議的ID
     $query = $this->db->select('recommend_id, accept, (checked_timestamp - annotation.create_timestamp) as check_interval, recommend_by_annotation_id')->from('recommend join annotation on recommended_annotation_id = annotation.annotation_id')->where('recommended_annotation_id', $annotation_id)->get();
     $recommend_table;
     if ($query->num_rows() == 0) {
         $recommend_table = '沒有建議';
     } else {
         $row = $query->row_array();
         $recommend_id = $row['recommend_id'];
         $recommed_by_annotation_id = $row['recommend_by_annotation_id'];
         $accept = $row['accept'];
         $recommend_table = '建議ID:' . $recommend_id;
         if ($accept == '') {
             //尚未確認
             $recommend_table .= ' <span class="state">尚未確認</span>';
         } else {
             $accept_text = '<span class="state accpet">接受</span>';
             if ($accept == 'f') {
                 $accept_text = '<span class="state reject">拒絕</span>';
             }
             $check_interval = $row['check_interval'];
             $point = strrpos($check_interval, '.');
             if ($point !== FALSE) {
                 $check_interval = substr($check_interval, 0, $point);
             }
             $recommend_table .= '; ' . $accept_text . '; 確認間隔: ' . $check_interval;
         }
         if ($recommed_by_annotation_id != '') {
             $recommend_table .= '; <a href="#annotation_' . $recommed_by_annotation_id . '">推薦標註: ' . $recommed_by_annotation_id . '</a>';
         }
     }
     $text .= '<tr> <td> <table class="row" border="1" cellpadding="0" cellspacing="0"><tbody><tr>' . '<th>喜愛共識:</th><td>' . $liked_count . '</td>' . '<th>範圍共識:</th><td>' . $consensus_count . '</td>' . '<th>回應:</th><td>' . $topic_respond_count . '</td>' . '<th>分數</th><td>' . $score . '</td>' . '<th>建議</th><td class="recommend">' . $recommend_table . '</td>' . '</tr></tbody></table> </td> </tr>';
     $note = $annotation->get_note();
     if ($note != '') {
         $text .= '<tr><td><table class="note" width="100%" border="1" cellpadding="0" cellspacing="0"><tbody><tr><td>' . $note . '</td></tr></tbody></table></td></tr>';
     }
     if ($topic_respond_count > 0) {
         $respond_annotation_table = $this->_print_respond($annotation);
         $text .= '<tr><td>' . $respond_annotation_table . '</td></tr>';
     }
     $text .= '</tbody></table>';
     return $text;
 }
Ejemplo n.º 6
0
 protected function get_feature(Annotation $annotation)
 {
     $feature = $annotation->get_scopes()->get_scope_length();
     return $feature;
 }
Ejemplo n.º 7
0
 private function _find_recommend_annotation(Annotation $annotation)
 {
     $scope_coll = $annotation->get_scopes();
     $user = $annotation->get_user();
     $recommend_scope = $annotation->get_recommend_by_scopes();
     if (is_null($recommend_scope)) {
         $recommend_scope = $scope_coll;
     }
     $target_over_score = $this->_get_recommend_by_threshold();
     $this->_CI_load('library', 'search/Search_order_score', 'search_order_score');
     $order_type_id = $this->CI->search_order_score->get_type_id();
     $this->_CI_load('library', 'search/Search_annotation_collection', 'search_annotation_collection');
     $search = new Search_annotation_collection();
     $search->set_limit(1);
     $search->add_order($order_type_id, TRUE);
     $search->set_overlap_scope($recommend_scope);
     $search->set_exclude_scope($scope_coll);
     $search->set_exclude_user($user);
     $search->set_target_over_score($target_over_score);
     if ($search->length() == 1) {
         return $search->get_item(0);
     } else {
         return NULL;
     }
 }