forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
047d741b1d
commit
39a98ed4a1
30 changed files with 1362 additions and 1690 deletions
|
|
@ -68,7 +68,7 @@ export default class LinkedDataLoader {
|
|||
coors
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map((n) => Number(n)),
|
||||
.map((n) => Number(n))
|
||||
),
|
||||
],
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ export default class LinkedDataLoader {
|
|||
}
|
||||
const compacted = await jsonld.compact(
|
||||
openingHoursSpecification,
|
||||
<any>LinkedDataLoader.COMPACTING_CONTEXT_OH,
|
||||
<any>LinkedDataLoader.COMPACTING_CONTEXT_OH
|
||||
)
|
||||
const spec: object = compacted["@graph"]
|
||||
if (!spec) {
|
||||
|
|
@ -190,12 +190,12 @@ export default class LinkedDataLoader {
|
|||
const compacted = await jsonld.compact(data, <any>LinkedDataLoader.COMPACTING_CONTEXT)
|
||||
|
||||
compacted["opening_hours"] = await LinkedDataLoader.ohToOsmFormat(
|
||||
compacted["opening_hours"],
|
||||
compacted["opening_hours"]
|
||||
)
|
||||
if (compacted["openingHours"]) {
|
||||
const ohspec: string[] = <any>compacted["openingHours"]
|
||||
compacted["opening_hours"] = OH.simplify(
|
||||
ohspec.map((r) => LinkedDataLoader.ohStringToOsmFormat(r)).join("; "),
|
||||
ohspec.map((r) => LinkedDataLoader.ohStringToOsmFormat(r)).join("; ")
|
||||
)
|
||||
delete compacted["openingHours"]
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ export default class LinkedDataLoader {
|
|||
static async fetchJsonLd(
|
||||
url: string,
|
||||
options?: JsonLdLoaderOptions,
|
||||
mode?: "fetch-lod" | "fetch-raw" | "proxy",
|
||||
mode?: "fetch-lod" | "fetch-raw" | "proxy"
|
||||
): Promise<object> {
|
||||
mode ??= "fetch-lod"
|
||||
if (mode === "proxy") {
|
||||
|
|
@ -251,7 +251,7 @@ export default class LinkedDataLoader {
|
|||
const div = document.createElement("div")
|
||||
div.innerHTML = htmlContent
|
||||
const script = Array.from(div.getElementsByTagName("script")).find(
|
||||
(script) => script.type === "application/ld+json",
|
||||
(script) => script.type === "application/ld+json"
|
||||
)
|
||||
|
||||
const snippet = JSON.parse(script.textContent)
|
||||
|
|
@ -266,7 +266,7 @@ export default class LinkedDataLoader {
|
|||
*/
|
||||
static removeDuplicateData(
|
||||
externalData: Record<string, string>,
|
||||
currentData: Record<string, string>,
|
||||
currentData: Record<string, string>
|
||||
): Record<string, string> {
|
||||
const d = { ...externalData }
|
||||
delete d["@context"]
|
||||
|
|
@ -332,7 +332,7 @@ export default class LinkedDataLoader {
|
|||
}
|
||||
|
||||
private static patchVeloparkProperties(
|
||||
input: Record<string, Set<string>>,
|
||||
input: Record<string, Set<string>>
|
||||
): Record<string, string[]> {
|
||||
const output: Record<string, string[]> = {}
|
||||
for (const k in input) {
|
||||
|
|
@ -473,7 +473,7 @@ export default class LinkedDataLoader {
|
|||
audience,
|
||||
"for",
|
||||
input["ref:velopark"],
|
||||
" assuming yes",
|
||||
" assuming yes"
|
||||
)
|
||||
return "yes"
|
||||
})
|
||||
|
|
@ -517,9 +517,9 @@ export default class LinkedDataLoader {
|
|||
private static async fetchVeloparkProperty<T extends string, G extends T>(
|
||||
url: string,
|
||||
property: string,
|
||||
variable?: string,
|
||||
variable?: string
|
||||
): Promise<SparqlResult<T, G>> {
|
||||
if(property === "schema:photos"){
|
||||
if (property === "schema:photos") {
|
||||
console.log(">> Getting photos")
|
||||
}
|
||||
const results = await new TypedSparql().typedSparql<T, G>(
|
||||
|
|
@ -533,7 +533,7 @@ export default class LinkedDataLoader {
|
|||
[url],
|
||||
undefined,
|
||||
" ?parking a <http://schema.mobivoc.org/BicycleParkingStation>",
|
||||
"?parking " + property + " " + (variable ?? ""),
|
||||
"?parking " + property + " " + (variable ?? "")
|
||||
)
|
||||
|
||||
return results
|
||||
|
|
@ -549,7 +549,7 @@ export default class LinkedDataLoader {
|
|||
private static async fetchVeloparkGraphProperty<T extends string>(
|
||||
url: string,
|
||||
property: string,
|
||||
subExpr?: string,
|
||||
subExpr?: string
|
||||
): Promise<SparqlResult<T, "g">> {
|
||||
const result = await new TypedSparql().typedSparql<T, "g">(
|
||||
{
|
||||
|
|
@ -563,7 +563,12 @@ export default class LinkedDataLoader {
|
|||
"g",
|
||||
" ?parking a <http://schema.mobivoc.org/BicycleParkingStation>",
|
||||
|
||||
S.graph("g", "?section " + property + " " + (subExpr ?? ""), "?section a ?type", "BIND(STR(?section) AS ?id)"),
|
||||
S.graph(
|
||||
"g",
|
||||
"?section " + property + " " + (subExpr ?? ""),
|
||||
"?section a ?type",
|
||||
"BIND(STR(?section) AS ?id)"
|
||||
)
|
||||
)
|
||||
|
||||
return result
|
||||
|
|
@ -605,7 +610,7 @@ export default class LinkedDataLoader {
|
|||
* remove section "key" afterwards
|
||||
* @param key
|
||||
*/
|
||||
function spreadSection(key: string){
|
||||
function spreadSection(key: string) {
|
||||
for (const section in r) {
|
||||
if (section === key) {
|
||||
continue
|
||||
|
|
@ -621,7 +626,6 @@ export default class LinkedDataLoader {
|
|||
// The other 'sections' need to get those copied! Then, we delete the "default"-section
|
||||
if (r["default"] !== undefined && Object.keys(r).length > 1) {
|
||||
spreadSection("default")
|
||||
|
||||
}
|
||||
if (Object.keys(r).length > 1) {
|
||||
// This result has multiple sections
|
||||
|
|
@ -630,16 +634,19 @@ export default class LinkedDataLoader {
|
|||
if (Object.keys(r).length > 2) {
|
||||
console.log("Multiple sections detected: ", JSON.stringify(keys))
|
||||
}
|
||||
const shortestKeyLength: number = Math.min(...keys.map(k => k.length))
|
||||
const key = keys.find(k => k.length === shortestKeyLength)
|
||||
if (keys.some(k => !k.startsWith(key))) {
|
||||
throw "Invalid multi-object: the shortest key is not the start of all the others: " + JSON.stringify(keys)
|
||||
const shortestKeyLength: number = Math.min(...keys.map((k) => k.length))
|
||||
const key = keys.find((k) => k.length === shortestKeyLength)
|
||||
if (keys.some((k) => !k.startsWith(key))) {
|
||||
throw (
|
||||
"Invalid multi-object: the shortest key is not the start of all the others: " +
|
||||
JSON.stringify(keys)
|
||||
)
|
||||
}
|
||||
spreadSection(key)
|
||||
}
|
||||
if (Object.keys(r).length == 1) {
|
||||
const key = Object.keys(r)[0]
|
||||
if(key.indexOf("#")>0){
|
||||
if (key.indexOf("#") > 0) {
|
||||
const newKey = key.split("#")[0]
|
||||
r[newKey] = r[key]
|
||||
delete r[key]
|
||||
|
|
@ -652,7 +659,7 @@ export default class LinkedDataLoader {
|
|||
directUrl: string,
|
||||
propertiesWithoutGraph: PropertiesSpec<T>,
|
||||
propertiesInGraph: PropertiesSpec<T>,
|
||||
extra?: string[],
|
||||
extra?: string[]
|
||||
): Promise<SparqlResult<T, string>> {
|
||||
const allPartialResults: SparqlResult<T, string>[] = []
|
||||
for (const propertyName in propertiesWithoutGraph) {
|
||||
|
|
@ -662,7 +669,7 @@ export default class LinkedDataLoader {
|
|||
const result = await this.fetchVeloparkProperty(
|
||||
directUrl,
|
||||
propertyName,
|
||||
"?" + variableName,
|
||||
"?" + variableName
|
||||
)
|
||||
allPartialResults.push(result)
|
||||
} else {
|
||||
|
|
@ -671,7 +678,7 @@ export default class LinkedDataLoader {
|
|||
const result = await this.fetchVeloparkProperty(
|
||||
directUrl,
|
||||
propertyName,
|
||||
`[${subProperty} ?${variableName}] `,
|
||||
`[${subProperty} ?${variableName}] `
|
||||
)
|
||||
allPartialResults.push(result)
|
||||
}
|
||||
|
|
@ -689,7 +696,7 @@ export default class LinkedDataLoader {
|
|||
const result = await this.fetchVeloparkGraphProperty(
|
||||
directUrl,
|
||||
propertyName,
|
||||
variableName,
|
||||
variableName
|
||||
)
|
||||
allPartialResults.push(result)
|
||||
}
|
||||
|
|
@ -701,7 +708,7 @@ export default class LinkedDataLoader {
|
|||
const result = await this.fetchVeloparkGraphProperty(
|
||||
directUrl,
|
||||
propertyName,
|
||||
variableName,
|
||||
variableName
|
||||
)
|
||||
allPartialResults.push(result)
|
||||
} else {
|
||||
|
|
@ -710,7 +717,7 @@ export default class LinkedDataLoader {
|
|||
const result = await this.fetchVeloparkGraphProperty(
|
||||
directUrl,
|
||||
propertyName,
|
||||
`[${subProperty} ?${variableName}] `,
|
||||
`[${subProperty} ?${variableName}] `
|
||||
)
|
||||
allPartialResults.push(result)
|
||||
}
|
||||
|
|
@ -735,7 +742,7 @@ export default class LinkedDataLoader {
|
|||
*/
|
||||
public static async fetchVeloparkEntry(
|
||||
url: string,
|
||||
includeExtras: boolean = false,
|
||||
includeExtras: boolean = false
|
||||
): Promise<Feature[]> {
|
||||
const cacheKey = includeExtras + url
|
||||
if (this.veloparkCache[cacheKey]) {
|
||||
|
|
@ -754,7 +761,7 @@ export default class LinkedDataLoader {
|
|||
"schema:email": "email",
|
||||
"schema:telephone": "phone",
|
||||
},
|
||||
// "schema:photos": "images",
|
||||
// "schema:photos": "images",
|
||||
"schema:dateModified": "_last_edit_timestamp",
|
||||
}
|
||||
if (includeExtras) {
|
||||
|
|
@ -796,13 +803,13 @@ export default class LinkedDataLoader {
|
|||
withProxyUrl,
|
||||
optionalPaths,
|
||||
graphOptionalPaths,
|
||||
extra,
|
||||
extra
|
||||
)
|
||||
for (const unpatchedKey in unpatched) {
|
||||
// Dirty hack
|
||||
const rawData = await Utils.downloadJsonCached<object>(url, 1000*60*60)
|
||||
const images = rawData["photos"]?.map(ph => <string> ph.image)
|
||||
if(images){
|
||||
const rawData = await Utils.downloadJsonCached<object>(url, 1000 * 60 * 60)
|
||||
const images = rawData["photos"]?.map((ph) => <string>ph.image)
|
||||
if (images) {
|
||||
unpatched[unpatchedKey].images = new Set<string>(images)
|
||||
}
|
||||
}
|
||||
|
|
@ -811,7 +818,7 @@ export default class LinkedDataLoader {
|
|||
const patched: Feature[] = []
|
||||
for (let section in unpatched) {
|
||||
const p = LinkedDataLoader.patchVeloparkProperties(unpatched[section])
|
||||
if(Object.keys(unpatched).length === 1 && section.endsWith("#section1")){
|
||||
if (Object.keys(unpatched).length === 1 && section.endsWith("#section1")) {
|
||||
section = section.split("#")[0]
|
||||
}
|
||||
p["ref:velopark"] = [section]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue