| 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 goog.provide('image.collections.extension.DocumentFeatureExtractor'); | 5 goog.provide('image.collections.extension.domextractor.DocumentFeatureExtractor'
); |
| 6 | 6 |
| 7 goog.require('goog.asserts'); | 7 goog.require('image.collections.extension.domextractor.DocumentFeature'); |
| 8 goog.require('image.collections.extension.DocumentFeature'); | 8 goog.require('image.collections.extension.domextractor.ElementFilter'); |
| 9 goog.require('image.collections.extension.ElementFilter'); | |
| 10 | 9 |
| 11 goog.scope(function() { | 10 goog.scope(function() { |
| 12 var DocumentFeature = image.collections.extension.DocumentFeature; | 11 var DocumentFeature = image.collections.extension.domextractor.DocumentFeature; |
| 13 var ElementFilter = image.collections.extension.ElementFilter; | 12 var ElementFilter = image.collections.extension.domextractor.ElementFilter; |
| 14 | 13 |
| 15 | 14 |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * A base class for document feature (title, snippet, image) extractors. | 17 * A base class for document feature (title, snippet, image) extractors. |
| 19 * @constructor | 18 * @constructor |
| 20 */ | 19 */ |
| 21 image.collections.extension.DocumentFeatureExtractor = function() { | 20 image.collections.extension.domextractor.DocumentFeatureExtractor = function() { |
| 22 /** @protected {!Array.<!ElementFilter>} */ | 21 /** @private {!Array.<!ElementFilter>} */ |
| 23 this.filters_ = []; | 22 this.filters_ = []; |
| 24 }; | 23 }; |
| 25 var DocumentFeatureExtractor = | 24 var DocumentFeatureExtractor = |
| 26 image.collections.extension.DocumentFeatureExtractor; | 25 image.collections.extension.domextractor.DocumentFeatureExtractor; |
| 27 | 26 |
| 28 | 27 |
| 29 /** | 28 /** |
| 30 * Installs an element filter. | 29 * Installs an element filter. |
| 31 * @param {!ElementFilter} filter | 30 * @param {!ElementFilter} filter |
| 32 * @protected | 31 * @protected |
| 33 */ | 32 */ |
| 34 DocumentFeatureExtractor.prototype.addFilter = function(filter) { | 33 DocumentFeatureExtractor.prototype.addFilter = function(filter) { |
| 35 this.filters_.push(filter); | 34 this.filters_.push(filter); |
| 36 }; | 35 }; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 85 |
| 87 /** | 86 /** |
| 88 * This function tries to extract a feature from every node in a nodelist | 87 * This function tries to extract a feature from every node in a nodelist |
| 89 * and returns an array of features. | 88 * and returns an array of features. |
| 90 * @param {!NodeList} nodeList DOM node list. | 89 * @param {!NodeList} nodeList DOM node list. |
| 91 * @param {!Object=} opt_context Optional context. | 90 * @param {!Object=} opt_context Optional context. |
| 92 * @return {!Array.<!DocumentFeature>} | 91 * @return {!Array.<!DocumentFeature>} |
| 93 */ | 92 */ |
| 94 DocumentFeatureExtractor.prototype.extractFromNodeList = function( | 93 DocumentFeatureExtractor.prototype.extractFromNodeList = function( |
| 95 nodeList, opt_context) { | 94 nodeList, opt_context) { |
| 96 goog.asserts.assert(goog.isArrayLike(nodeList)); | |
| 97 var result = []; | 95 var result = []; |
| 98 var nodeListLength = nodeList.length; | 96 var nodeListLength = nodeList.length; |
| 99 for (var j = 0; j < nodeListLength; ++j) { | 97 for (var j = 0; j < nodeListLength; ++j) { |
| 100 var feature = this.extractFromElement(nodeList[j], opt_context); | 98 var feature = this.extractFromElement(nodeList[j], opt_context); |
| 101 if (feature) { | 99 if (feature) { |
| 102 result.push(feature); | 100 result.push(feature); |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 return result; | 103 return result; |
| 106 }; | 104 }; |
| 107 | 105 |
| 108 | 106 |
| 109 /** | 107 /** |
| 110 * This function extracts a feature from an HTML element. It should be | 108 * This function extracts a feature from an HTML element. It should be |
| 111 * overridden in derived classes, unless the feature can be extracted without | 109 * overridden in derived classes, unless the feature can be extracted without |
| 112 * looking at DOM. | 110 * looking at DOM. |
| 113 * @param {!Element} element HTML element. | 111 * @param {!Element} element HTML element. |
| 114 * @param {!Object=} opt_context Optional context. | 112 * @param {!Object=} opt_context Optional context. |
| 115 * @return {DocumentFeature} | 113 * @return {DocumentFeature} |
| 116 */ | 114 */ |
| 117 DocumentFeatureExtractor.prototype.extractFromElement = function( | 115 DocumentFeatureExtractor.prototype.extractFromElement = function( |
| 118 element, opt_context) { | 116 element, opt_context) { |
| 119 return null; | 117 return null; |
| 120 }; | 118 }; |
| 121 }); // goog.scope | 119 }); // goog.scope |
| OLD | NEW |