NamedEntityExtractorSK.Finder.Search C# (CSharp) Method

Search() private method

Search word by input
private Search ( string word, int take = 2 ) : string
word string
take int
return string
		private string Search(string word, int take = 2)
		{
			double minimalSimilarity = 0.7;

			var p = GetMatches(word, take).ToList();
			var mostSimilary = p.Where(x => x.Item2 > 0.99);

			//if some word has similarity > 99%
			if (mostSimilary.Any())
			{
				var winner = mostSimilary.GroupBy(x => x.Item3).ToDictionary(group => group.Key, group => group.ToList())
					.Select(val => new
					{
						Similarity = val.Value.Sum(v => v.Item2),
						Text = string.Format("'{0}' is {1}", word, Enum.GetName(typeof(NamedEntityType), val.Key))
					});

				var max = winner.Max(x => x.Similarity);

				//write output 
				return "Words with 100% similarity:\n" + winner.Where(x => x.Similarity == max).Select(x => x.Text).Aggregate((a, b) => a + "\n" + b);
			}

			//if some word has similarity >= 70%
			if (p.Any(x => x.Item2 >= minimalSimilarity))
			{
				return p.Where(x => x.Item2 >= minimalSimilarity).Select(x => x.Item1).Aggregate((a, b) => a + "\n" + b);
			}
			else
			{
				//No match
				return "Nothing found (with similarity >= 70%)! The most likely word is:\n" + p.FirstOrDefault().Item1;
			}
		}