function index() { $url = 'http://www.plurk.com/p/67k6st#response-1739920625'; $text1 = '[CODING D17] 晚上睡覺時天氣、室溫、冷氣、電扇、被子的厚度與蓋的方法,組合起來就可以預測隔天會不會一整天過敏。但我還沒有明顯地分辨出他們的關聯。'; $text2 = '變項太多,這回歸的組合也不知道要排到什麼時候orz'; $note = '「西瓜牛奶去冰的話可能沒有滿杯喔」由於店員這樣說,所以我改口跟他說不用去冰好了……結果還是一樣沒有滿杯orz'; $email = '*****@*****.**'; $email_siroma = '*****@*****.**'; $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); $user_siroma = $this->user->create_user($url, $email_siroma); $annotation = $this->annotation->create_annotation($user, $scope_coll); $this->unit->run($annotation->get_id(), 9999, '是否有正確地存入資料庫?'); $scope_coll2 = $annotation->get_scopes(); $this->unit->run($scope_coll2->get_scope_length(), $len, '測試get_scopes()'); $annotation->set_note($note); $this->unit->run($annotation->get_note(), $note, '測試get_note()'); $annotation->set_type(3); $type = $annotation->get_type(); $this->unit->run($type->get_name(), 'annotation.type.confusion', '測試get_type()'); $user = $annotation->get_user(); $this->unit->run($user->get_email(), $email, '測試get_user()'); $this->unit->run($user->get_email(), $email, '測試get_user()'); $annotation_topic = $this->annotation->create_annotation($user_siroma, $scope2); $annotation_topic_id = $annotation_topic->get_id(); $annotation->set_respond_to_topic($annotation_topic); $topic = $annotation->get_respond_to_topic(); $this->unit->run($topic->get_id(), $annotation_topic_id, '測試respond_to_topic()'); //來測試respond_to_coll $scope3 = $this->annotation_scope->create_scope(104, 135, $note, $url); $annotation_respond = $this->annotation->create_annotation($user_siroma, $scope3); //$annotation_coll = new Annotation_collection($annotation_respond); $annotation->set_respond_to_coll($annotation_respond); $coll = $annotation->get_respond_to_coll(); $this->unit->run($coll->length(), 1, '測試respond_to_coll()的length'); ///$this->unit->run($coll->get_item(0)->get_id() // , $annotation_respond->get_id() // , '測試respond_to_coll()的get_id() | '.$annotation->get_id()); $annotation->set_feature(1, 1); $feature = $annotation->get_feature(1); $this->unit->run($feature->get_name(), 'annotation.feature.location', 'set_feature之後又get_feature->get_name()'); $this->unit->run($feature->get_value(), '1', 'set_feature之後又get_feature->get_value()'); $annotation->set_feature(1, 2); $feature = $annotation->get_feature(1); $this->unit->run($feature->get_value(), '2', '再一次set_feature之後又get_feature->get_value()'); $score_number = 2.36978; $score_number2 = 1.36978; $annotation->set_score(0, $score_number); $score = $annotation->get_score(0); $this->unit->run($score->get_name(), 'annotation.score.integrated', 'set_score之後又get_score->get_name()'); $this->unit->run($score->get_score(), $score_number, 'set_score之後又get_score->get_value()'); $annotation->set_score(0, $score_number2); $score = $annotation->get_score(0); $this->unit->run($score->get_score(), $score_number2, '再一次set_score之後又get_score->get_score()'); $email_like = '*****@*****.**'; $user_like = $this->user->create_user($url, $email_like); $this->unit->run_false($user->get_id(), $user_like->get_id(), '建立一個user_like,跟user不同人吧?'); $this->unit->run_false($annotation->get_user()->get_id(), $user_like->get_id(), 'user_like,跟標註的作者user不同人吧?'); $this->unit->run($annotation->get_like_count(), 0, 'like測試,加入user_like之前 get_like_count()'); $annotation->add_like($user_like); $this->unit->run($annotation->get_like_count(), 1, 'like測試,加入user_like之後 get_like_count()'); $annotation->remove_like($user_like); $this->unit->run($annotation->get_like_count(), 0, 'like測試,移除user_like之後 get_like_count()'); $annotation->add_like($user_like); $this->unit->run($annotation->get_like_count(), 1, 'like測試,再加入user_like之後 get_like_count()'); $this->unit->run($annotation->get_user()->get_unread_notification_count(), 1, '更新之前,到底annotation的作者收到幾封未讀通知呢?應該是有like的一封'); $annotation->update(); $this->unit->run(TRUE, TRUE, '======================更新完畢======================'); $this->unit->run($user_siroma->get_unread_notification_count(), 1, '更新之後,由於user_siroma被設為topic跟respond的對象,所以user_siroma應該只會收到1封通知'); $db = $this->db; $db->from('annotation2like_count'); $db->where('annotation_id', $annotation->get_id()); $db->select('like_count'); $query = $db->get(); $row = $query->row_array(); $like_count = intval($row['like_count']); $this->unit->run($like_count, 1, '測試annotation2like_count'); //---------------------------------------------------------------------------- //搜尋看看吧 $id = $annotation->get_id(); $annotation2 = new Annotation($id); $scope_coll3 = $annotation2->get_scopes(); $this->unit->run($annotation2->get_id(), $id, '$annotation2的id是否跟當初設定的相同?'); $this->unit->run($scope_coll3->get_scope_length(), $len, '取出$annotation2之後,測試scopes'); $this->unit->run($scope_coll3->length(), 2, '取出$annotation2之後,測試scopes有幾個'); $this->unit->run($scope_coll3->get_anchor_speech(), $scope_coll2->get_anchor_speech(), '取出$annotation2之後,測試scopes的get_anchor_speech()'); $this->unit->run($annotation2->get_note(), $note, '取出$annotation2之後,測試note'); $type2 = $annotation2->get_type(); $this->unit->run($type2->get_name(), 'annotation.type.confusion', '取出$annotation2之後,測試type'); $user2 = $annotation2->get_user(); $this->unit->run($user2->get_email(), $email, '取出$annotation2之後,測試get_user()'); $text2 = '雖然這邊太吵了應該聽不到尖叫聲,不過應該是會有人間叫'; $this->unit->run($annotation2->get_like_count(), 1, '搜尋之後,like測試,已經加入user_like'); $this->unit->run_false($annotation2->get_user()->get_id(), $user_like->get_id(), '確認一下兩個標註應該是不同人吧?'); $annotation2->set_note($text2); $annotation2->update(); $this->unit->run(TRUE, TRUE, '<h4>======================更新完畢======================</h4>'); //---------------------------------------------------------------------- $annotation3 = new Annotation($annotation2->get_id()); $this->unit->run($annotation3->get_note(), $text2, '更新note,取出$annotation3之後,測試get_note()'); $webpages = $annotation3->get_append_to_webpages(); $this->unit->run(count($webpages), 1, '測試get_append_to_webpages()'); $this->unit->run($webpages[0]->get_uri(), parse_uri($url), '測試get_append_to_webpages()是否相符'); $topic = $annotation3->get_respond_to_topic(); $this->unit->run($topic->get_id(), $annotation_topic_id, '測試respond_to_topic()'); $coll = $annotation3->get_respond_to_coll(); $this->unit->run($coll->length(), 1, '測試respond_to_coll()的length'); //$this->unit->run($coll->get_item(0)->get_id() // , $annotation_respond->get_id() // , '測試respond_to_coll()的get_id(),應該只有找到一個,並且就是剛剛插入的那一個 | '.$annotation3->get_id()); $this->unit->run($annotation2->get_id(), $annotation3->get_id(), 'annotation2跟3的id是否相同呢?應該一樣才是'); $topic_respond_coll = $topic->get_topic_respond_coll(); $this->unit->run($topic_respond_coll->length(), 1, '測試get_topic_responded_coll()的length'); $this->unit->run($topic_respond_coll->get_item(0)->get_id(), $annotation3->get_id(), '測試get_topic_responded_coll()的length'); $feature = $annotation3->get_feature(1); $this->unit->run($feature->get_value(), '2', '搜尋之後,get_feature->get_value()'); $feature = $annotation3->get_feature(2); $this->unit->run($feature->get_value(), NULL, '搜尋之後,get_feature沒設定的id,應該會有屬性,但是沒有值'); $feature = $annotation3->get_feature(3); $this->unit->run($feature, NULL, '搜尋之後,get_featur不再factory_item範圍內的id,應該直接是null'); $score = $annotation3->get_score(0); $this->unit->run($score->get_name(), 'annotation.score.integrated', '搜尋之後,get_score->get_name()'); $this->unit->run($score->get_score(), $score_number2, '搜尋之後,get_score->get_value()'); $query = $this->db->select('score')->limit(1)->where('annotation_id', $annotation3->get_id())->get('score'); $row = $query->row_array(); $this->unit->run($row['score'], $score_number2, '以資料庫查看是否有存入score'); $this->unit->run_false($annotation3->get_field('create_timestamp'), $annotation3->get_field('update_timestamp'), 'Annotation更新過後,create_timestamp跟update_timestamp應該要不同才對'); $this->unit->run($annotation->get_like_count(), 1, '搜尋之後,like測試,已經加入user_like'); $this->unit->run_false($annotation->get_user()->get_id(), $user_like->get_id(), '確認一下兩個標註應該是不同人吧?'); // $annotation->remove_like($user2); // $this->unit->run($annotation->get_like_count() // , 0 // , '搜尋之後,like測試,移除user2之後'); //context_complete(); // $this->unit->run($test_result // , $expected_result // , $test_name); unit_test_report($this); }
public function calculator() { $url = $this->url; $this->create_annotation(); $webpage = $this->webpage->create($url); $annotation = $this->annotation; $annotation3 = $this->annotation3; $this->unit->run($annotation->get_score(0)->get_score(), NULL, '先看看$annotation是否有分數?'); $this->unit->run($annotation3->get_score(0)->get_score(), NULL, '先看看$annotation3是否有分數?'); //---------------------------------- //$this->annotation_score_calculator->set_webpage($url); $annotation_score_calculator = $webpage->get_score_calculator(); //$annotation_score_calculator->set_annotation($annotation); //$annotation_score_calculator->set_annotation_scores(); // // $scores = $annotation_score_calculator->calculate_scores($annotation); // $annotation->set_scores($scores); // $annotation->update(); $annotation_score_calculator->setup_annotation_scores($annotation); $annotation_id = $annotation->get_id(); //annotation3要重新讀取,才能取得分數 $annotation3 = new Annotation($annotation3->get_id()); $this->unit->run($annotation->get_score(0)->get_score(), 'is_float', '看一下是否有存入資料庫?'); $this->unit->run($annotation3->get_score(0)->get_score(), 'is_float', '看一下共識範圍的是否也一併有了分數?'); $score_coll = $annotation->get_score_coll(); $this->unit->run($score_coll->length(), 7, '看一下是否有取得正確7個分數?'); $scores_array = $score_coll->get_scores_array(); $annotation_new = new Annotation($annotation_id); $this->unit->run($annotation_new->get_score(0)->get_score(), 'is_float', 'find之後,看一下是否有存入資料庫?'); $score_coll = $annotation_new->get_score_coll(); $this->unit->run($score_coll->length(), 7, 'find之後,看一下是否有取得正確7個分數?'); $this->unit->run($score_coll->get_scores_array(), $scores_array, 'find之後,比對一下是否跟儲存之前的分數一樣?'); unit_test_report($this, __METHOD__); }
/** * 輸出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; }
private function _get_integrated_score(Annotation $annotation) { $score = $annotation->get_score($this->integrated_score_type_id)->get_score(); return $score; }