조성현

중간저장

......@@ -53,4 +53,5 @@ void EdgeItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option
pen.setColor(color);
painter->setPen(pen);
painter->drawLine(QLineF(x1, y1, x2, y2));
//painter->drawText(QPoint((x1 + x2) / 2, (y1 + y2) / 2), "hi");
}
......
......@@ -444,21 +444,6 @@ void GraphItem::might_know()
}
}
void GraphItem::reset_color()
{
for (auto& n: nodeList) {
if (n->getType() == NODE_PAPER) {
n->setColor(QColor(Qt::darkGreen));
} else {
n->setColor(QColor(Qt::green));
}
}
for (auto& e: edgeList) {
e->setColor(Qt::black);
e->setWidth(0);
}
}
void GraphItem::topK_highlight_with_total()
{
// 전체 그래프 기준 topK highlight
......@@ -479,9 +464,22 @@ void GraphItem::topK_highlight_with_total()
// boost::put(vertex_record, *graph, *vi, 0);
//}
// <record, label>
//저자별 논문 수 계산
TopKHeap<pair<int, string>> heap(TOP_K);
//k 입력
bool isok = false;
QInputDialog *inputDialog = new QInputDialog();
//int inputK = inputDialog->getText(nullptr, "Enter target's name", "Start node's name:",
// QLineEdit::Normal, "Akira Idoue", &isok).toStdString();
int inputK = inputDialog->getInt(nullptr, "Enter K", "K:", 3,
1, whole_node_cnt, 1, &isok);
if (!isok) {
qDebug("input cancelled");
return;
}
//저자별 논문 수 계산 + TopK Heap 사용
//pair -> <num_of_record, label>
TopKHeap<pair<int, string>> heap(inputK);
for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) {
if (node_type_map[*vi] != NODE_TYPE::NODE_AUTHOR) {
continue;
......@@ -502,8 +500,9 @@ void GraphItem::topK_highlight_with_total()
}
//get top K records
pair<int, string> topk_arr[TOP_K];
for (int i = 0; i < TOP_K; ++i) {
//pair<int, string> topk_arr[inputK];
pair<int, string> *topk_arr = new pair<int, string>[inputK];
for (int i = 0; i < inputK; ++i) {
topk_arr[i] = heap.pop();
qDebug() << "topk["<<i<<"] = " << topk_arr[i].first << ", " << QString::fromStdString(topk_arr[i].second);
}
......@@ -512,13 +511,227 @@ void GraphItem::topK_highlight_with_total()
for (auto& n: nodeList) {
auto label = n->getLabel();
n->setColor(QColor(Qt::lightGray));
for (auto& p: topk_arr) {
for (int i = 0; i < inputK; ++i) {
auto& p = topk_arr[i];
if (label.toStdString() == p.second) {
n->setColor(QColor(Qt::red));
break;
}
}
}
delete[] topk_arr;
}
void GraphItem::topK_highlight_with_target()
{
// 선택한 사람 주변 topK highlight
// 저자 노드별 실적 계산
vertex_iterator vi, vi_end;
vertex_descriptor vtarget;
Graph::adjacency_iterator ai, ai_end,
ai2, ai2_end;
auto node_idx_map = boost::get(vertex_index, *graph);
auto node_label_map = boost::get(vertex_name, *graph);
auto node_type_map = boost::get(vertex_type, *graph);
auto node_records_map = boost::get(vertex_record, *graph);
vector<vertex_descriptor> paper_vec;
vector<string> visited;
vector<vertex_descriptor> target_desc_range_vec;
//k 입력
bool isok = false;
QInputDialog *inputDialog = new QInputDialog();
//int inputK = inputDialog->getText(nullptr, "Enter target's name", "Start node's name:",
// QLineEdit::Normal, "Akira Idoue", &isok).toStdString();
int inputK = inputDialog->getInt(nullptr, "Enter K", "K:", 3,
1, whole_node_cnt, 1, &isok);
if (!isok) {
qDebug("input cancelled");
return;
}
//std::string target_name = inputDialog->getText
std::string target_name = inputDialog->getText(nullptr, "Enter target's name",
"target node's name:", QLineEdit::Normal, "Tobias Scholand", &isok).toStdString();
if (!isok) {
qDebug("input cancelled");
return;
}
qDebug() << target_name.c_str();
// find target node
for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) {
if (node_label_map[*vi] == target_name) {
target_desc_range_vec.push_back(*vi);
vtarget = vertex(node_idx_map[*vi], *graph);
break;
}
}
visited.push_back(target_name);
//push target's papers
for (boost::tie(ai, ai_end) = boost::adjacent_vertices(vtarget, *graph);
ai != ai_end;
++ai) {
//ai: 타겟 노드의 이웃 노드(paper)
const string& node_label = node_label_map[*ai];
paper_vec.push_back(vertex(node_idx_map[*ai], *graph));
visited.push_back(node_label);
}
// find coauthor
for (auto paper : paper_vec) {
//paper: 타겟 저자의 논문
for (boost::tie(ai, ai_end) = boost::adjacent_vertices(paper, *graph);
ai != ai_end;
++ai) {
//ai: paper의 이웃. = 저자들
// == coauthors
const string& node_label = node_label_map[*ai];
if (find(visited.begin(), visited.end(), node_label) != visited.end()) {
continue;
}
target_desc_range_vec.push_back(vertex(node_idx_map[*ai], *graph));
visited.push_back(node_label);
}
}
//저자별 논문 수 계산 + TopK Heap 사용
//target range에 대해 topK 구하기
//pair -> <num_of_record, label>
TopKHeap<pair<int, string>> heap(inputK);
for (auto& n: target_desc_range_vec) {
//if not author --> skip
if (node_type_map[n] != NODE_TYPE::NODE_AUTHOR) {
continue;
}
const string& node_label = node_label_map[n];
int record_cnt = 0;
//cnt
for (boost::tie(ai, ai_end) = boost::adjacent_vertices(n, *graph);
ai != ai_end;
++ai) {
++record_cnt;
}
boost::put(vertex_record, *graph, n, record_cnt);
heap.push(make_pair(record_cnt, node_label));
}
//get top K records
int heap_sz = std::min(inputK, heap.getSize());
pair<int, string> *topk_arr = new pair<int, string>[heap_sz];
for (int i = 0; i < heap_sz; ++i) {
topk_arr[i] = heap.pop();
qDebug() << "topk[" << i << "] = " << topk_arr[i].first << ", " << QString::fromStdString(topk_arr[i].second);
}
for (auto& n : nodeList) {
auto label = n->getLabel();
if (label.toStdString() != target_name) {
n->setColor(QColor(Qt::lightGray));
}
else {
n->setColor(QColor(Qt::blue));
}
//in target range
if (find(visited.begin(), visited.end(), label.toStdString()) != visited.end()) {
n->setColor(QColor(Qt::green));
}
//if topK
for (int i = 0; i < heap_sz; ++i) {
auto& p = topk_arr[i];
if (label.toStdString() == p.second) {
n->setColor(QColor(Qt::red));
break;
}
}
}
delete[] topk_arr;
}
void GraphItem::topK_using_custom_score()
{
// 전체 그래프 기준 topK highlight
// 저자 노드별 실적 계산
vertex_iterator vi, vi_end;
Graph::adjacency_iterator ai, ai_end;
auto node_label_map = boost::get(vertex_name, *graph);
auto node_type_map = boost::get(vertex_type, *graph);
auto node_records_map = boost::get(vertex_record, *graph);
//k 입력
bool isok = false;
QInputDialog *inputDialog = new QInputDialog();
//int inputK = inputDialog->getText(nullptr, "Enter target's name", "Start node's name:",
// QLineEdit::Normal, "Akira Idoue", &isok).toStdString();
int inputK = inputDialog->getInt(nullptr, "Enter K", "K:", 3,
1, whole_node_cnt, 1, &isok);
if (!isok) {
qDebug("input cancelled");
return;
}
//저자별 논문 수 계산 + TopK Heap 사용
//pair -> <num_of_record, label>
TopKHeap<pair<int, string>> heap(inputK);
for (boost::tie(vi, vi_end) = boost::vertices(*graph); vi != vi_end; ++vi) {
if (node_type_map[*vi] != NODE_TYPE::NODE_AUTHOR) {
continue;
}
int record_cnt = 0;
for (boost::tie(ai, ai_end) = boost::adjacent_vertices(*vi, *graph);
ai != ai_end; ++ai) {
if (node_type_map[*ai] == NODE_TYPE::NODE_PAPER) {
++record_cnt;
}
}
boost::put(vertex_record, *graph, *vi, record_cnt);
heap.push(make_pair(record_cnt, node_label_map[*vi]));
//qDebug() << record_cnt;
}
//get top K records
//pair<int, string> topk_arr[inputK];
pair<int, string> *topk_arr = new pair<int, string>[inputK];
for (int i = 0; i < inputK; ++i) {
topk_arr[i] = heap.pop();
qDebug() << "topk[" << i << "] = " << topk_arr[i].first << ", " << QString::fromStdString(topk_arr[i].second);
}
for (auto& n : nodeList) {
auto label = n->getLabel();
n->setColor(QColor(Qt::lightGray));
for (int i = 0; i < inputK; ++i) {
auto& p = topk_arr[i];
if (label.toStdString() == p.second) {
n->setColor(QColor(Qt::red));
break;
}
}
}
delete[] topk_arr;
}
void GraphItem::find_shortest_path()
......@@ -529,8 +742,7 @@ void GraphItem::find_shortest_path()
auto node_idx_map = boost::get(vertex_index, *graph);
auto node_label_map = boost::get(vertex_name, *graph);
string target_start,
target_end;
string target_start, target_end;
bool isok = false;
......@@ -645,6 +857,21 @@ void GraphItem::find_shortest_path()
qDebug("* path highlighting end");
}
void GraphItem::reset_color()
{
for (auto& n: nodeList) {
if (n->getType() == NODE_PAPER) {
n->setColor(QColor(Qt::darkGreen));
} else {
n->setColor(QColor(Qt::green));
}
}
for (auto& e: edgeList) {
e->setColor(Qt::black);
e->setWidth(0);
}
}
void GraphItem::test()
{
qDebug("* test action start");
......
......@@ -27,9 +27,11 @@ public:
//methods
void might_know();
void reset_color();
void topK_highlight_with_total();
void topK_highlight_with_target();
void topK_using_custom_score();
void find_shortest_path();
void reset_color();
//test
void test();
......
......@@ -39,19 +39,25 @@ void MainWindow::createActions()
readMoreAct->setStatusTip(tr("read more lines from file"));
connect(readMoreAct, &QAction::triggered, this, &MainWindow::read_more);
mightKnowAct = new QAction(tr("Might know"), this);
mightKnowAct->setStatusTip(tr("highlight a research you might know"));
connect(mightKnowAct, &QAction::triggered, this, &MainWindow::might_know);
topkAct = new QAction(tr("topK"), this);
topkAct->setStatusTip(tr("highlight who was top k papers"));
connect(topkAct, &QAction::triggered, this, &MainWindow::topk);
resetColorAct = new QAction(tr("Reset colors"), this);
resetColorAct->setStatusTip(tr("Reset all node's color"));
connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color);
topkWithTotalAct = new QAction(tr("topK with total"), this);
topkWithTotalAct->setStatusTip(tr("highlight who was top k papers in whole graph"));
connect(topkWithTotalAct, &QAction::triggered, this, &MainWindow::topK_with_total);
topKWithTargetAct = new QAction(tr("topK with target"), this);
topKWithTargetAct->setStatusTip(tr("highlight who was top k papers in particular range"));
connect(topKWithTargetAct, &QAction::triggered, this, &MainWindow::topK_with_target);
findShortestPathAct = new QAction(tr("Find Shortest Path"), this);
findShortestPathAct->setStatusTip("Find shortest path between two node");
connect(findShortestPathAct, &QAction::triggered, this, &MainWindow::find_shortest_path);
resetColorAct = new QAction(tr("Reset colors"), this);
resetColorAct->setStatusTip(tr("Reset all node's color"));
connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color);
testAct = new QAction(tr("test action"), this);
testAct->setStatusTip(tr("test test"));
connect(testAct, &QAction::triggered, this, &MainWindow::test);
......@@ -64,10 +70,12 @@ void MainWindow::createMenus()
actionMenu = menuBar()->addMenu(tr("&Actions"));
actionMenu->addAction(mightKnowAct);
actionMenu->addAction(topkAct);
actionMenu->addAction(resetColorAct);
actionMenu->addAction(topkWithTotalAct);
actionMenu->addAction(topKWithTargetAct);
actionMenu->addAction(findShortestPathAct);
actionMenu->addAction(resetColorAct);
testMenu = menuBar()->addMenu(tr("&Test"));
testMenu->addAction(testAct);
}
......@@ -86,14 +94,14 @@ void MainWindow::might_know()
graphWidget->might_know();
}
void MainWindow::topk()
void MainWindow::topK_with_total()
{
graphWidget->topk_with_total();
}
void MainWindow::reset_color()
void MainWindow::topK_with_target()
{
graphWidget->reset_color();
graphWidget->topk_with_target();
}
void MainWindow::find_shortest_path()
......@@ -101,6 +109,11 @@ void MainWindow::find_shortest_path()
graphWidget->find_shortest_path();
}
void MainWindow::reset_color()
{
graphWidget->reset_color();
}
void MainWindow::test()
{
graphWidget->test();
......
......@@ -22,7 +22,8 @@ private:
QAction *readMoreAct;
QMenu *actionMenu;
QAction *mightKnowAct;
QAction *topkAct;
QAction *topkWithTotalAct;
QAction *topKWithTargetAct;
QAction *resetColorAct;
QAction *findShortestPathAct;
......@@ -37,9 +38,10 @@ private:
private slots:
void read_more();
void might_know();
void topk();
void reset_color();
void topK_with_total();
void topK_with_target();
void find_shortest_path();
void reset_color();
//test
void test();
};
......
......@@ -63,6 +63,12 @@ void PaperGraphWidget::topk_with_total()
scene->update();
}
void PaperGraphWidget::topk_with_target()
{
graphItem->topK_highlight_with_target();
scene->update();
}
void PaperGraphWidget::find_shortest_path()
{
graphItem->find_shortest_path();
......
......@@ -17,6 +17,7 @@ public:
void read_more();
void might_know();
void topk_with_total();
void topk_with_target();
void find_shortest_path();
void reset_color();
......
......@@ -104,10 +104,10 @@ namespace {
//const int SCREEN_SIZE = 3000;
const int SCREEN_SIZE = 500;
//const int READ_LINE_UNIT = 20; //한 번에 몇 라인을 읽을지
const int READ_LINE_UNIT = 40;
const int READ_LINE_UNIT = 100;
/* topK */
const int TOP_K = 5; //상위 몇 개 아이템에 대해 highlight 할 지
//const int TOP_K = 5; //상위 몇 개 아이템에 대해 highlight 할 지
/* a research you might know */
//const char* TARGET_AUTHOR_NAME = "Shuichi Itoh";
......@@ -200,4 +200,6 @@ public:
return ret;
}
}
int getSize() {return size;}
bool isFull() {return k==size;}
};
\ No newline at end of file
......