-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add withOptional flag that will trigger region when needed #42
base: master
Are you sure you want to change the base?
Conversation
05e1a9c
to
bbf316a
Compare
Heya, sorry I didn't reply earlier, I wanted to think about this a bit more before commenting. I think that generally this is a great approach, namely:
One change I would suggest is around code organisation. Just throwing out an idea, but could we change that so that each 'generator' (such as I think that has a few advantages:
Not sure, does that make sense? |
If I understand correctly, the schema should look something like this ? 'FRA': {
'valueFunctions': {
'local': getFirstProperty(['locality', 'localadmin']),
'country': getFRACountryValue()
},
'verbose': {
'valueFunctions': {
'local': getFirstProperty(['locality', 'localadmin']),
'regional': getFRARegionValue(),
'country': getFRACountryValue()
},
'meta': {
'separator': ',' // This is useless for FRA
}
},
'meta': {
'separator': ',' // This is useless for FRA
}
} I like the term I want to expand the best part of the label based on the results. That means:
With an option like Maybe I will need metadata from the API to identify similar parts... Or Metadata example for {
"country": 2, // same name and same ID
"macroregion": 0, // no match
"region": 0, // no match
"macrocounty": 0, // no match
"county": 0, // no match
"localadmin": 1, // same name
"locality": 1, // same name
"continent": 2, //same name and same ID
} Metadata example for {
"housenumber": 0, // no match
"street": 0, // no match
"postalcode": 0, // no match
"country": 2, //same name and same ID
"region": 2, //same name and same ID
"county": 2, //same name and same ID
"locality": 2, //same name and same ID
"borough": 2, //same name and same ID
"neighbourhood": 0, // no match
"continent": 2, //same name and same ID
} |
hmm yeah sorry if I'm actually making this more complicated 😆 Just throwing out an idea here but if we returned an array of objects from the generator, we could then pass it up to the API layer and let it make the decision about how to So off the top of my head, something like this: var doc = thePeliasDocForBagneux()
var parts = generator.fr(doc)
/**
parts would be equal to:
[
{ label: 'Bagneux', layer: 'locality', role: 'required' },
{ label: 'Hauts-de-Seine', layer: 'region', role: 'optional' },
{ label: 'France', layer: 'country', role: 'required' },
]
**/
// Get the existing 'simple' label
var simple = (p) => ['required'].includes(p.role)
var str = parts.filter(simple).join(', ')
// Get the label with 'optional' parts
var extended = (p) => ['required','optional'].includes(p.role)
var str = parts.filter(extended).join(', ') The generator would just be responsible for specifying the order of the array items, what is included or discarded from the array and what roles are assigned based on the document layer. The stringification could be performed either within this repo or in the 🤷♂️ |
Hum... Yes and in this case, if we return an array to the API:
We should not forget to return the separator character (space in Korea) This is of course a breaking change |
bbf316a
to
5374b64
Compare
Hi there, I updated this branch with pelias/api#1507 to apply your idea @missinglink. This is backward compatible, I added a new function {
parts: [
{ label: 'Bagneux', layer: 'locality', role: 'required' },
{ label: 'Hauts-de-Seine', layer: 'region', role: 'optional' },
{ label: 'France', layer: 'country', role: 'required' },
],
separator: ', '
}
Anyway, the result looks very good ! ➡️ Police nationale, Marseille, France
➡️ Bagneux, France
➡️ Starbucks, New York
|
5374b64
to
5936adf
Compare
12ab8d0
to
73ef845
Compare
Hello there, I did an update of this PR
Now I have two questions. I saw that there were spaces in Japanese labels. Maybe this PR is a perfect use case to handle this? Lines 73 to 75 in 73ef845
let labelParts = _.concat(postalcode, { label: ' ', role: 'newline' }, admin, distric, block, { label: ' ', role: 'newline' }, venue);
// OR
let labelParts = _.concat(postalcode, { label: ' ', role: 'separator' }, admin, distric, block, { label: ' ', role: 'separator' }, venue); Also, the space seems to be ignored when the label is built: labels/test/labelGenerator_JPN_JPN.js Lines 137 to 142 in 73ef845
|
f5b56ed
to
37056b8
Compare
This will help for label deduplication in the API. Sample of the response ```json { labelParts: [ { label: 'Bagneux', layer: 'name', role: 'required' }, { label: 'Hauts-de-Seine', layer: 'region', role: 'optional' }, { label: 'France', layer: 'country', role: 'required' }, ], separator: ', ' } ```
37056b8
to
762f22b
Compare
I added some minor fixes, now this is ready to review/merge |
We really need to test this out, you've done a lot of work here. Stand by :) |
I added a commit above #41 that implement my comment #41 (comment)
What do you think @missinglink ? The PR for the API is in progress 😉