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

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