Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: components/dom_distiller/core/distillable_page_detector.cc

Issue 1047223003: Add integration of the new heuristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dd-adaboost-model
Patch Set: whitelist resources for ios Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/core/distillable_page_detector.cc
diff --git a/components/dom_distiller/core/distillable_page_detector.cc b/components/dom_distiller/core/distillable_page_detector.cc
index d11e04258c2e0d4ce99c8ef357c45dbe6206a850..aa7ddcf302e0fa516611e7f600fb69acd63ba9a9 100644
--- a/components/dom_distiller/core/distillable_page_detector.cc
+++ b/components/dom_distiller/core/distillable_page_detector.cc
@@ -5,9 +5,25 @@
#include "components/dom_distiller/core/distillable_page_detector.h"
#include "base/logging.h"
+#include "grit/components_resources.h"
+#include "ui/base/resource/resource_bundle.h"
namespace dom_distiller {
+const DistillablePageDetector* DistillablePageDetector::GetDefault() {
+ static DistillablePageDetector* detector = nullptr;
+ if (!detector) {
+ std::string serialized_proto =
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL)
+ .as_string();
+ scoped_ptr<AdaBoostProto> proto(new AdaBoostProto);
+ CHECK(proto->ParseFromString(serialized_proto));
+ detector = new DistillablePageDetector(proto.Pass());
+ }
+ return detector;
+}
+
DistillablePageDetector::DistillablePageDetector(
scoped_ptr<AdaBoostProto> proto)
: proto_(proto.Pass()), threshold_(0.0) {
@@ -30,7 +46,9 @@ bool DistillablePageDetector::Classify(
double DistillablePageDetector::Score(
const std::vector<double>& features) const {
- CHECK(features.size() == size_t(proto_->num_features()));
+ if (features.size() != size_t(proto_->num_features())) {
+ return 0.0;
+ }
double score = 0.0;
for (int i = 0; i < proto_->num_stumps(); ++i) {
const StumpProto& stump = proto_->stump(i);

Powered by Google App Engine
This is Rietveld 408576698