7 #include "ArticleCollection.h"
8 #include "JsonSerializer.h"
9 #include "ToGraphvizWriter.h"
12 int main(int argc
, char** argv
)
15 std::cout
<< argv
[0] << " "
17 << "<dot file>" << std::endl
;
21 WikiWalker::JsonSerializer jser
;
22 std::ifstream
cache(argv
[1]);
24 // assumption: having write-only access to a file is so rare that I don't care
25 // also, currently the file is used for both read and write, so initially it
27 if(!cache
.is_open()) {
28 std::cerr
<< "Couldn't open cache file" << std::endl
;
32 WikiWalker::CollectionUtils::ArticleCollection ac
;
33 jser
.deserialize(ac
, cache
);
37 std::cerr
<< "Error reading from file" << std::endl
;
41 WikiWalker::CollectionUtils::ArticleCollection filteredColl
;
42 for(auto& anArticle
: ac
) {
43 auto art
= anArticle
.second
;
45 WikiWalker::CollectionUtils::add(filteredColl
, art
);
49 WikiWalker::ToGraphvizWriter g
;
50 std::ofstream
filteredGraph(argv
[2]);
52 if(!filteredGraph
.is_open()) {
53 std::cerr
<< "Couldn't open dot file for writing" << std::endl
;
57 g
.output(filteredColl
, filteredGraph
);
59 if(filteredGraph
.fail()) {
60 filteredGraph
.close();
61 std::cerr
<< "Error writing to file" << std::endl
;
65 filteredGraph
.close();
67 std::cout
<< "There are " << filteredColl
.size() << " analyzed articles"