public WordExtractor(WordExtractorSettings wordExtractorSettings) { if (wordExtractorSettings == null) throw new ArgumentNullException("wordExtractorSettings"); this._wordExtractorSettings = wordExtractorSettings; }
/// <summary> /// Pass fully match words from word sequence using word extractor settings provided. /// </summary> /// <param name="wordPartSequence">Sequence of full and partial words</param> /// <param name="wordExtractorSettings">Word extractor settings. Defaults settings inlude Full word length = 6, Ignore casing is off</param> /// <returns>Fully matched words from word part sequence</returns> public static List<string> Compose(string wordPartSequence, WordExtractorSettings wordExtractorSettings) { List<string> wordList; using (IWordComposer wordComposer = new WordComposer(new WordExtractor(wordExtractorSettings))) { wordList = wordComposer.Compose(wordPartSequence); } return wordList; }
public void CanComposeLargerThanDefaultSizeWordsFromWordPartSequence() { const string wordPartSequence = "ba Barely, be, befoul, ly, re, foul, trinitY, neo, subliminal, trinit, y"; WordExtractorSettings wordExtractorSettings = new WordExtractorSettings { WordLength = 7, IgnoreCase = true }; List<string> wordList = Composer.Compose(wordPartSequence, wordExtractorSettings); // "trinitY" will be found since is it 7 char in length Assert.AreEqual(1, wordList.Count); Assert.AreEqual(wordList[0], "trinitY"); }
public void CanComposeFullWordListUsingStaticComposerWithWordExtractorSettings() { const string wordPartSequence = "al, Albums, aver, bar, Barely, be, befoul, bums, by, cat, con, convex, ely, foul, here, hereby, jig, jigsaw, or, saw, tail, tailor, vex, we, weaver"; WordExtractorSettings wordExtractorSettings = new WordExtractorSettings { IgnoreCase = false, WordLength = 6 }; List<string> wordList = Composer.Compose(wordPartSequence, wordExtractorSettings); // Will not be able to match "Albums" and "Barely" because casing is not ignored Assert.IsTrue(wordList.Count == 6); Assert.IsFalse(wordList.Contains("Barely")); Assert.IsFalse(wordList.Contains("Albums")); }
public void CanComposeWordsFromOriginalWordPartSequence() { WordExtractorSettings wordExtractorSettings = new WordExtractorSettings { WordLength = 6, IgnoreCase = true }; const string wordPartSequence = "al, albums, aver, bar, barely, be, befoul, bums, by, cat, con, convex, ely, foul, here, hereby, jig, jigsaw, or, saw, tail, tailor, vex, we, weaver"; IWordExtractor wordExtractor = new WordExtractor(wordExtractorSettings); WordComposer wordComposer = new WordComposer(wordExtractor); List<string> composedWords = wordComposer.Compose(wordPartSequence); Assert.IsNotNull(composedWords); Assert.AreEqual(composedWords.Count, 8); foreach (var composedWord in composedWords) { Assert.AreEqual(composedWord.Length, wordExtractor.WordExtractorSettings.WordLength); } }
public void VerifyEarlyPartWordsCannotPreventMatchesFromOccuringWithLaterPartWords() { const string wordPartSequence = "ba sub, Lime, befoul,Sublime, be trinit, befo, ul y"; WordExtractorSettings wordExtractorSettings = new WordExtractorSettings { WordLength = 6, IgnoreCase = false }; List<string> wordList = Composer.Compose(wordPartSequence, wordExtractorSettings); // "be" will not prevent a match occuring between "befo" and "ul", even though "be" is a match. Assert.AreEqual(1, wordList.Count); Assert.AreEqual(wordList[0], "befoul"); }
public void EnsureOriginalCasingIsMaintainedInWordListReturned() { const string wordPartSequence = "ba Barely, sub, Lime, be, befoul, ly, re, foul, trinitY, neo, Sublime, trinit, y"; WordExtractorSettings wordExtractorSettings = new WordExtractorSettings { WordLength = 7, IgnoreCase = true }; List<string> wordList = Composer.Compose(wordPartSequence, wordExtractorSettings); // "trinitY" will be found since is it 7 char in length and casing is ignored Assert.AreEqual(2, wordList.Count); Assert.AreEqual(wordList[0], "trinitY"); // "Sublime" will be found since is it 7 char in length and casing is ignored Assert.AreEqual(wordList[1], "Sublime"); }