private bool IsUsing(Term term, string text) { if (term.IsFullMatch) { return(text.Contains(term.Name)); } var seperators = new Regex("[.,?!:;'\"_@#$%^&*=+()\\[\\]{}~\t\n-]"); var length = term.Name.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length; var descript = seperators.Replace(text, " "); var words = descript.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < words.Length - length; i++) { var item = words[i]; for (int j = i + 1; j < length; j++) { item += " " + words[j]; } var value = _wordComparison.Compare(term.Name, item); if (_wordComparison.IsSatisfy(value)) { return(true); } } return(false); }
private bool IsUsing(Term term, Term description) { if (term.IsFullMatch) { return(description.Description.Contains(term.Name)); } var length = term.Name.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length; var descript = seperators.Replace(description.Description, " "); var words = descript.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < words.Length - length; i++) { var item = words[i]; for (int j = i + 1; j < length; j++) { item += " " + words[j]; } var value = _wordComparison.Compare(term.Name, item); if (_wordComparison.IsSatisfy(value)) { return(true); } } return(false); }
private async Task <string> IndexDescription(Term term, IEnumerable <Term> relatedTerms) { var output = term.Description; var description = _seperators .Replace(term.Description, " ") .Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var item in relatedTerms) { var length = item.Name.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length; var words = new List <string>(); for (int i = 0; i < description.Length - length; i++) { var word = string.Join(" ", description.Skip(i).Take(length)); if (item.IsFullMatch) { if (item.Name == word) { words.Add(word); } } else { var value = _wordComparison.Compare(item.Name, word); if (_wordComparison.IsSatisfy(value)) { words.Add(word); } } } foreach (var word in words) { output = output.Replace(word, $"<term id=\"{item.Id}\">" + word + "</term>"); } } var termRegex = new Regex(@"(<term id=""\d+"">)+"); var termEndRegex = new Regex(@"(</term>)+"); var idRegex = new Regex(@"\d+"); output = termEndRegex.Replace(output, "</term>"); output = termRegex.Replace(output, v => { var ids = idRegex.Matches(v.Value); var idsString = string.Join(", ", ids.Select(s => s.Value)); return($"<term id=\"{idsString}\">"); }); return(output); }