Published
Edited
Mar 5, 2020
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
normalizedDoc = nlp(text.value).normalize({
whitespace: true, // remove hyphens, newlines, and force one space between words
punctuation: true, // remove commas, semicolons - but keep sentence-ending punctuation
case: true, // keep only first-word, and 'entity' titlecasing
numbers: true, // 'one' → '1'
plurals: true, // 'eyes' → 'eye'
verbs: true, // 'swtiched' → 'switch'
})
Insert cell
lines = text.value.split('\n')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md `${await printTable(headers, lines)}`
Insert cell
async function printTable(headers, lines) {
// header row
let markdown = `| ${headers.join(' | ')} |\n|`;
headers.forEach(header => { markdown += ' --- |'});
// run text lines through toxicity model classifier
const table = toxicityModel.classify(lines).then(predictions => {
for (let i=0; i<lines.length; i++) {
markdown += '\n| ' + lines[i] + ' |';
for (let k=0; k < labels.length; k++) {
// convert toxicity classifier predictions to md cells with ✔️
markdown += predictions[k].results[i].match ? ' ✔️ |': ' . |';
}
}
console.log(predictions);
return Promise.resolve(markdown);
});
return table;
}
Insert cell
Insert cell
tf = require('@tensorflow/tfjs@1.0')
Insert cell
toxicity = require('https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity')
Insert cell
nlp = require('compromise@11.14.3')
Insert cell
Insert cell
Insert cell
Insert cell
nlpStyles = html `
<style>
.scrollable-container {
max-height: 400px;
overflow: auto;
}
.short-list {
max-height: 200px;
}
.big{
font-size:1.5rem;
color:cornflowerblue;
}
.small{
color:grey;
margin-top:30px;
}
.term { color:grey; cursor:pointer;}
.nl-Person { border-bottom:2px solid #6393b9; }
.nl-Pronoun { border-bottom:2px solid #81acce; }
.nl-Plural { border-bottom:2px solid steelblue; }
.nl-Singular { border-bottom:2px solid lightsteelblue; }
.nl-Verb { border-bottom:2px solid palevioletred; }
.nl-Adverb { border-bottom:2px solid #f39c73; }
.nl-Adjective { border-bottom:2px solid #b3d3c6; }
.nl-Determiner { border-bottom:2px solid #d3c0b3; }
.nl-Preposition { border-bottom:2px solid #9794a8; }
.nl-Conjunction { border-bottom:2px solid #c8c9cf; }
.nl-Value { border-bottom:2px solid palegoldenrod; }
.nl-QuestionWord { border-bottom:2px solid lavender; }
.nl-Acronym { border-bottom:2px solid violet; }
.nl-Possessive { border-bottom:2px solid #7990d6; }
.nl-Noun { border-bottom:2px solid #7990d6; }
.nl-Expression { border-bottom:2px solid #b3d3c6; }
.nl-Negative { border-bottom:2px solid #b4adad; }
</style>
`
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more