diff --git a/hdt-lib/src/dictionary/LiteralDictionary.cpp b/hdt-lib/src/dictionary/LiteralDictionary.cpp index 71eb7780..2f8a6fb2 100644 --- a/hdt-lib/src/dictionary/LiteralDictionary.cpp +++ b/hdt-lib/src/dictionary/LiteralDictionary.cpp @@ -209,11 +209,11 @@ void LiteralDictionary::load(std::istream & input, ControlInformation & ci, Prog class LiteralIterator : public IteratorUCharString { private: IteratorUCharString *child; - unsigned char *nextItem; + unsigned char *previous, *nextItem; bool goon; public: - LiteralIterator(IteratorUCharString *child) : child(child), nextItem(NULL), goon(false) { + LiteralIterator(IteratorUCharString *child) : child(child), previous(NULL), nextItem(NULL), goon(false) { if(child->hasNext()) { nextItem = child->next(); } @@ -232,7 +232,10 @@ class LiteralIterator : public IteratorUCharString { } unsigned char *next() { - unsigned char *previous = nextItem; + if(previous) { + child->freeStr(previous); + } + previous = nextItem; if(child->hasNext()) { nextItem = child->next(); } else { diff --git a/hdt-lib/src/dictionary/PFCDictionary.cpp b/hdt-lib/src/dictionary/PFCDictionary.cpp index 0150568e..bae18521 100644 --- a/hdt-lib/src/dictionary/PFCDictionary.cpp +++ b/hdt-lib/src/dictionary/PFCDictionary.cpp @@ -269,19 +269,19 @@ void PFCDictionary::import(Dictionary *other, ProgressListener *listener) { } IteratorUCharString *PFCDictionary::getSubjects() { - throw "Not implemented"; + return subjects->listAll(); } IteratorUCharString *PFCDictionary::getPredicates() { - throw "Not implemented"; + return predicates->listAll(); } IteratorUCharString *PFCDictionary::getObjects() { - throw "Not implemented"; + return objects->listAll(); } IteratorUCharString *PFCDictionary::getShared() { - throw "Not implemented"; + return shared->listAll(); } void PFCDictionary::save(std::ostream & output, ControlInformation & controlInformation, ProgressListener *listener) diff --git a/hdt-lib/src/libdcs/CSD.h b/hdt-lib/src/libdcs/CSD.h index 826eb547..8ba178f3 100644 --- a/hdt-lib/src/libdcs/CSD.h +++ b/hdt-lib/src/libdcs/CSD.h @@ -79,6 +79,8 @@ class CSD virtual void dumpAll()=0; + virtual hdt::IteratorUCharString *listAll()=0; + /** Returns the number of strings in the dictionary. */ uint32_t getLength(); diff --git a/hdt-lib/src/libdcs/CSD_Cache.h b/hdt-lib/src/libdcs/CSD_Cache.h index 3589051b..11daf8dd 100644 --- a/hdt-lib/src/libdcs/CSD_Cache.h +++ b/hdt-lib/src/libdcs/CSD_Cache.h @@ -90,6 +90,8 @@ class CSD_Cache : public CSD */ uint decompress(unsigned char **dict); + hdt::IteratorUCharString *listAll() { return child->listAll(); } + /** Returns the size of the structure in bytes. */ uint64_t getSize(); diff --git a/hdt-lib/src/libdcs/CSD_Cache2.h b/hdt-lib/src/libdcs/CSD_Cache2.h index bffaa854..f9b4c27f 100644 --- a/hdt-lib/src/libdcs/CSD_Cache2.h +++ b/hdt-lib/src/libdcs/CSD_Cache2.h @@ -81,6 +81,8 @@ class CSD_Cache2 : public CSD */ uint decompress(unsigned char **dict); + hdt::IteratorUCharString *listAll() { return child->listAll(); } + /** Returns the size of the structure in bytes. */ uint64_t getSize(); diff --git a/hdt-lib/src/libdcs/CSD_FMIndex.cpp b/hdt-lib/src/libdcs/CSD_FMIndex.cpp index ca250b9f..1c090cc1 100644 --- a/hdt-lib/src/libdcs/CSD_FMIndex.cpp +++ b/hdt-lib/src/libdcs/CSD_FMIndex.cpp @@ -103,6 +103,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence, samplingsPositions.push_back(total); } + it->freeStr(currentStr); total++; } @@ -126,7 +127,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence, if (use_sample) { bitmap = new uint[(total + 1 + W) / W]; - memset((void*)bitmap, (total + 1 + W) / W, 0); + memset((void*)bitmap, 0, 4*((total + 1 + W) / W)); bitset(bitmap, 0); for (size_t i=0;i &out, int maxResults); + hdt::IteratorUCharString *listAll() { throw "Not implemented"; } + /** General destructor. */ ~CSD_FMIndex(); diff --git a/hdt-lib/src/libdcs/CSD_HTFC.cpp b/hdt-lib/src/libdcs/CSD_HTFC.cpp index b7bf6f6e..9112231b 100644 --- a/hdt-lib/src/libdcs/CSD_HTFC.cpp +++ b/hdt-lib/src/libdcs/CSD_HTFC.cpp @@ -51,12 +51,12 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progre this->nblocks = 0; uint64_t reservedSize = 1024; - uchar *textfc = (uchar*)malloc(reservedSize*sizeof(uchar)); + unsigned char *textfc = (unsigned char*)malloc(reservedSize*sizeof(unsigned char)); uint64_t bytesfc = 0; vector xblocks; // Temporal storage for start positions - uchar *previousStr, *currentStr = NULL; + unsigned char *previousStr, *currentStr = NULL; uint previousLength = 0, currentLength = 0; while (it->hasNext()) @@ -77,7 +77,7 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progre reservedSize=(bytesfc+currentLength+1)*2; } } - textfc = (uchar*)realloc(textfc, reservedSize*sizeof(uchar)); + textfc = (unsigned char*)realloc(textfc, reservedSize*sizeof(unsigned char)); } if ((numstrings % blocksize) == 0) @@ -120,9 +120,10 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progre // New string processed numstrings++; - previousStr = currentStr; + memcpy(previousStr, currentStr, currentLength); previousLength = currentLength; + it->freeStr(currentStr); //NOTIFYCOND(listener, "Converting dictionary to HTFC", length, it->getNumberOfElements()); } @@ -130,7 +131,7 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progre xblocks.push_back(bytesfc); // Trunc encoded sequence to save unused memory - textfc = (uchar *) realloc(textfc, bytesfc*sizeof(uchar)); + textfc = (unsigned char *) realloc(textfc, bytesfc*sizeof(unsigned char)); /******************************** * HERE STARTS HuTucker @@ -143,7 +144,7 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progre leafs = ht.getCodes(&HTcode, &tree); uint64_t tsize = reservedSize/2; - text = (uchar*)malloc(tsize*sizeof(uchar)); + text = (unsigned char*)malloc(tsize*sizeof(unsigned char)); for (uint64_t i=0; igetField(block); - uchar *string = new uchar[maxlength+1]; + unsigned char *string = new unsigned char[maxlength+1]; uint slen = strlen((char*)text+pos)+1; @@ -359,7 +360,7 @@ void CSD_HTFC::dumpBlock(uint block) { delete [] string; } -uchar* CSD_HTFC::extract(uint32_t id) +unsigned char* CSD_HTFC::extract(uint32_t id) { if(!text || !blocks) { return NULL; @@ -368,7 +369,7 @@ uchar* CSD_HTFC::extract(uint32_t id) if ((id > 0) && (id <= numstrings)) { // Allocating memory for the string - uchar *s = new uchar[maxlength+1]; + unsigned char *s = new unsigned char[maxlength+1]; // Calculating block and offset uint block = (id-1)/blocksize; @@ -393,7 +394,7 @@ uint64_t CSD_HTFC::getSize() if(!text || !blocks) { return 0; } - return bytes*sizeof(uchar)+blocks->getSize()+sizeof(CSD_HTFC); + return bytes*sizeof(unsigned char)+blocks->getSize()+sizeof(CSD_HTFC); } void CSD_HTFC::save(ofstream & fp) @@ -402,12 +403,12 @@ void CSD_HTFC::save(ofstream & fp) return; } - saveValue(fp, type); + saveValue(fp, type); saveValue(fp, numstrings); saveValue(fp, tlength); saveValue(fp, maxlength); saveValue(fp, bytes); - saveValue(fp, text, bytes); + saveValue(fp, text, bytes); saveValue(fp, blocksize); saveValue(fp, nblocks); blocks->save(fp); @@ -446,7 +447,7 @@ CSD* CSD_HTFC::load(ifstream & fp) } //cout << "FINAL Read: " << counter << " / " << dicc->bytes << endl; #else - dicc->text = (uchar *) malloc(dicc->bytes*sizeof(unsigned char*)); + dicc->text = (unsigned char *) malloc(dicc->bytes*sizeof(unsigned char*)); fp.read((char *)dicc->text, dicc->bytes); #endif @@ -515,10 +516,10 @@ CSD* CSD_HTFC::load(ifstream & fp) return dicc; } -bool CSD_HTFC::locateBlock(const uchar *s, uint *block) +bool CSD_HTFC::locateBlock(const unsigned char *s, uint *block) { uint slen = strlen((char*)s)+1; - uchar *encoded = new uchar[2*slen]; + unsigned char *encoded = new unsigned char[2*slen]; encoded[0] = 0; // Pattern (s) encoding @@ -583,14 +584,14 @@ bool CSD_HTFC::locateBlock(const uchar *s, uint *block) return false; } -uint CSD_HTFC::locateInBlock(uint block, const uchar *s, uint len) +uint CSD_HTFC::locateInBlock(uint block, const unsigned char *s, uint len) { if(block>=nblocks){ return 0; } - uchar *deltaseq = new uchar[DELTA]; - uchar *tmp = new uchar[maxlength]; + unsigned char *deltaseq = new unsigned char[DELTA]; + unsigned char *tmp = new unsigned char[maxlength]; uint delta, tmplen; uint offset = 0; @@ -652,9 +653,9 @@ uint CSD_HTFC::locateInBlock(uint block, const uchar *s, uint len) return id; } -void CSD_HTFC::extractInBlock(uint block, uint o, uchar *s) +void CSD_HTFC::extractInBlock(uint block, uint o, unsigned char *s) { - uchar *deltaseq = new uchar[DELTA]; + unsigned char *deltaseq = new unsigned char[DELTA]; uint delta; uint offset = 0; @@ -676,19 +677,19 @@ void CSD_HTFC::extractInBlock(uint block, uint o, uchar *s) delete [] deltaseq; } -void CSD_HTFC::decompressDelta(uchar *seq, uint *pos, uint *offset, uchar *deltaseq) +void CSD_HTFC::decompressDelta(unsigned char *seq, uint *pos, uint *offset, unsigned char *deltaseq) { uint i = 0; do { - deltaseq[i] = (uchar)decodeHT(seq, pos, offset); + deltaseq[i] = (unsigned char)decodeHT(seq, pos, offset); i++; } while (deltaseq[i-1] < 128); } -uint CSD_HTFC::decompressFirstWord(uchar *seq, uint *pos, uchar *word) +uint CSD_HTFC::decompressFirstWord(unsigned char *seq, uint *pos, unsigned char *word) { uint ptr = 0, offset = 0; @@ -703,7 +704,7 @@ uint CSD_HTFC::decompressFirstWord(uchar *seq, uint *pos, uchar *word) return ptr; } -uint CSD_HTFC::decompressWord(uchar *seq, uint *pos, uint* offset, uchar *suffix) +uint CSD_HTFC::decompressWord(unsigned char *seq, uint *pos, uint* offset, unsigned char *suffix) { uint ptr = 0; @@ -718,7 +719,7 @@ uint CSD_HTFC::decompressWord(uchar *seq, uint *pos, uint* offset, uchar *suffix return ptr; } -uchar CSD_HTFC::decodeHT(uchar *seq, uint *pos, uint *offset) +unsigned char CSD_HTFC::decodeHT(unsigned char *seq, uint *pos, uint *offset) { // REVISAR: OTRA IMPLEMENTACION QUE HAGA LOS DESPLAZAMIENTOS // DE UNO EN UNO CONSIDERANDO UNA ESTRUCTURA TEMPORAL DONDE @@ -739,12 +740,12 @@ uchar CSD_HTFC::decodeHT(uchar *seq, uint *pos, uint *offset) } } - return (uchar)HTtree[node].symbol; + return (unsigned char)HTtree[node].symbol; } -void CSD_HTFC::encodeHT(uint code, uint len, uchar *seq, uint *pos, uint *offset) +void CSD_HTFC::encodeHT(uint code, uint len, unsigned char *seq, uint *pos, uint *offset) { - uchar uccode; + unsigned char uccode; uint uicode; uint processed = 0; @@ -753,7 +754,7 @@ void CSD_HTFC::encodeHT(uint code, uint len, uchar *seq, uint *pos, uint *offset // "Saco fuera" los bits ya procesados en 'code'. uicode = code << (W-len+processed); // Me quedo con los que quiero - uccode = (uchar)(uicode >> (W-(8-(*offset)))); + uccode = (unsigned char)(uicode >> (W-(8-(*offset)))); // Los aado en la posicin actual seq[*pos] = seq[*pos] | uccode; @@ -766,13 +767,13 @@ void CSD_HTFC::encodeHT(uint code, uint len, uchar *seq, uint *pos, uint *offset if (len-processed > 0) { uicode = code << (W-len+processed); - uccode = (uchar)(uicode >> (W-(8-(*offset)))); + uccode = (unsigned char)(uicode >> (W-(8-(*offset)))); seq[*pos] = seq[*pos] | uccode; (*offset) += len-processed; } } -uint CSD_HTFC::longest_common_prefix(const uchar* str1, const uchar* str2, uint lstr1, uint lstr2) +uint CSD_HTFC::longest_common_prefix(const unsigned char* str1, const unsigned char* str2, uint lstr1, uint lstr2) { uint delta = 0; uint length = lstr1; diff --git a/hdt-lib/src/libdcs/CSD_HTFC.h b/hdt-lib/src/libdcs/CSD_HTFC.h index 5afab840..2ed5ad86 100644 --- a/hdt-lib/src/libdcs/CSD_HTFC.h +++ b/hdt-lib/src/libdcs/CSD_HTFC.h @@ -108,6 +108,8 @@ class CSD_HTFC : public CSD void fillSuggestions(const char *base, vector &out, int maxResults); + hdt::IteratorUCharString *listAll() { throw "Not implemented"; } + protected: uint64_t bytes; //! Size of the Front-Coding encoded sequence (in bytes). uchar *text; //! Front-Coding encoded sequence. diff --git a/hdt-lib/src/libdcs/CSD_PFC.cpp b/hdt-lib/src/libdcs/CSD_PFC.cpp index bf222556..a550446d 100644 --- a/hdt-lib/src/libdcs/CSD_PFC.cpp +++ b/hdt-lib/src/libdcs/CSD_PFC.cpp @@ -123,6 +123,8 @@ CSD_PFC::CSD_PFC(hdt::IteratorUCharString *it, uint32_t blocksize, hdt::Progress if((numstrings%100000)==0) { listener->notifyProgress(numstrings, " Loading to PFC "); } + + it->freeStr(currentStr); } free(previousStr); @@ -539,9 +541,12 @@ uint CSD_PFC::longest_common_prefix(const unsigned char* str1, const unsigned ch return delta; } + +hdt::IteratorUCharString *CSD_PFC::listAll() { + return new PFCIterator(this); } -void csd::CSD_PFC::fillSuggestions(const char *base, vector &out, int maxResults) +void CSD_PFC::fillSuggestions(const char *base, vector &out, int maxResults) { uint block; locateBlock((unsigned char *)base, &block); @@ -626,3 +631,5 @@ void csd::CSD_PFC::fillSuggestions(const char *base, vector &out, i delete [] string; } + +} diff --git a/hdt-lib/src/libdcs/CSD_PFC.h b/hdt-lib/src/libdcs/CSD_PFC.h index d585b6da..9dc68562 100644 --- a/hdt-lib/src/libdcs/CSD_PFC.h +++ b/hdt-lib/src/libdcs/CSD_PFC.h @@ -51,6 +51,8 @@ using namespace cds_utils; namespace csd { +class PFCIterator; + class CSD_PFC : public CSD { public: @@ -100,6 +102,7 @@ class CSD_PFC : public CSD void fillSuggestions(const char *base, vector &out, int maxResults); + hdt::IteratorUCharString *listAll(); protected: uint64_t bytes; //! Size of the Front-Coding encoded sequence (in bytes). unsigned char *text; //! Front-Coding encoded sequence. @@ -142,7 +145,43 @@ class CSD_PFC : public CSD @lstr2: length of the second string. */ inline uint longest_common_prefix(const unsigned char* str1, const unsigned char* str2, uint lstr1, uint lstr2); + + friend class PFCIterator; }; + +class PFCIterator : public hdt::IteratorUCharString { +private: + CSD_PFC *pfc; + size_t max; + size_t count; +public: + PFCIterator(CSD_PFC *pfc) : pfc(pfc), count(1) { + max = pfc->getLength(); + } + + virtual ~PFCIterator() { } + + bool hasNext() { + return count<=max; + } + + unsigned char *next() { + return pfc->extract(count++); + } + + unsigned int getNumberOfElements() { + return max; + } + + virtual void freeStr(unsigned char *ptr) { + pfc->freeString(ptr); + } }; + + +} + + + #endif diff --git a/hdt-lib/tests/confm.cpp b/hdt-lib/tests/confm.cpp new file mode 100644 index 00000000..a46442f5 --- /dev/null +++ b/hdt-lib/tests/confm.cpp @@ -0,0 +1,111 @@ +/* + * Tutorial01.cpp + * + * Created on: 02/03/2011 + * Author: mck + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "../src/dictionary/LiteralDictionary.hpp" + +#include "../src/util/StopWatch.hpp" + +using namespace hdt; +using namespace std; + +class ConvertProgress : public ProgressListener { +private: +public: + virtual ~ConvertProgress() { } + + void notifyProgress(float level, const char *section) { + cout << section << ": " << level << " %"; + cout << "\r " << section << ": " << level << " % \r"; + cout.flush(); + } + +}; + +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]; + + HDT *hdt = HDTFactory::createDefaultHDT(); + + try { + // LOAD + hdt->loadFromHDT(inputFile.c_str()); + + // CONVERT + Dictionary *dict = hdt->getDictionary(); + LiteralDictionary litDict; + ConvertProgress progress; + litDict.import(dict, &progress); + + // SAVE + ofstream out(outputFile.c_str(), ios::binary | ios::out); + ControlInformation ci; + + // HEADER + ci.clear(); + ci.setHeader(true); + hdt->getHeader()->save(out, ci, NULL); + + // NEW DICTIONARY + ci.clear(); + ci.setDictionary(true); + litDict.save(out, ci, NULL); + + // TRIPLES + ci.clear(); + ci.setTriples(true); + hdt->getTriples()->save(out, ci, NULL); + + out.close(); + + delete hdt; + } catch (char *e) { + cout << "ERROR: " << e << endl; + } catch (const char *e) { + cout << "ERROR: " << e << endl; + } +} + + + diff --git a/hdt-lib/tools/hdtSearch.cpp b/hdt-lib/tools/hdtSearch.cpp index 62a0ce3d..e32e0a74 100644 --- a/hdt-lib/tools/hdtSearch.cpp +++ b/hdt-lib/tools/hdtSearch.cpp @@ -35,6 +35,49 @@ void help() { //cout << "\t-v\tVerbose output" << endl; } +void iterate(HDT *hdt, char *query, ostream &out, bool measure) { + TripleString tripleString; + tripleString.read(query); + + const char *subj = tripleString.getSubject().c_str(); + const char *pred = tripleString.getPredicate().c_str(); + const char *obj = tripleString.getObject().c_str(); + if(strcmp(subj, "?")==0) { + subj=""; + } + if(strcmp(pred, "?")==0) { + pred=""; + } + if(strcmp(obj, "?")==0) { + obj=""; + } + +#if 0 + cout << "Subject: |" << subj <<"|"<< endl; + cout << "Predicate: |" << pred <<"|"<< endl; + cout << "Object: |" << obj << "|"<search(subj, pred, obj); + + StopWatch st; + unsigned int numTriples=0; + while(it->hasNext() && interruptSignal==0) { + TripleString *ts = it->next(); + if(!measure) + out << *ts << endl; + numTriples++; + } + cout << numTriples << " results in " << st << endl; + delete it; + + interruptSignal=0; // Interrupt caught, enable again. + } catch (char *e) { + cerr << e << endl; + } + +} int main(int argc, char **argv) { int c; @@ -77,105 +120,48 @@ int main(int argc, char **argv) { hdt->generateIndex(); - if(query!="") { - ostream *out; - ofstream outF; - - if(outputFile!="") { - outF.open(outputFile.c_str()); - out = &outF; - } else { - out = &cout; - } - - TripleString tripleString; - tripleString.read(query); - - const char *subj = tripleString.getSubject().c_str(); - const char *pred = tripleString.getPredicate().c_str(); - const char *obj = tripleString.getObject().c_str(); - if(strcmp(subj, "?")==0) { - subj=""; - } - if(strcmp(pred, "?")==0) { - subj=""; - } - if(strcmp(obj, "?")==0) { - obj=""; - } - - IteratorTripleString *it = hdt->search(subj, pred, obj); - - StopWatch st; - unsigned int numTriples=0; - while(it->hasNext()) { - TripleString *ts = it->next(); - if(!measure) - *out << *ts << endl; - numTriples++; - } - if(measure) - cout << numTriples << " results in " << st << endl; - delete it; + ostream *out; + ofstream outF; - if(outputFile!="") { - outF.close(); - } + if(outputFile!="") { + outF.open(outputFile.c_str()); + out = &outF; + } else { + out = &cout; + } + if(query!="") { + // Supplied query, search and exit. + iterate(hdt, (char*)query.c_str(), *out, measure); } else { - TripleString tripleString; + // No supplied query, show terminal. char line[1024*10]; signal(SIGINT, &signalHandler); cout << ">> "; while(cin.getline(line, 1024*10)) { - if(line[0]=='\0'||strcmp(line, "exit")==0|| strcmp(line,"quit")==0) { - //break; + if(strcmp(line, "exit")==0|| strcmp(line,"quit")==0) { + break; } - - tripleString.read(line); - - - const char *subj = tripleString.getSubject().c_str(); - const char *pred = tripleString.getPredicate().c_str(); - const char *obj = tripleString.getObject().c_str(); - if(strcmp(subj, "?")==0) { - subj=""; + if(strcmp(line, "help")==0) { + cout << "Please write Triple Search Pattern, using '?' for wildcards. e.g " << endl; + cout << " http://www.somewhere.com/mysubject ? ?" << endl; + cout << "If you just press 'enter', all triples will be shown, Interrupt with Control+C."<< endl; + cout << "Type 'exit', 'quit' or Control+D to exit the shell." << endl; + cout << ">> "; + continue; } - if(strcmp(pred, "?")==0) { - pred=""; - } - if(strcmp(obj, "?")==0) { - obj=""; - } - - cout << "Query: " << tripleString << endl; - - try { - IteratorTripleString *it = hdt->search(subj, pred, obj); - - StopWatch st; - unsigned int numTriples = 0; - interruptSignal = 0; - while(it->hasNext() && !interruptSignal) { - TripleString *ts = it->next(); - if(!measure) { - cout << *ts << endl; - } - - numTriples++; - } - cout << numTriples << " results in " << st << endl; - delete it; - } catch (char *e) { - cout << e << endl; - } + iterate(hdt, line, *out, measure); cout << ">> "; } } + if(outputFile!="") { + outF.close(); + } + delete hdt; } catch (char *e) { cout << "ERROR: " << e << endl; diff --git a/hdt-lib/tools/rdf2hdt.cpp b/hdt-lib/tools/rdf2hdt.cpp index 6d149d70..264a65b7 100644 --- a/hdt-lib/tools/rdf2hdt.cpp +++ b/hdt-lib/tools/rdf2hdt.cpp @@ -27,7 +27,7 @@ void help() { cout << "\t-i\t\tAlso generate index to solve all triple patterns." << endl; cout << "\t-c\t\tHDT Config options file" << endl; cout << "\t-o\t\tHDT Additional options (option1:value1;option2:value2;...)" << endl; - cout << "\t-f\t\tFormat of the RDF input (N3, Turtle, RDF-XML)" << endl; + cout << "\t-f\t\tFormat of the RDF input (ntriples, nquad, n3, turtle, rdfxml)" << endl; cout << "\t-B\t\"\"\tBase URI of the dataset." << endl; //cout << "\t-v\tVerbose output" << endl; } @@ -38,9 +38,9 @@ class ConvertProgress : public ProgressListener { virtual ~ConvertProgress() { } void notifyProgress(float level, const char *section) { - cout << section << ": " << level << " %" << endl; - //cout << "\r " << section << ": " << level << " % \r"; - //cout.flush(); + cout << section << ": " << level << " %"; + cout << "\r " << section << ": " << level << " % \r"; + cout.flush(); } }; @@ -109,10 +109,6 @@ int main(int argc, char **argv) { return 1; } - /*for (int i = optind; i < argc; i++) { - cout << "Non opt: " << argv[i] << endl; - }*/ - inputFile = argv[optind]; outputFile = argv[optind+1]; @@ -144,7 +140,7 @@ int main(int argc, char **argv) { } else if(rdfFormat=="rdfxml") { notation = XML; } else { - cout << "ERROR: The RDF input format must be one of: (ntriples, n3, turtle, rdfxml)" << endl; + cout << "ERROR: The RDF input format must be one of: (ntriples, nquad, n3, turtle, rdfxml)" << endl; help(); return 1; }