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; }
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)); }