-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix demo + change test framework to batr
Also fixing demo and moving stopword library from dependency to devDependency. So not bundled, but possible to test with.
- Loading branch information
Showing
18 changed files
with
8,914 additions
and
3,815 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,11 @@ | ||
language: node_js | ||
cache: | ||
directories: | ||
- node_modules | ||
os: linux | ||
dist: xenial | ||
notifications: | ||
email: true | ||
node_js: | ||
- '10' | ||
- '12' | ||
- '14' | ||
- '16' | ||
before_script: | ||
- npm prune | ||
branches: | ||
except: | ||
- /^v\d+\.\d+\.\d+$/ | ||
addons: | ||
apt: | ||
packages: | ||
- xvfb | ||
install: | ||
- export DISPLAY=':99.0' | ||
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & | ||
- npm install | ||
notifications: | ||
slack: norch:wLsHiXjnAH5BdtTq3qtAqGp7 | ||
email: true | ||
- npm prune |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const findKeywords = function (headline, body, cutoff = 0) { | ||
// remove duplicates in headline | ||
headline = [...new Set(headline)]; | ||
|
||
// keywords array of word objects with word count | ||
const keywordsCount = []; | ||
// returned array (cutoff if != 0) | ||
let keywords = []; | ||
|
||
// loop through headline and body | ||
for (let i = 0; i < headline.length; i++) { | ||
for (let j = 0; j < body.length; j++) { | ||
// headline/body mathching | ||
if (headline[i] === body[j]) { | ||
// check if word exists in keywordsCount first and update it | ||
const existing = findExistingWord(keywordsCount, 'word', headline[i]); | ||
if (existing > -1) { | ||
keywordsCount[existing].count++; | ||
} else { | ||
// create object and push to array | ||
const wordObj = { word: headline[i], count: 1 }; | ||
keywordsCount.push(wordObj); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Sort on most times used in body | ||
keywordsCount.sort(compareObjects); | ||
// loop through keywordsCount and push word to keywords | ||
for (let l = 0; l < keywordsCount.length; l++) { | ||
keywords.push(keywordsCount[l].word); | ||
} | ||
// slice, if cutoff set | ||
if (cutoff > 0) { | ||
keywords = keywords.slice(0, cutoff); | ||
} | ||
return keywords | ||
}; | ||
|
||
const findExistingWord = function (array, attr, value) { | ||
for (let k = 0; k < array.length; k += 1) { | ||
if (array[k][attr] === value) { | ||
return k | ||
} | ||
} | ||
return -1 | ||
}; | ||
|
||
const compareObjects = function (a, b) { | ||
if (a.count > b.count) { | ||
return -1 | ||
} | ||
if (a.count < b.count) { | ||
return 1 | ||
} | ||
return 0 | ||
}; | ||
|
||
var src = { | ||
findKeywords: findKeywords | ||
}; | ||
|
||
module.exports = src; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const findKeywords = function (headline, body, cutoff = 0) { | ||
// remove duplicates in headline | ||
headline = [...new Set(headline)]; | ||
|
||
// keywords array of word objects with word count | ||
const keywordsCount = []; | ||
// returned array (cutoff if != 0) | ||
let keywords = []; | ||
|
||
// loop through headline and body | ||
for (let i = 0; i < headline.length; i++) { | ||
for (let j = 0; j < body.length; j++) { | ||
// headline/body mathching | ||
if (headline[i] === body[j]) { | ||
// check if word exists in keywordsCount first and update it | ||
const existing = findExistingWord(keywordsCount, 'word', headline[i]); | ||
if (existing > -1) { | ||
keywordsCount[existing].count++; | ||
} else { | ||
// create object and push to array | ||
const wordObj = { word: headline[i], count: 1 }; | ||
keywordsCount.push(wordObj); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Sort on most times used in body | ||
keywordsCount.sort(compareObjects); | ||
// loop through keywordsCount and push word to keywords | ||
for (let l = 0; l < keywordsCount.length; l++) { | ||
keywords.push(keywordsCount[l].word); | ||
} | ||
// slice, if cutoff set | ||
if (cutoff > 0) { | ||
keywords = keywords.slice(0, cutoff); | ||
} | ||
return keywords | ||
}; | ||
|
||
const findExistingWord = function (array, attr, value) { | ||
for (let k = 0; k < array.length; k += 1) { | ||
if (array[k][attr] === value) { | ||
return k | ||
} | ||
} | ||
return -1 | ||
}; | ||
|
||
const compareObjects = function (a, b) { | ||
if (a.count > b.count) { | ||
return -1 | ||
} | ||
if (a.count < b.count) { | ||
return 1 | ||
} | ||
return 0 | ||
}; | ||
|
||
var src = { | ||
findKeywords: findKeywords | ||
}; | ||
|
||
export { src as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ehp = factory()); | ||
})(this, (function () { 'use strict'; | ||
|
||
const findKeywords = function (headline, body, cutoff = 0) { | ||
// remove duplicates in headline | ||
headline = [...new Set(headline)]; | ||
|
||
// keywords array of word objects with word count | ||
const keywordsCount = []; | ||
// returned array (cutoff if != 0) | ||
let keywords = []; | ||
|
||
// loop through headline and body | ||
for (let i = 0; i < headline.length; i++) { | ||
for (let j = 0; j < body.length; j++) { | ||
// headline/body mathching | ||
if (headline[i] === body[j]) { | ||
// check if word exists in keywordsCount first and update it | ||
const existing = findExistingWord(keywordsCount, 'word', headline[i]); | ||
if (existing > -1) { | ||
keywordsCount[existing].count++; | ||
} else { | ||
// create object and push to array | ||
const wordObj = { word: headline[i], count: 1 }; | ||
keywordsCount.push(wordObj); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Sort on most times used in body | ||
keywordsCount.sort(compareObjects); | ||
// loop through keywordsCount and push word to keywords | ||
for (let l = 0; l < keywordsCount.length; l++) { | ||
keywords.push(keywordsCount[l].word); | ||
} | ||
// slice, if cutoff set | ||
if (cutoff > 0) { | ||
keywords = keywords.slice(0, cutoff); | ||
} | ||
return keywords | ||
}; | ||
|
||
const findExistingWord = function (array, attr, value) { | ||
for (let k = 0; k < array.length; k += 1) { | ||
if (array[k][attr] === value) { | ||
return k | ||
} | ||
} | ||
return -1 | ||
}; | ||
|
||
const compareObjects = function (a, b) { | ||
if (a.count > b.count) { | ||
return -1 | ||
} | ||
if (a.count < b.count) { | ||
return 1 | ||
} | ||
return 0 | ||
}; | ||
|
||
var src = { | ||
findKeywords: findKeywords | ||
}; | ||
|
||
return src; | ||
|
||
})); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.