Unlisted
Edited
Nov 16, 2023
2 forks
Insert cell
Insert cell
Insert cell
username = "PAC2"
Insert cell
Insert cell
claim = "P27"
Insert cell
lang = "en"
Insert cell
Insert cell
df = await aq
.loadCSV(
"https://xtools.wmcloud.org/pages/" +
wikipedia +
"/" +
username +
"?format=csv",
{ parse: { date: Date } }
)
.then((d) => d.select(normalize).select("page_title", "date"))
Insert cell
Insert cell
page_title_split = df.array("page_title").reduce((all,one,i) => {
const ch = Math.floor(i/50);
all[ch] = [].concat((all[ch]||[]),one);
return all
}, [])
Insert cell
Insert cell
alldata = await Promise.all(page_title_split.map(d => fetch(wdk.getEntitiesFromSitelinks({titles: d, sites: get_shortwikipedianame(wikipedia)}))
.then(d => d.json())
.then(wdk.parse.wb.entities)
.then(d => Object.values(d).map(q => get_claim(q, claim, get_shortwikipedianame(wikipedia))))
.then(d => aq.from([ { article: "", qvalue: ""}])
.union(d.map(q => aq.from(q)))
.filter(aq.escape(p => p.article != "")))
)
)
Insert cell
Insert cell
df_alldata = aq.from([{article: "", qvalue: ""}])
.union(alldata.map(d => aq.from(d)))
.filter(aq.escape(d => d.article != ""))
Insert cell
df_alldata.view()
Insert cell
Insert cell
qvalues = df_alldata.dedupe("qvalue").array("qvalue")
Insert cell
Insert cell
qvalues_split = qvalues.reduce((all,one,i) => { const ch = Math.floor(i/50);
all[ch] = [].concat((all[ch]||[]),one);
return all
}, [])
Insert cell
qvalues_label = await Promise.all(qvalues_split.map(d => get_labels(d, lang)))
Insert cell
df_labels = aq.from([{qid: "", label: ""}])
.union(qvalues_label.map(d => aq.from(d)))
.filter(aq.escape(d => d.qid != ""))
.rename({qid: 'qvalue', label: 'qlabel'})
Insert cell
df_labels.view()
Insert cell
Insert cell
df_result = df_alldata.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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
get_P31 = (d) => {
if (d.id === undefined) {
return aq.table({qid: [""], qvalue: [""]} )
}
else if (d.claims["P31"] === undefined) {
return aq.table({qid: [""], qvalue: [""]} )
}
else {
return aq.table({qid: Array(d.claims["P31"].length).fill(d.id), qvalue: d.claims["P31"] } )
}
}

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