|
8 | 8 | #include <functional>
|
9 | 9 | #include <cctype>
|
10 | 10 | #include <locale>
|
| 11 | +#include <set> |
11 | 12 |
|
12 | 13 | #include <string.h>
|
13 | 14 |
|
@@ -363,26 +364,29 @@ void Postal::expand(const Postal::ParseResult &input, std::vector<Postal::ParseR
|
363 | 364 |
|
364 | 365 | std::vector< std::vector< std::string > > address_expansions;
|
365 | 366 | std::vector< std::string > address_keys;
|
366 |
| - for (const auto i: input) |
| 367 | + for (const auto &i: input) |
367 | 368 | {
|
368 | 369 | // in practice, its only one element at ParseResult at this stage
|
369 |
| - for (const std::string tonorm: i.second) |
| 370 | + for (const std::string &tonorm: i.second) |
370 | 371 | {
|
371 |
| - std::vector< std::string > norm; |
| 372 | + std::set< std::string > norm; |
| 373 | + // always add unexpanded result into address expansions |
| 374 | + // this will help with the partial entries as described in |
| 375 | + // issue #64 https://github.com/rinigus/geocoder-nlp/issues/64 |
| 376 | + norm.insert(tonorm); |
372 | 377 | // no need to keep postal code in normalized and expanded
|
373 |
| - if (i.first == ADDRESS_PARSER_LABEL_POSTAL_CODE || i.first == PRIMITIVE_ADDRESS_PARSER_POSTAL_CODE_KEY) |
374 |
| - norm.push_back(tonorm); |
375 |
| - else |
| 378 | + if (i.first != ADDRESS_PARSER_LABEL_POSTAL_CODE && i.first != PRIMITIVE_ADDRESS_PARSER_POSTAL_CODE_KEY) |
376 | 379 | {
|
377 | 380 | charbuff.resize(tonorm.length() + 1);
|
378 | 381 | std::copy(tonorm.c_str(), tonorm.c_str() + tonorm.length() + 1, charbuff.begin());
|
379 | 382 | char **expansions = libpostal_expand_address(charbuff.data(), options_norm, &num_expansions);
|
380 | 383 | for (size_t j = 0; j < num_expansions; j++)
|
381 |
| - norm.push_back(expansions[j]); |
| 384 | + norm.insert(expansions[j]); |
382 | 385 |
|
383 | 386 | libpostal_expansion_array_destroy(expansions, num_expansions);
|
384 | 387 | }
|
385 |
| - address_expansions.push_back(norm); |
| 388 | + address_expansions.push_back(std::vector< std::string >(norm.begin(), |
| 389 | + norm.end())); |
386 | 390 | address_keys.push_back(i.first);
|
387 | 391 | }
|
388 | 392 | }
|
@@ -417,7 +421,6 @@ void Postal::expand_string(const std::string &input, std::vector<std::string> &e
|
417 | 421 | std::copy(input.c_str(), input.c_str() + input.length() + 1, charbuff.begin());
|
418 | 422 |
|
419 | 423 | char **expansions_cstr = libpostal_expand_address(charbuff.data(), options_norm, &num_expansions);
|
420 |
| - std::vector< std::string > norm; |
421 | 424 | for (size_t j = 0; j < num_expansions; j++)
|
422 | 425 | expansions.push_back(expansions_cstr[j]);
|
423 | 426 |
|
|
0 commit comments