it\'s a question about Neighbourhood Search. I used perl to write a piece of cod
ID: 3869003 • Letter: I
Question
it's a question about Neighbourhood Search. I used perl to write a piece of code, like picture shows
below.The aim of this code is to help a string in one txt file named labelled-tokens.txt (file 1) find a best match in another txt file named dict.txt (file 2). As you can see I have to manually input the string (picture 2) in file 1, how can I automatically approximatedly match every string (one word per line) in file 1 with every token in file 2?
open (my $IN," ./labelled-tokens.txt") $corr 0: while ($line = ) { chomp($line) $token = $1: $code: $2; $canon = $3; $result =agrep-1 "^${token}$" ./dict.txt l head-1; chomp($result); if (Sresult eq $canon) $corr++; close($IN): print "Correct: $fcorrin"Explanation / Answer
Basically, you can directly open both the files as input and one by one iterate through each of the word in the file containing test strings. And follow the same procedure as you followed up in your program.
Open the test file and start a loop for it to give you the test strings.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.