forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
612e71a4b6
commit
511d20eb34
245 changed files with 43884 additions and 8661 deletions
|
|
@ -56,10 +56,15 @@ export interface NSIItem {
|
|||
}
|
||||
|
||||
const supportedTypes = ["brand", "flag", "operator", "transit"] as const
|
||||
export type NsiSupportedType = typeof supportedTypes[number]
|
||||
export type NsiSupportedType = (typeof supportedTypes)[number]
|
||||
|
||||
export default class NameSuggestionIndex {
|
||||
public static readonly supportedTypes: ReadonlyArray<NsiSupportedType> = ["brand", "flag", "operator", "transit"] as const
|
||||
public static readonly supportedTypes: ReadonlyArray<NsiSupportedType> = [
|
||||
"brand",
|
||||
"flag",
|
||||
"operator",
|
||||
"transit",
|
||||
] as const
|
||||
protected readonly _serverLocation: string
|
||||
protected readonly nsiFile: Readonly<NSIFile>
|
||||
private readonly loco: LocationConflation // Some additional boundaries
|
||||
|
|
@ -114,7 +119,6 @@ export default class NameSuggestionIndex {
|
|||
return merged
|
||||
}
|
||||
|
||||
|
||||
public async generateMappings(
|
||||
type: string,
|
||||
tags: Record<string, string>,
|
||||
|
|
@ -129,9 +133,7 @@ export default class NameSuggestionIndex {
|
|||
): Promise<Mapping[]> {
|
||||
const mappings: (Mapping & { frequency: number })[] = []
|
||||
const frequencies =
|
||||
country !== undefined
|
||||
? await this.fetchFrequenciesFor(type, country)
|
||||
: {}
|
||||
country !== undefined ? await this.fetchFrequenciesFor(type, country) : {}
|
||||
for (const key in tags) {
|
||||
if (key.startsWith("_")) {
|
||||
continue
|
||||
|
|
@ -166,7 +168,7 @@ export default class NameSuggestionIndex {
|
|||
// As such, it should be "true" but this is not supported
|
||||
priorityIf: frequency > 0 ? new RegexTag("id", /.*/) : undefined,
|
||||
searchTerms: { "*": [nsiItem.displayName, nsiItem.id] },
|
||||
frequency: frequency ?? -1
|
||||
frequency: frequency ?? -1,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -186,12 +188,11 @@ export default class NameSuggestionIndex {
|
|||
return baseUrl + "/logos/" + nsiItem.id + "." + nsiItem.ext
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Caching for the resolved sets, as they can take a while
|
||||
* @private
|
||||
*/
|
||||
private static resolvedSets: Record<string, { type, location, id, feature }> = {}
|
||||
private static resolvedSets: Record<string, { type; location; id; feature }> = {}
|
||||
|
||||
/**
|
||||
* Returns all suggestions for the given type (brand|operator) and main tag.
|
||||
|
|
@ -268,16 +269,11 @@ export default class NameSuggestionIndex {
|
|||
}
|
||||
const endpoint = Constants.nsiLogosEndpoint ?? "./assets/data/nsi/"
|
||||
const [nsi, features] = await Promise.all(
|
||||
[
|
||||
endpoint + "nsi.min.json",
|
||||
endpoint + "featureCollection.min.json"
|
||||
].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
|
||||
)
|
||||
return new NameSuggestionIndex(
|
||||
endpoint,
|
||||
<any>nsi,
|
||||
<any>features
|
||||
[endpoint + "nsi.min.json", endpoint + "featureCollection.min.json"].map((url) =>
|
||||
Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30)
|
||||
)
|
||||
)
|
||||
return new NameSuggestionIndex(endpoint, <any>nsi, <any>features)
|
||||
}
|
||||
|
||||
public supportedTypes(): NsiSupportedType[] {
|
||||
|
|
@ -295,9 +291,7 @@ export default class NameSuggestionIndex {
|
|||
return this._supportedTypes
|
||||
}
|
||||
|
||||
public supportedTags(
|
||||
type: NsiSupportedType
|
||||
): Record<string, string[]> {
|
||||
public supportedTags(type: NsiSupportedType): Record<string, string[]> {
|
||||
const tags: Record<string, string[]> = {}
|
||||
const keys = Object.keys(this.nsiFile.nsi)
|
||||
for (const key of keys) {
|
||||
|
|
@ -315,11 +309,7 @@ export default class NameSuggestionIndex {
|
|||
return tags
|
||||
}
|
||||
|
||||
|
||||
public static async getNsiIndex(endPoint ?: string): Promise<NameSuggestionIndex> {
|
||||
|
||||
}
|
||||
|
||||
public static async getNsiIndex(endPoint?: string): Promise<NameSuggestionIndex> {}
|
||||
|
||||
/**
|
||||
* Returns a list of all brands/operators
|
||||
|
|
@ -358,7 +348,6 @@ export default class NameSuggestionIndex {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
public static async generateMappings(
|
||||
key: string,
|
||||
tags: Exclude<Record<string, string>, undefined | null>,
|
||||
|
|
@ -372,7 +361,6 @@ export default class NameSuggestionIndex {
|
|||
return nsi.generateMappings(key, tags, country, center, options)
|
||||
}
|
||||
|
||||
|
||||
private static readonly brandPrefix = ["name", "alt_name", "operator", "brand"] as const
|
||||
|
||||
/**
|
||||
|
|
@ -443,7 +431,6 @@ export class NamgeSuggestionWikidata {
|
|||
return false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Where can we find the URL on the world wide web?
|
||||
* Probably facebook! Don't use in the website, might expose people
|
||||
|
|
@ -454,6 +441,4 @@ export class NamgeSuggestionWikidata {
|
|||
const logos = this.nsiWdFile[nsiItem.tags[type + ":wikidata"]]?.logos
|
||||
return logos?.facebook ?? logos?.wikidata
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue