OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/dom_distiller/core/distillable_page_detector.h" | 5 #include "components/dom_distiller/core/distillable_page_detector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "grit/components_resources.h" | 8 #include "grit/components_resources.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 | 10 |
11 namespace dom_distiller { | 11 namespace dom_distiller { |
12 | 12 |
13 const DistillablePageDetector* DistillablePageDetector::GetDefault() { | 13 const DistillablePageDetector* DistillablePageDetector::GetDefault() { |
14 static DistillablePageDetector* detector = nullptr; | 14 static DistillablePageDetector* detector = nullptr; |
15 if (!detector) { | 15 if (!detector) { |
16 std::string serialized_proto = | 16 std::string serialized_proto = |
17 ResourceBundle::GetSharedInstance() | 17 ResourceBundle::GetSharedInstance() |
18 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL) | 18 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL) |
19 .as_string(); | 19 .as_string(); |
20 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); | 20 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); |
21 CHECK(proto->ParseFromString(serialized_proto)); | 21 CHECK(proto->ParseFromString(serialized_proto)); |
22 detector = new DistillablePageDetector(proto.Pass()); | 22 detector = new DistillablePageDetector(proto.Pass()); |
23 } | 23 } |
24 return detector; | 24 return detector; |
25 } | 25 } |
26 | 26 |
| 27 const DistillablePageDetector* DistillablePageDetector::GetNewModel() { |
| 28 static DistillablePageDetector* detector = nullptr; |
| 29 if (!detector) { |
| 30 std::string serialized_proto = |
| 31 ResourceBundle::GetSharedInstance() |
| 32 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW) |
| 33 .as_string(); |
| 34 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); |
| 35 CHECK(proto->ParseFromString(serialized_proto)); |
| 36 detector = new DistillablePageDetector(proto.Pass()); |
| 37 } |
| 38 return detector; |
| 39 } |
| 40 |
27 DistillablePageDetector::DistillablePageDetector( | 41 DistillablePageDetector::DistillablePageDetector( |
28 scoped_ptr<AdaBoostProto> proto) | 42 scoped_ptr<AdaBoostProto> proto) |
29 : proto_(proto.Pass()), threshold_(0.0) { | 43 : proto_(proto.Pass()), threshold_(0.0) { |
30 CHECK(proto_->num_stumps() == proto_->stump_size()); | 44 CHECK(proto_->num_stumps() == proto_->stump_size()); |
31 for (int i = 0; i < proto_->num_stumps(); ++i) { | 45 for (int i = 0; i < proto_->num_stumps(); ++i) { |
32 const StumpProto& stump = proto_->stump(i); | 46 const StumpProto& stump = proto_->stump(i); |
33 CHECK(stump.feature_number() >= 0); | 47 CHECK(stump.feature_number() >= 0); |
34 CHECK(stump.feature_number() < proto_->num_features()); | 48 CHECK(stump.feature_number() < proto_->num_features()); |
35 threshold_ += stump.weight() / 2.0; | 49 threshold_ += stump.weight() / 2.0; |
36 } | 50 } |
(...skipping 20 matching lines...) Expand all Loading... |
57 } | 71 } |
58 } | 72 } |
59 return score; | 73 return score; |
60 } | 74 } |
61 | 75 |
62 double DistillablePageDetector::GetThreshold() const { | 76 double DistillablePageDetector::GetThreshold() const { |
63 return threshold_; | 77 return threshold_; |
64 } | 78 } |
65 | 79 |
66 } // namespace dom_distiller | 80 } // namespace dom_distiller |
OLD | NEW |