Public
Edited
Nov 13, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// createCSV(companies)
Insert cell
doc.entities().out(its.detail)
Insert cell
winkNLP = (await import("https://cdn.skypack.dev/wink-nlp")).default
Insert cell
model = (await import("https://cdn.skypack.dev/wink-eng-lite-web-model"))
.default
Insert cell
nlp = winkNLP(model)
Insert cell
its = nlp.its;
Insert cell
as = nlp.as
Insert cell
doc = {
// const text = 'Hello World🌎! How are you?';
const doc = nlp.readDoc(allItems);
return doc;
}
Insert cell
allItems = concatObjectItemsInArray(companies)
Insert cell
function concatObjectItemsInArray(arrayOfObjects) {
// Initialize the empty string
let concatenatedString = "";

// Iterate over the array of objects
for (const object of arrayOfObjects) {
// Get the values of all the object properties
const objectValues = Object.values(object);

// Concatenate the object values to the string, separated by new lines
concatenatedString += objectValues.join("\n");

// Add a new line character at the end of the string
concatenatedString += "\n\n";
}

// Return the concatenated string
return concatenatedString;
}
Insert cell
wordsFromText = {
const tokensFTByPoS = Object.create(null);
tokensFTByPoS.NOUN = Object.create(null);
tokensFTByPoS.ADJ = Object.create(null);
tokensFTByPoS.VERB = Object.create(null);
tokensFTByPoS.ADV = Object.create(null);
tokensFTByPoS.PROPN = Object.create(null);
doc.tokens().each((t) => {
const pos = t.out(its.pos);
const token = t.out(its.lemma);
if (!tokensFTByPoS[pos]) return;

tokensFTByPoS[pos] = tokensFTByPoS[pos] || Object.create(null);
tokensFTByPoS[pos][token] =
tokensFTByPoS[pos][token] || Object.create(null);
tokensFTByPoS[pos][token].value =
1 + (tokensFTByPoS[pos][token].value || 0);
tokensFTByPoS[pos][token].sentences =
tokensFTByPoS[pos][token].sentences || new Set();
tokensFTByPoS[pos][token].sentences.add(t.parentSentence().index());
});

let freqTable = new Array();
for (const pos in tokensFTByPoS) {
freqTable = Object.keys(tokensFTByPoS[pos])
.map((key) => ({
text: key,
value: tokensFTByPoS[pos][key].value,
pos: pos,
sentences: Array.from(tokensFTByPoS[pos][key].sentences)
}))
.filter((e) => e.value > 1 && e.text.length > 2)
.concat(freqTable);
} // for ( const pos in tokensFTByPoS )

return freqTable.sort((a, b) => b.value - a.value);
}
Insert cell
height = width
Insert cell
computeFontSize = d3
.scaleSqrt()
.domain([1, d3.max(wordsFromText.map((d) => d.value))])
.range([6, 82])
Insert cell
Insert cell
<style>
div.tooltip {
/* position: absolute;
text-align: left;
width: 300px;
height: auto;
padding: 2px;
font: 13px sans-serif;
background: white;
border-radius: 8px;
pointer-events: none;
padding: 10px;
border: 1px solid #333;
pointer-events: none; */

position: absolute;
text-align: left;
width: 300px;
height: auto;
padding: 2px;
font: 13px sans-serif;
background: white;
border-radius: 12px;
border-top-left-radius: 0;
pointer-events: none;
padding: 16px;
box-shadow: 0px 5px 15px 0px rgba(0,0,0,0.3);
pointer-events: none;

}

.word-hovered {
font-weight: bold;
}

mark {
padding: 1px 3px;
margin: 2px;
line-height: 1;
display: inline-block;
border-radius: 2px;
background: #fc3;
}
</style>
Insert cell
colorMap = {
const colorMap = Object.create(null);

colorMap.NOUN = "#67001f";
colorMap.PROPN = "#67001f";
colorMap.ADJ = "#878787";
colorMap.VERB = "#1a1a1a";
colorMap.ADV = "#d6604d";

return colorMap;
}
Insert cell
d3cloud = require("d3-cloud")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more