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

Commit

Permalink
#36: Update rules for better accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
biancadanforth committed Aug 10, 2018
1 parent 25836b7 commit a8f138b
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
web-ext-artifacts
build
gecko.log
.DS_Store
17 changes: 12 additions & 5 deletions src/fathom_coefficients.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"largerImageCoeff": 3,
"largerFontSizeCoeff": 1,
"largerFontSizePriceCoeff": 1,
"largerFontSizeTitleCoeff": 1,
"hasDollarSignCoeff": 3,
"hasTitleInIDCoeff": 10,
"hasTitleInClassNameCoeff": 5,
"isHiddenCoeff": -100,
"isHeaderElementCoeff": 10
"hasFeatureNameInIDTitleCoeff": 10,
"hasFeatureNameInIDPriceCoeff": 10,
"hasFeatureNameInClassNameTitleCoeff": 5,
"hasFeatureNameInClassNamePriceCoeff": 5,
"isAboveTheFoldPriceCoeff": 30,
"isAboveTheFoldImageCoeff": 15,
"isAboveTheFoldTitleCoeff": 15,
"isHeaderElementCoeff": 10,
"optimalPriceStringLengthCoeff": 5,
"closestToImageCoeff": 1
}
30 changes: 22 additions & 8 deletions src/fathom_extraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
import productRuleset from 'commerce/fathom_ruleset';
import {
largerImageCoeff,
largerFontSizeCoeff,
largerFontSizePriceCoeff,
largerFontSizeTitleCoeff,
hasDollarSignCoeff,
hasTitleInIDCoeff,
hasTitleInClassNameCoeff,
isHiddenCoeff,
hasFeatureNameInIDTitleCoeff,
hasFeatureNameInIDPriceCoeff,
hasFeatureNameInClassNameTitleCoeff,
hasFeatureNameInClassNamePriceCoeff,
isAboveTheFoldPriceCoeff,
isAboveTheFoldImageCoeff,
isAboveTheFoldTitleCoeff,
isHeaderElementCoeff,
optimalPriceStringLengthCoeff,
closestToImageCoeff,
} from 'commerce/fathom_coefficients.json';

const PRODUCT_FEATURES = ['title', 'price', 'image'];
Expand All @@ -34,12 +41,19 @@ function runRuleset(doc) {
for (const feature of PRODUCT_FEATURES) {
let fnodesList = rules([
largerImageCoeff,
largerFontSizeCoeff,
largerFontSizePriceCoeff,
largerFontSizeTitleCoeff,
hasDollarSignCoeff,
hasTitleInIDCoeff,
hasTitleInClassNameCoeff,
isHiddenCoeff,
hasFeatureNameInIDTitleCoeff,
hasFeatureNameInIDPriceCoeff,
hasFeatureNameInClassNameTitleCoeff,
hasFeatureNameInClassNamePriceCoeff,
isAboveTheFoldPriceCoeff,
isAboveTheFoldImageCoeff,
isAboveTheFoldTitleCoeff,
isHeaderElementCoeff,
optimalPriceStringLengthCoeff,
closestToImageCoeff,
]).against(doc).get(`${feature}`);
fnodesList = fnodesList.filter(fnode => fnode.scoreFor(`${feature}ish`) >= SCORE_THRESHOLD);
// It is possible for multiple elements to have the same highest score.
Expand Down
Loading

0 comments on commit a8f138b

Please sign in to comment.