Public
Edited
Dec 20, 2022
2 stars
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
Insert cell
df1 = get_namedentities(articles[0], articles[1])
.then(d => aq.from(d))
Insert cell
df2 = get_namedentities(articles[2], articles[3])
.then(d => aq.from(d))
Insert cell
similarity = 100 * df1.semijoin(df2, 'item').numRows() / df1.join_full(df2, 'item').numRows()
Insert cell
df_summary = aq.from([
{ label: "Intersection", value: df1.semijoin(df2, 'item').numRows()},
{ label: "Article 1 only", value: df1.antijoin(df2, 'item').numRows()},
{label: "Article 2 only", value: df2.antijoin(df1, "item").numRows()}
])
Insert cell
df_summary.view()
Insert cell
Insert cell
get_namedentities = (article, project = "en.wikipedia.org" ) => {
const query = `SELECT ?item ?itemLabel ?gender ?genderLabel
WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "` + project + `";
wikibase:api "Generator";
mwapi:generator "links";
mwapi:titles "` + article + `";.
?item wikibase:apiOutputItem mwapi:item.
}
FILTER BOUND (?item)
?item wdt:P31 wd:Q5 .
?item wdt:P21 ?gender .
?item rdfs:label ?itemLabel filter (lang(?itemLabel) = "en") .
?gender rdfs:label ?genderLabel filter (lang(?genderLabel) = "en") .
}
`
return fetch(`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`, {headers: {accept: "application/sparql-results+json"}})
.then(response => response.json())
.then( d => d.results.bindings.map(res => ({
project: project,
article: article,
item: res.item.value,
itemLabel: res.itemLabel.value,
gender: res.gender.value,
genderLabel: res.genderLabel.value,
}))
)
}
Insert cell
get_namedentities("Économie (discipline)", "fr.wikipedia.org")
Insert cell
get_namedentities("Économie (discipline)", "fr.wikipedia.org")
.then(d => aq.from(d))
.then(d => d.view())
Insert cell
Insert cell
Insert cell
import {aq, op} from "@uwdata/arquero"
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