size_t FourSectionDictionary::load(unsigned char *ptr, unsigned char *ptrMax, ProgressListener *listener)
{
    size_t count=0;

    IntermediateListener iListener(listener);
    ControlInformation ci;
    count += ci.load(&ptr[count], ptrMax);

    this->mapping = ci.getUint("mapping");
    this->sizeStrings = ci.getUint("sizeStrings");

    iListener.setRange(0,25);
    iListener.notifyProgress(0, "Dictionary read shared area.");
    delete shared;
    shared = csd::CSD::create(ptr[count]);
    if(shared==NULL){
        shared = new csd::CSD_PFC();
        throw "Could not read shared.";
    }
    count += shared->load(&ptr[count], ptrMax);
    //shared = new csd::CSD_Cache(shared);

    iListener.setRange(25,50);
    iListener.notifyProgress(0, "Dictionary read subjects.");
    delete subjects;
    subjects = csd::CSD::create(ptr[count]);
    if(subjects==NULL){
        subjects = new csd::CSD_PFC();
        throw "Could not read subjects.";
    }
    count += subjects->load(&ptr[count], ptrMax);
    //subjects = new csd::CSD_Cache(subjects);

    iListener.setRange(50,75);
    iListener.notifyProgress(0, "Dictionary read predicates.");
    delete predicates;
    predicates = csd::CSD::create(ptr[count]);
    if(predicates==NULL){
        predicates = new csd::CSD_PFC();
        throw "Could not read predicates.";
    }
    count += predicates->load(&ptr[count], ptrMax);
    predicates = new csd::CSD_Cache2(predicates);

    iListener.setRange(75,100);
    iListener.notifyProgress(0, "Dictionary read objects.");
    delete objects;
    objects = csd::CSD::create(ptr[count]);
    if(objects==NULL){
        objects = new csd::CSD_PFC();
        throw "Could not read objects.";
    }
    count += objects->load(&ptr[count], ptrMax);
    //objects = new csd::CSD_Cache(objects);

    return count;
}
void FourSectionDictionary::load(std::istream & input, ControlInformation & ci, ProgressListener *listener)
{
	std::string format = ci.getFormat();
	if(format!=getType()) {
		throw "Trying to read a FourSectionDictionary but the data is not FourSectionDictionary";
	}
	this->mapping = ci.getUint("mapping");
	this->sizeStrings = ci.getUint("sizeStrings");

	IntermediateListener iListener(listener);

	iListener.setRange(0,25);
	iListener.notifyProgress(0, "Dictionary read shared area.");
	delete shared;
	shared = csd::CSD::load(input);
	if(shared==NULL){
		shared = new csd::CSD_PFC();
		throw "Could not read shared.";
	}
	//shared = new csd::CSD_Cache(shared);

	iListener.setRange(25,50);
	iListener.notifyProgress(0, "Dictionary read subjects.");
	delete subjects;
	subjects = csd::CSD::load(input);
	if(subjects==NULL){
		subjects = new csd::CSD_PFC();
		throw "Could not read subjects.";
	}
	//subjects = new csd::CSD_Cache(subjects);

	iListener.setRange(50,75);
	iListener.notifyProgress(0, "Dictionary read predicates.");
	delete predicates;
	predicates = csd::CSD::load(input);
	if(predicates==NULL){
		predicates = new csd::CSD_PFC();
		throw "Could not read predicates.";
	}
	predicates = new csd::CSD_Cache2(predicates);

	iListener.setRange(75,100);
	iListener.notifyProgress(0, "Dictionary read objects.");
	delete objects;
	objects = csd::CSD::load(input);
	if(objects==NULL){
		objects = new csd::CSD_PFC();
		throw "Could not read objects.";
	}
	//objects = new csd::CSD_Cache(objects);
}
Beispiel #3
0
void PlainTriples::load(std::istream &input, ControlInformation &controlInformation, ProgressListener *listener)
{
	std::string format = controlInformation.getFormat();
	if(format!=getType()) {
		throw std::runtime_error("Trying to read PlainTriples but the data is not PlainTriples");
	}

	//unsigned int numTriples = controlInformation.getUint("numTriples");
	order = (TripleComponentOrder) controlInformation.getUint("order");

	IntermediateListener iListener(listener);

	iListener.setRange(0,33);
	iListener.notifyProgress(0, "PlainTriples loading subjects");
	delete streamX;
	streamX = IntSequence::getArray(input);
	streamX->load(input);

	iListener.setRange(33, 66);
	iListener.notifyProgress(0, "PlainTriples loading predicates");
	delete streamY;
	streamY = IntSequence::getArray(input);
	streamY->load(input);

	iListener.setRange(66, 100);
	iListener.notifyProgress(0, "PlainTriples loading objects");
	delete streamZ;
	streamZ = IntSequence::getArray(input);
    streamZ->load(input);
}
size_t PlainHeader::load(unsigned char *ptr, unsigned char *ptrMax, ProgressListener *listener)
{
    size_t count = 0;

    // Read ControlInformation
    ControlInformation controlInformation;
    count += controlInformation.load(&ptr[count], ptrMax);

	std::string format = controlInformation.getFormat();
	uint32_t headerSize = controlInformation.getUint("length");

	// FIXME: Use format to create custom parser.
	if(format!=HDTVocabulary::HEADER_NTRIPLES) {
		throw "This Header format is not supported";
	}

    string str(&ptr[count], &ptr[count+headerSize]);

    // Convert into a stringstream
    stringstream strstream(str, stringstream::in);
    triples.clear();

    // Parse header
    RDFParserNtriples parser(strstream, NTRIPLES);
    while(parser.hasNext()) {
        TripleString *ts = parser.next();
        triples.push_back(*ts);
    }

    count+=headerSize;

    return count;
}
void PlainHeader::load(std::istream & input, ControlInformation &controlInformation, ProgressListener *listener)
{
	std::string format = controlInformation.getFormat();
	uint32_t headerSize = controlInformation.getUint("length");

	// FIXME: Use format to create custom parser.
	if(format!=HDTVocabulary::HEADER_NTRIPLES) {
		throw "This Header format is not supported";
	}
	
	// Read all header into a string
	string str(headerSize,'\0');
	input.read(&str[0], headerSize);
	if(input.gcount()!=headerSize) {
	    throw "Error reading header";
	}

	// Convert into a stringstream
	stringstream strstream(str, stringstream::in);
    triples.clear();

	// Parse header
	RDFParserNtriples parser(strstream, NTRIPLES);
	while(parser.hasNext()) {
		TripleString *ts = parser.next();
		triples.push_back(*ts);
    }
}
Beispiel #6
0
void PlainDictionary::load(std::istream & input, ControlInformation &ci, ProgressListener *listener)
{
    std::string line;
    unsigned char region = 1;

    startProcessing();

    std::string format = ci.getFormat();
    if(format!=getType()) {
        throw "Trying to read a PlainDictionary but the data is not PlainDictionary";
    }

    this->mapping = ci.getUint("mapping");
    this->sizeStrings = ci.getUint("sizeStrings");
    unsigned int numElements = ci.getUint("numEntries");
    unsigned int numLine = 0;

    IntermediateListener iListener(listener);
    iListener.setRange(0,25);
    while(region<5 && getline(input, line,'\1')) {
        //std::cout << line << std::endl;
        if(line!="") {
            if (region == 1) { //shared SO
                NOTIFYCOND(&iListener, "Dictionary loading shared area.", numLine, numElements);
                insert(line, SHARED_SUBJECT);
            } else if (region == 2) { //not shared Subjects
                NOTIFYCOND(&iListener, "Dictionary loading subjects.", numLine, numElements);
                insert(line, NOT_SHARED_SUBJECT);
                NOTIFYCOND(&iListener, "Dictionary loading objects.", numLine, numElements);
            } else if (region == 3) { //not shared Objects
                insert(line, NOT_SHARED_OBJECT);
                NOTIFYCOND(&iListener, "Dictionary loading predicates.", numLine, numElements);
            } else if (region == 4) { //predicates
                insert(line, NOT_SHARED_PREDICATE);
            }
        } else {
            region++;
        }

        numLine++;
    }

    // No stopProcessing() Needed. Dictionary already split and sorted in file.
    updateIDs();
}
void CompactTriples::load(std::istream &input, ControlInformation &controlInformation, ProgressListener *listener)
{
	std::string format = controlInformation.getFormat();
	if(format != HDTVocabulary::TRIPLES_TYPE_COMPACT) {
		throw "Trying to read CompactTriples but data is not CompactTriples";
	}

	numTriples = controlInformation.getUint("numTriples");
	order = (TripleComponentOrder) controlInformation.getUint("order");

	IntermediateListener iListener(listener);

	iListener.setRange(0,30);
	iListener.notifyProgress(0, "CompactTriples loading Stream Y");
	delete streamY;
	streamY = IntSequence::getArray(input);
	streamY->load(input);

	iListener.setRange(30,100);
	iListener.notifyProgress(0, "CompactTriples saving Stream Y");
	delete streamZ;
	streamZ = IntSequence::getArray(input);
    streamZ->load(input);
}