Skip to content

Guide: include a new fountain property (operator id) in the processing pipeline

mmmatthew edited this page Aug 25, 2018 · 3 revisions

This guide assumes that the fountain property in question is already available in Wikidata. In this guide, we will be using the fountain operator ID property as an example.

How the data is stored in Wikidata and Open Street Map

The operator ID information we are interested in is stored as a catalog code statement (P528) in Wikidata. It is distinguished from other catalog codes by a catalog qualifier (P9720) that links the catalog code to a catalog with the IDs used by the fountain operator.

In Open Street Map, the information is stored in the ref key (at least in the case of Zurich's fountains).

Example: operator ID

This statement can be seen for [example] (https://www.wikidata.org/wiki/Q27229889) under the statement catalog code for the catalog fountainsWVZ (Q53629101), which is a catalog of water fountains operated by Wasserversorgung Zürich (WVZ, Q27229237) and published online at https://data.stadt-zuerich.ch/dataset/brunnen.

How data is read from Wikidata and Open Street Map

Fountain properties are read from Wikidata using the Wikidata SDK tool suite, which allows data to be queried and simplified. For Open Street Map data, the query-overpass tool is used.

How to include a new property in the processing pipeline

Not all fountain properties are processed by datablue by default. To add a new fountain property to the pipeline, first edit default.fountain.object.js and include a new property in the default_fountain_template object by following the example of pre-existing properties:

  • the property name (e.g. name, name_en, description_short) is the name that will be used within datablue and proximap (frontend) to reference the property. When creating a compound name, put the general attribute before the specifying attribute, e.g. id_operator.
  • essential indicates whether this property should be available in the application within the map and list interface for overview display and filtering purposes. In our example: true.
  • type can be string, number, url, coords, or boolean_string, and indicates how the property should be displayed in the application. In our example: string
id_operator:{
   essential: true,
   type: 'string'
}

We then define how the property should be read and translated from the two data sources.

Translating operator id from Wikidata

In fountains.sources.wikidata.js, add an object element to the props array of the claims attribute in the wikidata_fountain_config object. For the operator id, the object must have the following attributes:

  • src_p_name: the property name in Wikidata ("P528")
  • dst_p_name: the property name that should be used within datablue and proximap ("id_operator")
  • rank: the priority that should be given to this datasource (wikidata) for this property if there is conflicting information coming from Open Street Map (1 in this case - lower is better)
  • value_translation is an optional attribute providing a function that should be used to process incoming property values. In the present example, the function is used to only retain catalog codes for which the associated catalog corresponds to that maintained by the city's fountain operator.
{
  "src_p_name": "P528",
  "dst_p_name": "id_operator",
  "rank": 1,
  "value_translation": catCodes=>{
    let catCode = null;
    // loop through all catalog codes to find the right one
    catCodes.forEach(code=>{
      // return value only if qualifier matches the operator id
      if(code.qualifiers['P972'][0] == locations.zurich.operator_qid){
        catCode = code.value
      }
    });
    return catCode;
}

Translating operator id from Open Street Map

In fountains.sources.osm.js, add an element to the keys list of the osm_fountain_config object. It must have the following attributes:

  • key: the name of the property in Open Street Map ("ref")
  • property: the name of the property as used in datablue and proximap, again "id_operator"
  • rank: the priority that should be given to this datasource (Open Street Map) for this property if there is conflicting information coming from Wikidata (2 in this case - we assume Wikidata is more reliable)
{
   "key": "ref",
   "property": "id_operator",
   "rank": 2
}

Conclusion

With these changes, the operator ID will now be available to proximap via the datablue API endpoints.