Showing
7 changed files
with
80 additions
and
28 deletions
| ... | @@ -108,7 +108,7 @@ void GraphItem::read_more() | ... | @@ -108,7 +108,7 @@ void GraphItem::read_more() |
| 108 | boost::put(vertex_name, *graph, *vi, node_label); | 108 | boost::put(vertex_name, *graph, *vi, node_label); |
| 109 | boost::put(vertex_record, *graph, *vi, 0); | 109 | boost::put(vertex_record, *graph, *vi, 0); |
| 110 | 110 | ||
| 111 | - qDebug() << "** index: " << i << ", name: " << node_label.c_str(); | 111 | + //qDebug() << "** index: " << i << ", name: " << node_label.c_str(); |
| 112 | 112 | ||
| 113 | //node type 설정 | 113 | //node type 설정 |
| 114 | if (boost::regex_match(node_label, paper_reg)) { | 114 | if (boost::regex_match(node_label, paper_reg)) { |
| ... | @@ -268,13 +268,64 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | ... | @@ -268,13 +268,64 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| 268 | } | 268 | } |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | -void GraphItem::path_highlighting(std::string start, std::string end) | 271 | +void GraphItem::might_know() |
| 272 | { | 272 | { |
| 273 | - //path highlight | 273 | + // 알 수도 있는 연구원 찾기 |
| 274 | - //nodeList, edgeList 속성을 수정 | 274 | + vertex_iterator vi, vi_end, vtarget; |
| 275 | + Graph::adjacency_iterator ai, ai_end; | ||
| 276 | + vector<string> might_know_vec; | ||
| 277 | + | ||
| 278 | + auto label = get(vertex_name, *graph); | ||
| 279 | + auto nodeType = get(vertex_type, *graph); | ||
| 280 | + | ||
| 281 | + // 회색 색칠 | ||
| 282 | + for (auto& n : nodeList) { | ||
| 283 | + if (n->getLabel().toStdString() != TARGET_AUTHOR_NAME) { | ||
| 284 | + n->setColor(QColor(Qt::lightGray)); | ||
| 285 | + } else { | ||
| 286 | + n->setColor(QColor(Qt::blue)); | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + // find target node | ||
| 291 | + for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi!=vi_end; ++vi) { | ||
| 292 | + if (label[*vi] == std::string(TARGET_AUTHOR_NAME)) { | ||
| 293 | + vtarget = vi; | ||
| 294 | + break; | ||
| 295 | + } | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + // bfs | ||
| 299 | + //std::queue<vertex_iterator> q; | ||
| 300 | + //q.push(vtarget); | ||
| 301 | + //while (!q.empty()) { | ||
| 302 | + // /*auto next_vi = q.front(); | ||
| 303 | + // q.pop(); | ||
| 304 | + | ||
| 305 | + // if (nodeType[*next_vi] == NODE_TYPE::NODE_PAPER) | ||
| 306 | + // continue; | ||
| 307 | + | ||
| 308 | + // for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*next_vi, *graph); | ||
| 309 | + // ai != ai_end; ++ai) { | ||
| 310 | + // if (nodeType[*ai] == NODE_TYPE::NODE_PAPER) | ||
| 311 | + // continue; | ||
| 312 | + // else | ||
| 313 | + // q.push(ai); | ||
| 314 | + // }*/ | ||
| 315 | + //} | ||
| 316 | + | ||
| 317 | + for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vtarget, *graph); | ||
| 318 | + ai != ai_end; | ||
| 319 | + ++ai) { | ||
| 320 | + might_know_vec.push_back(label[*ai]); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + // highlight | ||
| 275 | for (auto& n: nodeList) { | 324 | for (auto& n: nodeList) { |
| 276 | - if (n->getLabel() == QString("Seongsoo Park")) { | 325 | + if (std::find(might_know_vec.begin(), might_know_vec.end(), n->getLabel().toStdString()) |
| 277 | - n->setColor(QColor(255, 0, 0)); | 326 | + != might_know_vec.end()) { |
| 327 | + //found | ||
| 328 | + n->setColor(Qt::red); | ||
| 278 | } | 329 | } |
| 279 | } | 330 | } |
| 280 | } | 331 | } |
| ... | @@ -318,20 +369,24 @@ void GraphItem::topK_highlight() | ... | @@ -318,20 +369,24 @@ void GraphItem::topK_highlight() |
| 318 | int record_cnt = 0; | 369 | int record_cnt = 0; |
| 319 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vi, *graph); | 370 | for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vi, *graph); |
| 320 | ai != ai_end; ++ai) { | 371 | ai != ai_end; ++ai) { |
| 321 | - if (nodeType[*vi] == NODE_TYPE::NODE_PAPER) { | 372 | + if (nodeType[*ai] == NODE_TYPE::NODE_PAPER) { |
| 322 | ++record_cnt; | 373 | ++record_cnt; |
| 323 | } | 374 | } |
| 324 | } | 375 | } |
| 325 | 376 | ||
| 326 | boost::put(vertex_record, *graph, *vi, record_cnt); | 377 | boost::put(vertex_record, *graph, *vi, record_cnt); |
| 327 | heap.push(make_pair(record_cnt, nodeLabel[*vi])); | 378 | heap.push(make_pair(record_cnt, nodeLabel[*vi])); |
| 379 | + | ||
| 380 | + //qDebug() << record_cnt; | ||
| 328 | } | 381 | } |
| 329 | 382 | ||
| 330 | //get top K records | 383 | //get top K records |
| 331 | pair<int, string> topk_arr[TOP_K]; | 384 | pair<int, string> topk_arr[TOP_K]; |
| 332 | for (int i = 0; i < TOP_K; ++i) { | 385 | for (int i = 0; i < TOP_K; ++i) { |
| 333 | topk_arr[i] = heap.pop(); | 386 | topk_arr[i] = heap.pop(); |
| 387 | + qDebug() << "topk["<<i<<"] = " << topk_arr[i].first << ", " << QString::fromStdString(topk_arr[i].second); | ||
| 334 | } | 388 | } |
| 389 | + | ||
| 335 | 390 | ||
| 336 | for (auto& n: nodeList) { | 391 | for (auto& n: nodeList) { |
| 337 | auto label = n->getLabel(); | 392 | auto label = n->getLabel(); |
| ... | @@ -343,8 +398,6 @@ void GraphItem::topK_highlight() | ... | @@ -343,8 +398,6 @@ void GraphItem::topK_highlight() |
| 343 | } | 398 | } |
| 344 | } | 399 | } |
| 345 | } | 400 | } |
| 346 | - | ||
| 347 | - //delete[] topk_arr; | ||
| 348 | } | 401 | } |
| 349 | 402 | ||
| 350 | //event handler | 403 | //event handler | ... | ... |
| ... | @@ -26,7 +26,7 @@ public: | ... | @@ -26,7 +26,7 @@ public: |
| 26 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; | 26 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; |
| 27 | 27 | ||
| 28 | //methods | 28 | //methods |
| 29 | - void path_highlighting(std::string start, std::string end); | 29 | + void might_know(); |
| 30 | void reset_color(); | 30 | void reset_color(); |
| 31 | void topK_highlight(); | 31 | void topK_highlight(); |
| 32 | 32 | ... | ... |
| ... | @@ -17,7 +17,7 @@ MainWindow::MainWindow(QWidget *parent) | ... | @@ -17,7 +17,7 @@ MainWindow::MainWindow(QWidget *parent) |
| 17 | statusBar()->showMessage(message); | 17 | statusBar()->showMessage(message); |
| 18 | 18 | ||
| 19 | setMinimumSize(160, 160); | 19 | setMinimumSize(160, 160); |
| 20 | - resize(800, 600); | 20 | + resize(1200, 650); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | MainWindow::~MainWindow() | 23 | MainWindow::~MainWindow() |
| ... | @@ -44,9 +44,9 @@ void MainWindow::createActions() | ... | @@ -44,9 +44,9 @@ void MainWindow::createActions() |
| 44 | readMoreAct->setStatusTip(tr("read more lines from file")); | 44 | readMoreAct->setStatusTip(tr("read more lines from file")); |
| 45 | connect(readMoreAct, &QAction::triggered, this, &MainWindow::read_more); | 45 | connect(readMoreAct, &QAction::triggered, this, &MainWindow::read_more); |
| 46 | 46 | ||
| 47 | - testHighlightAct = new QAction(tr("Highlight"), this); | 47 | + mightKnowAct = new QAction(tr("Might know"), this); |
| 48 | - testHighlightAct->setStatusTip(tr("Highlighting node")); | 48 | + mightKnowAct->setStatusTip(tr("highlight a research you might know")); |
| 49 | - connect(testHighlightAct, &QAction::triggered, this, &MainWindow::test_highlighting); | 49 | + connect(mightKnowAct, &QAction::triggered, this, &MainWindow::might_know); |
| 50 | topkAct = new QAction(tr("topK"), this); | 50 | topkAct = new QAction(tr("topK"), this); |
| 51 | topkAct->setStatusTip(tr("highlight who was top k papers")); | 51 | topkAct->setStatusTip(tr("highlight who was top k papers")); |
| 52 | connect(topkAct, &QAction::triggered, this, &MainWindow::topk); | 52 | connect(topkAct, &QAction::triggered, this, &MainWindow::topk); |
| ... | @@ -61,7 +61,7 @@ void MainWindow::createMenus() | ... | @@ -61,7 +61,7 @@ void MainWindow::createMenus() |
| 61 | fileMenu->addAction(readMoreAct); | 61 | fileMenu->addAction(readMoreAct); |
| 62 | 62 | ||
| 63 | actionMenu = menuBar()->addMenu(tr("&Actions")); | 63 | actionMenu = menuBar()->addMenu(tr("&Actions")); |
| 64 | - actionMenu->addAction(testHighlightAct); | 64 | + actionMenu->addAction(mightKnowAct); |
| 65 | actionMenu->addAction(topkAct); | 65 | actionMenu->addAction(topkAct); |
| 66 | actionMenu->addAction(resetColorAct); | 66 | actionMenu->addAction(resetColorAct); |
| 67 | } | 67 | } |
| ... | @@ -75,12 +75,9 @@ void MainWindow::read_more() | ... | @@ -75,12 +75,9 @@ void MainWindow::read_more() |
| 75 | graphWidget->read_more(); | 75 | graphWidget->read_more(); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | -void MainWindow::test_highlighting() | 78 | +void MainWindow::might_know() |
| 79 | { | 79 | { |
| 80 | - /*QMessageBox::information(this, "test", | 80 | + graphWidget->might_know(); |
| 81 | - "test: "+QString::number(11));*/ | ||
| 82 | - graphWidget->path_highlight(); | ||
| 83 | - //graphWidget->update(); | ||
| 84 | } | 81 | } |
| 85 | 82 | ||
| 86 | void MainWindow::topk() | 83 | void MainWindow::topk() | ... | ... |
| ... | @@ -22,7 +22,7 @@ private: | ... | @@ -22,7 +22,7 @@ private: |
| 22 | QMenu *fileMenu; | 22 | QMenu *fileMenu; |
| 23 | QAction *readMoreAct; | 23 | QAction *readMoreAct; |
| 24 | QMenu *actionMenu; | 24 | QMenu *actionMenu; |
| 25 | - QAction *testHighlightAct; | 25 | + QAction *mightKnowAct; |
| 26 | QAction *topkAct; | 26 | QAction *topkAct; |
| 27 | QAction *resetColorAct; | 27 | QAction *resetColorAct; |
| 28 | 28 | ||
| ... | @@ -32,7 +32,7 @@ private: | ... | @@ -32,7 +32,7 @@ private: |
| 32 | 32 | ||
| 33 | private slots: | 33 | private slots: |
| 34 | void read_more(); | 34 | void read_more(); |
| 35 | - void test_highlighting(); | 35 | + void might_know(); |
| 36 | void topk(); | 36 | void topk(); |
| 37 | void reset_color(); | 37 | void reset_color(); |
| 38 | }; | 38 | }; | ... | ... |
| ... | @@ -54,9 +54,9 @@ void PaperGraphWidget::read_more() | ... | @@ -54,9 +54,9 @@ void PaperGraphWidget::read_more() |
| 54 | scene->update(); | 54 | scene->update(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | -void PaperGraphWidget::path_highlight() | 57 | +void PaperGraphWidget::might_know() |
| 58 | { | 58 | { |
| 59 | - graphItem->path_highlighting(std::string(""), std::string("")); | 59 | + graphItem->might_know(); |
| 60 | scene->update(); | 60 | scene->update(); |
| 61 | } | 61 | } |
| 62 | 62 | ... | ... |
| ... | @@ -105,12 +105,14 @@ namespace { | ... | @@ -105,12 +105,14 @@ namespace { |
| 105 | /* visualization */ | 105 | /* visualization */ |
| 106 | const int NODE_SIZE = 4; | 106 | const int NODE_SIZE = 4; |
| 107 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; | 107 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; |
| 108 | - const int SCREEN_SIZE = 1000; | 108 | + const int SCREEN_SIZE = 500; |
| 109 | - const int READ_LINE_UNIT = 5; //한 번에 몇 라인을 읽을지 | 109 | + const int READ_LINE_UNIT = 20; //한 번에 몇 라인을 읽을지 |
| 110 | 110 | ||
| 111 | /* topK */ | 111 | /* topK */ |
| 112 | - const int TOP_K = 10; //상위 몇 개 아이템에 대해 highlight 할 지 | 112 | + const int TOP_K = 5; //상위 몇 개 아이템에 대해 highlight 할 지 |
| 113 | 113 | ||
| 114 | + /* a research you might know */ | ||
| 115 | + const char* TARGET_AUTHOR_NAME = "Shuichi Itoh"; | ||
| 114 | } | 116 | } |
| 115 | 117 | ||
| 116 | /* boost */ | 118 | /* boost */ | ... | ... |
-
Please register or login to post a comment