/** * Convert a TripleID object to a TripleString, using the dictionary to perform the conversion. * If any of the components do not exist in the dictionary, it throws an exception. * @param tripleID TripleID to be converted. * @return resultant TripleSTring */ void tripleIDtoTripleString(TripleID &tripleID, TripleString &ts) { string s = idToString(tripleID.getSubject(), SUBJECT); string p = idToString(tripleID.getPredicate(), PREDICATE); string o = idToString(tripleID.getObject(), OBJECT); ts.setSubject(s); ts.setPredicate(p); ts.setObject(o); }
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 << "|"<<endl; #endif try { IteratorTripleString *it = hdt->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; } }
/** * Convert a TripleString object to a TripleID, using the dictionary to perform the conversion. * If any of the components do not exist in the dictionary, it throws an exception. * @param tripleString TripleString to be converted. * @return resulting TripleID */ void tripleStringtoTripleID(TripleString &tripleString, TripleID &tid) { tid.setSubject(stringToId(tripleString.getSubject(), SUBJECT)); tid.setPredicate(stringToId(tripleString.getPredicate(), PREDICATE)); tid.setObject(stringToId(tripleString.getObject(), OBJECT)); }
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; } }
unsigned short getComparisons(TripleString &a, TripleString &b) { unsigned short out=0; out |= CHECK_COND(a.getSubject(), b.getSubject()); out |= CHECK_COND(a.getSubject(), b.getPredicate()) << 1; out |= CHECK_COND(a.getSubject(), b.getObject()) << 2; out |= CHECK_COND(a.getPredicate(), b.getSubject()) << 3; out |= CHECK_COND(a.getPredicate(), b.getPredicate()) << 4; out |= CHECK_COND(a.getPredicate(), b.getObject()) << 5; out |= CHECK_COND(a.getObject(), b.getSubject()) << 6; out |= CHECK_COND(a.getObject(), b.getPredicate()) << 7; out |= CHECK_COND(a.getObject(), b.getObject()) << 8; out |= CHECK_COND(a.getSubject(), a.getPredicate()) << 9; out |= CHECK_COND(a.getSubject(), a.getObject()) << 10; out |= CHECK_COND(a.getPredicate(), a.getObject()) << 11; out |= CHECK_COND(b.getSubject(), b.getPredicate()) << 12; out |= CHECK_COND(b.getSubject(), b.getObject()) << 13; out |= CHECK_COND(b.getPredicate(), b.getObject()) << 14; //dumpComparisons(out); return out; }