Commit
15f62f3
1 Parent(s): 44c45da

create function.js

Browse files
Files changed (1) hide show
  1. feature.js +26 -0
feature.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function create_token_frequency_chart(tokenized_text) {
2
+ // Count token frequencies
3
+ const token_counts = {};
4
+ for (const token of tokenized_text) {
5
+ token_counts[token] = (token_counts[token] || 0) + 1;
6
+ }
7
+
8
+ // Create Plotly chart data
9
+ const data = [
10
+ {
11
+ x: Object.keys(token_counts),
12
+ y: Object.values(token_counts),
13
+ type: 'bar',
14
+ },
15
+ ];
16
+
17
+ // Create chart layout
18
+ const layout = {
19
+ title: 'Token Frequency',
20
+ xaxis: { title: 'Tokens' },
21
+ yaxis: { title: 'Frequency' },
22
+ };
23
+
24
+ // Generate and return chart HTML
25
+ return Plotly.newPlot('chart-div', data, layout);
26
+ }