SPB Git

Repository Public BSD-3-Clause

main.swift 7.8 KB 147 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Infrastructure/geocoder-builder/Sources/orix-geocoder-inspect/main.swift10// Module           : orix-geocoder-inspect11// Repository       : https://git.spboucher.ai/orix-maps12// Created          : 2026-11-2513// Last Modified    : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import ORIXOSM9091// Usage: orix-geocoder-inspect <file.osm.pbf> — tag statistics that drive the geocoder builder's design.92guard CommandLine.arguments.count == 2 else { FileHandle.standardError.write(Data("usage: orix-geocoder-inspect <file.osm.pbf>\n".utf8)); exit(2) }93func bump(_ d: inout [String: Int], _ k: String) { d[k, default: 0] += 1 }94func top(_ d: [String: Int], _ n: Int = 25) -> String { d.sorted { $0.value > $1.value }.prefix(n).map { "\($0.key)=\($0.value)" }.joined(separator: " ") }95do {96    let reader = try OSMPBFReader(url: URL(fileURLWithPath: CommandLine.arguments[1]))97    var addrNodes = 0, addrNodesNoStreet = 0, addrWays = 0, addrWaysNoStreet = 0, interp = 0, entrances = 098    var adminLevels: [String: Int] = [:], places: [String: Int] = [:], hwNamed: [String: Int] = [:], hwRefOnly: [String: Int] = [:]99    var refSamples: [String: Int] = [:], namedHwNodes = 0, amenity: [String: Int] = [:], shop: [String: Int] = [:], tourism: [String: Int] = [:], leisure: [String: Int] = [:]100    var relTypes: [String: Int] = [:], namedNodes = 0, namedWays = 0, assoc = 0, parkingAccess: [String: Int] = [:], natural: [String: Int] = [:]101    var mpNamed = 0102    try reader.read { block in103        for n in block.nodes where !n.tags.isEmpty {104            if n.tags["addr:housenumber"] != nil { addrNodes += 1; if n.tags["addr:street"] == nil { addrNodesNoStreet += 1 }; if n.tags["entrance"] != nil { entrances += 1 } }105            if let p = n.tags["place"] { bump(&places, p) }106            if n.tags["name"] != nil { namedNodes += 1 }107            if let a = n.tags["amenity"] { bump(&amenity, a) }108            if let a = n.tags["shop"] { bump(&shop, a) }109            if let a = n.tags["tourism"] { bump(&tourism, a) }110            if let a = n.tags["leisure"] { bump(&leisure, a) }111            if let a = n.tags["natural"], n.tags["name"] != nil { bump(&natural, a) }112        }113        for w in block.ways {114            if w.tags["addr:housenumber"] != nil { addrWays += 1; if w.tags["addr:street"] == nil { addrWaysNoStreet += 1 } }115            if w.tags["addr:interpolation"] != nil { interp += 1 }116            if let h = w.tags["highway"] {117                if w.tags["name"] != nil { bump(&hwNamed, h); namedHwNodes += w.nodeRefs.count }118                else if let r = w.tags["ref"] { bump(&hwRefOnly, h); if h == "motorway" || h == "trunk" || h == "primary" { bump(&refSamples, "\(h):\(r)") } }119                if h == "motorway", let r = w.tags["ref"], w.tags["name"] != nil { bump(&refSamples, "named-motorway:\(r)|\(w.tags["name"]!)") }120            } else if w.tags["name"] != nil { namedWays += 1 }121            if let a = w.tags["amenity"] { bump(&amenity, "w:" + a); if a == "parking" { bump(&parkingAccess, (w.tags["access"] ?? "-") + (w.tags["name"] != nil ? "+name" : "")) } }122            if let a = w.tags["leisure"] { bump(&leisure, "w:" + a + (w.tags["name"] != nil ? "+name" : "")) }123            if let a = w.tags["natural"], w.tags["name"] != nil { bump(&natural, "w:" + a) }124        }125        for r in block.relations {126            bump(&relTypes, r.tags["type"] ?? "-")127            if r.tags["boundary"] == "administrative" { bump(&adminLevels, r.tags["admin_level"] ?? "-") }128            if r.tags["type"] == "associatedStreet" { assoc += 1 }129            if r.tags["type"] == "multipolygon", r.tags["name"] != nil { mpNamed += 1 }130        }131    }132    print("addr nodes \(addrNodes) (no street \(addrNodesNoStreet), entrances \(entrances)) addr ways \(addrWays) (no street \(addrWaysNoStreet)) interpolation ways \(interp) associatedStreet \(assoc)")133    print("admin levels: \(top(adminLevels))")134    print("places: \(top(places, 40))")135    print("named highways: \(top(hwNamed, 40)) nodes \(namedHwNodes)")136    print("ref-only highways: \(top(hwRefOnly))")137    print("ref samples: \(top(refSamples, 40))")138    print("named nodes \(namedNodes) named non-highway ways \(namedWays) named multipolygons \(mpNamed)")139    print("amenity: \(top(amenity, 60))")140    print("shop: \(top(shop, 30))")141    print("tourism: \(top(tourism, 30))")142    print("leisure: \(top(leisure, 40))")143    print("natural(named): \(top(natural, 30))")144    print("parking access: \(top(parkingAccess, 20))")145    print("relation types: \(top(relTypes))")146} catch { FileHandle.standardError.write(Data("error: \(error)\n".utf8)); exit(1) }147
Files main
Menu

Theme