MCPcopy Create free account
hub / github.com/comaps/comaps / FindStreets

Function FindStreets

libs/search/streets_matcher.cpp:46–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void 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 };

Callers 2

GoMethod · 0.85
FindStreetsMethod · 0.85

Calls 15

ASSERTFunction · 0.85
LooksLikeHouseNumberFunction · 0.85
NeedToFilterMethod · 0.80
backMethod · 0.80
NumTokensMethod · 0.80
IsTokenUsedMethod · 0.80
IsPrefixTokenMethod · 0.80
TokenRangeClass · 0.70
SetFullMethod · 0.45
IsEmptyMethod · 0.45
IsFullMethod · 0.45
FilterMethod · 0.45

Tested by

no test coverage detected