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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 ResourceBundle::GetSharedInstance() | 34 ResourceBundle::GetSharedInstance() |
35 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW) | 35 .GetRawDataResource(IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW) |
36 .as_string(); | 36 .as_string(); |
37 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); | 37 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); |
38 CHECK(proto->ParseFromString(serialized_proto)); | 38 CHECK(proto->ParseFromString(serialized_proto)); |
39 detector = new DistillablePageDetector(std::move(proto)); | 39 detector = new DistillablePageDetector(std::move(proto)); |
40 } | 40 } |
41 return detector; | 41 return detector; |
42 } | 42 } |
43 | 43 |
| 44 const DistillablePageDetector* DistillablePageDetector::GetLongPageModel() { |
| 45 static DistillablePageDetector* detector = nullptr; |
| 46 if (!detector) { |
| 47 std::string serialized_proto = |
| 48 ResourceBundle::GetSharedInstance() |
| 49 .GetRawDataResource(IDR_LONG_PAGE_SERIALIZED_MODEL) |
| 50 .as_string(); |
| 51 scoped_ptr<AdaBoostProto> proto(new AdaBoostProto); |
| 52 CHECK(proto->ParseFromString(serialized_proto)); |
| 53 detector = new DistillablePageDetector(std::move(proto)); |
| 54 } |
| 55 return detector; |
| 56 } |
| 57 |
44 DistillablePageDetector::DistillablePageDetector( | 58 DistillablePageDetector::DistillablePageDetector( |
45 scoped_ptr<AdaBoostProto> proto) | 59 scoped_ptr<AdaBoostProto> proto) |
46 : proto_(std::move(proto)), threshold_(0.0) { | 60 : proto_(std::move(proto)), threshold_(0.0) { |
47 CHECK(proto_->num_stumps() == proto_->stump_size()); | 61 CHECK(proto_->num_stumps() == proto_->stump_size()); |
48 for (int i = 0; i < proto_->num_stumps(); ++i) { | 62 for (int i = 0; i < proto_->num_stumps(); ++i) { |
49 const StumpProto& stump = proto_->stump(i); | 63 const StumpProto& stump = proto_->stump(i); |
50 CHECK(stump.feature_number() >= 0); | 64 CHECK(stump.feature_number() >= 0); |
51 CHECK(stump.feature_number() < proto_->num_features()); | 65 CHECK(stump.feature_number() < proto_->num_features()); |
52 threshold_ += stump.weight() / 2.0; | 66 threshold_ += stump.weight() / 2.0; |
53 } | 67 } |
(...skipping 20 matching lines...) Expand all Loading... |
74 } | 88 } |
75 } | 89 } |
76 return score; | 90 return score; |
77 } | 91 } |
78 | 92 |
79 double DistillablePageDetector::GetThreshold() const { | 93 double DistillablePageDetector::GetThreshold() const { |
80 return threshold_; | 94 return threshold_; |
81 } | 95 } |
82 | 96 |
83 } // namespace dom_distiller | 97 } // namespace dom_distiller |
OLD | NEW |