Ejemplo n.º 1
0
void Pretreatment::paperDatePretreat(string path)
{

	int max = 0, min = INT_MAX;
	set<string> s;

	PaperReader pr(path);

	Paper p;
	
	while(pr.getNextPaper(p))
	{
		cout<<p.getIndex()<<endl;
		if(p.getYear() < min && p.getYear() != 0)
		{
			min = p.getYear();
		}

		if(p.getYear() > max)
		{
			max = p.getYear();
		}

		s.insert(p.getVenue());
	}

	ofstream fout;
	fout.open("./paperResult_2000", ios::out);
	fout<<"min : "<<min<<" max : "<<max<<endl;

	set<string>::iterator it;

	for(it=s.begin(); it != s.end(); it++)
	{
		fout<<*it<<endl;
	}
	fout.close();

}
Ejemplo n.º 2
0
void Pretreatment::countPaper(std::string path)
{
	int num[100] = {0};
	PaperReader pr(path);

	Paper p;
	while(pr.getNextPaper(p))
	{
		cout<<p.getIndex()<<endl;
		if(p.getYear() != 0)
		{
			num[p.getYear()-1936]++;
		}
	}

	ofstream fout;
	fout.open("./paperCount", ios::out);
	
	for(int i = 0; i < 100; i++)
	{
		fout<<i+1936<<" "<<num[i]<<endl;
	}
	fout.close();
}
Ejemplo n.º 3
0
int DatabaseHelper::addPaper(const Paper& paper)
{
    int bookTitleId = getBookTitleId(paper.getBookTitle());
    if (bookTitleId == -1) {
        bookTitleId = addBookTitle(paper.getBookTitle());
    }

    vector<int> authorsId(paper.getAuthors().size());
    for (vector<int>::size_type i = 0; i < paper.getAuthors().size(); ++i) {
        const string& author = paper.getAuthors().at(i);
        int authorId = getAuthorId(author);
        if (authorId == -1) {
            authorId = addAuthor(author);
        }
        authorsId[i] = authorId;
    }

    vector<int> tagsId(paper.getTags().size());
    for (vector<int>::size_type i = 0; i < paper.getTags().size(); ++i) {
        const string& tag = paper.getTags().at(i);
        int tagId = getTagId(tag);
        if (tagId == -1) {
            tagId = addTag(tag);
        }
        tagsId[i] = tagId;
    }

    QSqlQuery query;
    if (paper.getId() <= 0) {
        query.prepare("INSERT INTO pl_paper(year, book_title_id, title, path, comment) "
                      "VALUES(:year, :book_title_id, :title, :path, :comment)");
        query.bindValue(":year", paper.getYear());
        query.bindValue(":book_title_id", bookTitleId);
        query.bindValue(":title", paper.getTitle().c_str());
        query.bindValue(":path", paper.getPath().c_str());
        query.bindValue(":comment", paper.getComment().c_str());
    } else {
        query.prepare("INSERT INTO pl_paper(paper_id, year, book_title_id, title, path, comment) "
                      "VALUES(:paper_id, :year, :book_title_id, :title, :path, :comment)");
        query.bindValue(":paper_id", paper.getId());
        query.bindValue(":year", paper.getYear());
        query.bindValue(":book_title_id", bookTitleId);
        query.bindValue(":title", paper.getTitle().c_str());
        query.bindValue(":path", paper.getPath().c_str());
        query.bindValue(":comment", paper.getComment().c_str());
    }
    query.exec();

    int paperId = query.lastInsertId().toInt();
    QVariantList paperIdList, authorIdList;
    for (int i = 0; i < static_cast<int>(authorsId.size()); ++i) {
        paperIdList.append(paperId);
        authorIdList.append(authorsId[i]);
    }

    query.prepare("INSERT INTO pl_paper2author(paper_id, author_id) "
                  "VALUES(:paper_id, :author_id)");
    query.bindValue(":paper_id", paperIdList);
    query.bindValue(":author_id", authorIdList);
    query.execBatch();

    paperIdList.clear();
    QVariantList tagIdList;
    for (int i = 0; i < static_cast<int>(tagsId.size()); ++i) {
        paperIdList.append(paperId);
        tagIdList.append(tagsId[i]);
    }

    query.prepare("INSERT INTO pl_paper2tag(paper_id, tag_id) "
                  "VALUES(:paper_id, :tag_id)");
    query.bindValue(":paper_id", paperIdList);
    query.bindValue(":tag_id", tagIdList);
    query.execBatch();

    return paperId;
}