Skip to content

v0.2.55..v0.2.56 changeset Address.h

Garret Voltz edited this page Aug 14, 2020 · 3 revisions
diff --git a/hoot-core/src/main/cpp/hoot/core/conflate/address/Address.h b/hoot-core/src/main/cpp/hoot/core/conflate/address/Address.h
index d885c35..11b6fa1 100644
--- a/hoot-core/src/main/cpp/hoot/core/conflate/address/Address.h
+++ b/hoot-core/src/main/cpp/hoot/core/conflate/address/Address.h
@@ -22,19 +22,28 @@
  * This will properly maintain the copyright information. DigitalGlobe
  * copyrights will be updated automatically.
  *
- * @copyright Copyright (C) 2016, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2016, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 #ifndef ADDRESSS_H
 #define ADDRESSS_H
 
-// hoot
-#include <hoot/core/algorithms/string/ExactStringDistance.h>
+// Hoot
+#include <hoot/core/algorithms/string/StringDistance.h>
+
+// Qt
+#include <QSet>
+#include <QMap>
 
 namespace hoot
 {
 
 /**
- * Encapsulates a street address for conflation purposes
+ * Encapsulates a street address for conflation purposes. This class has become less object-oriented
+ * over time and likely needs some re-design.
+ *
+ * Note that a QMap can be used to represent the street type full names and their abbreviations
+ * b/c we currently only support a one to one mapping. If we expand it to support multiple
+ * abbreviations per full name, then we'll need to switch to a QMultiMap.
  */
 class Address
 {
@@ -48,12 +57,119 @@ public:
 
   QString toString() const { return "Address: " + _address; }
 
+  /**
+   * Determines if an address string represents a street intersection
+   *
+   * @param addressStr address to examine
+   * @param requireStreetTypeInIntersection if true, a street type token must be present at the end
+   * of the input
+   * @return true if the input represents a street intersection address; false otherwise
+   */
+  static bool isStreetIntersectionAddress(const QString& addressStr,
+                                          const bool requireStreetTypeInIntersection = false);
+
+  /**
+   * Determines if an address represents a street intersection
+   *
+   * @param address address to examine
+   * @param requireStreetTypeInIntersection if true, a street type token must be present at the end
+   * of the input
+   * @return true if the input represents a street intersection address; false otherwise
+   */
+  static bool isStreetIntersectionAddress(const Address& address,
+                                          const bool requireStreetTypeInIntersection = false);
+
+  /**
+   * Returns a collection of street type (suffix) tokens; e.g. "Street"
+   *
+   * @param includeAbbreviations if true, abbreviations for the tokens are also included
+   * @return a collection of string tokens
+   */
+  static QSet<QString> getStreetTypes(const bool includeAbbreviations = true);
+
+  /**
+   * Returns a mapping of street type (suffix) tokens mapped to accepted abbreviations for them;
+   * e.g. "Street" --> "St"
+   *
+   * @return a mapping of string tokens
+   */
+  static QMap<QString, QString> getStreetFullTypesToTypeAbbreviations();
+
+  /**
+   * Returns a mapping of street type (suffix) abbreviation tokens mapped to accepted full names for
+   * them; e.g "St" --> "Street"
+   *
+   * @return a mapping of string tokens
+   */
+  static QMap<QString, QString> getStreetTypeAbbreviationsToFullTypes();
+
+  /**
+   * Returns a collection of string tokens used to separate the two parts of an intersection address
+   *
+   * @return a collection of string tokens
+   */
+  static QList<QRegExp> getIntersectionSplitTokens();
+
+  /**
+   * Returns the intersection parts of the address
+   *
+   * @return a string list with two entries for the intersection parts if the address is an
+   * intersection address; an empty list otherwise
+   */
+  QStringList getIntersectionParts() const;
+
+  /**
+   * Removes street type (suffix) text from the address
+   */
+  void removeStreetTypes();
+
+  /**
+   * Removes the house number from the address if its not an intersection address
+   */
+  void removeHouseNumber();
+
+  bool getParsedFromAddressTag() const { return _parsedFromAddressTag; }
+  void setParsedFromAddressTag(bool from) { _parsedFromAddressTag = from; }
+
+  QString getAddressStr() const { return _address; }
+
+  bool getIsRange() const { return _isRange; }
+  void setIsRange(bool isRange) { _isRange = isRange; }
+
+  bool getIsSubLetter() const { return _isSubLetter; }
+  void setIsSubLetter(bool isSubLetter) { _isSubLetter = isSubLetter; }
+
+  QString getHouseNumber() const;
+
 private:
 
   QString _address;
-  ExactStringDistance _addrComp;
+
+  // This has been made configurable, but due to the fact that address strings are usually
+  // normalized before being set on this class, its seems unlikely at this point that anything other
+  // than ExactStringDistance will be used.
+  static StringDistancePtr _stringComp;
+
   //see AddressParser::addressesMatchDespiteSubletterDiffs
   bool _allowLenientHouseNumberMatching;
+
+  // was the address parsed from an OSM address tag or some other auxiliary tag (name, etc.)?
+  bool _parsedFromAddressTag;
+
+  // determines if the address has a house number range; like: 120-130 Sutter St
+  bool _isRange;
+
+  // determines if the address has a subletter in the house number; like 120a Sutter St
+  bool _isSubLetter;
+
+  // see getStreetTypes
+  static QSet<QString> _streetTypes;
+  // see getStreetFullTypesToTypeAbbreviations
+  static QMap<QString, QString> _streetFullTypesToTypeAbbreviations;
+  // see getStreetTypeAbbreviationsToFullTypes
+  static QMap<QString, QString> _streetTypeAbbreviationsToFullTypes;
+
+  void _initializeStringComparator();
 };
 
 }
Clone this wiki locally