Commit b7262a2b authored by Sam Bowen's avatar Sam Bowen Committed by Commit Bot

Support boolean values as string in schema.org extractor

Bug: 1065554
Change-Id: I4425e1d43a506ebe6dabacb5c29a6bd8c35c84a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127434
Commit-Queue: Sam Bowen <sgbowen@google.com>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754735}
parent 17460753
......@@ -110,6 +110,16 @@ bool ParseStringValue(const std::string& property_type,
return true;
}
}
if (prop_config.boolean) {
if (value == "https://schema.org/True" || value == "true") {
values->bool_values.push_back(true);
return true;
}
if (value == "https://schema.org/False" || value == "false") {
values->bool_values.push_back(false);
return true;
}
}
return false;
}
......@@ -180,6 +190,7 @@ void ExtractEntity(const base::DictionaryValue& val,
type = "Thing";
}
entity->type = type;
for (const auto& entry : val.DictItems()) {
if (entity->properties.size() >= kMaxNumFields) {
break;
......
......@@ -157,6 +157,20 @@ TEST_F(SchemaOrgExtractorTest, BooleanValue) {
EXPECT_EQ(expected, extracted);
}
TEST_F(SchemaOrgExtractorTest, BooleanValueAsString) {
EntityPtr extracted = Extract(
"{\"@type\": \"VideoObject\", \"requiresSubscription\": "
"\"https://schema.org/True\" }");
ASSERT_FALSE(extracted.is_null());
EntityPtr expected = Entity::New();
expected->type = "VideoObject";
expected->properties.push_back(
CreateBooleanProperty("requiresSubscription", true));
EXPECT_EQ(expected, extracted);
}
TEST_F(SchemaOrgExtractorTest, LongValue) {
EntityPtr extracted =
Extract("{\"@type\": \"VideoObject\", \"position\": 111 }");
......
......@@ -20,6 +20,7 @@ PropertyConfiguration GetPropertyConfiguration(const std::string& name) {
/* .date_time = */ {{'true' if property.has_date_time else 'false'}},
/* .number = */ {{'true' if property.has_number else 'false'}},
/* .url = */ {{'true' if property.has_url else 'false'}},
/* .boolean = */ {{'true' if property.has_boolean else 'false'}},
/* .thing_types = */ {
{% for thing_type in property.thing_types %}
"{{thing_type}}",
......
......@@ -21,6 +21,7 @@ struct PropertyConfiguration {
bool date_time;
bool number;
bool url;
bool boolean;
std::set<std::string> thing_types;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment