// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Spludlow { public class Variations { public Dictionary> WordVariations; public Variations(string[] definition) { this.WordVariations = new Dictionary>(); foreach (string line in definition) { string[] words = Spludlow.Text.Split(line, '\t', true); List list = new List(); foreach (string word in words) list.Add(word.ToLower()); this.WordVariations.Add(words[0], list); } List allList = new List(); foreach (string key in this.WordVariations.Keys) { foreach (string word in this.WordVariations[key]) { if (allList.Contains(word) == true) throw new ApplicationException("Word Variations; Duplicate word:\t" + word); allList.Add(word); } } } public string Match(string keyword) { string keywordLower = keyword.ToLower(); foreach (string key in this.WordVariations.Keys) { if (this.WordVariations[key].Contains(keywordLower) == true) return key; } return keywordLower; } } }