Showing
6 changed files
with
154 additions
and
42 deletions
... | @@ -35,6 +35,7 @@ void GraphItem::read_more() | ... | @@ -35,6 +35,7 @@ void GraphItem::read_more() |
35 | auto node_position_map = boost::get(vertex_position, *graph); | 35 | auto node_position_map = boost::get(vertex_position, *graph); |
36 | auto node_label_map = boost::get(vertex_name, *graph); | 36 | auto node_label_map = boost::get(vertex_name, *graph); |
37 | auto node_type_map = boost::get(vertex_type, *graph); | 37 | auto node_type_map = boost::get(vertex_type, *graph); |
38 | + auto node_citation_map = boost::get(vertex_citation, *graph); | ||
38 | 39 | ||
39 | int line_cnt = 0; | 40 | int line_cnt = 0; |
40 | qDebug() << "* graph reading start"; | 41 | qDebug() << "* graph reading start"; |
... | @@ -110,15 +111,49 @@ void GraphItem::read_more() | ... | @@ -110,15 +111,49 @@ void GraphItem::read_more() |
110 | 111 | ||
111 | //qDebug() << "** index: " << i << ", name: " << node_label.c_str(); | 112 | //qDebug() << "** index: " << i << ", name: " << node_label.c_str(); |
112 | 113 | ||
113 | - //node type 설정 | 114 | + //node type에 따라 |
114 | if (boost::regex_match(node_label, paper_reg)) { | 115 | if (boost::regex_match(node_label, paper_reg)) { |
115 | - //Paper | 116 | + //Paper일 경우 |
117 | + //vertex type 설정 | ||
116 | boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_PAPER); | 118 | boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_PAPER); |
119 | + | ||
120 | + //citation counting | ||
121 | + //bibtex 다운로드 | ||
122 | + std::string dblp_url = std::string("http://dblp.uni-trier.de/rec/bib1/") + node_label; | ||
123 | + _curl_processor.set_url(dblp_url.c_str()); | ||
124 | + _curl_processor.perform(); | ||
125 | + | ||
126 | + //bibtex 파싱 | ||
127 | + _bibtex_processor.read(_curl_processor.get_buffer()); | ||
128 | + | ||
129 | + std::string doi; | ||
130 | + if (!_bibtex_processor.get_value("doi", doi)) { | ||
131 | + //doi가 없는 경우 | ||
132 | + node_citation_map[*vi] = 0; //citation count 0으로 설정 | ||
133 | + } | ||
134 | + else { | ||
135 | + //doi가 존재하는 경우 | ||
136 | + std::string json_address = std::string("http://api.crossref.org/works/") + doi; | ||
137 | + _curl_processor.set_url(json_address.c_str()); | ||
138 | + _curl_processor.perform(); | ||
139 | + | ||
140 | + _json_processor.read_json(_curl_processor.get_buffer()); | ||
141 | + if (!_json_processor.is_ok()) { | ||
142 | + node_citation_map[*vi] = 0; | ||
143 | + } | ||
144 | + else { | ||
145 | + node_citation_map[*vi] = _json_processor.get_citation_count(); | ||
146 | + } | ||
147 | + } | ||
117 | } else { | 148 | } else { |
118 | //Author | 149 | //Author |
119 | boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_AUTHOR); | 150 | boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_AUTHOR); |
120 | } | 151 | } |
121 | 152 | ||
153 | + | ||
154 | + | ||
155 | + //counter | ||
156 | + //printf("%d end: %s\n", i, node_label.c_str()); | ||
122 | ++i; | 157 | ++i; |
123 | } | 158 | } |
124 | qDebug() << "* set vertex property end"; | 159 | qDebug() << "* set vertex property end"; |
... | @@ -876,13 +911,22 @@ void GraphItem::test() | ... | @@ -876,13 +911,22 @@ void GraphItem::test() |
876 | { | 911 | { |
877 | qDebug("* test action start"); | 912 | qDebug("* test action start"); |
878 | 913 | ||
879 | - //count 테스트 | ||
880 | 914 | ||
881 | //전체노드 색 변경 | 915 | //전체노드 색 변경 |
882 | for (auto& n: nodeList) { | 916 | for (auto& n: nodeList) { |
883 | n->setColor(Qt::lightGray); | 917 | n->setColor(Qt::lightGray); |
884 | } | 918 | } |
885 | 919 | ||
920 | + //citation 디버그 | ||
921 | + auto node_citation_map = boost::get(vertex_citation, *graph); | ||
922 | + auto node_label_map = boost::get(vertex_name, *graph); | ||
923 | + auto node_type_map = boost::get(vertex_type, *graph); | ||
924 | + vertex_iterator vi, vi_end; | ||
925 | + for (boost::tie(vi, vi_end) = vertices(*graph); vi != vi_end; ++vi) { | ||
926 | + if (node_type_map[*vi] != NODE_TYPE::NODE_PAPER) continue; | ||
927 | + printf("%s, %d\n", node_label_map[*vi].c_str(), | ||
928 | + node_citation_map[*vi]); | ||
929 | + } | ||
886 | 930 | ||
887 | 931 | ||
888 | qDebug("* test action end"); | 932 | qDebug("* test action end"); | ... | ... |
... | @@ -89,6 +89,9 @@ | ... | @@ -89,6 +89,9 @@ |
89 | <ClCompile Include="bibtex_processor.cpp"> | 89 | <ClCompile Include="bibtex_processor.cpp"> |
90 | <Filter>Source Files</Filter> | 90 | <Filter>Source Files</Filter> |
91 | </ClCompile> | 91 | </ClCompile> |
92 | + <ClCompile Include="json_processor.cpp"> | ||
93 | + <Filter>Source Files</Filter> | ||
94 | + </ClCompile> | ||
92 | </ItemGroup> | 95 | </ItemGroup> |
93 | <ItemGroup> | 96 | <ItemGroup> |
94 | <CustomBuild Include="PaperGraphWidget.h"> | 97 | <CustomBuild Include="PaperGraphWidget.h"> |
... | @@ -123,5 +126,8 @@ | ... | @@ -123,5 +126,8 @@ |
123 | <ClInclude Include="bibtex_processor.h"> | 126 | <ClInclude Include="bibtex_processor.h"> |
124 | <Filter>Header Files</Filter> | 127 | <Filter>Header Files</Filter> |
125 | </ClInclude> | 128 | </ClInclude> |
129 | + <ClInclude Include="json_processor.h"> | ||
130 | + <Filter>Header Files</Filter> | ||
131 | + </ClInclude> | ||
126 | </ItemGroup> | 132 | </ItemGroup> |
127 | </Project> | 133 | </Project> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
PaperGraph/json_processor.cpp
0 → 100644
1 | +#include "stdafx.h" | ||
2 | +#include "json_processor.h" | ||
3 | + | ||
4 | +////////////////////////////////////////////////////////////////// | ||
5 | +// constructor, destructor | ||
6 | +////////////////////////////////////////////////////////////////// | ||
7 | +json_processor::json_processor() { | ||
8 | +} | ||
9 | + | ||
10 | +json_processor::~json_processor() { | ||
11 | + //document.Clear(); | ||
12 | +} | ||
13 | + | ||
14 | + | ||
15 | +////////////////////////////////////////////////////////////////// | ||
16 | +// methods | ||
17 | +////////////////////////////////////////////////////////////////// | ||
18 | +void json_processor::read_json(const std::string& json_str) { | ||
19 | + document.Parse(json_str.c_str()); | ||
20 | +} | ||
21 | + | ||
22 | +bool json_processor::is_ok() { | ||
23 | + rapidjson::Value& value_status = document["status"]; | ||
24 | + std::string status_str = value_status.GetString(); | ||
25 | + return (status_str == "ok"); | ||
26 | +} | ||
27 | + | ||
28 | +int json_processor::get_citation_count() { | ||
29 | + //원래는 json_processor를 상속받는 클래스를 만들어야 하지만 | ||
30 | + //빠른 구현을 위해서 대충 이 클래스에 구현 | ||
31 | + rapidjson::Value& citation_count = document["message"]["is-referenced-by-count"]; | ||
32 | + return citation_count.GetInt(); | ||
33 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
PaperGraph/json_processor.h
0 → 100644
1 | +#pragma once | ||
2 | +#include "stdafx.h" | ||
3 | + | ||
4 | +class json_processor | ||
5 | +{ | ||
6 | + //private var | ||
7 | +private: | ||
8 | + rapidjson::Document document; | ||
9 | + | ||
10 | + //constructor, destructor | ||
11 | +public: | ||
12 | + json_processor(); | ||
13 | + ~json_processor(); | ||
14 | + | ||
15 | + //methods | ||
16 | +public: | ||
17 | + void read_json(const std::string& json_str); | ||
18 | + bool is_ok(); | ||
19 | + int get_citation_count(); | ||
20 | +}; | ||
21 | + |
... | @@ -3,42 +3,46 @@ | ... | @@ -3,42 +3,46 @@ |
3 | #include "MainWindow.h" | 3 | #include "MainWindow.h" |
4 | 4 | ||
5 | int main(int argc, char *argv[]) { | 5 | int main(int argc, char *argv[]) { |
6 | - if (1) { | 6 | + //if (1) { |
7 | - _curl_processor.set_url("http://dblp.uni-trier.de/rec/bib1/conf/sbrn/WedemannCD06"); | 7 | + // _curl_processor.set_url("http://dblp.uni-trier.de/rec/bib1/conf/sbrn/WedemannCD06"); |
8 | - _curl_processor.perform(); | 8 | + // _curl_processor.perform(); |
9 | - printf("%s", _curl_processor.get_buffer().c_str()); | 9 | + // printf("%s", _curl_processor.get_buffer().c_str()); |
10 | - | 10 | + // |
11 | - _bibtex_processor.read(_curl_processor.get_buffer()); | 11 | + // _bibtex_processor.read(_curl_processor.get_buffer()); |
12 | - std::string doi; | 12 | + // std::string doi; |
13 | - _bibtex_processor.get_value("doi", doi); | 13 | + // _bibtex_processor.get_value("doi", doi); |
14 | - | 14 | + |
15 | - std::string address = std::string("http://api.crossref.org/works/")+doi; | 15 | + // std::string address = std::string("http://api.crossref.org/works/")+doi; |
16 | - _curl_processor.set_url(address.c_str()); | 16 | + // _curl_processor.set_url(address.c_str()); |
17 | - _curl_processor.perform(); | 17 | + // _curl_processor.perform(); |
18 | - | 18 | + |
19 | - printf("json: %s\n", _curl_processor.get_buffer().c_str()); | 19 | + // printf("json: %s\n", _curl_processor.get_buffer().c_str()); |
20 | - | 20 | + |
21 | - //rapidjson test | 21 | + // //rapidjson test |
22 | - rapidjson::Document d; | 22 | + // rapidjson::Document d; |
23 | - d.Parse(_curl_processor.get_buffer().c_str()); | 23 | + // d.Parse(_curl_processor.get_buffer().c_str()); |
24 | - | 24 | + |
25 | - rapidjson::Value& value_status = d["status"]; | 25 | + // rapidjson::Value& value_status = d["status"]; |
26 | - std::string status_str = value_status.GetString(); | 26 | + // std::string status_str = value_status.GetString(); |
27 | - printf("status: %s\n", status_str.c_str()); | 27 | + // printf("status: %s\n", status_str.c_str()); |
28 | - | 28 | + |
29 | - //if (status_str != "ok") { | 29 | + // if (status_str != "ok") { |
30 | - // printf("status: %s\n", status_str.c_str()); | 30 | + // printf("status: %s\n", status_str.c_str()); |
31 | - // printf("not ok\n"); | 31 | + // printf("not ok\n"); |
32 | - // return 1; | 32 | + // return 1; |
33 | - //} | 33 | + // } |
34 | - | 34 | + |
35 | - rapidjson::Value& value_message = d["message"]; | 35 | + // rapidjson::Value& value_message = d["message"]; |
36 | - rapidjson::Value& citation_count = value_message["is-referenced-by-count"]; | 36 | + // rapidjson::Value& citation_count = value_message["is-referenced-by-count"]; |
37 | - int cit_cnt = citation_count.GetInt(); | 37 | + // int cit_cnt = citation_count.GetInt(); |
38 | - printf("citation: %d\n", cit_cnt); | 38 | + // printf("citation: %d\n", cit_cnt); |
39 | - | 39 | + |
40 | - return 0; | 40 | + // // |
41 | - } | 41 | + // rapidjson::Value& citation_count2 = d["message"]["is-referenced-by-count"]; |
42 | + // printf("%d\n", citation_count2.GetInt()); | ||
43 | + | ||
44 | + // return 0; | ||
45 | + //} | ||
42 | 46 | ||
43 | QApplication app(argc, argv); | 47 | QApplication app(argc, argv); |
44 | 48 | ... | ... |
... | @@ -55,6 +55,7 @@ | ... | @@ -55,6 +55,7 @@ |
55 | 55 | ||
56 | #include "bibtex_processor.h" | 56 | #include "bibtex_processor.h" |
57 | #include "curl_processor.h" | 57 | #include "curl_processor.h" |
58 | +#include "json_processor.h" | ||
58 | 59 | ||
59 | using bibtex::BibTeXEntry; | 60 | using bibtex::BibTeXEntry; |
60 | using namespace boost; | 61 | using namespace boost; |
... | @@ -93,7 +94,7 @@ typedef boost::property<vertex_index_t, int, | ... | @@ -93,7 +94,7 @@ typedef boost::property<vertex_index_t, int, |
93 | boost::property<vertex_position_t, point, //좌표값 | 94 | boost::property<vertex_position_t, point, //좌표값 |
94 | boost::property<vertex_type_t, int, //타입. enum NODE_TYPE에 정의됨 | 95 | boost::property<vertex_type_t, int, //타입. enum NODE_TYPE에 정의됨 |
95 | boost::property<vertex_record_t, int, //이웃 노드 개수 | 96 | boost::property<vertex_record_t, int, //이웃 노드 개수 |
96 | - boost::property<vertex_citation_t, int> | 97 | + boost::property<vertex_citation_t, int> //피인용수 |
97 | >>>> | 98 | >>>> |
98 | > VertexProperties; | 99 | > VertexProperties; |
99 | typedef boost::adjacency_list< | 100 | typedef boost::adjacency_list< |
... | @@ -122,14 +123,17 @@ namespace { | ... | @@ -122,14 +123,17 @@ namespace { |
122 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; | 123 | const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; |
123 | //const int SCREEN_SIZE = 3000; | 124 | //const int SCREEN_SIZE = 3000; |
124 | const int SCREEN_SIZE = 500; | 125 | const int SCREEN_SIZE = 500; |
125 | - //const int READ_LINE_UNIT = 20; //한 번에 몇 라인을 읽을지 | 126 | + const int READ_LINE_UNIT = 100; //한 번에 몇 라인을 읽을지 |
126 | - const int READ_LINE_UNIT = 100; | 127 | + //const int READ_LINE_UNIT = 100; |
127 | 128 | ||
128 | /* curl processor */ | 129 | /* curl processor */ |
129 | curl_processor _curl_processor; | 130 | curl_processor _curl_processor; |
130 | 131 | ||
131 | /* bibtex processor */ | 132 | /* bibtex processor */ |
132 | bibtex_processor _bibtex_processor; | 133 | bibtex_processor _bibtex_processor; |
134 | + | ||
135 | + /* json processor */ | ||
136 | + json_processor _json_processor; | ||
133 | } | 137 | } |
134 | 138 | ||
135 | /* boost */ | 139 | /* boost */ | ... | ... |
-
Please register or login to post a comment