
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
distributed-ngram
Advanced tools
Simply put predict next word user will write.
git clone git@github.com:syzer/distributedNgram.git && cd $_
npm install
npm install --save-dev
The file nGram.js offers more compact version of code:
npm start
var jsSpark = require('js-spark')({workers: 16});
var task = jsSpark.jsSpark;
var q = jsSpark.q;
task([20, 30, 40, 50])
// this is executed on client side
.map(function addOne(num) {
return num + 1;
})
.reduce(function sumUp(sum, num) {
return sum + num;
})
.run()
.then(function(data) {
// this is executed on back on server
console.log('i finished calculating', data);
})
npm test
clone https://github.com/syzer/distributedNgram.git
load:
dracula
lodash
load helpers
(gist)
make function prepare()
// remove special characters
function prepare(str){}
prepare('“Listen to them, the children of the night. What music they make!”')
//=>"listen to them the children of the night what music they make"
(gist)
make bigramText()
bigramText("to listen to them the children of the night what music they make");
//=>{to: {listen: 1, them:1} , listen:{to:1}, the:{children:1}}...
function bigramText(str) {
return arr.reduce(bigramArray);
}
(gist)
function mergeSmall()
create 2 tasks ch01, and ch02
use tasks to bigram those chapters
reduce response with _.merge
(gist)
function mergeBig(texts)
load [ch1, ch2, ch3] or texts
make distinct tasks to bigram this text
reduce with _.mergeObjectsInArr
cache result
return result
(gist)
function predict(word)
load appropriate key/word from cache
calc total hits
sort all hits in order,
may use helper function objToSortedArr(obj)
(gist)
function train(fileName, splitter)
load file
prepare
use splitter(string) to create separate tasks
calculate tasks on clients using mergeBig()
[ ] git checkout [ ] js-spark adventure
FAQs
npm i --save js-spark
We found that distributed-ngram demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.