<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compare strings and assign most matched in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760185#M93864</link>
    <description>&lt;P&gt;Loop over your list, perform calculation using Shortest Edit Script (or write your own algorithm) for each of the values, pick the one with best match?&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2024 13:22:56 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-05-22T13:22:56Z</dc:date>
    <item>
      <title>Compare values</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/758698#M93852</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;here is an example of a list&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the final result I would like to achieve:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 18:48:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/758698#M93852</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-29T18:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/759546#M93855</link>
      <description>&lt;P&gt;It isn't obvious are from your question + post that are you looking for most matching characters or closest match as a string (two different things with two different solutions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For matching strings one of these might help&amp;nbsp;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/utility-functions.shtml?os=win&amp;amp;source=application#ww3843203" target="_blank" rel="noopener"&gt;Shortest Edit Script&lt;/A&gt;&amp;nbsp;and Choose Closest (scripting index isn't able to get link for help page for this).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link from JMP help&amp;nbsp;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/identify-differences-between-strings-lines-or-sequences.shtml#ww670330" target="_blank"&gt;Identify Differences Between Strings, Lines, or Sequences (jmp.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 05:38:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/759546#M93855</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-22T05:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760180#M93863</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;I am looking for the closet match as a string from the list. I am aware of the Shortest Edit script index however I am trying to figure out how can I assign the closest match string from the sample list which is randomly sorted&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:10:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760180#M93863</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-22T13:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760185#M93864</link>
      <description>&lt;P&gt;Loop over your list, perform calculation using Shortest Edit Script (or write your own algorithm) for each of the values, pick the one with best match?&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:22:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760185#M93864</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-22T13:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760212#M93866</link>
      <description>&lt;P&gt;What criteria can I use to determine the best match among the strings? "Common" in the SES? Can you share an example?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:35:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760212#M93866</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-22T13:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760231#M93869</link>
      <description>&lt;P&gt;I think this depends what you consider "most matched". Few examples:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;PortX_Currents_5879_On&lt;/STRONG&gt; which is closer &lt;STRONG&gt;PortX_Curre_589_On&lt;/STRONG&gt; or &lt;STRONG&gt;Port_Currents_587_On&lt;/STRONG&gt;?&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Port3_Currents_5879_On&lt;/STRONG&gt; which is closer &lt;STRONG&gt;Port3_Currents_587&lt;/STRONG&gt; or &lt;STRONG&gt;Port_Currents_587_On&lt;/STRONG&gt;?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;and why?&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:58:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760231#M93869</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-22T13:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760247#M93871</link>
      <description>&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Thx&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 29 May 2024 18:48:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760247#M93871</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-29T18:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760249#M93872</link>
      <description>&lt;P&gt;Most likely your algorithm wouldn't consider those equal. If I would have to make a guess, quite many would consider the second option closer as it requires less edits. For simple check using &lt;STRONG&gt;shortest edit distance()&lt;/STRONG&gt; you could just check for inserts, removes and how many letters were edited. &lt;STRONG&gt;Choose Closest()&lt;/STRONG&gt; might be a bit more brute-force method as you could just allow it use 9999 edits or something similar. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My fairly quick solutions disagree with Most Matched string you provided (would just just wish to check how long common sequence there is at the beginning)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1716389377400.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/64461i923B06602E192D2D/image-size/large?v=v2&amp;amp;px=999" role="button" title="jthi_0-1716389377400.png" alt="jthi_0-1716389377400.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Few links to read regarding edit distance&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://en.wikipedia.org/wiki/Edit_distance" target="_blank"&gt;https://en.wikipedia.org/wiki/Edit_distance&lt;/A&gt; &lt;BR /&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://en.wikipedia.org/wiki/Levenshtein_distance" target="_blank"&gt;https://en.wikipedia.org/wiki/Levenshtein_distance&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance" target="_blank"&gt;https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance&lt;/A&gt; &lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Just for fun and not directly related to this &lt;A href="https://norvig.com/spell-correct.html" target="_blank"&gt;https://norvig.com/spell-correct.html&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you have JMP18 you could also use Python for string distance comparison (but most likely JMP's methods are more than enough). If you allow yourself to use non-standard libraries with Python you get even more options.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 14:51:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760249#M93872</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-22T14:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760317#M93873</link>
      <description>&lt;P&gt;I will take a look. Thanks Jarmo.&lt;/P&gt;&lt;P&gt;Did you manually create the ShorestEdit/ChooseCloset Columns in the above snippet? If not, do you mind sharing your logic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 15:34:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760317#M93873</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-22T15:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Compare strings and assign most matched</title>
      <link>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760351#M93874</link>
      <description>&lt;P&gt;Too much of a work to try manually calculate the closest matches so I did use those functions which I have mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Choose Closest is very easy to implement if you check the scripting index example which allows edits (first argument is your value in table, second is your sample list and increase max edit count as necessary).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1716393519623.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/64462iEE3AF17B55842C04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1716393519623.png" alt="jthi_0-1716393519623.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Here is the script used to create the table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// https://norvig.com/spell-correct.html
// https://en.wikipedia.org/wiki/Edit_distance
// https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
// https://en.wikipedia.org/wiki/Levenshtein_distance

Names Default To Here(1);

samples = {"Port3_Currents_587", "Port1_Volt_8_Off", "PortC_Volt_12",
"PortX_Curre_589_On", "Curren_Port_1280_On", "Currents_5sd_On_Port1", "Port_Currents_587_On"};


dt = Open("$DOWNLOADS/dt_stings.jmp");
dt &amp;lt;&amp;lt; clear select &amp;lt;&amp;lt; Clear Column Selection;

new_col = dt &amp;lt;&amp;lt; New Column("ShortestEdit", Character, Nominal);

For Each Row(dt,
	matches_dif = {};
	
	For Each({cur_sample}, samples,
		edits = Shortest Edit Script(:Strings[], cur_sample);
		difs = 0;
		For Each({cur_edit}, edits,
			If(cur_edit[1] != "Common",
				difs = difs + Length(cur_edit[2]);
			);
		);
		Insert Into(matches_dif, difs);
	);
	
	:ShortestEdit = samples[Loc Min(Matrix(matches_dif))];
);

newcol = dt &amp;lt;&amp;lt; new column("ChooseClosest", character, nominal, formula(
	Choose Closest(:Strings, samples, Max Edit Count(9999)) // Col Max(Length(:Strings))
));
newcol &amp;lt;&amp;lt; delete formula;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 May 2024 15:45:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Compare-values/m-p/760351#M93874</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-26T15:45:56Z</dc:date>
    </item>
  </channel>
</rss>

