<commit_before>/*=============================================================================
# Filename: ginit.cpp
# Author: suxunbin
# Mail: <EMAIL>
# Last Modified: 2018-10-17 14:59
# Description: used to initialize the system.db
# Modified by liwenjie
# Modified Date: 2020-03-26 10:33
# Description£ºAdd the args "-cv" for updating the coreversion and the args "-av" for updating the apiversion in ginit function
# Description£ºAdd the args "-u" for updating the version information when updating the gstore.
=============================================================================*/

#include "../Util/Util.h"
#include "../Database/Database.h"
#include <iostream>
#include <fstream>
//#include "../Util/Slog.h"
using namespace std;

int main(int argc, char * argv[])
{
	
	Util util;
	//Log.init("slog.properties");
	
	if (argc == 1)
	{
		/*cout << "please input the complete command:\t" << endl;
		cout << "\t bin/gadd -h" << endl;*/
		long tv_begin = Util::get_cur_time();
		cout<<"begin rebuild the system database ...."<<endl;
		if (Util::dir_exist("system.db"))
		{
			string cmd;
			cmd = "rm -r system.db";
			system(cmd.c_str());
			
		}
		string _db_path = "system";
		string _rdf = "./data/system/system.nt";
		Database* _db = new Database(_db_path);
		bool flag = _db->build(_rdf);
		if (flag)
		{
			
			ofstream f;
			f.open("./" + _db_path + ".db/success.txt");
			f.close();

			cout<<"system.db rebuild successfully!"<<endl;
			delete _db;
			_db = NULL;
			Util::init_backuplog();
			cout<<"init backuplog successfully!"<<endl;
			Util::configure_new();
			string version = Util::getConfigureValue("version");
			string update_sparql = "insert data {<CoreVersion> <value> \"" + version + "\". }";
			cout<<"version:"<<version<<",update_sparql:"<<update_sparql<<endl;
			ResultSet _rs;
			FILE* ofp = stdout;
			string msg;
			_db = new Database(_db_path);
			_db->load();
			int ret = _db->query(update_sparql, _rs, ofp);
			if (ret >= 0)
				msg = "update num : " + Util::int2string(ret);
			else //update error
				msg = "update failed.";
			if (ret != -100)
				cout<<"Insert data result:" + msg<<endl;

			
		
			delete _db;
		    _db = NULL;
			long tv_end = Util::get_cur_time();
			//stringstream ss;
			cout << "system.db init successfully! Used " << (tv_end - tv_begin) << " ms"<<endl;
			//Log.Info(ss.str().c_str());
			return 0;

		}
		else
		{
			cout<<"Build RDF database failure!"<<endl;
			return 0;
		}
		

	}
	else if (argc == 2)
	{
		string command = argv[1];
		if (command == "-h" || command == "--help")
		{
			cout << endl;
			cout << "gStore Initialize Data Tools(ginit)" << endl;
			cout << endl;
			cout << "Usage:\tbin/ginit  -db [dbname] " << endl;
			cout << endl;
			cout << "Options:" << endl;
			cout << "\t-h,--help\t\tDisplay this message." << endl;
			cout << "\t-db,--database,\t\t The database names.Use , to split database name. e.g. databaseA,databaseB" << endl;
			cout << "If you want to rebuild the system database,please use bin/ginit \n"
				 << endl;
			cout << "If you want to add database info into system database,please use bin/ginit -db db1,db2,...\n"
				 << endl;
			cout << endl;
			return 0;
		}
		else if (command == "-m" || command == "--make")
		{
			if (Util::dir_exist("system.db") == false)
			{
				cout << "system.db is not exist. Now create it." << endl;
				long tv_begin = Util::get_cur_time();

				string _db_path = "system";
				string _rdf = "./data/system/system.nt";
				Database *_db = new Database(_db_path);
				bool flag = _db->build(_rdf);
				if (flag)
				{

					ofstream f;
					f.open("./" + _db_path + ".db/success.txt");
					f.close();

					cout << "system.db built successfully!" << endl;
					delete _db;
					_db = NULL;
					Util::init_backuplog();
					Util::configure_new();
					string version = Util::getConfigureValue("version");
					string update_sparql = "insert data {<CoreVersion> <value> " + version + ". }";

					ResultSet _rs;
					FILE *ofp = stdout;
					string msg;
					_db = new Database(_db_path);
					_db->load();<commit_msg>Fixed Runtime Error in ginit --make <commit_after>/*=============================================================================
# Filename: ginit.cpp
# Author: suxunbin
# Mail: <EMAIL>
# Last Modified: 2018-10-17 14:59
# Description: used to initialize the system.db
# Modified by liwenjie
# Modified Date: 2020-03-26 10:33
# Description£ºAdd the args "-cv" for updating the coreversion and the args "-av" for updating the apiversion in ginit function
# Description£ºAdd the args "-u" for updating the version information when updating the gstore.
=============================================================================*/

#include "../Util/Util.h"
#include "../Database/Database.h"
#include <iostream>
#include <fstream>
//#include "../Util/Slog.h"
using namespace std;

int main(int argc, char * argv[])
{
	
	Util util;
	//Log.init("slog.properties");
	
	if (argc == 1)
	{
		/*cout << "please input the complete command:\t" << endl;
		cout << "\t bin/gadd -h" << endl;*/
		long tv_begin = Util::get_cur_time();
		cout<<"begin rebuild the system database ...."<<endl;
		if (Util::dir_exist("system.db"))
		{
			string cmd;
			cmd = "rm -r system.db";
			system(cmd.c_str());
			
		}
		string _db_path = "system";
		string _rdf = "./data/system/system.nt";
		Database* _db = new Database(_db_path);
		bool flag = _db->build(_rdf);
		if (flag)
		{
			
			ofstream f;
			f.open("./" + _db_path + ".db/success.txt");
			f.close();

			cout<<"system.db rebuild successfully!"<<endl;
			delete _db;
			_db = NULL;
			Util::init_backuplog();
			cout<<"init backuplog successfully!"<<endl;
			Util::configure_new();
			string version = Util::getConfigureValue("version");
			string update_sparql = "insert data {<CoreVersion> <value> \"" + version + "\". }";
			cout<<"version:"<<version<<",update_sparql:"<<update_sparql<<endl;
			ResultSet _rs;
			FILE* ofp = stdout;
			string msg;
			_db = new Database(_db_path);
			_db->load();
			int ret = _db->query(update_sparql, _rs, ofp);
			if (ret >= 0)
				msg = "update num : " + Util::int2string(ret);
			else //update error
				msg = "update failed.";
			if (ret != -100)
				cout<<"Insert data result:" + msg<<endl;

			
		
			delete _db;
		    _db = NULL;
			long tv_end = Util::get_cur_time();
			//stringstream ss;
			cout << "system.db init successfully! Used " << (tv_end - tv_begin) << " ms"<<endl;
			//Log.Info(ss.str().c_str());
			return 0;

		}
		else
		{
			cout<<"Build RDF database failure!"<<endl;
			return 0;
		}
		

	}
	else if (argc == 2)
	{
		string command = argv[1];
		if (command == "-h" || command == "--help")
		{
			cout << endl;
			cout << "gStore Initialize Data Tools(ginit)" << endl;
			cout << endl;
			cout << "Usage:\tbin/ginit  -db [dbname] " << endl;
			cout << endl;
			cout << "Options:" << endl;
			cout << "\t-h,--help\t\tDisplay this message." << endl;
			cout << "\t-db,--database,\t\t The database names.Use , to split database name. e.g. databaseA,databaseB" << endl;
			cout << "If you want to rebuild the system database,please use bin/ginit \n"
				 << endl;
			cout << "If you want to add database info into system database,please use bin/ginit -db db1,db2,...\n"
				 << endl;
			cout << endl;
			return 0;
		}
		else if (command == "-m" || command == "--make")
		{
			if (Util::dir_exist("system.db") == false)
			{
				cout << "system.db is not exist. Now create it." << endl;
				long tv_begin = Util::get_cur_time();

				string _db_path = "system";
				string _rdf = "./data/system/system.nt";
				Database *_db = new Database(_db_path);
				bool flag = _db->build(_rdf);
				if (flag)
				{

					ofstream f;
					f.open("./" + _db_path + ".db/success.txt");
					f.close();

					cout << "system.db built successfully!" << endl;
					delete _db;
					_db = NULL;
					Util::init_backuplog();
					Util::configure_new();
					string version = Util::getConfigureValue("version");
					string update_sparql = "insert data {<CoreVersion> <value> \"" + version + "\". }";

					ResultSet _rs;
					FILE *ofp = stdout;
					string msg;
					_db = new Database(_db_path);
					_db->load();
{'fraction_non_alphanumeric': 0.205077885440942, 'fraction_numerical': 0.009076413590089538, 'mean_word_length': 3.136986301369863, 'pattern_counts': {'":': 0, '<': 197, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1945693', 'n_tokens_mistral': 3310, 'n_tokens_neox': 2733, 'n_words': 751}