closest match - csv file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tpitera
Posts: 31
Joined: 27 Oct 2020, 15:56

closest match - csv file

22 Apr 2021, 11:32

I need to take an city (broken down from full address from a website and then check a csv file for the city and then get the appropriate info from that row. The one problem is that the city value is often inputted incorrectly (either misspelling or spaces when there should be none). My code thus far

Code: Select all

City := "North Smith Field"  ;In csv it is North Smithfield
State := "RI"
CSV_Load(Path2, "RIstatecodes")
Cell1 := CSV_Search("RIstatecodes", City) ;Generates zero when exact match not found
if (Cell1 = 0)
{
	Cell1A := StrSplit(City, " ")
	Loop % Cell1A.length()  ;3
	{
		LoopVar := A_Index
		MsgBox % "LoopVar = " . LoopVar
		Loop, % CSV_TotalRows("RIstatecodes") 
		{
			found := CSV_Search("RIstatecodes", Cell1A[LoopVar], A_Index)
			MsgBox % "Found = " . found . "`nCell1A[A_Index] = " . Cell1A[LoopVar] . "`nA_Index = " . A_Index . "`nLoop Var = " . LoopVar
			if found=0
				Break
			Result := StrSplit(found, ",")
			Results .= Result[1] ","
			MsgBox % "Results = " . Results
		}
	Results .= ";"
	}
}
The results are Results := 29,30,31,;31,38,;31,38
The question is how do i go through each row and getting the matching 31 value as my final Cell value
I started with this but dont know where to go from here

Code: Select all

ResultsR := StrSplit(Results, ";")
Loop % ResultsR.Length()
{
	ResultsC := StrSplit(ResultsR[A_Index], ",")
	Loop % ResultsC.Length()
	{
		
	}
}
User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: closest match - csv file  Topic is solved

22 Apr 2021, 13:02

string-similarity.ahk might be useful. If you have a list of correctly spelled cities you can easily see what the user's input is most similar to.

Code: Select all

oStringSimilarity := new stringsimilarity() ; requires https://www.npmjs.com/package/string-similarity.ahk

citiesArray := ["Los Angeles", "Boston", "Dallas", "East Los Angeles"]
userInput := "losangles"

msgbox, % oStringSimilarity.simpleBestMatch(userInput, citiesArray)
; => "Los Angeles"
tpitera
Posts: 31
Joined: 27 Oct 2020, 15:56

Re: closest match - csv file

22 Apr 2021, 13:54

that is awesome! thanks!
tpitera
Posts: 31
Joined: 27 Oct 2020, 15:56

Re: closest match - csv file

22 Apr 2021, 15:26

Are there better instructions on how to do this?
In a terminal or command line navigated to your project folder:

npm install string-similarity.ahk

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], ShatterCoder and 132 guests