I'm struggling with an n-gram problem and have been hunting the Web for examples to help me out and have noticed n-grams being discussed on this forum. I'm working on a system where we've got scraped titles and are trying to reduce the number of unrecognised texts. There are roughly 60,000 known good titles and about 6,000,000 unmatched titles. 1:100 is not a very impressive ratio. Some of the bad titles aren't in the list of canonical titles and can't ever be matched, but others are failing to be matched because of punctuation/positional/editing/spelling inconsistencies and errors. Typical dirty data.
To avoid confusion I'll clarify what I mean by n-gram as the term is used for two different things. I'm talking n-grams where you break a string into a series of n-length substrings. These are sometimes called "q-grams", for some reason. I'm not talking about something like Google's corpus of word combination "n-grams". So, with a length of 3 for n, the string "hello" breaks down into:
__h
_he
hel
ell
lo_
o__
(The padding before and after isn't always used but, based on my data set, I think that it will be helpful.)
There is a plug-in for MySQL that parses texts into 2-character blocks, but I'm very likely to need lengths of 3 and possibly other lengths. Testing will show what's most effective.
Despite being a programmer for a long time, I'm poor enough at SQL that I haven't sorted out how to build the n-grams or how to rank similarities based on the n-grams. If it comes to it, I can build the n-grams in another language without any trouble and load them all into MySQL. That leaves me with needing to figure out how to construct the SELECT to compare strings.
Do you happen to have or know of an example that you might be able to refer me to?
For background, the rest of the team has been trying to solve this using some code I provided with a variety of algoritms, phonetic and statistical:
Soundex and metaphone: Not really appropriate for this data (too many languages) and not great on a good day anyway.
Levenshtein distance, longest common subsequence, and Jaro-Winkler: Much higher quality, but too expensive to run on-the-fly for a data set of this size.
Thanks in advance for any help or suggestions.