Wikidata-input-field now interprets 'removePostfixes' and 'removePrefixes' as regexes instead of normal strings, fix #1340
This commit is contained in:
parent
c44fbac077
commit
0597d57326
2 changed files with 63 additions and 241 deletions
|
@ -257,11 +257,11 @@ class WikidataTextField extends TextFieldDef {
|
|||
[
|
||||
[
|
||||
"removePrefixes",
|
||||
"remove these snippets of text from the start of the passed string to search. This is either a list OR a hash of languages to a list",
|
||||
"remove these snippets of text from the start of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes",
|
||||
],
|
||||
[
|
||||
"removePostfixes",
|
||||
"remove these snippets of text from the end of the passed string to search. This is either a list OR a hash of languages to a list",
|
||||
"remove these snippets of text from the end of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes.",
|
||||
],
|
||||
[
|
||||
"instanceOf",
|
||||
|
@ -294,7 +294,8 @@ class WikidataTextField extends TextFieldDef {
|
|||
"square",
|
||||
"plaza",
|
||||
],
|
||||
"nl": ["straat","plein","pad","weg",laan"]
|
||||
"nl": ["straat","plein","pad","weg",laan"],
|
||||
"fr":["route (de|de la|de l'| de le)"]
|
||||
},
|
||||
|
||||
"#": "Remove streets and parks from the search results:"
|
||||
|
@ -360,34 +361,34 @@ Another example is to search for species and trees:
|
|||
if (searchFor !== undefined && options !== undefined) {
|
||||
const prefixes = <string[] | Record<string, string[]>>options["removePrefixes"] ?? []
|
||||
const postfixes = <string[] | Record<string, string[]>>options["removePostfixes"] ?? []
|
||||
|
||||
Locale.language
|
||||
.map((lg) => {
|
||||
const prefixesUnrwapped: string[] = Array.isArray(prefixes)
|
||||
? prefixes
|
||||
: prefixes[lg] ?? []
|
||||
const postfixesUnwrapped: string[] = Array.isArray(postfixes)
|
||||
? postfixes
|
||||
: postfixes[lg] ?? []
|
||||
const defaultValueCandidate = Locale.language.map((lg) => {
|
||||
const prefixesUnrwapped: RegExp[] = (
|
||||
Array.isArray(prefixes) ? prefixes : prefixes[lg] ?? []
|
||||
).map((s) => new RegExp("^" + s, "i"))
|
||||
const postfixesUnwrapped: RegExp[] = (
|
||||
Array.isArray(postfixes) ? postfixes : postfixes[lg] ?? []
|
||||
).map((s) => new RegExp(s + "$", "i"))
|
||||
let clipped = searchFor
|
||||
|
||||
for (const postfix of postfixesUnwrapped) {
|
||||
if (searchFor.endsWith(postfix)) {
|
||||
clipped = searchFor.substring(0, searchFor.length - postfix.length)
|
||||
const match = searchFor.match(postfix)
|
||||
if (match !== null) {
|
||||
clipped = searchFor.substring(0, searchFor.length - match[0].length)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Prefixes are: ", prefixesUnrwapped)
|
||||
for (const prefix of prefixesUnrwapped) {
|
||||
if (searchFor.startsWith(prefix)) {
|
||||
clipped = searchFor.substring(prefix.length)
|
||||
const match = searchFor.match(prefix)
|
||||
if (match !== null) {
|
||||
clipped = searchFor.substring(match[0].length)
|
||||
break
|
||||
}
|
||||
}
|
||||
return clipped
|
||||
})
|
||||
.addCallbackAndRun((clipped) => searchForValue.setData(clipped))
|
||||
|
||||
defaultValueCandidate.addCallbackAndRun((clipped) => searchForValue.setData(clipped))
|
||||
}
|
||||
|
||||
let instanceOf: number[] = Utils.NoNull(
|
||||
|
@ -425,7 +426,7 @@ class OpeningHoursTextField extends TextFieldDef {
|
|||
[
|
||||
[
|
||||
"prefix",
|
||||
"Piece of text that will always be added to the front of the generated opening hours. If the OSM-data does not start with this, it will fail to parse",
|
||||
"Piece of text that will always be added to the front of the generated opening hours. If the OSM-data does not start with this, it will fail to parse.",
|
||||
],
|
||||
[
|
||||
"postfix",
|
||||
|
|
|
@ -62,219 +62,40 @@
|
|||
],
|
||||
"removePrefixes": {
|
||||
"#": "no-translations",
|
||||
"nl": [
|
||||
"(basis|lagere |middelbare |secondaire| secundaire)?school"
|
||||
],
|
||||
"fr": [
|
||||
"allée des ",
|
||||
"allée de la ",
|
||||
"allée de l'",
|
||||
"allée de ",
|
||||
"allée du ",
|
||||
"allée",
|
||||
"autoroute des ",
|
||||
"autoroute de la ",
|
||||
"autoroute de l'",
|
||||
"autoroute de ",
|
||||
"autoroute du ",
|
||||
"autoroute",
|
||||
"avenue des ",
|
||||
"avenue de la ",
|
||||
"avenue de l'",
|
||||
"avenue de ",
|
||||
"avenue du ",
|
||||
"avenue",
|
||||
"bibliothèque des ",
|
||||
"bibliothèque de la ",
|
||||
"bibliothèque de l'",
|
||||
"bibliothèque de ",
|
||||
"bibliothèque du ",
|
||||
"bibliothèque",
|
||||
"boulevard des ",
|
||||
"boulevard de la ",
|
||||
"boulevard de l'",
|
||||
"boulevard de ",
|
||||
"boulevard du ",
|
||||
"boulevard",
|
||||
"centre culturel des ",
|
||||
"centre culturel de la ",
|
||||
"centre culturel de l'",
|
||||
"centre culturel de ",
|
||||
"centre culturel du ",
|
||||
"centre culturel",
|
||||
"centre des ",
|
||||
"centre de la ",
|
||||
"centre de l'",
|
||||
"centre de ",
|
||||
"centre du ",
|
||||
"centre",
|
||||
"chaussée des ",
|
||||
"chaussée de la ",
|
||||
"chaussée de l'",
|
||||
"chaussée de ",
|
||||
"chaussée du ",
|
||||
"chaussée",
|
||||
"chemin des ",
|
||||
"chemin de la ",
|
||||
"chemin de l'",
|
||||
"chemin de ",
|
||||
"chemin du ",
|
||||
"chemin",
|
||||
"clos des ",
|
||||
"clos de la ",
|
||||
"clos de l'",
|
||||
"clos de ",
|
||||
"clos du ",
|
||||
"clos ",
|
||||
"collège des ",
|
||||
"collège de la ",
|
||||
"collège de l'",
|
||||
"collège de ",
|
||||
"collège du ",
|
||||
"collège privé ",
|
||||
"collège public ",
|
||||
"collège",
|
||||
"complexe sportif des ",
|
||||
"complexe sportif de la ",
|
||||
"complexe sportif de l'",
|
||||
"complexe sportif de ",
|
||||
"complexe sportif du ",
|
||||
"complexe sportif",
|
||||
"drève des ",
|
||||
"drève de la ",
|
||||
"drève de l'",
|
||||
"drève de ",
|
||||
"drève du ",
|
||||
"drève",
|
||||
"école élémentaire des ",
|
||||
"école élémentaire de la ",
|
||||
"école élémentaire de l'",
|
||||
"école élémentaire de ",
|
||||
"école élémentaire du ",
|
||||
"école élémentaire",
|
||||
"école maternelle des ",
|
||||
"école maternelle de la ",
|
||||
"école maternelle de l'",
|
||||
"école maternelle de ",
|
||||
"école maternelle du ",
|
||||
"école maternelle",
|
||||
"école primaire des ",
|
||||
"école primaire de la ",
|
||||
"école primaire de l'",
|
||||
"école primaire de ",
|
||||
"école primaire du ",
|
||||
"école primaire",
|
||||
"école des ",
|
||||
"école de la ",
|
||||
"école de l'",
|
||||
"école de ",
|
||||
"école du ",
|
||||
"école privée ",
|
||||
"école publique ",
|
||||
"école",
|
||||
"esplanade des ",
|
||||
"esplanade de la ",
|
||||
"esplanade de l'",
|
||||
"esplanade de ",
|
||||
"esplanade du ",
|
||||
"esplanade",
|
||||
"groupe scolaire des ",
|
||||
"groupe scolaire de la ",
|
||||
"groupe scolaire de l'",
|
||||
"groupe scolaire de ",
|
||||
"groupe scolaire du ",
|
||||
"groupe scolaire privé ",
|
||||
"groupe scolaire public ",
|
||||
"groupe scolaire",
|
||||
"gymnase des ",
|
||||
"gymnase de la ",
|
||||
"gymnase de l'",
|
||||
"gymnase de ",
|
||||
"gymnase du ",
|
||||
"gymnase",
|
||||
"impasse des ",
|
||||
"impasse de la ",
|
||||
"impasse de l'",
|
||||
"impasse de ",
|
||||
"impasse du ",
|
||||
"impasse",
|
||||
"lycée des ",
|
||||
"lycée de la ",
|
||||
"lycée de l'",
|
||||
"lycée de ",
|
||||
"lycée du ",
|
||||
"lycée privé ",
|
||||
"lycée public ",
|
||||
"lycée",
|
||||
"mail des ",
|
||||
"mail de la ",
|
||||
"mail de l'",
|
||||
"mail de ",
|
||||
"mail du ",
|
||||
"mail",
|
||||
"médiathèque des ",
|
||||
"médiathèque de la ",
|
||||
"médiathèque de l'",
|
||||
"médiathèque de ",
|
||||
"médiathèque du ",
|
||||
"médiathèque",
|
||||
"musée des ",
|
||||
"musée de la ",
|
||||
"musée de l'",
|
||||
"musée de ",
|
||||
"musée du ",
|
||||
"musée",
|
||||
"parc des ",
|
||||
"parc de la ",
|
||||
"parc de l'",
|
||||
"parc de ",
|
||||
"parc du ",
|
||||
"parc",
|
||||
"place des ",
|
||||
"place de la ",
|
||||
"place de l'",
|
||||
"place de ",
|
||||
"place du ",
|
||||
"place",
|
||||
"résidence des ",
|
||||
"résidence de la ",
|
||||
"résidence de l'",
|
||||
"résidence de ",
|
||||
"résidence du ",
|
||||
"résidence",
|
||||
"route des ",
|
||||
"route de la ",
|
||||
"route de l'",
|
||||
"route de ",
|
||||
"route du ",
|
||||
"route",
|
||||
"rue des ",
|
||||
"rue de la ",
|
||||
"rue de l'",
|
||||
"rue de ",
|
||||
"rue du ",
|
||||
"rue",
|
||||
"sentier des ",
|
||||
"sentier de la ",
|
||||
"sentier de l'",
|
||||
"sentier de ",
|
||||
"sentier du ",
|
||||
"sentier",
|
||||
"square des ",
|
||||
"square de la ",
|
||||
"square de l'",
|
||||
"square de ",
|
||||
"square du ",
|
||||
"square",
|
||||
"stade des ",
|
||||
"stade de la ",
|
||||
"stade de l'",
|
||||
"stade de ",
|
||||
"stade du ",
|
||||
"stade",
|
||||
"villa des ",
|
||||
"villa de la ",
|
||||
"villa de l'",
|
||||
"villa de ",
|
||||
"villa du ",
|
||||
"villa"
|
||||
"allée (des |de la |de l'|de |du )?",
|
||||
"autoroute (des |de la |de l'|de |du )?",
|
||||
"avenue (des |de la |de l'|de |du )?",
|
||||
"bibliothèque (des |de la |de l'|de |du )?",
|
||||
"boulevard (des |de la |de l'|de |du )?",
|
||||
"centre (culturel |sportif )?(des |de la |de l'|de |du )?",
|
||||
"chaussée (des |de la |de l'|de |du )?",
|
||||
"chemin (des |de la |de l'|de |du )?",
|
||||
"clos (des |de la |de l'|de |du )?",
|
||||
"collège (privé |public )?(des |de la |de l'|de |du )?",
|
||||
"complexe sportif (des |de la |de l'|de |du )?",
|
||||
"drève (des |de la |de l'|de |du )?",
|
||||
"école (maternelle |primaire |élémentaire)?(privée |publique )?(des |de la |de l'|de |du )?",
|
||||
"esplanade (des |de la |de l'|de |du )?",
|
||||
"groupe scolaire (privé |public )?(des |de la |de l'|de |du )?",
|
||||
"gymnase (des |de la |de l'|de |du )?",
|
||||
"impasse (des |de la |de l'|de |du )?",
|
||||
"lycée (privé |public )?(des |de la |de l'|de |du )?",
|
||||
"mail (des |de la |de l'|de |du )?",
|
||||
"médiathèque (des |de la |de l'|de |du )?",
|
||||
"musée (des |de la |de l'|de |du )?",
|
||||
"parc (des |de la |de l'|de |du )?",
|
||||
"place (des |de la |de l'|de |du )?",
|
||||
"résidence (des |de la |de l'|de |du )?",
|
||||
"route (des |de la |de l'|de |du )?",
|
||||
"rue (des |de la |de l'|de |du )?",
|
||||
"sentier (des |de la |de l'|de |du )?",
|
||||
"square (des |de la |de l'|de |du )?",
|
||||
"stade (des |de la |de l'|de |du )?",
|
||||
"villa (des |de la |de l'|de |du )?"
|
||||
]
|
||||
},
|
||||
"removePostfixes": {
|
||||
|
|
Loading…
Reference in a new issue