public void GetLocationCodes_GazContainsDuplicateCombinedLevel1And2_CorrectCodesAdded() { // Arrange // gazetteer data GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - string[] inputNames = {"P1T", "1", "V1"}; // names 3 Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // correct codes added (codes 3) Assert.AreEqual(codes3[0], codedLocation.GeoCode1.Code); Assert.AreEqual(codes3[1], codedLocation.GeoCode2.Code); Assert.AreEqual(codes3[2], codedLocation.GeoCode3.Code); }
public void GetCodes_Leve1And2CorrectAndLevel3HasSavedMatch_AllCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 3 miss-spelt string[] inputNames = {"P1", "T1", "V1x"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // saved matches MatchProviderStub matchProviderStub = MatchProviderStubLevel3(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1, 2 and 3 codes added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(codes1[2], codedLocation.GeoCode3.Code); Assert.AreEqual(names1[2], codedLocation.GeoCode3.Name); }
/// <summary> /// Adds the codes and the names used to find those codes, to the input data. /// </summary> /// <param name="coder">The location codes.</param> public void CodeAll(Coder coder) { coder.RefreshMatchedNamesCache(); foreach (DataRow dataRow in Data.Rows) { CodedLocation codedLocation = FindCodes( coder, dataRow, UseMatchedNamesCache); ClearExistingCodes(dataRow); AddCodes(codedLocation, dataRow); } }
public void GetLocationCodes_Level1And2GazetteerAltName_AllCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 and // an alternate name for name 1 and 2 string[] altNames = {"P1A", "T1A", null}; GazetteerRecords gazetteerRecords = GazetteerTestData(altNames); // gazetteerRecords.AddLine(names2, codes2); // input data - Level 1 and 2 contains alt spelling, the rest are spelt correctly string[] inputNames = {"P1A", "T1A", "V1"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1, 2 and 3 codes added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(codes1[2], codedLocation.GeoCode3.Code); Assert.AreEqual(names1[2], codedLocation.GeoCode3.Name); }
private CodedLocation FindCodes( Coder coder, DataRow dataRow, bool useCache) { //create location, use the original name Location location = new Location(); location.Name1 = dataRow[ColumnHeaders.Level1].ToString(); // level 2 is optional if (!string.IsNullOrEmpty(ColumnHeaders.Level2)) { location.Name2 = dataRow[ColumnHeaders.Level2].ToString(); } // level 3 is optional if (!string.IsNullOrEmpty(ColumnHeaders.Level3)) { location.Name3 = dataRow[ColumnHeaders.Level3].ToString(); } // get codes CodedLocation codedLocation = coder.GetCodes(location, useCache); return codedLocation; }
public void GetLocationCodes_Level1Incorrect_NoCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 2 miss-spelt string[] inputNames = {"P1x", "T1", "V1"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // no codes added Assert.AreEqual(null, codedLocation.GeoCode1); Assert.AreEqual(null, codedLocation.GeoCode2); Assert.AreEqual(null, codedLocation.GeoCode3); }
public void GetLocationCodes_Level1Correct_Level1CodeAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - no level 3 supplied string[] inputNames = {"P1", null, null}; Location location = new Location( inputNames[0]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // level 1 code only added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(null, codedLocation.GeoCode2); Assert.AreEqual(null, codedLocation.GeoCode3); }
public void GetLocationCodes_Leve1And2CorrectAndLevel3Incorrect_Level1And2CodeAddedOnly() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 3 miss-spelt string[] inputNames = {"P1", "T1", "V1x"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1 and 2 only are added, no level 3 code added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(null, codedLocation.GeoCode3); }