More improvements to loading linked data (esp. velopark)

This commit is contained in:
Pieter Vander Vennet 2024-04-10 13:23:54 +02:00
parent 1bc45c1c0c
commit 4a65ab69f8

View file

@ -295,10 +295,16 @@ export default class LinkedDataLoader {
private static patchVeloparkProperties(input: Record<string, Set<string>>): Record<string, string[]> { private static patchVeloparkProperties(input: Record<string, Set<string>>): Record<string, string[]> {
const output: Record<string, string[]> = {} const output: Record<string, string[]> = {}
console.log("Input for patchVelopark:", input)
for (const k in input) { for (const k in input) {
output[k] = Array.from(input[k]) output[k] = Array.from(input[k])
} }
if (output["type"][0] === "https://data.velopark.be/openvelopark/terms#BicycleLocker") {
output["bicycle_parking"] = ["lockers"]
}
delete output["type"]
function on(key: string, applyF: (s: string) => string) { function on(key: string, applyF: (s: string) => string) {
if (!output[key]) { if (!output[key]) {
return return
@ -341,6 +347,10 @@ export default class LinkedDataLoader {
for (const attribute in LinkedDataLoader.formatters) { for (const attribute in LinkedDataLoader.formatters) {
on(attribute, p => LinkedDataLoader.formatters[attribute].reformat(p)) on(attribute, p => LinkedDataLoader.formatters[attribute].reformat(p))
} }
rename("phone", "operator:phone")
rename("email", "operator:email")
rename("website", "operator:website")
on("charge", (p => { on("charge", (p => {
if (Number(p) === 0) { if (Number(p) === 0) {
output["fee"] = ["no"] output["fee"] = ["no"]
@ -379,10 +389,10 @@ export default class LinkedDataLoader {
on("access", audience => { on("access", audience => {
if (["brede publiek", "iedereen", "bezoekers", "iedereen - vooral bezoekers gemeentehuis of bibliotheek."].indexOf(audience.toLowerCase()) >= 0) { if (["brede publiek", "iedereen", "bezoekers", "iedereen - vooral bezoekers gemeentehuis of bibliotheek."].indexOf(audience.toLowerCase()) >= 0) {
return "public" return "yes"
} }
if (audience.toLowerCase().startsWith("bezoekers")) { if (audience.toLowerCase().startsWith("bezoekers")) {
return "public" return "yes"
} }
if (["abonnees"].indexOf(audience.toLowerCase()) >= 0) { if (["abonnees"].indexOf(audience.toLowerCase()) >= 0) {
return "members" return "members"
@ -400,8 +410,8 @@ export default class LinkedDataLoader {
return "customers" return "customers"
} }
console.warn("Suspicious 'access'-tag:", audience, "for", input["ref:velopark"]," assuming public") console.warn("Suspicious 'access'-tag:", audience, "for", input["ref:velopark"], " assuming yes")
return "public" return "yes"
}) })
@ -458,8 +468,8 @@ export default class LinkedDataLoader {
} }
private static async fetchVeloparkGraphProperty<T extends string>(url: string, property: string, subExpr?: string): private static async fetchVeloparkGraphProperty<T extends string>(url: string, property: string, subExpr?: string):
Promise<SparqlResult<T, "section">> { Promise<SparqlResult<T, "g">> {
const results = await new TypedSparql().typedSparql<T, "g">( return await new TypedSparql().typedSparql<T, "g">(
{ {
schema: "http://schema.org/", schema: "http://schema.org/",
mv: "http://schema.mobivoc.org/", mv: "http://schema.mobivoc.org/",
@ -476,7 +486,6 @@ export default class LinkedDataLoader {
"?section a ?type" "?section a ?type"
) )
) )
return results
} }
/** /**
@ -594,11 +603,12 @@ export default class LinkedDataLoader {
"schema:contactPoint": { "schema:contactPoint": {
"schema:email": "email", "schema:email": "email",
"schema:telephone": "phone" "schema:telephone": "phone"
},
} "schema:dateModified":"_last_edit_timestamp"
} }
const graphOptionalPaths = { const graphOptionalPaths = {
"a": "type",
"vp:covered": "covered", "vp:covered": "covered",
"vp:maximumParkingDuration": "maxstay", "vp:maximumParkingDuration": "maxstay",
"mv:totalCapacity": "capacity", "mv:totalCapacity": "capacity",
@ -614,11 +624,7 @@ export default class LinkedDataLoader {
"schema:priceSpecification": { "schema:priceSpecification": {
"mv:freeOfCharge": "fee", "mv:freeOfCharge": "fee",
"schema:price": "charge" "schema:price": "charge"
},
"schema:amenityFeature": {
"a": "fixme_nearby_amenity"
} }
} }
const extra = [ const extra = [