return new Promise(function (resolve, reject){ retext().use(syllable).use(function () { return function(cst){ resolve(cst.data.syllableCount) } }).process(str) })
function process(str) { output = {}; retext().use(shopify).process(str, function (err, file) { output = file; }); return output; }
test('should ignore literal words', function (t) { t.plan(2); retext().use(spell, enGB).process('“color”', function (err, file) { t.equal(err, null); t.deepEqual(file.messages.map(String), []); }); });
test('should throw when without `options`', function (t) { t.plan(1); try { retext().use(spell); } catch (err) { t.equal(err.message, 'Expected `Object`, got `undefined`'); } });
var get_sentiment_of_audiobook_sample = function(audiobook_sample, callback){ retext().use(sentiment).use(function () { return function (cst) { var polarity = cst.data.polarity; return callback(polarity); //console.log(inspect(cst)); }; }).process( audiobook_sample ); }
test('should warn for misspelt words', function (t) { t.plan(4); retext().use(spell, enGB).process('color', function (err, file) { t.equal(err, null); t.deepEqual(file.messages.map(String), [ '1:1-1:6: color > colour, colon, col or, col-or, Colorado' ]); }); retext().use(spell, enUS).process('colour and utilise', function (err, file) { t.equal(err, null); t.deepEqual(file.messages.map(String), [ '1:1-1:7: colour > color, co lour, co-lour, col our, col-our, lour', '1:12-1:19: utilise > utilize' ]); }); });
describe('pos()', function () { retext().use(pos).process(sentence, function (err, file) { it('should work', function (done) { var index = -1; visit(file.namespace('retext').cst, 'WordNode', function (node) { assert.equal(node.data.partOfSpeech, tags[++index]); }); done(err); }); }); });
test('...unless `ignoreLiteral` is false', function (t) { t.plan(2); retext().use(spell, { 'dictionary': enGB, 'ignoreLiteral': false }).process('“color”', function (err, file) { t.equal(err, null); t.deepEqual(file.messages.map(String), [ '1:2-1:7: color > colour, colon, col or, col-or, Colorado' ]); }); });
describe('stemmer()', function () { retext().use(stemmer).process(sentence, function (err, file) { it('should work', function (done) { var index = -1; visit(file.namespace('retext').cst, 'WordNode', function (node) { assert('stem' in node.data); assert.equal(node.data.stem, stems[++index]); }); done(err); }); }); });
function do_retext(text, reply){ let map_pos; retext() .use(english) .use(pos) .use(sentiment) .use(keywords) .use(function(){return collect}) .process(text,cb); function cb(err,file){ if (err) { console.error(err); } try{ let space = file.namespace('retext'); let keywords = space.keywords.map(_keyword); let keyphrases = space.keyphrases.map(_keyphrase); reply({text,keywords,keyphrases,map_pos}); }catch(err){ console.error(err); } } function collect(cst){ map_pos = {}; visit(cst,'WordNode',function(node){ map_pos[nlcstToString(node)] = node.data; }); } function _keyword(keyword){ let score = keyword.score; let key = nlcstToString(keyword.matches[0].node); return {key,score}; } function _keyphrase(keyphrase){ let score = keyphrase.score; let weight = keyphrase.weight; let key = keyphrase.matches[0].nodes.map(nlcstToString).join(''); return {key,score,weight}; } }
test('should warn for invalid words (coverage)', function (t) { var english = retext().use(spell, enGB); t.plan(3); english.process('color', function (err, file) { t.equal(err, null); t.deepEqual(file.messages.map(String), [ '1:1-1:6: color > colour, colon, col or, col-or, Colorado' ]); /* * Coverage: future files can start faster. */ english.process('colour', function (err, file) { t.deepEqual(file.messages.map(String), []); }); }); });
module.exports = function reshapeRetext (plugins) { const retext = Retext() Array.prototype.concat(plugins).map((plugin) => { Array.isArray(plugin) ? retext.use.apply(retext, plugin) : retext.use(plugin) }) return function retextPlugin (tree) { return modifyNodes(tree, (node) => node.type === 'tag', (node) => { // if node has skip property, remove it and move on if (node.attrs && node.attrs['retext-skip']) { delete node.attrs['retext-skip'] return node } // if it's a blacklisted tag, move on if (blacklist.indexOf(node.name) > -1) return node // if it has no content, move on if (!node.content) return node // otherwise, run through its content return when.map(node.content, (n) => { // if its not a text node, or is only whitespace, move on if (n.type !== 'text') return n if (/^\n\s*$/.test(n.content)) return n // otherwise, process it with retext return nodefn.call(retext.process.bind(retext), n.content) .then((res) => { n.content = res.contents return n }) }).then((contents) => { node.content = contents return node }) }) } }
test('should fail load errors on the VFile', function (t) { var processor = retext().use(spell, failingLoader); t.plan(3); processor.process('', function (err) { var failed; t.equal(err.message, 'load error'); /* * Coverage: future files can fail immediatly. */ processor.process('', function (err) { t.equal(err.message, 'load error'); failed = true; }); t.equal(failed, true); }); });
test('should fail construct errors on the VFile', function (t) { var processor = retext().use(spell, failingConstructor); t.plan(3); processor.process('', function (err) { var failed; t.equal(err.message, 'First argument must be a buffer'); /* * Coverage: future files can fail immediatly. */ processor.process('', function (err) { t.equal(err.message, 'First argument must be a buffer'); failed = true; }); t.equal(failed, true); }); });
/* * Dependencies. */ var retext = require('retext'); var remark2retext = require('remark-retext'); var readability = require('retext-readability'); var profanities = require('retext-profanities'); var equality = require('retext-equality'); var simplify = require('retext-simplify'); /* * Processor. */ var naturalLanguage = retext() .use(equality) .use(profanities) .use(readability, { 'age': 20 }) .use(simplify, { 'ignore': [ 'option', 'plugin', 'interface', 'parameters', 'function', 'modify', 'component', 'render',
var Retext = require('retext'), sentiment = require('retext-sentiment'); var retext = Retext().use(sentiment); function textSentiment(text){ var data; retext.process(text, function (err, tree) { // For some reason, the actual sentiment data is buried way down in this tree var sentimentTree = tree.data.retext.tree; // Data isnt there for some reason if (!sentimentTree.data) { console.log(sentimentTree); console.log("error") return } // Only keep track of the original text, and it's sentiment data = { text: text, valence: sentimentTree.data.valence, polarity: sentimentTree.data.polarity } }) return data; } module.exports = { textSentiment: textSentiment };
test('keywords()', function (t) { retext().use(keywords).process(fixture, function (err, file) { var namespace = file.namespace('retext'); t.ifErr(err, 'should not fail'); t.test('should work', function (st) { st.ok('keywords' in namespace); st.assert('keyphrases' in namespace); st.equal(namespace.keywords.length, 6); st.equal(namespace.keyphrases.length, 5); st.end(); }); t.test('should have scores', function (st) { namespace.keywords.forEach(function (keyword, n) { st.equal( Math.round(keyword.score * 1e2) / 1e2, keyScores[n] ); }); namespace.keyphrases.forEach(function (phrase, n) { st.equal( Math.round(phrase.score * 1e2) / 1e2, phraseScores[n] ); }); st.end(); }); t.test('should have stems', function (st) { namespace.keywords.forEach(function (keyword) { st.ok('stem' in keyword); }); namespace.keyphrases.forEach(function (phrase) { st.ok('stems' in phrase); }); st.end(); }); t.test('should have matches', function (st) { namespace.keywords.forEach(function (keyword) { st.ok('matches' in keyword); }); namespace.keyphrases.forEach(function (phrase) { st.ok('matches' in phrase); }); st.end(); }); t.test('keywords[n].matches[n]', function (st) { namespace.keywords.forEach(function (keyword) { keyword.matches.forEach(function (match) { st.assert('node' in match); st.assert('parent' in match); st.assert('index' in match); }); }); st.end(); }) t.test('keyphrases', function (st) { st.test('should have a weight', function (sst) { namespace.keyphrases.forEach(function (phrase) { sst.ok('weight' in phrase); }); sst.end(); }); st.test('should have a value', function (sst) { namespace.keyphrases.forEach(function (phrase) { sst.ok('value' in phrase); }); sst.end(); }); st.end(); }); t.test('keyphrases[n].matches[n]', function (st) { namespace.keyphrases.forEach(function (phrase) { phrase.matches.forEach(function (match) { st.ok('nodes' in match); st.ok('parent' in match); }); }); st.end(); }) t.end(); }); });
'host', // technical 'parameters', // technical 'function', // technical 'option', // technical 'additional', // sales 'equivalent', // equal does not have identical connotation 'combined', // no good alternative 'provide', // i don't think this is really that complicated a word 'delete', // this is what the UI says 'it is', // no good alternative 'there are' // no good alternative ] }; var markdown = remark(); var english = retext() .use(parser) .use(mapboxStandard) .use(equality) .use(simplify, simplifyConfig); function standard(value) { var result; if (typeof value === 'string') { value = stripLiquid(value); } else { value.contents = stripLiquid(value.contents); } remark() .use(remark2retext, english) .use(control, {