5 ms·
This is too complicated... echo $sentence | rs -T | sort | uniq -c | sort -rn|head -10
by stass 13y ago
This is too complicated...
echo $sentence | rs -T | sort | uniq -c | sort -rn|head -10
- mzs 13y agoOoh that's a clever use of reshape, but wrong sadly. Yet you're right I could make it simpler, it was just what came first to mind, I did not even check it. Imagine typical sentences: $ echo Foo foo foo. | rs -T Foo foo foo. $ echo Foo foo foo. | tr 'a-z' 'A-Z' | sed 's/[^A-Z]/\ /g' | grep -v '^$' FOO FOO FOO Also the link mentioned using wiki articles for testing, so they would have paragraphs and that's where reshape shines for things like emails, but fails here: $ cat foo Foo foo foo. $ <foo rs -T Foo foo foo. $ <foo tr 'a-z' 'A-Z' | sed 's/[^A-Z]/\ /g' | grep -v '^$' FOO FOO FOO That that's though makes me think, should I treat contractions special? What about plurals? It's starting to get silly now.
- stass 13y agoI think it goes beyond the original question now. :) If one wants to do proper thing, then definitely contractions, word variations, etc should be considered. For this, I guess something like OpenNLP can be used. What's interesting though is how UNIX shell, being essentially a symbolic FP language, allows one to solve the problem in a clear and concise way. And if one desires, the program can be easily modified to read sentences, say, from network from ssh tunneled via HTTPS. That kind of flexibility can rarely be achieved in languages like C# with tight coupling between the units of abstraction.