So basically I have this loop where every sentence in the processedSentencesList gets iterated and checked for words that exist in the entityString list. And each String entity found in each sentence is added to var valid_words.
But the entities "Harry Potter" and "Ford Card" are not added due to the sentence "sentence .Split ()".
How can I change this code so that existing objects with spaces are not divided into two words?
List <string> entityString = new List<string>();
entityString.Add("Harry Potter");
entityString.Add("Ford Car");
entityString.Add("Broom");
entityString.Add("Ronald");
List <string> processedSentencesList = new List<string>();
processedSentencesList.Add("Harry Potter is a wizard");
processedSentencesList.Add("Ronald had a Broom and a Ford Car");
foreach (string sentence in processedSentencesList)
{
var words = sentence.Split(" ".ToCharArray());
var valid_words = words.Where(w =>
entityStrings.Any(en_li => en_li.Equals(w)));
}
When it prints, I get the output right now:
Broom
Ronald
The result that I expect:
Harry Potter
Ford car
Broom
Ronald
In principle, objects with spaces between (2 or more words) are separated and therefore cannot be matched with existing objects. How to fix it?