void RingoFastIndex::_match (OracleEnv &env, int idx) { _last_id = idx; BingoStorage &storage = this->_context.context().context().storage; QS_DEF(Array<char>, stored); storage.get(idx, stored); if (stored[0] != 0) return; // reaction was removed from index BufferScanner scanner(stored); scanner.skip(1); // skip the deletion mark scanner.skip(scanner.readByte()); // skip the compessed rowid profTimerStart(tall, "match"); bool res = _context.substructure.matchBinary(scanner); profTimerStop(tall); if (res) { OraRowidText & rid = matched.at(matched.add()); _decompressRowid(stored, rid); profIncTimer("match.found", profTimerGetTime(tall)); _matched++; } else { profIncTimer("match.not_found", profTimerGetTime(tall)); _unmatched++; } }
bool RingoFastIndex::getLastRowid (OraRowidText &id) { if (_last_id < 0) return false; BingoStorage &storage = this->_context.context().context().storage; QS_DEF(Array<char>, stored); storage.get(_last_id, stored); _decompressRowid(stored, id); return true; }
void MangoFastIndex::_match (OracleEnv &env, int idx) { _last_id = idx; BingoStorage &storage = this->_context.context().context().storage; QS_DEF(Array<char>, stored); storage.get(idx, stored); if (stored[0] != 0) return; // molecule was removed from index BufferScanner scanner(stored); scanner.skip(1); // skip the deletion mark scanner.skip(scanner.readByte()); // skip the compessed rowid scanner.skip(2); // skip 'ord' bits count bool res = false; profTimerStart(tall, "match"); if (_fetch_type == _SUBSTRUCTURE) { QS_DEF(Array<char>, xyz_buf); if (_context.substructure.needCoords()) { OraRowidText rid; _decompressRowid(stored, rid); if (_loadCoords(env, rid.ptr(), xyz_buf)) { BufferScanner xyz_scanner(xyz_buf); res = _context.substructure.matchBinary(scanner, &xyz_scanner); } else // no XYZ --> skip the molecule res = false; } else res = _context.substructure.matchBinary(scanner, 0); } else if (_fetch_type == _TAUTOMER_SUBSTRUCTURE) res = _context.tautomer.matchBinary(scanner); else // _fetch_type == _SIMILARITY res = _context.similarity.matchBinary(scanner); profTimerStop(tall); if (res) { OraRowidText & rid = matched.at(matched.add()); _decompressRowid(stored, rid); profIncTimer("match.found", profTimerGetTime(tall)); _matched++; } else { profIncTimer("match.not_found", profTimerGetTime(tall)); _unmatched++; } }
void MangoFastIndex::_fetchSimilarity (OracleEnv &env, int max_matches) { BingoFingerprints &fingerprints = _context.context().fingerprints; int i; if (!fingerprints.ableToScreen(_screening)) { env.dbgPrintfTS("no bits in query fingerprint, can not do similarity search\n"); return; } profTimerStart(tsimfetch, "sim.fetch"); while (matched.size() < max_matches) { if (!fingerprints.countOnes_Init(env, _screening)) { env.dbgPrintfTS("screening ended\n"); break; } BingoStorage &storage = _context.context().context().storage; QS_DEF(Array<int>, max_common_ones); QS_DEF(Array<int>, min_common_ones); QS_DEF(Array<int>, target_ones); QS_DEF(Array<char>, stored); max_common_ones.clear_resize(_screening.block->used); min_common_ones.clear_resize(_screening.block->used); target_ones.clear_resize(_screening.block->used); for (i = 0; i < _screening.block->used; i++) { storage.get(fingerprints.getStorageIndex_NoMap(_screening, i), stored); BufferScanner scanner(stored); scanner.skip(1); // skip the deletion mark scanner.skip(scanner.readByte()); // skip the compessed rowid target_ones[i] = scanner.readBinaryWord(); max_common_ones[i] = _context.similarity.getUpperBound(target_ones[i]); min_common_ones[i] = _context.similarity.getLowerBound(target_ones[i]); } bool first = true; bool entire = false; _screening.passed.clear(); while (true) { if (!fingerprints.countOnes_Next(env, _screening)) { env.dbgPrintf("read all %d bits, writing %d results... ", _screening.query_ones.size(), _screening.passed.size()); entire = true; break; } if (first) { first = false; for (i = 0; i < _screening.block->used; i++) { int min_possible_ones = _screening.one_counters[i]; int max_possible_ones = _screening.one_counters[i] + _screening.query_ones.size() - _screening.query_bit_idx; if (min_possible_ones <= max_common_ones[i] && max_possible_ones >= min_common_ones[i]) _screening.passed.add(i); } } else { int j; for (j = _screening.passed.begin(); j != _screening.passed.end(); ) { i = _screening.passed[j]; int min_possible_ones = _screening.one_counters[i]; int max_possible_ones = _screening.one_counters[i] + _screening.query_ones.size() - _screening.query_bit_idx; int next_j = _screening.passed.next(j); if (min_possible_ones > max_common_ones[i] || max_possible_ones < min_common_ones[i]) _screening.passed.remove(j); j = next_j; } } if (_screening.passed.size() <= _context.context().context().sim_screening_pass_mark) { env.dbgPrintfTS("stopping reading fingerprints on bit %d/%d; have %d molecules to check... ", _screening.query_bit_idx, _screening.query_ones.size(), _screening.passed.size()); _unmatched += _screening.block->used - _screening.passed.size(); break; } } if (entire) { for (i = 0; i < _screening.block->used; i++) { if (_context.similarity.match(target_ones[i], _screening.one_counters[i])) { OraRowidText &rid = matched.at(matched.add()); storage.get(fingerprints.getStorageIndex_NoMap(_screening, i), stored); _decompressRowid(stored, rid); _matched++; } else _unmatched++; } } else if (_screening.passed.size() > 0) { profTimerStart(tfine, "sim.fetch.fine"); for (i = _screening.passed.begin(); i != _screening.passed.end(); i = _screening.passed.next(i)) _match(env, fingerprints.getStorageIndex_NoMap(_screening, _screening.passed[i])); profTimerStop(tfine); } env.dbgPrintf("done\n"); fingerprints.countOnes_End(env, _screening); } profTimerStop(tsimfetch); }