void Eval(CTreeNode<CBDB_QueryNode>& tr) { GetArguments(tr); CBDB_QueryNode& qnode = tr.GetValue(); const string* arg0 = GetArg(0); const string* arg1 = GetArg(1); const CBDB_Field* fld0 = GetArgField(0); const CBDB_Field* fld1 = GetArgField(1); // here we check two cases: // field = "value" // "value" == field if (fld0 != 0 && fld1 == 0) { CBoyerMooreMatcher* matcher = GetMatcher(*arg1, 0); int pos = matcher->Search(*arg0); if (pos == -1) { // not found qnode.SetValue("0"); } else { qnode.SetValue("1"); } return; } if (fld0 == 0 && fld1 != 0) { CBoyerMooreMatcher* matcher = GetMatcher(*arg0, 0); int pos = matcher->Search(*arg1); if (pos == -1) { // not found qnode.SetValue("0"); } else { qnode.SetValue("1"); } return; } // Plain equal bool res = (*arg0 == *arg1); if (IsNot()) res = !res; SetResult(qnode, res); }
/// Checks if value is equal to any field in the database bool IsAnyField(CBDB_File& dbf, const string& search_value, unsigned int arg_idx) { CBoyerMooreMatcher* matcher = GetMatcher(search_value, arg_idx); CBDB_File::TUnifiedFieldIndex fidx = BDB_find_field(dbf, *matcher, &m_TmpStr); return (fidx != 0); }
void Features::Match(const Mat& descTarget, const Mat& descScene, vector<Point2f>& target, vector<Point2f> scene) const { cv::DescriptorMatcher* matcher = GetMatcher(this->flag); std::vector<std::vector<cv::DMatch> > all_matches; matcher->knnMatch(descTarget, descScene, all_matches, 2); std::vector<cv::DMatch> goods; for(unsigned i = 0; i < all_matches.size(); i++) if(all_matches[i][0].distance < 0.7 * all_matches[i][1].distance) goods.push_back(all_matches[i][0]); // for(unsigned i = 0; i < goods.size(); i++ ){ // //Get the keypoints from the good matches // target.push_back(imageKeys[goods[i].queryIdx].pt); // scene.push_back(frameKeys[goods[i].trainIdx].pt); // } }
bool SearchReplaceEngine::ReplaceAll() { if (!initialized) return false; size_t count = 0; auto matches = GetMatcher(settings); auto const& sel = context->selectionController->GetSelectedSet(); bool selection_only = settings.limit_to == SearchReplaceSettings::Limit::SELECTED; for (auto& diag : context->ass->Events) { if (selection_only && !sel.count(&diag)) continue; if (settings.ignore_comments && diag.Comment) continue; if (settings.use_regex) { if (MatchState ms = matches(&diag, 0)) { auto& diag_field = diag.*get_dialogue_field(settings.field); std::string const& text = diag_field.get(); count += std::distance( boost::u32regex_iterator<std::string::const_iterator>(begin(text), end(text), *ms.re), boost::u32regex_iterator<std::string::const_iterator>()); diag_field = u32regex_replace(text, *ms.re, settings.replace_with); } continue; } size_t pos = 0; while (MatchState ms = matches(&diag, pos)) { ++count; Replace(&diag, ms); pos = ms.end; } } if (count > 0) { context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT); wxMessageBox(fmt_plural(count, "One match was replaced.", "%d matches were replaced.", (int)count)); } else { wxMessageBox(_("No matches found.")); } return true; }
bool SearchReplaceEngine::FindReplace(bool replace) { if (!initialized) return false; auto matches = GetMatcher(settings); AssDialogue *line = context->selectionController->GetActiveLine(); auto it = context->ass->iterator_to(*line); size_t pos = 0; auto replace_ms = bad_match; if (replace) { if (settings.field == SearchReplaceSettings::Field::TEXT) pos = context->textSelectionController->GetSelectionStart(); if ((replace_ms = matches(line, pos))) { size_t end = bad_pos; if (settings.field == SearchReplaceSettings::Field::TEXT) end = context->textSelectionController->GetSelectionEnd(); if (end == bad_pos || (pos == replace_ms.start && end == replace_ms.end)) { Replace(line, replace_ms); pos = replace_ms.end; context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT); } else { // The current line matches, but it wasn't already selected, // so the match hasn't been "found" and displayed to the user // yet, so do that rather than replacing context->textSelectionController->SetSelection(replace_ms.start, replace_ms.end); return true; } } } // Search from the end of the selection to avoid endless matching the same thing else if (settings.field == SearchReplaceSettings::Field::TEXT) pos = context->textSelectionController->GetSelectionEnd(); // For non-text fields we just look for matching lines rather than each // match within the line, so move to the next line else if (settings.field != SearchReplaceSettings::Field::TEXT) it = circular_next(it, context->ass->Events); auto const& sel = context->selectionController->GetSelectedSet(); bool selection_only = sel.size() > 1 && settings.limit_to == SearchReplaceSettings::Limit::SELECTED; do { if (selection_only && !sel.count(&*it)) continue; if (settings.ignore_comments && it->Comment) continue; if (MatchState ms = matches(&*it, pos)) { if (selection_only) // We're cycling through the selection, so don't muck with it context->selectionController->SetActiveLine(&*it); else context->selectionController->SetSelectionAndActive({ &*it }, &*it); if (settings.field == SearchReplaceSettings::Field::TEXT) context->textSelectionController->SetSelection(ms.start, ms.end); return true; } } while (pos = 0, &*(it = circular_next(it, context->ass->Events)) != line); // Replaced something and didn't find another match, so select the newly // inserted text if (replace_ms && settings.field == SearchReplaceSettings::Field::TEXT) context->textSelectionController->SetSelection(replace_ms.start, replace_ms.end); return true; }