| 44 | } |
| 45 | |
| 46 | void FindStreets(BaseContext const & ctx, CBV const & candidates, FeaturesFilter const & filter, |
| 47 | QueryParams const & params, size_t startToken, bool withMisprints, |
| 48 | vector<StreetsMatcher::Prediction> & predictions) |
| 49 | { |
| 50 | // Here we try to match as many tokens as possible while |
| 51 | // intersection is a non-empty bit vector of streets. Single |
| 52 | // tokens that are synonyms to streets are ignored. Moreover, |
| 53 | // each time a token that looks like a beginning of a house number |
| 54 | // is met, we try to use current intersection of tokens as a |
| 55 | // street layer and try to match BUILDINGs or POIs. |
| 56 | CBV streets(candidates); |
| 57 | |
| 58 | CBV all; |
| 59 | all.SetFull(); |
| 60 | |
| 61 | size_t curToken = startToken; |
| 62 | |
| 63 | // This variable is used for prevention of duplicate calls to |
| 64 | // CreateStreetsLayerAndMatchLowerLayers() with the same |
| 65 | // arguments. |
| 66 | size_t lastToken = startToken; |
| 67 | |
| 68 | // When true, no bit vectors were intersected with |streets| at all. |
| 69 | bool emptyIntersection = true; |
| 70 | |
| 71 | auto emit = [&]() |
| 72 | { |
| 73 | if (streets.IsEmpty() || emptyIntersection || lastToken == curToken) |
| 74 | return; |
| 75 | |
| 76 | CBV fs(streets); |
| 77 | CBV fa(all); |
| 78 | |
| 79 | ASSERT(!fs.IsFull(), ()); |
| 80 | ASSERT(!fa.IsFull(), ()); |
| 81 | |
| 82 | if (filter.NeedToFilter(fs)) |
| 83 | fs = filter.Filter(fs); |
| 84 | |
| 85 | if (fs.IsEmpty()) |
| 86 | return; |
| 87 | |
| 88 | if (filter.NeedToFilter(fa)) |
| 89 | fa = filter.Filter(fa).Union(fs); |
| 90 | |
| 91 | predictions.emplace_back(); |
| 92 | auto & prediction = predictions.back(); |
| 93 | |
| 94 | prediction.m_tokenRange = TokenRange(startToken, curToken); |
| 95 | |
| 96 | ASSERT_NOT_EQUAL(fs.PopCount(), 0, ()); |
| 97 | ASSERT_LESS_OR_EQUAL(fs.PopCount(), fa.PopCount(), ()); |
| 98 | prediction.m_prob = static_cast<double>(fs.PopCount()) / static_cast<double>(fa.PopCount()); |
| 99 | |
| 100 | prediction.m_features = std::move(fs); |
| 101 | prediction.m_hash = prediction.m_features.Hash(); |
| 102 | prediction.m_withMisprints = withMisprints; |
| 103 | }; |
no test coverage detected