![]() Normalizing the textĭown to business: how do we normalize a text using SQL? Well, once again, string walking and string unwalking to the rescue. ![]() ‘hello’ and ‘lolhe’ both normalize to ‘ehllo’, hence are permutations. So, to see if two strings are permutations of each other, we rearrange both in alphabetical order, and see if we got the same text. This rearrangement is in itself a permutation of the string (hence, one last mathematical statement, it can be seen as a representative of the equivalence class). Can you see what normalization means here? I’m merely rearranging the characters in alphabetical order. What exactly is a normal form? Well, anything you like, really, as long as it’s deterministic and works the same for all elements in the equivalence class (mathematically speaking, this was a really bad definition, I know).Įnough of mathematical notions: on the practical side, I’ll normalize ‘CAB’ to ‘ABC’, and ‘DOG’ to ‘DGO’. The two string are permutations of each other if both have the same normal form. The solution I’m suggesting checks for permutation between 2 strings by permuting both to a third, normal form. While the solution discussed is targeted at string characters, it can be easily converted to work with string tokens. Here, the permutation is not with string characters, but with string tokens. On a slightly different scale, the two queries: SELECT * FROM City WHERE id IN (5, 21, 13) and SELECT * FROM City WHERE id IN (13, 5, 21) are identical.We may still disallow a permutation of the text. We may disallow a password which is identical to the login name but we may also disallow upper-lower-case-only transformations of the text. We may be interested in permutations when a user chooses a password.Mathematically, string permutation is an equivalence relation, and divides all strings to equivalence classes. The REVERSE() of a text is an example of permutation. So, if ‘lolhe’ is a permutation of ‘hello’, then ‘hello’ is a permutation of ‘lolhe’, as well and both are permutations of ‘elloh’. I wish to present an SQL solution for checking if two strings are permutations of the same text. Thus, ‘lolhe’ is a permuted ‘hello’ (commonly referred to as ‘scrambled text’).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |