Find Semantically Correct Word Splits in UTF-8 Strings

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 1 04:47:40 PDT 2014


On Wednesday, 1 October 2014 at 11:06:24 UTC, Nordlöw wrote:
> I'm looking for a way to make my algorithm
>

Update:

     S[] findMeaningfulWordSplit(S)(S word,
                                    HLang[] langs = []) if 
(isSomeString!S)
     {
         for (size_t i = 1; i + 1 < word.length; i++)
         {
             const first = word.takeExactly(i).to!string;
             const second = word.dropExactly(i).to!string;
             if (this.canMeanSomething(first, langs) &&
                 this.canMeanSomething(second, langs))
             {
                 return [first,
                         second];
             }
         }
         return typeof(return).init;
     }

works but has unfortunately O(word.length^^2) time-complexity.

Do we need a new InputRange algorithm for this?


More information about the Digitalmars-d-learn mailing list