• 0

Comparing 2 street addresses


Question

Need a little help:

I need a function to find if 2 addresses are similar. You may think that this is a simple compare, however you can have a bunch of different formatted addresses that are the same thing:

ie 123 Fake Street = 123 Fake St. = 123 Fake St = 123 Fake Street Apt 123

Now I have a decent function in place, but I need to fix some lingering errors and I dont know the best way of doing it.

(I'm doing this in vba, but I just need pseudocode)

Function addresscheck(ByVal first As String, ByVal last As String) As String

Dim name1 As Variant
Dim name2 As Variant
Dim num, textAs Boolean

num = False
text = False

name1 = Split(first, " ")
name2 = Split(last, " ")

For i = 0 To UBound(name1)
	For j = 0 To UBound(name2)
	'if both are numbers and equal, the street number is correct
		If IsNumeric(name1(i)) Then
			If IsNumeric(name2(j)) Then
				If name1(i) = name2(j) Then
					num = True
				End If
			End If
	'if both are strings and equal, the street name is correct
		ElseIf Len(name1(i)) > 3 Then
			If UCase(name1(i)) = UCase(name2(j)) Then
				text = True
			End If


		End If

	Next j
Next i
If UCase(first) = UCase(last) Then
	addresscheck = "Match"
ElseIf Not num And Not text Then
	addresscheck = "No Match"
ElseIf Not num And text Then
	addresscheck = "Text Only"
ElseIf num And Not text Then
	addresscheck = "Number Only"
ElseIf num And text Then
	addresscheck = "Match"
End If
End Function

Problem is this will give me a match if I have something like this: 2 Queen Street & 2 King Street because Street is equal (I tried to get rid of this by only allowing words with a length greater than 3 to be compared, but same problems arise I guess)

And it will give a match if I have 2 King Street & 2 King Cresent.

I can't do comparisons by placement because then something like Apt. 100 2 King Street = 2 King Street = 2 King Street Apt. 100 will return as no match.

Any help is appreciated.

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

I think this is complicated enough to warrant several methods, if not a whole class. A good approach would be to recognize different parts of the address. Have the code ask questions like "Do we have an appartement number here? - yes, it's 100; Do we have a street address here? - yes, it's 3030 Fake St., etc. Convert each part to a standard form; for instance, appartement numbers are just a number, street addresses are all lowercase or all uppercase, "[street number], [street name] st.", for instance. Store addresses in this standard form, and if two addresses convert to the same thing, then they match, otherwise they don't.

Link to comment
Share on other sites

  • 0

The fastest way I could/would do it is look for key positions within the string. If you look at your examples, they are all "Address Number + space + street name + space + type of street" simply use spaces as your markers and compare each position. If at any point they don't match then stop (meaning: if street name does not match, why even look at Ave., Blvd., etc?)

Link to comment
Share on other sites

  • 0

@Rohdekill - Thats not neccesarily true. I have seen Apt. 123 - 234 Fake St. and 234 Fake St. - Apt. 123, so I cant compare each position.

@Dr_Asik - I am going for a more cutthroat solution, one where I would not have to build up a dictionary to resolve street acronyms or go through a parser which might not narrow results because of the many different ways these things can be formatted. I don't mind having a few stragglers that they will have to go through one by one that do match, I'm just trying to diminish the potential non matches that show up as matches

Link to comment
Share on other sites

  • 0

How are you capturing the address?

If you captured the address in its parts (street, city, state, zip) then doing a direct compare would be a lot easier at that point.

-or-

if you are trying to create this as a generic method, why dont you create this as a class and have the implementer worry about separating out the parts of the address?

In the class you can create a struct for place 1 vs place 2 and do a compare of the structs?

I dont know BASIC but I would take this approach for C++, C#, or JAVA

*EDIT*

edited for clarity and information

Link to comment
Share on other sites

  • 0

Where are you getting these duplicates from?

If it's when the user is entering his information then I would recommend a system where the user would be presented with a relevant choice rather than trying to do it all automatically.

ex.:

User enters:

123 Road st.

Canbridge, MA

USA 02140

You would then compare with the zip code database (http://sourceforge.net/projects/zips/) and narrow it down, and then offer a choice:

Did you mean?

123 Road street

Cambridge, Massachusetts

USA 02140

Yes, correct the address for me

No, use the address I entered

You can also handle multiple choices if your algorithm can't narrow it down to only one.

Link to comment
Share on other sites

  • 0

I'm doing a compare from addresses from two systems. Because these 2 systems were implemented at different times, the addresses could of been entered in differently or changed. This is why I need this, so instead of going line by line, I can cut down the amount of manual work done.

And I'm only doing the street address, and it is one full string.

Link to comment
Share on other sites

  • 0

The only thing I can think of its to create regular expressions to do some pattern matching on the address. Since I dont know what the data looks like (i.e. street apt#, city, state, zip -or- apt# street, state, city, zip) there isnt a lot we can do.

There can be a lot of variations on how the address could have been created, so regular expressions might be the only way to do this.

Wesley

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.