git clone https://garage44.eu/jeroen/cartopolis.gitcartopolis-agent · 2026-11-29T16:41:54Z
feat(atlas): carry a statue's Wikidata title in the registers cell The art query now asks for each work's label (Dutch, else English), and the cell file carries it as `prop_names`, index for index with `props`, `""` where a prop has none and absent when nothing in the cell is named. A key of its own rather than a fifth element of `Prop`, because serde_json refuses a row longer than the tuple and every installed client would drop the whole cell — the reason `tree_forms` is one too. Checked against query.wikidata.org over central Groningen: 52 works, all 52 with a Dutch or English label.
crates/atlas/src/pipeline/registers.rs | 52 ++++++++++++++++++++++++++++++----
crates/geo/src/formats/registers.rs | 43 ++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 6 deletions(-)
diff --git a/crates/atlas/src/pipeline/registers.rs b/crates/atlas/src/pipeline/registers.rs
index 0ee870be..de043e65 100644
--- a/crates/atlas/src/pipeline/registers.rs
+++ b/crates/atlas/src/pipeline/registers.rs
@@ -515,8 +515,9 @@ const NOT_FREE_STANDING: &[&str] = &[
];
/// Every free-standing work Wikidata places inside `[west, south, east, north]`,
-/// with all its classes and genres, leaving out the demolished and removed
-/// (`P576`). One request for the whole area.
+/// with all its classes and genres and its title (Dutch, else English),
+/// leaving out the demolished and removed (`P576`). One request for the whole
+/// area.
#[must_use]
pub fn art_query(bbox: [f64; 4]) -> String {
let [west, south, east, north] = bbox;
@@ -525,12 +526,15 @@ pub fn art_query(bbox: [f64; 4]) -> String {
.map(|q| format!("wd:{q}"))
.collect();
format!(
- "SELECT ?item ?coord (GROUP_CONCAT(DISTINCT STRAFTER(STR(?type), \"/entity/\"); separator=\" \") AS ?types) WHERE {{\
+ "SELECT ?item ?coord (GROUP_CONCAT(DISTINCT STRAFTER(STR(?type), \"/entity/\"); separator=\" \") AS ?types) \
+ (SAMPLE(COALESCE(?nl, ?en)) AS ?label) WHERE {{\
SERVICE wikibase:box {{ ?item wdt:P625 ?coord . \
bd:serviceParam wikibase:cornerSouthWest \"Point({west:.5} {south:.5})\"^^geo:wktLiteral . \
bd:serviceParam wikibase:cornerNorthEast \"Point({east:.5} {north:.5})\"^^geo:wktLiteral . }} \
VALUES ?art {{ {} }} ?item wdt:P31 ?art . \
{{ ?item wdt:P31 ?type . }} UNION {{ ?item wdt:P136 ?type . }} \
+ OPTIONAL {{ ?item rdfs:label ?nl . FILTER(LANG(?nl) = \"nl\") }} \
+ OPTIONAL {{ ?item rdfs:label ?en . FILTER(LANG(?en) = \"en\") }} \
FILTER NOT EXISTS {{ ?item wdt:P576 ?gone . }} }} GROUP BY ?item ?coord",
classes.join(" ")
)
@@ -543,6 +547,9 @@ pub struct Artwork {
pub qid: String,
pub lat: f64,
pub lng: f64,
+ /// Its title, what the proximity prompt says; `None` where Wikidata has
+ /// it in neither Dutch nor English.
+ pub name: Option<String>,
}
/// The works in a SPARQL answer, each item once, less those whose class or genre
@@ -588,6 +595,11 @@ pub fn read_art(doc: &Value) -> Result<(Vec<Artwork>, usize), String> {
qid: qid.to_string(),
lat: round(lat, 7),
lng: round(lng, 7),
+ name: row["label"]["value"]
+ .as_str()
+ .map(str::trim)
+ .filter(|n| !n.is_empty())
+ .map(str::to_string),
});
}
}
@@ -802,7 +814,7 @@ pub fn run(ctx: &Ctx) -> Outcome<DatasetResult> {
crate::osm::Out::Center,
)?;
let osm = read_osm_art(&doc).map_err(|e| PipelineError::Failed(format!("osm: {e}")))?;
- let (mut n_art, mut in_osm) = (0usize, 0usize);
+ let (mut n_art, mut n_named, mut in_osm) = (0usize, 0usize, 0usize);
for work in &art {
let Some(d) = docs.get_mut(&lat_lng_to_cell(work.lat, work.lng)) else {
continue;
@@ -811,6 +823,11 @@ pub fn run(ctx: &Ctx) -> Outcome<DatasetResult> {
in_osm += 1;
continue;
}
+ // The names pair up with the props: the city's own props, pushed above,
+ // have none, and a cell where nothing is named drops the list below.
+ d.prop_names.resize(d.props.len(), String::new());
+ d.prop_names.push(work.name.clone().unwrap_or_default());
+ n_named += usize::from(work.name.is_some());
d.props.push(Prop(
work.lat,
work.lng,
@@ -820,7 +837,7 @@ pub fn run(ctx: &Ctx) -> Outcome<DatasetResult> {
n_art += 1;
}
ctx.log(format!(
- "wikidata: {n_art} statues and memorials added, {in_osm} already in OSM, \
+ "wikidata: {n_art} statues and memorials added ({n_named} by name), {in_osm} already in OSM, \
{refused} on a wall or in the paving"
));
counts.push(Count::new("artworks", n_art));
@@ -833,6 +850,9 @@ pub fn run(ctx: &Ctx) -> Outcome<DatasetResult> {
if doc.tree_forms.iter().all(String::is_empty) {
doc.tree_forms.clear();
}
+ if doc.prop_names.iter().all(String::is_empty) {
+ doc.prop_names.clear();
+ }
}
for (cell, doc) in &docs {
ctx.check()?;
@@ -988,12 +1008,31 @@ mod tests {
vec![Artwork {
qid: "Q1".into(),
lat: 53.218_441_5,
- lng: 6.567_325_7
+ lng: 6.567_325_7,
+ name: None,
}]
);
assert_eq!(refused, 1, "the war memorial that is a plaque");
}
+ /// A work's title comes with it, and a blank one is no title.
+ #[test]
+ fn a_statue_keeps_its_title() {
+ let doc = json!({"results":{"bindings":[
+ {"item":{"value":"http://www.wikidata.org/entity/Q1"},
+ "coord":{"value":"Point(6.56 53.21)"},
+ "types":{"value":"Q179700"},
+ "label":{"value":"Het Peerd van Ome Loeks"}},
+ {"item":{"value":"http://www.wikidata.org/entity/Q2"},
+ "coord":{"value":"Point(6.57 53.22)"},
+ "types":{"value":"Q241045"},
+ "label":{"value":" "}}]}});
+ let (art, _) = read_art(&doc).unwrap();
+ assert_eq!(art[0].name.as_deref(), Some("Het Peerd van Ome Loeks"));
+ assert_eq!(art[1].name, None);
+ assert!(art_query([6.45, 53.1, 6.77, 53.32]).contains("AS ?label"));
+ }
+
/// A work OSM names, or stands beside, is OSM's to draw; one it lacks is ours.
#[test]
fn a_statue_osm_already_has_is_left_to_it() {
@@ -1006,6 +1045,7 @@ mod tests {
qid: qid.into(),
lat,
lng,
+ name: None,
};
assert!(osm_has(&work("Q7", 53.3, 6.6), &osm), "named, however far");
assert!(osm_has(&work("Q8", 53.2101, 6.5101), &osm), "13 m away");
diff --git a/crates/geo/src/formats/registers.rs b/crates/geo/src/formats/registers.rs
index 18d41b06..75be2f00 100644
--- a/crates/geo/src/formats/registers.rs
+++ b/crates/geo/src/formats/registers.rs
@@ -53,6 +53,15 @@ pub struct Cell {
/// them, so a bay holds at most one car.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub bays: Vec<Vec<LatLng>>,
+ /// Each prop's name, index for index with `props`, `""` where it has none;
+ /// absent when no prop in the cell has one. Use [`Cell::prop_name`] rather
+ /// than indexing.
+ ///
+ /// A statue's title from Wikidata, which is the only source that names
+ /// any — so a key of its own for the reason `tree_forms` is one: a fifth
+ /// element of [`Prop`] would make every installed client drop the cell.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub prop_names: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub props: Vec<Prop>,
/// What this cell's registers are the authority on: `"trees"`, or a
@@ -86,6 +95,16 @@ impl Cell {
}
crate::tree_form::TreeForm::from_slug(&self.tree_forms[i]).unwrap_or_default()
}
+
+ /// Prop `i`'s name, or `None` when it has none or the list does not pair
+ /// up with the props (a name on its neighbour is worse than none).
+ #[must_use]
+ pub fn prop_name(&self, i: usize) -> Option<&str> {
+ if self.prop_names.len() != self.props.len() {
+ return None;
+ }
+ Some(self.prop_names[i].as_str()).filter(|n| !n.is_empty())
+ }
}
/// The `supplies` entry for trees.
@@ -123,6 +142,7 @@ mod tests {
Prop(53.2195, 6.5666, "recycling".into(), Some(0x3E_5D_8C)),
],
supplies: vec!["trees".into(), "lamp".into()],
+ prop_names: Vec::new(),
tree_forms: Vec::new(),
trees: vec![
Tree(53.2196, 6.5667, Some(16.5)),
@@ -187,6 +207,29 @@ mod tests {
);
}
+ /// A statue's title rides beside the props, and pairs up or not at all.
+ #[test]
+ fn prop_names_ride_beside_the_props() {
+ let text = concat!(
+ r#"{"prop_names":["","Het Peerd van Ome Loeks"],"#,
+ r#""props":[[53.2,6.5,"lamp"],[53.21,6.56,"artwork"]],"supplies":[]}"#
+ );
+ let named = parse(text).unwrap();
+ assert_eq!(
+ String::from_utf8(super::super::to_vec(&named).unwrap()).unwrap(),
+ text
+ );
+ assert_eq!(named.prop_name(0), None, "a lamp has no name");
+ assert_eq!(named.prop_name(1), Some("Het Peerd van Ome Loeks"));
+
+ assert_eq!(cell().prop_name(1), None, "a cell from before names");
+ let short = Cell {
+ prop_names: vec!["Het Peerd van Ome Loeks".into()],
+ ..cell()
+ };
+ assert_eq!(short.prop_name(0), None, "a list that does not pair up");
+ }
+
/// What an installed client does with a new cell: a reader that has never
/// heard of `tree_forms` still gets every tree, prop and bay.
#[test]