Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
#36: Reorganize files into an 'extraction' subfolder.
Browse files Browse the repository at this point in the history
  • Loading branch information
biancadanforth committed Aug 24, 2018
1 parent 7567ca3 commit 4b1d448
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* 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 <meta> tags to extract
* a product from its product page, where a 'product' is defined by the bundle
* of features that makes it identifiable.
*
* 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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* 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.
*
* 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'];
Expand Down
8 changes: 7 additions & 1 deletion src/ruleset_factory.js → src/extraction/ruleset_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/product_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions src/trainees.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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`
Expand Down

0 comments on commit 4b1d448

Please sign in to comment.