Public
Edited
Dec 30, 2021
Importers
Insert cell
Insert cell
Insert cell
input = ["Paris", "Économie (discipline)", "Bamako", "Tokyo", "Wikipédia", "Wikipédia en français", "Le Capital au XXIe siècle", "Canada", "Brésil", "Bretagne", "France"]
Insert cell
Insert cell
data = fetch(wdk.getEntitiesFromSitelinks({titles: input, sites: "frwiki"}))
.then(d => d.json())
.then(wdk.parse.wb.entities)
Insert cell
Insert cell
get_claim = (d, claim, wiki) => {
if (d.id === undefined) {
return aq.table({article: [""], qvalue: [""]} )
}
else if (d.claims[claim] === undefined) {
return aq.table({article: [""], qvalue: [""]} )
}
else {
return aq.table({article: Array(d.claims[claim].length).fill(d.sitelinks[wiki]), qvalue: d.claims[claim] } )
}
}

Insert cell
Insert cell
get_claim(data.Q90, "P31", "frwiki").view()
Insert cell
get_claim(data.Q90, "P17", "frwiki").view()
Insert cell
Insert cell
output = Object.values(data).map(d => get_claim(d, "P31", "frwiki"))
Insert cell
Insert cell
df_output = aq.from([ { article: "", qvalue: ""}])
.union(output.map(d => aq.from(d)))
.filter(aq.escape(d => d.article != ""))
Insert cell
df_output.view()
Insert cell
Insert cell
df_labels = get_labels(df_output.dedupe("qvalue").array("qvalue"))
.then(d => d.rename({qid: 'qvalue', label: 'qlabel'}))
Insert cell
Insert cell
df_result = df_output.join_left(df_labels, "qvalue")
Insert cell
df_result.view()
Insert cell
df_result
.groupby("qlabel")
.count()
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {get_labels} from "@pac02/what-kind-of-articles-have-you-created"
Insert cell
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