Platform
Resources
Pricing
Sign in
Get started
Gabriel Credico
Interaction designer and developer.
Workspace
Fork
Published
By
Gabriel Credico
Edited
Oct 23, 2018
Insert cell
Insert cell
Insert cell
// Load the list of qualified keywords per article
// subarticle csv
// keywordData = d3.csv("https://gist.githubusercontent.com/rielc/2194210a928725b3cbedfac08ffbf717/raw/b7630275d6a970afafe7216c2dfa32647dceec5e/2018-10-23_qualified_keywords_by_subarticle.csv")
// pdf csv
keywordData
=
d3
.
csv
(
"https://gist.githubusercontent.com/rielc/2194210a928725b3cbedfac08ffbf717/raw/0ba3a84934749738a0f8d3aeb0c5a62987c8e386/2018-10-23_qualified_keywords_by_pdf.csv"
)
Insert cell
Insert cell
// Instead of the article, lets only have an array of the keywords
keywordCombinations
=
keywordData
//.filter(article => !!article.qualified_keywords)
.
map
(
article
=>
article
.
qualified_keywords
.
split
(
' '
)
.
map
(
kw
=>
kw
.
split
(
'='
)
.
reverse
(
)
.
join
(
' ['
)
+
']'
)
)
Insert cell
// Reduce the array of keywords to an array of all (n*n)-n keyword combinations
reduceToLinks
=
(
acc
,
el
,
i
,
arr
)
=>
{
const
allCurrentLinks
=
arr
.
filter
(
f
=>
f
!==
el
)
.
map
(
kw
=>
[
el
,
kw
]
.
sort
(
)
.
join
(
' + '
)
)
;
allCurrentLinks
.
forEach
(
(
currentLink
)
=>
{
if
(
!
acc
.
includes
(
currentLink
)
)
acc
.
push
(
currentLink
)
;
}
)
;
return
acc
;
}
Insert cell
// Apply the reducer and collect ALL combinations of all articles
allCombinations
=
keywordCombinations
.
map
(
m
=>
m
.
reduce
(
reduceToLinks
,
[
]
)
)
.
reduce
(
(
acc
,
el
)
=>
[
...
acc
,
...
el
]
)
Insert cell
// Count how often each combination occurs
stat
=
allCombinations
.
reduce
(
(
acc
,
el
)
=>
{
if
(
!
acc
[
el
]
)
{
acc
[
el
]
=
1
;
return
acc
;
}
acc
[
el
]
+=
1
;
return
acc
;
}
,
{
}
)
Insert cell
//Print the result to the console
// console.log(Object.entries(stat).map(([key, count]) => `${key},${count}`).join('\n'))
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
keywordData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
keywordCombinations
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
reduceToLinks
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
allCombinations
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stat
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML