Stored Transformation
Stored transformation detail
Inspect version history, edit inputs, and save a new version without overwriting prior records.
def v($k): .[$k].value // null;
def trim:
gsub("^\\s+|\\s+$"; "");
def clean_text:
tostring
| gsub("\\s+"; " ")
| trim;
def province_from_postal_code($cp):
if $cp | startswith("28") then "Madrid" else null end;
def ac_from_postal_code($cp):
if $cp | startswith("28") then "Comunidad de Madrid" else null end;
def parsed_address:
(v("address")) as $a
| if ($a == null) or (($a | type) != "string") or (($a | clean_text) == "") then
null
else
($a | clean_text | gsub("\\.$"; "")) as $raw
| if ($raw | test("\\b\\d{5}\\b")) then
($raw
| capture("^(?<streetAddress>.*?)[,.;]?\\s*(?<postalCode>\\d{5})\\s+(?<locality>[^,.;]+)")) as $m
| {
streetAddress: ($m.streetAddress | clean_text | gsub("[,.;]$"; "")),
postalCode: $m.postalCode,
locality: ($m.locality | clean_text),
province: province_from_postal_code($m.postalCode),
autonomousCommunity: ac_from_postal_code($m.postalCode)
}
| with_entries(select(.value != null and .value != ""))
else
{
streetAddress: $raw
}
end
end;
(parsed_address) as $loc
| {
id: .id,
type: "Hotel",
name: v("name")
}
+ (if v("description") != null then
{hasDescription: {shortDescription: v("description")}}
else
{}
end)
+ (if $loc != null then
{hasLocation: $loc}
else
{}
end)
{
"hasDescription": {
"shortDescription": "Aparthotel TH Las Rozas"
},
"hasLocation": {
"autonomousCommunity": "Comunidad de Madrid",
"locality": "Las Rozas",
"postalCode": "28230",
"province": "Madrid",
"streetAddress": "Camino Viejo de Madrid, 38"
},
"id": "building:hoteles.ayto-xlsx.141",
"name": "Aparthotel TH Las Rozas",
"type": "Hotel"
}