size_t BasicHDT::loadMMap(unsigned char *ptr, unsigned char *ptrMax, ProgressListener *listener) { size_t count=0; ControlInformation controlInformation; IntermediateListener iListener(listener); // Load Global ControlInformation count+=controlInformation.load(&ptr[count], ptrMax); std::string hdtFormat = controlInformation.getFormat(); if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { throw "This software cannot open this version of HDT File."; } // Load Header iListener.setRange(0,5); controlInformation.load(&ptr[count], ptrMax); delete header; header = HDTFactory::readHeader(controlInformation); count+= header->load(&ptr[count], ptrMax, &iListener); // Load dictionary iListener.setRange(5, 60); controlInformation.load(&ptr[count], ptrMax); delete dictionary; dictionary = HDTFactory::readDictionary(controlInformation); count += dictionary->load(&ptr[count], ptrMax, &iListener); // Load triples iListener.setRange(60,100); controlInformation.load(&ptr[count], ptrMax); delete triples; triples = HDTFactory::readTriples(controlInformation); count += triples->load(&ptr[count], ptrMax, &iListener); return count; }
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); } }
void FourSectionDictionary::load(std::istream & input, ControlInformation & ci, ProgressListener *listener) { std::string format = ci.getFormat(); if(format!=getType()) { throw std::runtime_error("Trying to read a FourSectionDictionary but the data is not FourSectionDictionary"); } //this->mapping = ci.getUint("mapping"); this->mapping = MAPPING2; 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 std::runtime_error("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 std::runtime_error("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 std::runtime_error("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 std::runtime_error("Could not read objects."); } //objects = new csd::CSD_Cache(objects); }
void TripleListDisk::load(std::istream & input, ControlInformation &controlInformation, ProgressListener *listener) { // FIXME: Read controlInformation std::string format = controlInformation.getFormat(); if(format!=getType()) { throw "Trying to read a FourSectionDictionary but the data is not FourSectionDictionary"; } this->ensureSize(numTotalTriples); unsigned int numRead=0; while(input.good() && numRead<numTotalTriples) { input.read((char *)&arrayTriples[numRead], sizeof(TripleID)); numRead++; } cout << "Succesfully read triples: " << numRead << endl; }
void BasicHDT::loadFromHDT(std::istream & input, ProgressListener *listener) { try { ControlInformation controlInformation; IntermediateListener iListener(listener); // Load Global ControlInformation. controlInformation.load(input); std::string hdtFormat = controlInformation.getFormat(); if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { throw "This software cannot open this version of HDT File."; } // Load header iListener.setRange(0,5); controlInformation.load(input); delete header; header = HDTFactory::readHeader(controlInformation); header->load(input, controlInformation, &iListener); //Load Dictionary. iListener.setRange(5, 60); controlInformation.load(input); delete dictionary; dictionary = HDTFactory::readDictionary(controlInformation); dictionary->load(input, controlInformation, &iListener); // Load Triples iListener.setRange(60,100); controlInformation.load(input); delete triples; triples = HDTFactory::readTriples(controlInformation); triples->load(input, controlInformation, &iListener); } catch (const char *ex) { cout << "Exception loading HDT: " << ex; deleteComponents(); createComponents(); throw ex; } catch (char *ex) { cout << "Exception loading HDT: " << ex; deleteComponents(); createComponents(); throw ex; } }
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); }