public void SetUp() { _config = new Config("../../Tests/TestConfig.config", "TestConfig"); GeocoderSourceDummy dummy = new GeocoderSourceDummy(_config, "DummyProcessorWithConfig"); _normalizer = new Processors.ScoreNormalizer(_config, "ScoreNormalizerTest"); _zero = new GeocodeCandidate { MatchType = "Locator0" }; _one = new GeocodeCandidate { MatchType = "Locator1" }; _two = new GeocodeCandidate { MatchType = "Locator2" }; List <GeocodeCandidate> candidates = new List <GeocodeCandidate> { _zero, _one, _two }; _response = new GeocodeResponse(candidates, dummy); }
public void PitchCityState() { GeocoderSourceDummy dummy = new GeocoderSourceDummy(_config, "DummyProcessorWithConfig"); _typeSelector = new Processors.MatchTypeSelectorProcessor(_config, "MatchTypeSelectorProcessorTest"); _zero = new GeocodeCandidate { MatchType = "US_Zip4" }; _one = new GeocodeCandidate { MatchType = "US_CityState" }; _two = new GeocodeCandidate { MatchType = "US_RoofTops" }; _three = new GeocodeCandidate { MatchType = "US_RoofTops" }; List<GeocodeCandidate> candidates = new List<GeocodeCandidate> { _zero, _one, _two, _three }; _response = new GeocodeResponse(candidates, dummy); _typeSelector.ProcessResponse(_response); Assert.AreEqual(3, _response.Count); Assert.Contains(_zero, _response.Candidates); Assert.Contains(_two, _response.Candidates); Assert.Contains(_three, _response.Candidates); }
private bool IsNotAllowedByMatchType(GeocodeCandidate candidate) { string type = candidate.MatchType; if (!string.IsNullOrEmpty(type) && !_allowedMatchTypes.Contains(type)) { return true; } return false; }
private bool IsNotAllowedByMatchType(GeocodeCandidate candidate) { string type = candidate.MatchType; if (!string.IsNullOrEmpty(type) && !_allowedMatchTypes.Contains(type)) { return(true); } return(false); }
/// <summary> /// Parse the response StandardizedAddress into address parts. /// </summary> /// <param name="response">A geocode response.</param> public void ProcessResponse(GeocodeResponse response) { for (int i = 0; i < response.Candidates.Count; i++) { GeocodeCandidate candidate = response.Candidates[i]; candidate = Parse(candidate, candidate.StandardizedAddress); response.Candidates[i] = candidate; } }
/// <exclude/> protected override GeocodeResponse InternalGeocode(GeocodeRequest request) { if (request.Address == "340 N 12th St") { GeocodeCandidate c = new GeocodeCandidate(); c.Latitude = 238554; c.Longitude = 2694727; c.Address = request.Address; c.PostalCode = "19107"; c.Country = "USA"; return new GeocodeResponse(new[] {c}, this); } return new GeocodeResponse(new GeocodeCandidate[] {}, this); }
/// <exclude/> protected override GeocodeResponse InternalGeocode(GeocodeRequest request) { if (request.Address == "340 N 12th St") { GeocodeCandidate c = new GeocodeCandidate(); c.Latitude = 238554; c.Longitude = 2694727; c.Address = request.Address; c.PostalCode = "19107"; c.Country = "USA"; return(new GeocodeResponse(new[] { c }, this)); } return(new GeocodeResponse(new GeocodeCandidate[] {}, this)); }
public void TestCandidateSort() { GeocodeCandidate lowestCandidate = new GeocodeCandidate { StandardizedAddress = "1234 Street Ave", MatchScore = 0.67d }; GeocodeCandidate higherCandidate = new GeocodeCandidate { StandardizedAddress = "5678 Avenue St", MatchScore = 0.83d }; GeocodeCandidate highestCandidate = new GeocodeCandidate { StandardizedAddress = "9876 Boulevard Cyn", MatchScore = 0.99d }; List<GeocodeCandidate> candidates = new List<GeocodeCandidate>(); candidates.Add(higherCandidate); candidates.Add(lowestCandidate); candidates.Add(highestCandidate); candidates.Sort(); Assert.AreEqual(highestCandidate.StandardizedAddress, candidates[0].StandardizedAddress, "Expected different candidate for first value"); Assert.AreEqual(lowestCandidate.StandardizedAddress, candidates[2].StandardizedAddress, "Expected different candidate for last value"); }
public void TestCandidateSort() { GeocodeCandidate lowestCandidate = new GeocodeCandidate { StandardizedAddress = "1234 Street Ave", MatchScore = 0.67d }; GeocodeCandidate higherCandidate = new GeocodeCandidate { StandardizedAddress = "5678 Avenue St", MatchScore = 0.83d }; GeocodeCandidate highestCandidate = new GeocodeCandidate { StandardizedAddress = "9876 Boulevard Cyn", MatchScore = 0.99d }; List <GeocodeCandidate> candidates = new List <GeocodeCandidate>(); candidates.Add(higherCandidate); candidates.Add(lowestCandidate); candidates.Add(highestCandidate); candidates.Sort(); Assert.AreEqual(highestCandidate.StandardizedAddress, candidates[0].StandardizedAddress, "Expected different candidate for first value"); Assert.AreEqual(lowestCandidate.StandardizedAddress, candidates[2].StandardizedAddress, "Expected different candidate for last value"); }
public void PitchCityState() { GeocoderSourceDummy dummy = new GeocoderSourceDummy(_config, "DummyProcessorWithConfig"); _typeSelector = new Processors.MatchTypeSelectorProcessor(_config, "MatchTypeSelectorProcessorTest"); _zero = new GeocodeCandidate { MatchType = "US_Zip4" }; _one = new GeocodeCandidate { MatchType = "US_CityState" }; _two = new GeocodeCandidate { MatchType = "US_RoofTops" }; _three = new GeocodeCandidate { MatchType = "US_RoofTops" }; List <GeocodeCandidate> candidates = new List <GeocodeCandidate> { _zero, _one, _two, _three }; _response = new GeocodeResponse(candidates, dummy); _typeSelector.ProcessResponse(_response); Assert.AreEqual(3, _response.Count); Assert.Contains(_zero, _response.Candidates); Assert.Contains(_two, _response.Candidates); Assert.Contains(_three, _response.Candidates); }
private static GeocodeCandidate XMLCandidate2GeocodeCandidate(XmlNode XMLCandidate) { GeocodeCandidate curCandidate = new GeocodeCandidate(); curCandidate.RawData = XMLCandidate.InnerXml; //Test for presence of each tag. If it exists, assign it to appropriate value in Geocode Candidate object. //Accuracy - Actually the Gecode *level* of the geocode. Invert. //0 Unknown location. //1 Country level accuracy. //2 Region (state, province, prefecture, etc.) level accuracy. //3 Sub-region (county, municipality, etc.) level accuracy. //4 Town (city, village) level accuracy. //5 Post code (zip code) level accuracy. //6 Street level accuracy. //7 Intersection level accuracy. //8 Address level accuracy. //9 Premise (building name, etc) level accuracy XmlElement addressDetailsNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::AddressDetails"); if (addressDetailsNode != null) { string accuracy = addressDetailsNode.GetAttribute("Accuracy"); curCandidate.MatchScore = Convert.ToDouble(accuracy); switch (accuracy) /* Set our MatchType string from Google's list */ { case "0": curCandidate.MatchType = "Unknown"; break; case "1": curCandidate.MatchType = "Country"; break; case "2": curCandidate.MatchType = "Region"; break; case "3": curCandidate.MatchType = "Sub-Region"; break; case "4": curCandidate.MatchType = "Town"; break; case "5": curCandidate.MatchType = "Post code"; break; case "6": curCandidate.MatchType = "Street"; break; case "7": curCandidate.MatchType = "Intersection"; break; case "8": curCandidate.MatchType = "Address"; break; case "9": curCandidate.MatchType = "Premise"; break; } } //Standardized Address XmlElement standardAddressNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::address"); if (standardAddressNode != null) { curCandidate.StandardizedAddress = standardAddressNode.InnerText; } //Address XmlElement addressNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::ThoroughfareName"); if (addressNode != null) { curCandidate.Address = addressNode.InnerText; } //City XmlElement cityNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::LocalityName"); if (cityNode != null) { curCandidate.City = cityNode.InnerText; } //State XmlElement stateNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::AdministrativeAreaName"); if (stateNode != null) { curCandidate.State = stateNode.InnerText; } //PostalCode XmlElement postalNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::PostalCodeNumber"); if (postalNode != null) { curCandidate.PostalCode = postalNode.InnerText; } //latLong XmlElement latLongNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::Point/coordinates"); if (latLongNode != null) { string latLong = latLongNode.InnerText; string[] location = latLong.Split(','); curCandidate.Longitude = Convert.ToDouble(location[0]); curCandidate.Latitude = Convert.ToDouble(location[1]); } return(curCandidate); }
private static GeocodeCandidate XMLCandidate2GeocodeCandidate(XmlNode XMLCandidate) { var candidate = new GeocodeCandidate { RawData = XMLCandidate.InnerXml, MatchType = ChildNodeText(XMLCandidate, "type"), StandardizedAddress = ChildNodeText(XMLCandidate, "formatted_address") }; switch (candidate.MatchType) { case "street_address": case "premise": case "intersection": case "route": candidate.Address = candidate.StandardizedAddress.Split(',')[0]; break; case "point_of_interest": // Points of interest look like this // Union Station, 1 Main Street, Burlington, VT 05401, USA // We want the second CSV value candidate.Address = candidate.StandardizedAddress.Split(',')[1]; break; default: candidate.Address = ""; break; } var locationNode = XMLCandidate.SelectSingleNode("//location"); if (locationNode != null) { candidate.Longitude = Convert.ToDouble(ChildNodeText(locationNode, "lng")); candidate.Latitude = Convert.ToDouble(ChildNodeText(locationNode, "lat")); } var componentNodes = XMLCandidate.SelectNodes("//address_component"); if (componentNodes != null) { foreach (XmlNode componentNode in componentNodes) { var componentType = ChildNodeText(componentNode, "type"); var value = ChildNodeText(componentNode, "long_name"); switch (componentType) { case "street_address": // indicates a precise street address. break; case "route": // indicates a named route (such as "US 101"). break; case "intersection": // indicates a major intersection, usually of two major roads. break; case "street_number": // indicates a major intersection, usually of two major roads. break; case "country": // indicates the national political entity, and is typically the highest order type returned by the Geocoder. candidate.Country = value; break; case "administrative_area_level_1": // indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. candidate.State = value; break; case "administrative_area_level_2": // indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels. break; case "administrative_area_level_3": // indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. break; case "colloquial_area": // indicates a commonly-used alternative name for the entity. break; case "locality": // indicates an incorporated city or town political entity. candidate.City = value; break; case "sublocality": // indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 through to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area. break; case "neighborhood": // indicates a named neighborhood break; case "premise": // indicates a named location, usually a building or collection of buildings with a common name break; case "subpremise": // indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name break; case "postal_code": // indicates a postal code as used to address postal mail within the country. candidate.PostalCode = value; break; case "natural_feature": // indicates a prominent natural feature. break; case "airport": // indicates an airport. break; case "park": // indicates a named park. break; case "point_of_interest": // indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty." break; } } } candidate.MatchScore = ScoreCandidate(XMLCandidate); return candidate; }
private static GeocodeCandidate XMLCandidate2GeocodeCandidate(XmlNode XMLCandidate) { var candidate = new GeocodeCandidate { RawData = XMLCandidate.InnerXml, MatchType = ChildNodeText(XMLCandidate, "type"), StandardizedAddress = ChildNodeText(XMLCandidate, "formatted_address") }; switch (candidate.MatchType) { case "street_address": case "premise": case "intersection": case "route": candidate.Address = candidate.StandardizedAddress.Split(',')[0]; break; case "point_of_interest": // Points of interest look like this // Union Station, 1 Main Street, Burlington, VT 05401, USA // We want the second CSV value candidate.Address = candidate.StandardizedAddress.Split(',')[1]; break; default: candidate.Address = ""; break; } var locationNode = XMLCandidate.SelectSingleNode("//location"); if (locationNode != null) { candidate.Longitude = Convert.ToDouble(ChildNodeText(locationNode, "lng")); candidate.Latitude = Convert.ToDouble(ChildNodeText(locationNode, "lat")); } var componentNodes = XMLCandidate.SelectNodes("//address_component"); if (componentNodes != null) { foreach (XmlNode componentNode in componentNodes) { var componentType = ChildNodeText(componentNode, "type"); var value = ChildNodeText(componentNode, "long_name"); switch (componentType) { case "street_address": // indicates a precise street address. break; case "route": // indicates a named route (such as "US 101"). break; case "intersection": // indicates a major intersection, usually of two major roads. break; case "street_number": // indicates a major intersection, usually of two major roads. break; case "country": // indicates the national political entity, and is typically the highest order type returned by the Geocoder. candidate.Country = value; break; case "administrative_area_level_1": // indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. candidate.State = value; break; case "administrative_area_level_2": // indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels. break; case "administrative_area_level_3": // indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels. break; case "colloquial_area": // indicates a commonly-used alternative name for the entity. break; case "locality": // indicates an incorporated city or town political entity. candidate.City = value; break; case "sublocality": // indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 through to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area. break; case "neighborhood": // indicates a named neighborhood break; case "premise": // indicates a named location, usually a building or collection of buildings with a common name break; case "subpremise": // indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name break; case "postal_code": // indicates a postal code as used to address postal mail within the country. candidate.PostalCode = value; break; case "natural_feature": // indicates a prominent natural feature. break; case "airport": // indicates an airport. break; case "park": // indicates a named park. break; case "point_of_interest": // indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty." break; } } } candidate.MatchScore = ScoreCandidate(XMLCandidate); return(candidate); }
public void SetUp() { _config = new Config("../../Tests/TestConfig.config", "TestConfig"); GeocoderSourceDummy dummy = new GeocoderSourceDummy(_config, "DummyProcessorWithConfig"); _normalizer = new Processors.ScoreNormalizer(_config, "ScoreNormalizerTest"); _zero = new GeocodeCandidate { MatchType = "Locator0" }; _one = new GeocodeCandidate { MatchType = "Locator1" }; _two = new GeocodeCandidate { MatchType = "Locator2" }; List<GeocodeCandidate> candidates = new List<GeocodeCandidate>{_zero, _one, _two}; _response = new GeocodeResponse(candidates, dummy); }
private static IList<GeocodeCandidate> CSVList2GeocodeCandidates(string csvList) { IList<GeocodeCandidate> candidates = new List<GeocodeCandidate>(); string[] strSplit = new string[1]; strSplit[0] = "\r\n"; string[] strCandidates = csvList.Split(strSplit, StringSplitOptions.RemoveEmptyEntries); if (strCandidates.Length == 0) return candidates; //check for unfound address if (strCandidates[0].Contains("couldn't find this address")) return candidates; foreach (string strCandidate in strCandidates) { string[] splitCandidate = strCandidate.Split(','); GeocodeCandidate curCandidate = new GeocodeCandidate(); string[] parse = splitCandidate[0].Split('='); curCandidate.Latitude = Convert.ToDouble(parse[1]); parse = splitCandidate[1].Split('='); curCandidate.Longitude = Convert.ToDouble(parse[1]); curCandidate.Address = ""; parse = splitCandidate[2].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[3].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[4].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[5].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[6].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } //Remove trailing space if (curCandidate.Address.Length > 0) curCandidate.Address = curCandidate.Address.Remove(curCandidate.Address.Length - 1, 1); parse = splitCandidate[7].Split('='); if (parse.Length > 1) { curCandidate.City = parse[1]; } parse = splitCandidate[8].Split('='); if (parse.Length > 1) { curCandidate.State = parse[1]; } parse = splitCandidate[9].Split('='); if (parse.Length > 1) { curCandidate.PostalCode = parse[1]; } curCandidate.RawData = strCandidate; curCandidate.StandardizedAddress = curCandidate.Address + ", " + curCandidate.City + " " + curCandidate.State + ", " + curCandidate.PostalCode; candidates.Add(curCandidate); } return candidates; }
private static IList <GeocodeCandidate> CSVList2GeocodeCandidates(string csvList) { IList <GeocodeCandidate> candidates = new List <GeocodeCandidate>(); string[] strSplit = new string[1]; strSplit[0] = "\r\n"; string[] strCandidates = csvList.Split(strSplit, StringSplitOptions.RemoveEmptyEntries); if (strCandidates.Length == 0) { return(candidates); } //check for unfound address if (strCandidates[0].Contains("couldn't find this address")) { return(candidates); } foreach (string strCandidate in strCandidates) { string[] splitCandidate = strCandidate.Split(','); GeocodeCandidate curCandidate = new GeocodeCandidate(); string[] parse = splitCandidate[0].Split('='); curCandidate.Latitude = Convert.ToDouble(parse[1]); parse = splitCandidate[1].Split('='); curCandidate.Longitude = Convert.ToDouble(parse[1]); curCandidate.Address = ""; parse = splitCandidate[2].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[3].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[4].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[5].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } parse = splitCandidate[6].Split('='); if (parse.Length > 1) { curCandidate.Address += parse[1] + " "; } //Remove trailing space if (curCandidate.Address.Length > 0) { curCandidate.Address = curCandidate.Address.Remove(curCandidate.Address.Length - 1, 1); } parse = splitCandidate[7].Split('='); if (parse.Length > 1) { curCandidate.City = parse[1]; } parse = splitCandidate[8].Split('='); if (parse.Length > 1) { curCandidate.State = parse[1]; } parse = splitCandidate[9].Split('='); if (parse.Length > 1) { curCandidate.PostalCode = parse[1]; } curCandidate.RawData = strCandidate; curCandidate.StandardizedAddress = curCandidate.Address + ", " + curCandidate.City + " " + curCandidate.State + ", " + curCandidate.PostalCode; candidates.Add(curCandidate); } return(candidates); }
private static GeocodeCandidate XMLCandidate2GeocodeCandidate(XmlNode XMLCandidate) { GeocodeCandidate curCandidate = new GeocodeCandidate(); curCandidate.RawData = XMLCandidate.InnerXml; //Test for presence of each tag. If it exists, assign it to appropriate value in Geocode Candidate object. //Accuracy - Actually the Gecode *level* of the geocode. Invert. //0 Unknown location. //1 Country level accuracy. //2 Region (state, province, prefecture, etc.) level accuracy. //3 Sub-region (county, municipality, etc.) level accuracy. //4 Town (city, village) level accuracy. //5 Post code (zip code) level accuracy. //6 Street level accuracy. //7 Intersection level accuracy. //8 Address level accuracy. //9 Premise (building name, etc) level accuracy XmlElement addressDetailsNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::AddressDetails"); if (addressDetailsNode != null) { string accuracy = addressDetailsNode.GetAttribute("Accuracy"); curCandidate.MatchScore = Convert.ToDouble(accuracy); switch (accuracy) /* Set our MatchType string from Google's list */ { case "0": curCandidate.MatchType = "Unknown"; break; case "1": curCandidate.MatchType = "Country"; break; case "2": curCandidate.MatchType = "Region"; break; case "3": curCandidate.MatchType = "Sub-Region"; break; case "4": curCandidate.MatchType = "Town"; break; case "5": curCandidate.MatchType = "Post code"; break; case "6": curCandidate.MatchType = "Street"; break; case "7": curCandidate.MatchType = "Intersection"; break; case "8": curCandidate.MatchType = "Address"; break; case "9": curCandidate.MatchType = "Premise"; break; } } //Standardized Address XmlElement standardAddressNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::address"); if (standardAddressNode != null) curCandidate.StandardizedAddress = standardAddressNode.InnerText; //Address XmlElement addressNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::ThoroughfareName"); if (addressNode != null) curCandidate.Address = addressNode.InnerText; //City XmlElement cityNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::LocalityName"); if (cityNode != null) curCandidate.City = cityNode.InnerText; //State XmlElement stateNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::AdministrativeAreaName"); if (stateNode != null) curCandidate.State = stateNode.InnerText; //PostalCode XmlElement postalNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::PostalCodeNumber"); if (postalNode != null) curCandidate.PostalCode = postalNode.InnerText; //latLong XmlElement latLongNode = (XmlElement)XMLCandidate.SelectSingleNode("descendant::Point/coordinates"); if (latLongNode != null) { string latLong = latLongNode.InnerText; string[] location = latLong.Split(','); curCandidate.Longitude = Convert.ToDouble(location[0]); curCandidate.Latitude = Convert.ToDouble(location[1]); } return curCandidate; }