Created
May 1, 2017 09:36
-
-
Save pjho/6d50d49df6d942ef64530071535d76ad to your computer and use it in GitHub Desktop.
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
/* | |
{ | |
"name": "language", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"dictionary-en-gb": "^1.2.1", | |
"install": "^0.8.9", | |
"npm": "^4.5.0", | |
"retext": "^5.0.0", | |
"retext-equality": "^3.0.0", | |
"retext-profanities": "^4.1.0", | |
"retext-simplify": "^4.1.0", | |
"retext-spell": "^2.2.0", | |
"unist-util-inspect": "^4.1.0", | |
"vfile-reporter": "^3.0.0" | |
} | |
} | |
*/ | |
var retext = require('retext'); | |
var report = require('vfile-reporter'); | |
var profanities = require('retext-profanities'); | |
var inspect = require('unist-util-inspect'); | |
var sentiment = require('retext-sentiment'); | |
var spell = require('retext-spell'); | |
var dictionary = require('dictionary-en-gb'); | |
const examples = [ | |
'Hey guys, utilize a shorter word.', | |
'Fuk dis sht Dis izz bullshit I cud do beta!', | |
'Fuck this shit. This is bullshit. I could do better!!!', | |
'asd sadh asklj hdalsjdlkajsdlkasjd lkasjd aslk' | |
]; | |
const eg = examples[3]; | |
retext() | |
.use(profanities) | |
.use(spell, dictionary) | |
.process([eg].join('\n'), function (err, file) { | |
console.error(report(err || file)); | |
}); | |
retext() | |
.use(sentiment) | |
.use(function () { | |
return transformer; | |
function transformer(tree) { | |
// console.log(tree.children); | |
console.log('Overall: ', tree.data); | |
tree.children.forEach(child => { | |
if (child.type !== 'WhiteSpaceNode') { | |
console.log(' ', child.type, child.data); | |
child.children.forEach(grandchild => { | |
if (grandchild.type !== 'WhiteSpaceNode') { | |
console.log(' ', grandchild.type, grandchild.data); | |
} | |
}) | |
} | |
}) | |
} | |
}) | |
.processSync( | |
'I HATE EVERYTHING!!!' + | |
'I love you so much!! :)' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment