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': help(); break; case 'q': query = optarg; break; case 'o': outputFile = optarg; break; case 'm': measure = true; break; default: cout << "ERROR: Unknown option" << endl; help(); return 1; } } if(argc-optind<2) { cout << "ERROR: You must supply an HDT File" << endl << endl; help(); return 1; } inputFile = argv[optind]; outputFile = argv[optind+1]; try { HDT *hdt = HDTManager::mapHDT(inputFile.c_str()); hdt->saveToHDT(outputFile.c_str()); cout << "IN: " << inputFile << " Out: " << outputFile << endl; delete hdt; } catch (std::exception& e) { cout << "ERROR: " << e.what() << endl; } }
int main(int argc, char **argv) { string inputFile; string outputFile; bool verbose=false; bool showProgress=false; bool generateIndex=false; string configFile; string options; string rdfFormat; string baseUri; /** * Input file format. If no -f is specified and we can't guess which * format it is, we will use NTRIPLES by default. */ RDFNotation notation = NTRIPLES; int flag; while ((flag = getopt (argc, argv, "c:o:vpf:B:iVh")) != -1) { switch (flag) { case 'c': configFile = optarg; break; case 'o': options = optarg; break; case 'v': verbose = true; break; case 'p': showProgress = true; break; case 'f': rdfFormat = optarg; break; case 'B': baseUri = optarg; break; case 'i': generateIndex=true; break; case 'V': cout << HDTVersion::get_version_string(".") << endl; return 0; case 'h': help(); return 0; default: cerr << "ERROR: Unknown option" << endl; help(); return 1; } } #define vout if (!verbose) {} else std::cerr /* Verbose output */ if (!configFile.empty()) { vout << "Configfile: " << configFile << endl; } if (!options.empty()) { vout << "Options: " << options << endl; } if(argc-optind<2) { cerr << "ERROR: You must supply an input and output" << endl << endl; help(); return 1; } inputFile = argv[optind]; outputFile = argv[optind+1]; if(inputFile=="") { cerr << "ERROR: You must supply an RDF input file" << endl << endl; help(); return 1; } if(outputFile=="") { cerr << "ERROR: You must supply an HDT output file" << endl << endl; help(); return 1; } if(baseUri=="") { baseUri="<file://"+inputFile+">"; } /** * If -f flag (input format) was not specified, we try to guess it * by reading the file extension. */ if (rdfFormat == "") { vout << "Input format not given. Guessing from file extension..." << endl; // Get position of right-most '.' to find file extension. size_t dot_position = inputFile.rfind ('.', inputFile.length ()); if (dot_position != string::npos) // Extract extension from file name rdfFormat = inputFile.substr (dot_position + 1, string::npos); /** * If rdfFormat is still "", it means -f was not specified and the file * didn't have any extension. The default format is defined at the top * of this file: RDFNotation notation = NTRIPLES; */ if (rdfFormat == "" || rdfFormat == "gz") { rdfFormat = "nt"; vout << "No input format detected: using N-Triples by default." << endl; } } // ASSERT: here rdfFormat must be != "" // Lower-case rdfFormat transform (rdfFormat.begin (), rdfFormat.end (), rdfFormat.begin (), ::tolower); // Detect input format if (rdfFormat=="nquads" || rdfFormat=="nq") { notation = NQUADS; } else if (rdfFormat== "ntriples" || rdfFormat=="nt") { notation = NTRIPLES; } else if (rdfFormat=="trig") { notation = TRIG; } else if (rdfFormat=="turtle" || rdfFormat=="ttl") { notation = TURTLE; // -f or file extension detected, but didn't match any valid format. } else { cerr << "ERROR: Input format `" << rdfFormat << "' is not supported.\n" << "Use either of the following:\n" << "\t- `ntriples' or `nt' for N-Triples\n" << "\t- `nquads' or `nq' for N-Quads\n" << "\t- `turtle' or `ttl' for Turtle\n" << "\t- `trig' for TriG" << endl; return 1; } vout << "Detected RDF input format: " << rdfFormat << endl; // Process HDTSpecification spec(configFile); spec.setOptions(options); try { // Read RDF StopWatch globalTimer; ProgressListener* progress = showProgress ? new StdoutProgressListener() : NULL; HDT *hdt = HDTManager::generateHDT(inputFile.c_str(), baseUri.c_str(), notation, spec, progress); ofstream out; // Save HDT hdt->saveToHDT(outputFile.c_str(), progress); globalTimer.stop(); vout << "HDT Successfully generated." << endl; vout << "Total processing time: "; vout << "Clock(" << globalTimer.getRealStr(); vout << ") User(" << globalTimer.getUserStr(); vout << ") System(" << globalTimer.getSystemStr() << ")" << endl; if(generateIndex) { hdt = HDTManager::indexedHDT(hdt, progress); } delete hdt; delete progress; } catch (std::exception& e) { cerr << "ERROR: " << e.what() << endl; return 1; } }
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; } }