function index() { $url = $this->url; $webpage = $this->webpage->create($url); $tutor = $webpage->get_tutor(); $annotation = new Annotation(1017); $user = $annotation->get_user(); $unread_count = $user->get_unread_notification_count(); $this->unit->run($unread_count, 'is_int', '先看一下user的未讀通知有幾封'); $tutor->setup_recommend($annotation); $recommend = $annotation->get_recommend(); $this->unit->run($recommend->get_id(), 'is_int', '有取得建議'); $recommend_annotation = $recommend->get_recommend_by(); $this->unit->run($recommend_annotation, NULL, '沒有推薦標註'); $tips = $recommend->get_tips_text_array(); $this->unit->run_false(count($tips), 0, '有建議'); //------------------------------------------------ $recommend_annotation = new Annotation(783); $recommend_annotation->set_score(0, 3); $recommend_annotation->update(); $scope = new Annotation_scope(129); $recommend_scope = new Annotation_scope_collection(); $recommend_scope->add_scope($scope); $annotation->set_recommend_scopes($recommend_scope); $tutor->setup_recommend($annotation); $recommend->reload(); $recommend_annotation = $recommend->get_recommend_by(); $this->unit->run($recommend_annotation->get_id(), 783, '有找到推薦標註'); $this->unit->run($user->get_unread_notification_count(TRUE), $unread_count + 2, '因為新增了兩次推薦,所以應該有兩封通知?'); // $this->unit->run($test_result // , $expected_result // , $test_name); //context_complete(); unit_test_report($this, __METHOD__); }
public function load_default() { $db = $this->setup_search(); $db->distinct(); $db->join('annotation2scope AS select_annotation2scope', 'select_annotation2scope.annotation_id = annotation.annotation_id'); $db->join('scope AS select_scope', 'select_annotation2scope.scope_id = select_scope.scope_id'); $db->select('select_scope.*'); //加入other_from foreach ($this->other_from as $from) { $db->from($from); } $db->from('annotation'); $query = $db->get(); $this->members = array(); $this->_CI_load('library', 'scope/Annotation_scope', 'annotation_scope'); $this->_CI_load('library', 'scope/Annotation_scope_collection', 'annotation_scope_collection'); $scope_coll = new Annotation_scope_collection(); foreach ($query->result_array() as $row) { $scope = new Annotation_scope($row); $scope_coll->add_scope($scope); } foreach ($scope_coll as $scope) { $this->members[] = $scope; } $this->scope_coll = $scope_coll; return TRUE; }
/** * 取得搜尋結果的範圍位置 * @return Annotation_scope_collection */ public function get_result_scope_coll() { $scope_coll = new Annotation_scope_collection(); foreach ($this as $index => $annotation) { $annotation_scope_coll = $annotation->get_scopes(); //test_msg("get_result_scope_coll" . $index, $annotation_scope_coll->export_); $scope_coll->add_scope_collection($annotation_scope_coll); } return $scope_coll; }
function webpage() { $scope1 = $this->scope->create_scope(0, 2); $scope2 = $this->scope->create_scope(6, 9); $url = 'http://www.plurk.com/p/6cz3zb'; $text = '雖然感覺上70/182的進度大有嶄進,但是之前寫好的一些仍有問題,要想辦法做測試才行。 '; $scope_another = $this->scope->create_scope(1, 7, $text, $url); $coll = new Annotation_scope_collection(); $coll->add_scope($scope1); $this->unit->run($coll->get_scope_length(), 3, "set_scopes 0~2之後測試get_scope_length()"); $coll->add_scope($scope2); $this->unit->run($coll->get_scope_length(), 7, "set_scopes 6~9之後測試get_scope_length()"); $coll->add_scope($scope_another); $this->unit->run($coll->get_scope_length(), 14, "set_scopes 1~7 another webpage之後測試get_scope_length()"); $this->unit->run($coll->length(), 3, "set_scopes 1~7 another webpage之後測試length()"); unit_test_report($this); }
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__); }
/** * @return Annotation */ function create_annotation() { $url = $this->url; $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); $len = $scope_coll->get_scope_length(); $user = $this->user->create_user($url, $email); $annotation = $this->annotation->create_annotation($user, $scope_coll); $this->association_user = $user; return $annotation; }
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(); }
function search_without_context() { $user_found = new User(225); $user_not_found = new User(9999); $url_nf = 'http://www.plurk.com/p/6c5cdt#response-1777726347'; $webpage_nf = $this->webpage->create($url_nf); $url_f = 'http://www.plurk.com/p/67k6st'; $webpage_f = $this->webpage->create($url_f); $text = '話說回來,其實本篇主題是要講,目前階段是Search,加入了Collection概念,並強化應用Active Record的方式之後,應該是更強大,卻也複雜到一種境界。'; $target_scope_nf = new Annotation_scope_collection(); $target_scope_nf->add_scope($this->annotation_scope->create_scope(18, 33, $text, $webpage_f)); $target_scope_f = new Annotation_scope_collection(); $target_scope_f->add_scope($this->annotation_scope->create_scope(3, 20, $text, $webpage_f)); $target_scope_f->add_scope($this->annotation_scope->create_scope(26, 40, $text, $webpage_f)); $overlap_scope_nf = new Annotation_scope_collection(); $overlap_scope_nf->add_scope($this->annotation_scope->create_scope(23, 25, $text, $webpage_f)); $overlap_scope_f = new Annotation_scope_collection(); $overlap_scope_f->add_scope($this->annotation_scope->create_scope(23, 25, $text, $webpage_f)); $overlap_scope_f->add_scope($this->annotation_scope->create_scope(39, 40, $text, $webpage_f)); //----------------------------------------------------------- $search = new Search_annotation_collection(); $search->set_target_user($user_not_found); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤user_id,看length()'); $search = new Search_annotation_collection(); $search->set_target_user($user_found); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的user_id,看length()'); $search = new Search_annotation_id_collection(); $search->set_target_user($user_found); $this->unit->run($search->length(), 2, 'Search_annotation_id_collection,搜尋正確的user_id,看length(),耗費時間應該比Search_annotation_collection還短'); $this->unit->run($search->get_item(0), 'is_string', 'Search_annotation_id_collection,搜尋正確的user_id,get_item(),值應該是id'); //---- $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的webpage,看length()'); $this->unit->run($webpage_f->get_id(), 138, '先檢查webpage正確的id'); $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_f); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋正確的webpage,看length()'); //---- $search = new Search_annotation_collection(); $search->set_target_scope($target_scope_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的target_scope,看length()'); $this->unit->run($target_scope_f->length(), 2, '先確定一下target_scope_f的數量沒錯'); $search = new Search_annotation_collection(); $search->set_target_scope($target_scope_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的target_scope,看length()'); //---- $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_scope,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'order scope之前'); $this->unit->run($search->get_item(0)->get_user()->get_name(), 'puddingchen.35', 'order scope之前,查看一下user name'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(2, TRUE); $this->unit->run($search->get_item(0)->get_id(), 1017, 'order scope desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(3); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order like desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(4); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order respond desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(5, TRUE); $this->unit->run($search->get_item(0)->get_user()->get_name(), 'pulipuli', 'order author desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(6); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order update desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(7); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order update desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的exclude_scope,看length(),應該是跟上上個測試剛好是相反地'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的exclude_scope,get_item(0)並檢查id,應該是指定的784才對'); //---- $search = new Search_annotation_collection(); $search->set_overlap_scope($overlap_scope_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的overlap_scope,看length()'); $search = new Search_annotation_collection(); $search->set_overlap_scope($overlap_scope_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的overlay_scope,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的overlay_scope,get_item() get_id()看看'); //---- $type_id_nf = 3; $type_id_f = 2; //$search = new Search_scope_collection(); $search = new Search_annotation_collection(); $search->set_target_type($type_id_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的target_id,看length()'); $search = new Search_annotation_collection(); $search->set_target_type($type_id_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的target_id,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的type_id,get_item() get_id()看看'); //---- $search = new Search_annotation_collection(); $search->set_exclude_user($user_not_found); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_user_id,看length()'); $search = new Search_annotation_collection(); $search->set_exclude_user($user_found); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的exclude_user_id,看length()'); //---- $annotation_id_nf = 9999; $annotation_id_f = 1017; $search = new Search_annotation_collection(); $search->set_exclude_annotation($annotation_id_nf); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_annotation_id,看length()'); $search = new Search_annotation_collection(); $search->set_exclude_annotation($annotation_id_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的exclude_annotation_id,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的exclude_annotation_id,get_item get_id'); //---- $note_nf = '搜尋錯誤'; $note_f = '變項回歸'; $search = new Search_annotation_id_collection(); $search->set_search_note($note_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的search_note,看length()'); $search = new Search_annotation_collection(); $search->set_search_note($note_f); $search->add_order(8); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的search_note,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的search_note,get_item get_id'); //---- $anchor_text_f = '冷氣電扇被子'; $search = new Search_scope_collection(); $search->set_search_anchor_text($note_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的search_anchor_text,看length()'); $search = new Search_annotation_collection(); $search->set_search_anchor_text($note_f); $search->add_order(9); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的search_anchor_text,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的search_anchor_text,get_item get_id'); $search = new Search_annotation_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,並關掉權限檢查,搜尋正確的search_anchor_text,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'order score之前'); $search = new Search_annotation_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $search->add_order(1); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order score之後'); $search = new Search_scope_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $this->unit->run($search->get_scope_length(), 20 - 3 + 1 + 40 - 26 + 1, 'Search_scope_collection,並關掉權限檢查,搜尋正確的search_anchor_text,看get_scope_length()'); //---- $score_over_nf = 3; $score_over_f = 2.1214435; $search = new Search_scope_collection(); $search->set_target_over_score($score_over_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的target_over_score,看length()'); $search = new Search_annotation_collection(); $search->set_target_over_score($score_over_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的target_over_score,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1018, 'Search_annotation_collection,搜尋正確的target_over_score,get_item get_id'); $search = new Search_annotation_user_collection(); $search->set_target_over_score($score_over_f); $this->unit->run($search->length(), 1, 'Search_annotation_user_collection,搜尋正確的target_over_score,length'); $this->unit->run($search->get_item(0)->get_id(), 225, 'Search_annotation_user_collection,搜尋正確的target_over_score,get_item get_id'); // //-------------------------------------------------------------------------------- // $search = new Search_annotation_collection(); // $search->set_check_authorize(FALSE); // $search->set_target_user($user_not_found); // $this->unit->run($search->length() // , 0 // , 'Search_annotation_collection,取消auth,搜尋錯誤user_id,看length()'); // // $search = new Search_annotation_collection(); // $search->set_check_authorize(FALSE); // $search->set_target_user($user_found); // $this->unit->run($search->length() // , 4 // , 'Search_annotation_collection,取消auth,搜尋正確的user_id,看length()'); // $this->unit->run($test_result // , $expected_result // , $test_name); // $this->unit->run($test_result // , $expected_result // , $test_name); //context_complete(); unit_test_report($this); }
public function import_webpage_search_data($webpage_id, $scope_indices) { if (is_string($webpage_id)) { $this->_CI_load('library', 'kals_resource/Webpage', 'webpage'); $webpage_id = $this->CI->webpage->filter_webpage_id($webpage_id); } $members = array(); if (is_int($scope_indices) || is_string($scope_indices)) { $scope_indices = array(array(intval($scope_indices), intval($scope_indices))); } foreach ($scope_indices as $scope_index) { $from = $scope_index[0]; $to = $scope_index[1]; //test_msg('import webpage list data', $scope_index); $scope = new Annotation_scope(); $scope->set_webpage($webpage_id); $scope->set_index($from, $to); $members[] = $scope; } $scope_coll = new Annotation_scope_collection(); $scope_coll->set_members($members); return $scope_coll; }
public function set_recommend_scopes(Annotation_scope_collection $scope_coll) { $value = $scope_coll->export_json(); $this->_CI_load('library', 'annotation/Annotation_feature_recommend_scope', 'annotation_feature_recommend_scope'); $feature_type_id = $this->CI->annotation_feature_recommend_scope->get_type_id(); //test_msg('set_recommend_scopes', $value); $this->set_feature($feature_type_id, $value); return $this; }
public function create_annotation() { $url = $this->url; $email = '*****@*****.**'; $email2 = '*****@*****.**'; $email3 = '*****@*****.**'; $user = $this->user->create_user($url, $email); $user2 = $this->user->create_user($url, $email2); $user3 = $this->user->create_user($url, $email3); $text1 = '[CODING D27] 喝了萊爾富的咖啡,玩了一下流浪者之歌,今天很有精神地繼續挑戰模糊理論!其實已經寫一段時間了,作業用BGM播到「閃光」才想起來要記錄一下XDD'; $text2 = '感謝José,k-means分群器運作成效良好。雖然k-means天生無法擺脫極端值的影響,但此例中效率高於準確度,所以還是派得上用場的。'; $scope1 = $this->annotation_scope->create_scope(103, 120, $text1, $url); //18 $scope2 = $this->annotation_scope->create_scope(126, 140, $text2, $url); //15 $scope_coll = new Annotation_scope_collection(); $scope_coll->add_scope($scope1); $scope_coll->add_scope($scope2); $annotation = $this->annotation->create_annotation($user, $scope_coll); $annotation2 = $this->annotation->create_annotation($user2, $scope_coll); $annotation3 = $this->annotation->create_annotation($user3, $scope_coll); $annotation->add_like($user2); $annotation->add_like($user3); $this->annotation = $annotation; $this->annotation2 = $annotation2; $this->annotation3 = $annotation3; }