예제 #1
0
int main(int argc, char **argv) {
	int c;
	string query, inputFile, outputFile;
	bool measure = false;

	while( (c = getopt(argc,argv,"hq:o:m"))!=-1) {
		switch(c) {
		case 'h':
			break;
		case 'q':
			query = optarg;
			break;
		case 'o':
			outputFile = optarg;
			break;
		case 'm':
			measure = true;
			break;
		default:
			cout << "ERROR: Unknown option" << endl;
			return 1;
		}
	}

	if(argc-optind<1) {
		cout << "ERROR: You must supply an input and HDT File" << endl << endl;
		return 1;
	}

	inputFile = argv[optind];

	try {
		// LOAD
		HDT *hdt = HDTManager::mapHDT(inputFile.c_str());

		// CONVERT
		Dictionary *dict = hdt->getDictionary();
		//LiteralDictionary litDict;
		FourSectionDictionary litDict;
		StdoutProgressListener progress;
		litDict.import(dict, &progress);

		// SAVE
		ofstream out(outputFile.c_str(), ios::binary | ios::out);
		ControlInformation ci;

		// GLOBAL
		ci.clear();
		ci.setType(GLOBAL);
		ci.setFormat(HDTVocabulary::HDT_CONTAINER);
		ci.save(out);

		// HEADER
		ci.clear();
		ci.setType(HEADER);
		hdt->getHeader()->save(out, ci, NULL);

		// NEW DICTIONARY
		ci.clear();
		ci.setType(DICTIONARY);
		litDict.save(out, ci, NULL);

		// TRIPLES
		ci.clear();
		ci.setType(TRIPLES);
		hdt->getTriples()->save(out, ci, NULL);

		out.close();

		delete hdt;
	} catch (std::exception& e) {
		cout << "ERROR: " << e.what() << endl;
	}
}
예제 #2
0
파일: conops.cpp 프로젝트: akjoshi/hdt-it
int main(int argc, char **argv) {
	int c;
	string query, inputFile, outputFile;
	bool measure = false;

	while( (c = getopt(argc,argv,"hq:o:m"))!=-1) {
		switch(c) {
		case 'h':
			break;
		case 'q':
			query = optarg;
			break;
		case 'o':
			outputFile = optarg;
			break;
		case 'm':
			measure = true;
			break;
		default:
			cout << "ERROR: Unknown option" << endl;
			return 1;
		}
	}

	if(argc-optind<2) {
		cout << "ERROR: You must supply an input and HDT File" << endl << endl;
		return 1;
	}

	inputFile = argv[optind];
	outputFile = argv[optind+1];

	ConvertProgress progress;
	StopWatch st;

	try {
		// LOAD
		HDT *hdt = HDTManager::mapHDT(inputFile.c_str());

		// CONVERT triples to TripleList
		TriplesList tlist;
		Triples *triples = hdt->getTriples();
		cout << "Old Triples -> TriplesList" << endl;
		st.reset();
		IteratorTripleID *it = triples->searchAll();
		tlist.insert(it);
		delete it;
		cout << "         Old Triples -> TriplesList time" << st <<  endl;

		// Convert tlist to OPS
		cout << "TriplesList sort OPS" << endl;
		st.reset();
		tlist.sort(OPS, &progress);
		cout << "    TriplesList sort OPS time: " << st << endl;

		// Generate new OPS BitmapTriples
		cout << "TriplesList to new BitmapTriples" << endl;
		HDTSpecification spec;
		spec.set("triplesOrder", "OPS");
		BitmapTriples bt(spec);
		st.reset();
		bt.load(tlist, &progress);
		cout << "       TriplesList to new BitmapTriples time" << st << endl;

		// Update Header
#if 1
		cout << "Update Header" << endl;
		string rootNode("_:triples");
		TripleString ts (rootNode, "", "");
		hdt->getHeader()->remove(ts);
		bt.populateHeader(*hdt->getHeader(), "_:triples");
#endif

		// SAVE
		cout << "Save to " << outputFile << endl;
		ofstream out(outputFile.c_str(), ios::binary | ios::out);
		ControlInformation ci;

		ci.clear();
		ci.setType(GLOBAL);
		ci.setFormat(HDTVocabulary::HDT_CONTAINER);
		ci.save(out);

		// HEADER
		ci.clear();
		ci.setType(HEADER);
		hdt->getHeader()->save(out, ci, NULL);

		// DICTIONARY
		ci.clear();
		ci.setType(DICTIONARY);
		hdt->getDictionary()->save(out, ci, NULL);

		// NEW TRIPLES
		ci.clear();
		ci.setType(TRIPLES);
		bt.save(out, ci, NULL);

		out.close();

		delete hdt;
	} catch (char *e) {
		cout << "ERROR: " << e << endl;
	} catch (const char *e) {
		cout << "ERROR: " << e << endl;
	}
}
예제 #3
0
int main(int argc, char **argv) {
	int c;
	char *inputFile=NULL, *insertFile=NULL, *removeFile=NULL, *outputFile=NULL;
	char *insertSubject=NULL, *insertPredicate=NULL, *insertObject=NULL;
	char *removeSubject=NULL, *removePredicate=NULL, *removeObject=NULL;
	bool insertSingle = false;
	bool removeSingle = false;

	bool insertMultiple = false;
	bool removeMultiple = false;

	while ((c = getopt(argc, argv, "hO:i:r:I:R:")) != -1) {
		switch (c) {
		case 'h':
			help();
			break;
		case 'O':
			outputFile = optarg;
			break;
		case 'i':
			insertSingle = true;
			insertSubject = optarg;
			insertPredicate = argv[optind++];
			insertObject = argv[optind++];
			break;
		case 'r':
			removeSingle = true;
			removeSubject = optarg;
			removePredicate = argv[optind++];
			removeObject = argv[optind++];
			break;
		case 'I':
			insertMultiple = true;
			insertFile = optarg;
			break;
		case 'R':
			removeMultiple = true;
			removeFile = optarg;
			break;
		default:
			cout << "ERROR: Unknown option" << endl;
			help();
			return 1;
		}
	}

	if (argc - optind < 2) {
		cout << "ERROR: You must supply an input and output HDT File" << endl << endl;
		help();
		return 1;
	}
	inputFile = argv[optind];
	outputFile = argv[optind+1];
	if (strcmp(inputFile,outputFile)==0){
		cerr<< "ERROR: input and output files must me different" << endl <<endl;
		return 1;
	}

	try {
		// LOAD
		HDT *hdt = HDTManager::mapHDT(inputFile);

		// Replace header
		Header *head = hdt->getHeader();

		if (insertSingle) {
			TripleString ti(insertSubject, insertPredicate, insertObject);
			head->insert(ti);
		}
		if (removeSingle) {
			TripleString ti(removeSubject, removePredicate, removeObject);
			head->remove(ti);
		}
		if (insertMultiple) {
			string line;
			std::ifstream infile(insertFile);
			while (getline(infile, line)) {
				TripleString ti;
				ti.read(line);
				head->insert(ti);
			}
		}
		if (removeMultiple) {
			string line;
			std::ifstream infile(removeFile);
			while (getline(infile, line)) {
				TripleString ti;
				ti.read(line);
				head->remove(ti);
			}
		}
		// SAVE
		hdt->saveToHDT(outputFile);

		delete hdt;
	} catch (std::exception& e) {
		cerr << "ERROR: " << e.what() << endl;
		return 1;
	}
}