Skip to content
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

Attribute conflation fix #5573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions hoot-core/src/main/cpp/hoot/core/conflate/address/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Maxar (http://www.maxar.com/)
*/
#include "Address.h"

Expand All @@ -38,6 +38,7 @@ namespace hoot
{

QSet<QString> Address::_streetTypes;
bool Address::_streetTypesIncludesAbbreviations = false;
QMap<QString, QString> Address::_streetFullTypesToTypeAbbreviations;
QMap<QString, QString> Address::_streetTypeAbbreviationsToFullTypes;
StringDistancePtr Address::_stringComp;
Expand Down Expand Up @@ -111,22 +112,7 @@ QList<QRegExp> Address::getIntersectionSplitTokens()

QSet<QString> Address::getStreetTypes(const bool includeAbbreviations)
{
if (_streetTypes.isEmpty())
{
// Possibly, this could be expanded to use something like:
// https://pe.usps.com/text/pub28/28apc_002.htm[this] instead.
const QStringList streetTypesRaw = ConfigOptions().getAddressStreetTypes();
for (const auto& streetTypeEntry : qAsConst(streetTypesRaw))
{
const QStringList streetTypeEntryParts = streetTypeEntry.split("=");
// Currently we only support 1:1 street type to abbreviation pairings.
if (streetTypeEntryParts.size() != 2)
throw HootException("Invalid street type entry: " + streetTypeEntry);
_streetTypes.insert(streetTypeEntryParts.at(0).toLower());
if (includeAbbreviations)
_streetTypes.insert(streetTypeEntryParts.at(1).toLower());
}
}
_loadStreetTypes(includeAbbreviations);
return _streetTypes;
}

Expand Down Expand Up @@ -197,7 +183,8 @@ bool Address::isStreetIntersectionAddress(const Address& address,
void Address::removeStreetTypes()
{
LOG_TRACE(_address);

// When removing street types, reload them with abbreviations
_loadStreetTypes(true);
// If its a non-intersection, just remove the last street type token. We're assuming its at the
// end, which may not be alway true.
if (!isStreetIntersectionAddress(_address, !_parsedFromAddressTag))
Expand Down Expand Up @@ -231,4 +218,29 @@ void Address::removeHouseNumber()
LOG_VART(_address);
}

void Address::_loadStreetTypes(const bool includeAbbreviations)
{
if (_streetTypesIncludesAbbreviations != includeAbbreviations || _streetTypes.isEmpty())
{
// Remember what the current settings are
_streetTypesIncludesAbbreviations = includeAbbreviations;
// Clear the set in all cases
_streetTypes.clear();
// Possibly, this could be expanded to use something like:
// https://pe.usps.com/text/pub28/28apc_002.htm[this] instead.
const QStringList streetTypesRaw = ConfigOptions().getAddressStreetTypes();
for (const auto& streetTypeEntry : qAsConst(streetTypesRaw))
{
const QStringList streetTypeEntryParts = streetTypeEntry.split("=");
// Currently we only support 1:1 street type to abbreviation pairings.
if (streetTypeEntryParts.size() != 2)
throw HootException("Invalid street type entry: " + streetTypeEntry);
_streetTypes.insert(streetTypeEntryParts.at(0).toLower());
if (includeAbbreviations)
_streetTypes.insert(streetTypeEntryParts.at(1).toLower());
}
}

}

}
5 changes: 4 additions & 1 deletion hoot-core/src/main/cpp/hoot/core/conflate/address/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Maxar (http://www.maxar.com/)
*/
#ifndef ADDRESSS_H
#define ADDRESSS_H
Expand Down Expand Up @@ -146,12 +146,15 @@ class Address

// see getStreetTypes
static QSet<QString> _streetTypes;
static bool _streetTypesIncludesAbbreviations;
// see getStreetFullTypesToTypeAbbreviations
static QMap<QString, QString> _streetFullTypesToTypeAbbreviations;
// see getStreetTypeAbbreviationsToFullTypes
static QMap<QString, QString> _streetTypeAbbreviationsToFullTypes;

void _initializeStringComparator() const;

static void _loadStreetTypes(const bool includeAbbreviations);
};

}
Expand Down