Better filtering of some LOD-properties

This commit is contained in:
Pieter Vander Vennet 2024-04-09 15:12:18 +02:00
parent 087c099e2e
commit 6b381e05c6
2 changed files with 80 additions and 53 deletions

View file

@ -24,7 +24,8 @@ export default class LinkedDataLoader {
image: { "@id": "http://schema.org/image", "@type": "@id" }, image: { "@id": "http://schema.org/image", "@type": "@id" },
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"}
} }
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" },
@ -188,6 +189,11 @@ export default class LinkedDataLoader {
compacted["geo"] = <any>await LinkedDataLoader.geoToGeometry(compacted["geo"]) compacted["geo"] = <any>await LinkedDataLoader.geoToGeometry(compacted["geo"])
} }
if(compacted["alt_name"]){
if(compacted["alt_name"] === compacted["name"]){
delete compacted["alt_name"]
}
}
for (const k in compacted) { for (const k in compacted) {
if (compacted[k] === "") { if (compacted[k] === "") {

View file

@ -34,7 +34,7 @@
let knownImages = new Set( let knownImages = new Set(
Object.keys(osmProperties) Object.keys(osmProperties)
.filter((k) => k.match(imageKeyRegex)) .filter((k) => k.match(imageKeyRegex))
.map((k) => osmProperties[k]), .map((k) => osmProperties[k])
) )
let unknownImages = externalKeys let unknownImages = externalKeys
.filter((k) => k.match(imageKeyRegex)) .filter((k) => k.match(imageKeyRegex))
@ -43,9 +43,30 @@
let propertyKeysExternal = externalKeys.filter((k) => k.match(imageKeyRegex) === null) let propertyKeysExternal = externalKeys.filter((k) => k.match(imageKeyRegex) === null)
let missing = propertyKeysExternal.filter((k) => osmProperties[k] === undefined && typeof externalProperties[k] === "string") let missing = propertyKeysExternal.filter((k) => osmProperties[k] === undefined && typeof externalProperties[k] === "string")
let same = propertyKeysExternal.filter((key) => osmProperties[key] === externalProperties[key]) // let same = propertyKeysExternal.filter((key) => osmProperties[key] === externalProperties[key])
let different = propertyKeysExternal.filter( let different = propertyKeysExternal.filter(
(key) => osmProperties[key] !== undefined && osmProperties[key] !== externalProperties[key] && typeof externalProperties[key] === "string", (key) => {
if (osmProperties[key] === undefined) {
return false
}
if (typeof externalProperties[key] !== "string") {
return false
}
if (osmProperties[key] === externalProperties[key]) {
return false
}
if (key === "website")
{
const osmCanon = new URL(osmProperties[key]).toString()
const externalCanon = new URL(externalProperties[key]).toString()
if(osmCanon === externalCanon){
return false
}
}
return true
}
) )
let currentStep: "init" | "applying_all" | "all_applied" = "init" let currentStep: "init" | "applying_all" | "all_applied" = "init"
@ -56,7 +77,7 @@
const tagsToApply = missing.map((k) => new Tag(k, externalProperties[k])) const tagsToApply = missing.map((k) => new Tag(k, externalProperties[k]))
const change = new ChangeTagAction(tags.data.id, new And(tagsToApply), tags.data, { const change = new ChangeTagAction(tags.data.id, new And(tagsToApply), tags.data, {
theme: state.layout.id, theme: state.layout.id,
changeType: "import", changeType: "import"
}) })
await state.changes.applyChanges(await change.CreateChangeDescriptions()) await state.changes.applyChanges(await change.CreateChangeDescriptions())
currentStep = "all_applied" currentStep = "all_applied"