Ask HN: How do you split strings (to get keywords)?
First trial, one splits on whitespace, but this sucks on interpunction and special characters.
Second trial, you use a alpha-numeric whitelist and split on anything else, but what about umlauts? What about hebrew or cyrillic?
Third trial: split on characters < 32, whitespace and interpunction characters; this works somehow but is ugly. What would you do to get keywords from a string?
7 comments
[ 5.0 ms ] story [ 33.4 ms ] threadedit: Based on what you said in your original post, I would say to have a list of possible delimiters (which would probably need to be added to for some time), and tokenize the string according to that, and discard any token that appears in a second list of words that don't matter (conjunctions, articles, prepositions, etc...). Before discarding said strings, you'd also want to check if they're operators used in your app, or anything like that.
Basically, I think of a string like "ham, egg." which should result in "ham" and "egg", and "Ветчина, яйцо." should also result in "Ветчина" and "яйцо".
The challenge is that you cannot whitelist all possible characters as there are (imho) too many charsets.
However, that does nothing to eliminate words like 'in' and 'of' in a query, which you may want to do. It isn't very practical at all, I think, and you probably want to look at more practical ways to list possible delimiters, etc... Although the above could help you determine what charset you're using.
Try looking up "Lex" or "Flex"...these were the tools we used. There may be better ones around now.
Here's a quick google: http://dinosaur.compilertools.net/
A multi-lingual version of this could use the Unicode "General Category" character classes (Letter, Mark, Number, Punctuation, Symbol, Separator, Other).
http://developer.yahoo.com/search/content/V1/termExtraction....
anybody have any comments about it?