Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking Purchase Intent Classifier Issues #5162

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PurchaseIntentSegmentList Keywords::GetSegments(
for (const auto& keyword : _automotive_segment_keywords) {
auto list_keyword_set = TransformIntoSetOfWords(keyword.keywords);

// Intended behaviour relies on early return from list traversal and
// implicitely on the ordering of |_automotive_segment_keywords| to ensure
// specific segments are matched over general segments, e.g. "audi a6"
// segments should be returned over "audi" segments if possible.
if (Keywords::IsSubset(search_query_keyword_set, list_keyword_set)) {
segment_list = keyword.segments;
return segment_list;
Expand All @@ -37,15 +41,17 @@ uint16_t Keywords::GetFunnelWeight(
const std::string& search_query) {
auto search_query_keyword_set = TransformIntoSetOfWords(search_query);

uint16_t max_weight = _default_signal_weight;
for (const auto& keyword : _automotive_funnel_keywords) {
auto list_keyword_set = TransformIntoSetOfWords(keyword.keywords);

if (Keywords::IsSubset(search_query_keyword_set, list_keyword_set)) {
return keyword.weight;
if (Keywords::IsSubset(search_query_keyword_set, list_keyword_set) &&
keyword.weight > max_weight) {
max_weight = keyword.weight;
}
}

return _default_signal_weight;
return max_weight;
}

// TODO(Moritz Haller): Rename to make explicit that method checks set_a is
Expand Down
105 changes: 105 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/purchase_intent/keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,111 @@ SegmentKeywordInfo({
"automotive purchase intent by make-volvo",
"automotive purchase intent by category-luxury suv"},
"Volvo XC90"),
SegmentKeywordInfo({
"automotive purchase intent by make-acura"},
"Acura"),
SegmentKeywordInfo({
"automotive purchase intent by make-audi"},
"Audi"),
SegmentKeywordInfo({
"automotive purchase intent by make-bmw"},
"BMW"),
SegmentKeywordInfo({
"automotive purchase intent by make-buick"},
"Buick"),
SegmentKeywordInfo({
"automotive purchase intent by make-cadillac"},
"Cadillac"),
SegmentKeywordInfo({
"automotive purchase intent by make-chevrolet"},
"Chevrolet"),
SegmentKeywordInfo({
"automotive purchase intent by make-chrysler"},
"Chrysler"),
SegmentKeywordInfo({
"automotive purchase intent by make-dodge"},
"Dodge"),
SegmentKeywordInfo({
"automotive purchase intent by make-fiat"},
"Fiat"),
SegmentKeywordInfo({
"automotive purchase intent by make-ford"},
"Ford"),
SegmentKeywordInfo({
"automotive purchase intent by make-gmc"},
"GMC"),
SegmentKeywordInfo({
"automotive purchase intent by make-honda"},
"Honda"),
SegmentKeywordInfo({
"automotive purchase intent by make-hyundai"},
"Hyundai"),
SegmentKeywordInfo({
"automotive purchase intent by make-infiniti"},
"Infiniti"),
SegmentKeywordInfo({
"automotive purchase intent by make-jaguar"},
"Jaguar"),
SegmentKeywordInfo({
"automotive purchase intent by make-jeep"},
"Jeep"),
SegmentKeywordInfo({
"automotive purchase intent by make-kia"},
"Kia"),
SegmentKeywordInfo({
"automotive purchase intent by make-land rover"},
"Land Rover"),
SegmentKeywordInfo({
"automotive purchase intent by make-lexus"},
"Lexus"),
SegmentKeywordInfo({
"automotive purchase intent by make-lincoln"},
"Lincoln"),
SegmentKeywordInfo({
"automotive purchase intent by make-mazda"},
"Mazda"),
SegmentKeywordInfo({
"automotive purchase intent by make-mercedes-benz"},
"Mercedes-Benz"),
SegmentKeywordInfo({
"automotive purchase intent by make-mini"},
"Mini"),
SegmentKeywordInfo({
"automotive purchase intent by make-mitsubishi"},
"Mitsubishi"),
SegmentKeywordInfo({
"automotive purchase intent by make-nissan"},
"Nissan"),
SegmentKeywordInfo({
"automotive purchase intent by make-porsche"},
"Porsche"),
SegmentKeywordInfo({
"automotive purchase intent by make-ram"},
"RAM"),
SegmentKeywordInfo({
"automotive purchase intent by make-saab"},
"Saab"),
SegmentKeywordInfo({
"automotive purchase intent by make-scion"},
"Scion"),
SegmentKeywordInfo({
"automotive purchase intent by make-smart"},
"smart"),
SegmentKeywordInfo({
"automotive purchase intent by make-subaru"},
"Subaru"),
SegmentKeywordInfo({
"automotive purchase intent by make-suzuki"},
"Suzuki"),
SegmentKeywordInfo({
"automotive purchase intent by make-toyota"},
"Toyota"),
SegmentKeywordInfo({
"automotive purchase intent by make-volkswagen"},
"Volkswagen"),
SegmentKeywordInfo({
"automotive purchase intent by make-volvo"},
"Volvo"),
};

static const std::vector<FunnelKeywordInfo>& _automotive_funnel_keywords = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@ using ::testing::_;

namespace {

const std::vector<std::string> kAudiSegments = {
"automotive purchase intent by make-audi"
};

const std::vector<std::string> kBmwSegments = {
"automotive purchase intent by make-bmw"
};

const std::vector<std::string> kAudiA4Segments = {
"automotive purchase intent by make-audi",
"automotive purchase intent by category-entry luxury car"
};

const std::vector<std::string> kAudiA5Segments = {
"automotive purchase intent by make-audi",
"automotive purchase intent by category-entry luxury car"
};

const std::vector<std::string> kAudiA6Segments = {
"automotive purchase intent by make-audi",
"automotive purchase intent by category-mid luxury car"
Expand All @@ -39,11 +52,14 @@ struct TestTriplet {
};

const std::vector<TestTriplet> kTestSearchqueries = {
{"BMW", kBmwSegments, 1},
{"latest audi a6 review", kAudiA6Segments, 2},
{" \tlatest audi\na6 !?# @& review \t ", kAudiA6Segments, 2},
{"latest audi a4 dealer reviews", kAudiA4Segments, 3},
{"latest audi a6 ", kAudiA6Segments, 1},
{"this is a test", kNoSegments, 1},
{"audi a5 dealer opening times sell", kAudiA5Segments, 3},
{"audi", kAudiSegments, 1},
};

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ using ::testing::_;

namespace ads {

const std::vector<std::string> audi_segments = {
"automotive purchase intent by make-audi"
};

const std::vector<std::string> audi_a4_segments = {
"automotive purchase intent by make-audi",
"automotive purchase intent by category-entry luxury car"
};

const std::vector<std::string> audi_a6_segments = {
"automotive purchase intent by make-audi",
"automotive purchase intent by category-mid luxury car"
Expand All @@ -39,6 +48,8 @@ struct TestTriplets {
};

std::vector<TestTriplets> kTestSearchQueries = {
{"https://yandex.com/search/?text=audi&lr=104995",
audi_segments, 1},
{"https://yandex.com/search/?text=audi%20a6%20review%202020&lr=109565",
audi_a6_segments, 2},
{"https://www.google.com/search?q=audi+a6+review+2020&gs_l=psy-ab.3..0j0i22i30l3.26031.26031..26262...0.0..0.82.82.1......0....2j1..gws-wiz.MZlXqcvydls&ved=0ahUKEwjAjpziu8fnAhVLzYUKHSriDZMQ4dUDCAg&uact=5", // NOLINT
Expand All @@ -65,6 +76,10 @@ std::vector<TestTriplets> kTestSearchQueries = {
no_segments, 0},
{"https://creators.brave.com/",
no_segments, 0},
{"https://www.google.com/search?ei=bY2CXvHBMK2tytMPqYq--A4&q=audi+a4",
audi_a4_segments, 1},
{"https://www.google.com/search?source=hp&ei=y2eDXsWuI6fIrgThwZuQDw&q=audi+a4", // NOLINT
audi_a4_segments, 1},
};

class AdsPurchaseIntentClassifierTest : public ::testing::Test {
Expand Down
26 changes: 10 additions & 16 deletions vendor/bat-native-ads/src/bat/ads/internal/search_providers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,17 @@ std::string SearchProviders::ExtractSearchQueryKeywords(
continue;
}

size_t index = search_provider.search_template.find('{');
std::string substring = search_provider.search_template.substr(0, index);
size_t href_index = url.find(substring);

if (index != std::string::npos && href_index != std::string::npos) {
// Checking if search template in as defined in |search_providers.h|
// is defined, e.g. |https://searx.me/?q={searchTerms}&categories=general|
// matches |?q={|
std::string key;
if (!RE2::PartialMatch(
search_provider.search_template, "\\?(.*?)\\={", &key)) {
return search_query_keywords;
}

search_query_keywords = helper::Uri::GetValueForKeyInQuery(url, key);
break;
// Checking if search template in as defined in |search_providers.h|
// is defined, e.g. |https://searx.me/?q={searchTerms}&categories=general|
// matches |?q={|
std::string key;
if (!RE2::PartialMatch(
search_provider.search_template, "\\?(.*?)\\={", &key)) {
return search_query_keywords;
}

search_query_keywords = helper::Uri::GetValueForKeyInQuery(url, key);
break;
}

return search_query_keywords;
Expand Down