diff --git a/src/fallback_extraction.js b/src/extraction/fallback_extraction.js similarity index 97% rename from src/fallback_extraction.js rename to src/extraction/fallback_extraction.js index db1f6ee..5b3535f 100644 --- a/src/fallback_extraction.js +++ b/src/extraction/fallback_extraction.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* +/** * Uses CSS selectors, or failing that, Open Graph tags to extract * a product from its product page, where a 'product' is defined by the bundle * of features that makes it identifiable. @@ -10,7 +10,7 @@ * Features: title, image, price */ -import extractionData from 'commerce/product_extraction_data.json'; +import extractionData from 'commerce/extraction/product_extraction_data.json'; const OPEN_GRAPH_PROPERTY_VALUES = { title: 'og:title', diff --git a/src/fathom_default_coefficients.json b/src/extraction/fathom_default_coefficients.json similarity index 100% rename from src/fathom_default_coefficients.json rename to src/extraction/fathom_default_coefficients.json diff --git a/src/fathom_extraction.js b/src/extraction/fathom_extraction.js similarity index 93% rename from src/fathom_extraction.js rename to src/extraction/fathom_extraction.js index 263c366..0b59e84 100644 --- a/src/fathom_extraction.js +++ b/src/extraction/fathom_extraction.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* +/** * Uses Fathom to extract a product from its product page, * where a 'product' is defined by the bundle of features that * makes it identifiable. @@ -10,8 +10,8 @@ * Features: title, image, price */ -import defaultCoefficients from 'commerce/fathom_default_coefficients.json'; -import RulesetFactory from 'commerce/ruleset_factory'; +import defaultCoefficients from 'commerce/extraction/fathom_default_coefficients.json'; +import RulesetFactory from 'commerce/extraction/ruleset_factory'; import {SCORE_THRESHOLD} from 'commerce/config'; const PRODUCT_FEATURES = ['title', 'price', 'image']; diff --git a/src/product_extraction_data.json b/src/extraction/product_extraction_data.json similarity index 100% rename from src/product_extraction_data.json rename to src/extraction/product_extraction_data.json diff --git a/src/ruleset_factory.js b/src/extraction/ruleset_factory.js similarity index 97% rename from src/ruleset_factory.js rename to src/extraction/ruleset_factory.js index 2053ec0..7e4744f 100644 --- a/src/ruleset_factory.js +++ b/src/extraction/ruleset_factory.js @@ -2,13 +2,19 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/** + * Exports a RulesetFactory class, which when instantiated, binds Fathom + * coefficients to a ruleset. An instance of this class is used for product + * feature extraction (`fathom_extraction.js`) and for training (`trainees.js`). + */ + import {dom, out, rule, ruleset, score, type} from 'fathom-web'; // Since the fathom-trainees add-on currently uses a submodule of Fathom, for // training, replace 'utils' with 'utilsForFrontend' import {ancestors} from 'fathom-web/utils'; // relative URLs are needed for training, as the 'commerce' alias doesn't exist // in that context -import {SCORE_THRESHOLD} from './config'; +import {SCORE_THRESHOLD} from '../config'; const DEFAULT_BODY_FONT_SIZE = 14; const DEFAULT_SCORE = 1; diff --git a/src/product_info.js b/src/product_info.js index e5de47c..9aa01a2 100644 --- a/src/product_info.js +++ b/src/product_info.js @@ -7,8 +7,8 @@ * "document_idle", which is after all DOM content has been loaded. */ -import extractProductWithFathom from 'commerce/fathom_extraction'; -import extractProductWithFallback from 'commerce/fallback_extraction'; +import extractProductWithFathom from 'commerce/extraction/fathom_extraction'; +import extractProductWithFallback from 'commerce/extraction/fallback_extraction'; /** * Checks to see if any product information for the page was found, diff --git a/src/trainees.js b/src/trainees.js index 6863517..a8ce8fb 100644 --- a/src/trainees.js +++ b/src/trainees.js @@ -2,8 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import defaultCoefficients from './fathom_default_coefficients.json'; -import RulesetFactory from './ruleset_factory'; +import defaultCoefficients from './extraction/fathom_default_coefficients.json'; +import RulesetFactory from './extraction/ruleset_factory'; // Array of numbers corresponding to the coefficients const coeffs = Object.values(defaultCoefficients); @@ -20,9 +20,12 @@ const coeffs = Object.values(defaultCoefficients); * * How to train: * 1. Fork the `mozilla/fathom-trainees` repo, - * 2. Copy this file, `fathom_default_coefficients.json`, `ruleset_factory.js` - * and `config.js` over to the `./src` folder in the `fathom-trainees` add-on. - * 3. Follow instructions at: https://github.com/erikrose/fathom-fox#the-trainer + * 2. In the `fathom-trainees` add-on, copy this file and `config.js` over to the + * `./src` folder, and copy `./extraction/fathom_default_coefficients.json` and + * `./extraction/ruleset_factory.js` to a new `./src/extraction` subfolder. + * * Note: You will have to replace 'utils' with 'utilsForFrontend' on the + * import in `ruleset_factory.js`. See that file for more information. + * 3. Follow instructions at: https://github.com/erikrose/fathom-fox#the-trainer. * * Notes: * - The FathomFox Trainer assumes that the value of your corpus' `data-fathom`