コード例 #1
0
void FourSectionDictionary::save(std::ostream & output, ControlInformation & controlInformation, ProgressListener *listener)
{
	controlInformation.setFormat(HDTVocabulary::DICTIONARY_TYPE_FOUR);

	controlInformation.setUint("mapping", this->mapping);
	controlInformation.setUint("sizeStrings", this->sizeStrings);

	controlInformation.save(output);

	IntermediateListener iListener(listener);

	iListener.setRange(0,10);
	iListener.notifyProgress(0, "Dictionary save shared area.");
	shared->save(output);

	iListener.setRange(10,45);
	iListener.notifyProgress(0, "Dictionary save subjects.");
	subjects->save(output);

	iListener.setRange(45,60);
	iListener.notifyProgress(0, "Dictionary save predicates.");
	predicates->save(output);

	iListener.setRange(60,100);
	iListener.notifyProgress(0, "Dictionary save objects.");
	objects->save(output);
}
コード例 #2
0
ファイル: BasicHDT.cpp プロジェクト: akjoshi/hdt-it
void BasicHDT::saveToHDT(std::ostream & output, ProgressListener *listener)
{
	ControlInformation controlInformation;
	IntermediateListener iListener(listener);

	controlInformation.clear();
	controlInformation.setType(GLOBAL);
	controlInformation.setFormat(HDTVocabulary::HDT_CONTAINER);
	controlInformation.save(output);

	controlInformation.clear();
    controlInformation.setType(HEADER);
	iListener.setRange(0,5);
	header->save(output, controlInformation, &iListener);

	controlInformation.clear();
    controlInformation.setType(DICTIONARY);
	iListener.setRange(5,70);
	dictionary->save(output, controlInformation, &iListener);

	controlInformation.clear();
    controlInformation.setType(TRIPLES);
	iListener.setRange(70,100);
	triples->save(output, controlInformation, &iListener);
}
コード例 #3
0
ファイル: PlainDictionary.cpp プロジェクト: datagraph/hdt-cpp
void PlainDictionary::save(std::ostream &output, ControlInformation &controlInformation, ProgressListener *listener)
{
    controlInformation.setFormat(HDTVocabulary::DICTIONARY_TYPE_PLAIN);
    controlInformation.setUint("mapping", this->mapping);
    controlInformation.setUint("sizeStrings", this->sizeStrings);
    controlInformation.setUint("numEntries", this->getNumberOfElements());

    controlInformation.save(output);

    unsigned int i = 0;
    unsigned int counter=0;
    const char marker = '\1';

    //shared subjects-objects from subjects
    for (i = 0; i < shared.size(); i++) {
        output << shared[i]->str;
        output.put(marker); //character to split file
        counter++;
        NOTIFYCOND(listener, "PlainDictionary saving shared", counter, getNumberOfElements());
    }

    output.put(marker); //extra line to set the begining of next part of dictionary

    //not shared subjects
    for (i = 0; i < subjects.size(); i++) {
        output << subjects[i]->str;
        output.put(marker); //character to split file
        counter++;
        NOTIFYCOND(listener, "PlainDictionary saving subjects", counter, getNumberOfElements());
    }

    output.put(marker); //extra line to set the begining of next part of dictionary

    //not shared objects
    for (i = 0; i < objects.size(); i++) {
        output << objects[i]->str;
        output.put(marker); //character to split file
        counter++;
        NOTIFYCOND(listener, "PlainDictionary saving objects", counter, getNumberOfElements());
    }

    output.put(marker); //extra line to set the begining of next part of dictionary

    //predicates
    for (i = 0; i < predicates.size(); i++) {
        output << predicates[i]->str;
        output.put(marker); //character  to split file
        counter++;
        NOTIFYCOND(listener, "PlainDictionary saving predicates", counter, getNumberOfElements());
    }

    output.put(marker);
}
コード例 #4
0
void TripleListDisk::save(std::ostream & output, ControlInformation &controlInformation, ProgressListener *listener)
{
	controlInformation.setFormat(getType());
	controlInformation.save(output);

	for(unsigned int i=0; i<numTotalTriples; i++) {
		TripleID *tid = getTripleID(i);
		if(tid->isValid()) {
			//cout << "Write: " << tid << " " << *tid << endl;
			output.write((char *)tid, sizeof(TripleID));
		}
	}
}
コード例 #5
0
void CompactTriples::save(std::ostream & output, ControlInformation &controlInformation, ProgressListener *listener)
{
	controlInformation.clear();
	controlInformation.setUint("numTriples", getNumberOfElements());
	controlInformation.setFormat(HDTVocabulary::TRIPLES_TYPE_COMPACT);
	controlInformation.setUint("order", order);
	controlInformation.save(output);

	IntermediateListener iListener(listener);

	iListener.setRange(0,30);
	iListener.notifyProgress(0, "CompactTriples saving Stream Y");
	streamY->save(output);

	iListener.setRange(30,100);
	iListener.notifyProgress(0, "CompactTriples saving Stream Z");
	streamZ->save(output);
}
コード例 #6
0
void PlainHeader::save(std::ostream & output, ControlInformation &controlInformation, ProgressListener *listener)
{
	// TODO: Choose format from spec (NTRIPLES, RDFXML...) and implement.

	// Dump header into a stringbuffer to know size.
	stringstream strbuf(stringstream::out);
	for(vector<TripleString>::iterator it = triples.begin(); it!=triples.end(); it++){
		strbuf << *it << " ." << endl;
	}
	string str = strbuf.str();

	// Dump header
	controlInformation.setFormat(HDTVocabulary::HEADER_NTRIPLES);
	controlInformation.setUint("length", str.length());
	controlInformation.save(output);

	// Dump data
	output << str;
}
コード例 #7
0
ファイル: PlainTriples.cpp プロジェクト: rdmpage/hdt-cpp
void PlainTriples::save(std::ostream & output, ControlInformation &controlInformation, ProgressListener *listener)
{
	controlInformation.clear();
	controlInformation.setUint("numTriples", getNumberOfElements());
	controlInformation.setFormat(HDTVocabulary::TRIPLES_TYPE_PLAIN);
	controlInformation.setUint("order", order);
	controlInformation.save(output);

	IntermediateListener iListener(listener);

	iListener.setRange(0,33);
	iListener.notifyProgress(0, "PlainTriples saving subjects");
	streamX->save(output);

	iListener.setRange(33, 66);
	iListener.notifyProgress(0, "PlainTriples saving predicates");
	streamY->save(output);

	iListener.setRange(66, 100);
	iListener.notifyProgress(0, "PlainTriples saving objects");
	streamZ->save(output);
}
コード例 #8
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;
	}
}
コード例 #9
0
ファイル: conpfc.cpp プロジェクト: OpenTriply/hdt-cpp
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;
	}
}