Velopark: include name in maproulette items

This commit is contained in:
Pieter Vander Vennet 2024-05-08 14:20:59 +02:00
parent c2a7f2adcd
commit 782926c09d
2 changed files with 33 additions and 34 deletions

View file

@ -27,23 +27,23 @@ export default class LinkedDataLoader {
opening_hours: { "@id": "http://schema.org/openingHoursSpecification" }, opening_hours: { "@id": "http://schema.org/openingHoursSpecification" },
openingHours: { "@id": "http://schema.org/openingHours", "@container": "@set" }, openingHours: { "@id": "http://schema.org/openingHours", "@container": "@set" },
geo: { "@id": "http://schema.org/geo" }, geo: { "@id": "http://schema.org/geo" },
alt_name: { "@id": "http://schema.org/alternateName" }, alt_name: { "@id": "http://schema.org/alternateName" }
} }
private static COMPACTING_CONTEXT_OH = { private static COMPACTING_CONTEXT_OH = {
dayOfWeek: { "@id": "http://schema.org/dayOfWeek", "@container": "@set" }, dayOfWeek: { "@id": "http://schema.org/dayOfWeek", "@container": "@set" },
closes: { closes: {
"@id": "http://schema.org/closes", "@id": "http://schema.org/closes",
"@type": "http://www.w3.org/2001/XMLSchema#time", "@type": "http://www.w3.org/2001/XMLSchema#time"
}, },
opens: { opens: {
"@id": "http://schema.org/opens", "@id": "http://schema.org/opens",
"@type": "http://www.w3.org/2001/XMLSchema#time", "@type": "http://www.w3.org/2001/XMLSchema#time"
}, }
} }
private static formatters: Record<"phone" | "email" | "website", Validator> = { private static formatters: Record<"phone" | "email" | "website", Validator> = {
phone: new PhoneValidator(), phone: new PhoneValidator(),
email: new EmailValidator(), email: new EmailValidator(),
website: new UrlValidator(undefined, undefined, true), website: new UrlValidator(undefined, undefined, true)
} }
private static ignoreKeys = [ private static ignoreKeys = [
"http://schema.org/logo", "http://schema.org/logo",
@ -56,7 +56,7 @@ export default class LinkedDataLoader {
"http://schema.org/description", "http://schema.org/description",
"http://schema.org/hasMap", "http://schema.org/hasMap",
"http://schema.org/priceRange", "http://schema.org/priceRange",
"http://schema.org/contactPoint", "http://schema.org/contactPoint"
] ]
private static shapeToPolygon(str: string): Polygon { private static shapeToPolygon(str: string): Polygon {
@ -69,8 +69,8 @@ export default class LinkedDataLoader {
.trim() .trim()
.split(" ") .split(" ")
.map((n) => Number(n)) .map((n) => Number(n))
), )
], ]
} }
} }
@ -92,18 +92,18 @@ export default class LinkedDataLoader {
const context = { const context = {
lat: { lat: {
"@id": "http://schema.org/latitude", "@id": "http://schema.org/latitude",
"@type": "http://www.w3.org/2001/XMLSchema#double", "@type": "http://www.w3.org/2001/XMLSchema#double"
}, },
lon: { lon: {
"@id": "http://schema.org/longitude", "@id": "http://schema.org/longitude",
"@type": "http://www.w3.org/2001/XMLSchema#double", "@type": "http://www.w3.org/2001/XMLSchema#double"
}, }
} }
const flattened = await jsonld.compact(geo, context) const flattened = await jsonld.compact(geo, context)
return { return {
type: "Point", type: "Point",
coordinates: [Number(flattened.lon), Number(flattened.lat)], coordinates: [Number(flattened.lon), Number(flattened.lat)]
} }
} }
@ -194,7 +194,7 @@ export default class LinkedDataLoader {
) )
delete compacted["openingHours"] delete compacted["openingHours"]
} }
if(compacted["opening_hours"] === undefined){ if (compacted["opening_hours"] === undefined) {
delete compacted["opening_hours"] delete compacted["opening_hours"]
} }
if (compacted["geo"]) { if (compacted["geo"]) {
@ -288,7 +288,7 @@ export default class LinkedDataLoader {
if (properties["latitude"] && properties["longitude"]) { if (properties["latitude"] && properties["longitude"]) {
geometry = { geometry = {
type: "Point", type: "Point",
coordinates: [Number(properties["longitude"]), Number(properties["latitude"])], coordinates: [Number(properties["longitude"]), Number(properties["latitude"])]
} }
delete properties["latitude"] delete properties["latitude"]
delete properties["longitude"] delete properties["longitude"]
@ -300,7 +300,7 @@ export default class LinkedDataLoader {
const geo: GeoJSON = { const geo: GeoJSON = {
type: "Feature", type: "Feature",
properties, properties,
geometry, geometry
} }
delete linkedData.geo delete linkedData.geo
delete properties.shape delete properties.shape
@ -331,7 +331,7 @@ export default class LinkedDataLoader {
return return
} }
output[key] = output[key].map((v) => applyF(v)) output[key] = output[key].map((v) => applyF(v))
if(!output[key].some(v => v !== undefined)){ if (!output[key].some(v => v !== undefined)) {
delete output[key] delete output[key]
} }
} }
@ -416,7 +416,7 @@ export default class LinkedDataLoader {
"brede publiek", "brede publiek",
"iedereen", "iedereen",
"bezoekers", "bezoekers",
"iedereen - vooral bezoekers gemeentehuis of bibliotheek.", "iedereen - vooral bezoekers gemeentehuis of bibliotheek."
].indexOf(audience.toLowerCase()) >= 0 ].indexOf(audience.toLowerCase()) >= 0
) { ) {
return "yes" return "yes"
@ -483,7 +483,6 @@ export default class LinkedDataLoader {
} }
rename("capacityElectric", "capacity:electric_bicycle") rename("capacityElectric", "capacity:electric_bicycle")
delete output["name"]
delete output["numberOfLevels"] delete output["numberOfLevels"]
return output return output
@ -500,13 +499,14 @@ export default class LinkedDataLoader {
mv: "http://schema.mobivoc.org/", mv: "http://schema.mobivoc.org/",
gr: "http://purl.org/goodrelations/v1#", gr: "http://purl.org/goodrelations/v1#",
vp: "https://data.velopark.be/openvelopark/vocabulary#", vp: "https://data.velopark.be/openvelopark/vocabulary#",
vpt: "https://data.velopark.be/openvelopark/terms#", vpt: "https://data.velopark.be/openvelopark/terms#"
}, },
[url], [url],
undefined, undefined,
" ?parking a <http://schema.mobivoc.org/BicycleParkingStation>", " ?parking a <http://schema.mobivoc.org/BicycleParkingStation>",
"?parking " + property + " " + (variable ?? "") "?parking " + property + " " + (variable ?? "")
) )
console.log("Fetching a velopark property gave", property, results)
return results return results
} }
@ -521,7 +521,7 @@ export default class LinkedDataLoader {
mv: "http://schema.mobivoc.org/", mv: "http://schema.mobivoc.org/",
gr: "http://purl.org/goodrelations/v1#", gr: "http://purl.org/goodrelations/v1#",
vp: "https://data.velopark.be/openvelopark/vocabulary#", vp: "https://data.velopark.be/openvelopark/vocabulary#",
vpt: "https://data.velopark.be/openvelopark/terms#", vpt: "https://data.velopark.be/openvelopark/terms#"
}, },
[url], [url],
"g", "g",
@ -646,7 +646,7 @@ export default class LinkedDataLoader {
return this.mergeResults(...allPartialResults) return this.mergeResults(...allPartialResults)
} }
private static veloparkCache : Record<string, Feature[]> = {} private static veloparkCache: Record<string, Feature[]> = {}
/** /**
* Fetches all data relevant to velopark. * Fetches all data relevant to velopark.
@ -654,29 +654,29 @@ export default class LinkedDataLoader {
* @param url * @param url
*/ */
public static async fetchVeloparkEntry(url: string, includeExtras: boolean = false): Promise<Feature[]> { public static async fetchVeloparkEntry(url: string, includeExtras: boolean = false): Promise<Feature[]> {
const cacheKey = includeExtras+url const cacheKey = includeExtras + url
if(this.veloparkCache[cacheKey]){ if (this.veloparkCache[cacheKey]) {
return this.veloparkCache[cacheKey] return this.veloparkCache[cacheKey]
} }
const withProxyUrl = Constants.linkedDataProxy.replace("{url}", encodeURIComponent(url)) const withProxyUrl = Constants.linkedDataProxy.replace("{url}", encodeURIComponent(url))
const optionalPaths: Record<string, string | Record<string, string>> = { const optionalPaths: Record<string, string | Record<string, string>> = {
"schema:interactionService": { "schema:interactionService": {
"schema:url": "website", "schema:url": "website"
}, },
"schema:name": "name",
"mv:operatedBy": { "mv:operatedBy": {
"gr:legalName": "operator", "gr:legalName": "operator"
}, },
"schema:contactPoint": { "schema:contactPoint": {
"schema:email": "email", "schema:email": "email",
"schema:telephone": "phone", "schema:telephone": "phone"
}, },
"schema:dateModified": "_last_edit_timestamp", "schema:dateModified": "_last_edit_timestamp"
} }
if(includeExtras){ if (includeExtras) {
optionalPaths["schema:address"] = { optionalPaths["schema:address"] = {
"schema:streetAddress":"addr" "schema:streetAddress": "addr"
} }
optionalPaths["schema:name"] = "name"
optionalPaths["schema:description"] = "description" optionalPaths["schema:description"] = "description"
} }
@ -692,11 +692,11 @@ export default class LinkedDataLoader {
"schema:geo": { "schema:geo": {
"schema:latitude": "latitude", "schema:latitude": "latitude",
"schema:longitude": "longitude", "schema:longitude": "longitude",
"schema:polygon": "shape", "schema:polygon": "shape"
}, },
"schema:priceSpecification": { "schema:priceSpecification": {
"mv:freeOfCharge": "fee", "mv:freeOfCharge": "fee",
"schema:price": "charge", "schema:price": "charge"
} }
} }
@ -704,7 +704,7 @@ export default class LinkedDataLoader {
"schema:priceSpecification [ mv:dueForTime [ mv:timeStartValue ?chargeStart; mv:timeEndValue ?chargeEnd; mv:timeUnit ?timeUnit ] ]", "schema:priceSpecification [ mv:dueForTime [ mv:timeStartValue ?chargeStart; mv:timeEndValue ?chargeEnd; mv:timeUnit ?timeUnit ] ]",
"vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#CargoBicycle>; vp:bicyclesAmount ?capacityCargobike; vp:bicycleType ?cargoBikeType]", "vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#CargoBicycle>; vp:bicyclesAmount ?capacityCargobike; vp:bicycleType ?cargoBikeType]",
"vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#ElectricBicycle>; vp:bicyclesAmount ?capacityElectric; vp:bicycleType ?electricBikeType]", "vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#ElectricBicycle>; vp:bicyclesAmount ?capacityElectric; vp:bicycleType ?electricBikeType]",
"vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#TandemBicycle>; vp:bicyclesAmount ?capacityTandem; vp:bicycleType ?tandemBikeType]", "vp:allows [vp:bicycleType <https://data.velopark.be/openvelopark/terms#TandemBicycle>; vp:bicyclesAmount ?capacityTandem; vp:bicycleType ?tandemBikeType]"
] ]
const unpatched = await this.fetchEntry( const unpatched = await this.fetchEntry(

View file

@ -1814,7 +1814,6 @@ console.log(">>> ",helpTexts.join("\n\n"))
) ?? features[0] ) ?? features[0]
const properties = feature.properties const properties = feature.properties
properties["ref:velopark"] = url properties["ref:velopark"] = url
delete properties["name"]
console.log("Got properties from velopark:", properties) console.log("Got properties from velopark:", properties)
return properties return properties
} catch (e) { } catch (e) {