Public
Edited
Jul 6, 2024
1 fork
Importers
1 star
Also listed in…
Wikipedia tools
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
claim_labels = get_labels(
[
"P17",
"P21",
"P27",
"P31",
"P106",
"P101",
"P103",
"P1412",
"P6886",
"P140",
"P91",
"P172",
"P69",
"P166",
"P1387",
"P1142",
"P136",
"P1050",
"P1884"
],
lang
).then((d) => d.objects())
Insert cell
labels_map = new Map(claim_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid]))
Insert cell
Insert cell
Insert cell
data = {
let result = [];
let offset = "";
while (offset !== undefined) {
let data = await get_pagescreated({
username: username,
wikipedia: wikipedia,
offset: offset
});
offset = data.continue;
result = result.concat(aq.from(Object.values(data.pages[0])));
yield result;
}
return result;
}
Insert cell
df = data[0].union(data)
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
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
df_alldata = aq.from([{article: "", qvalue: ""}])
.union(alldata.map(d => aq.from(d)))
.filter(aq.escape(d => d.article != ""))
Insert cell
Insert cell
qvalues = df_alldata.dedupe("qvalue").array("qvalue")
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
Insert cell
df_result = df_alldata.join_left(df_labels, "qvalue")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {BubbleChart} from "@d3/bubble-chart"
Insert cell
import { get_pagescreated } from "@pac02/look-at-your-list-of-created-articles-with-the-xtools-page-ap"
Insert cell
import { wikipedias } from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
username: "PAC2",
wikipedia: "en.wikipedia.org",
lang: "en",
claim: "P31"
} ;
if (params.has("username")) {
defaults.username = params.get("username")
}
if (params.has("wikipedia")) {
defaults.wikipedia = params.get("wikipedia")
}
if (params.has("claim")) {
defaults.claim = params.get("claim")
}
if (params.has("lang")) {
defaults.lang = params.get("lang")
}
return defaults
}
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