The HomophoneDictionary class is designed to store homophones in an index. For information on searching using homophones, see the Homophone search page.
To get the number of homophones in the dictionary, use the Count property.
To add groups of homophones to the dictionary, use the AddRange method.
The Clear method is used to remove all homophones from the dictionary.
The GetHomophones method is used to get a list of synonyms for a given word.
The GetHomophoneGroups method is used to get all synonym groups to which a given word belongs.
To get all synonym groups from the dictionary, use the GetAllHomophoneGroups method.
To export homophones to a file, use the ExportDictionary method.
To import homophones from a file, use the ImportDictionary method.
The following example demonstrates the use of methods of the homophone dictionary.
C#
stringindexFolder=@"c:\MyIndex\";// Creating an index from in specified folderIndexindex=newIndex(indexFolder);// Getting homophones for word 'braid'string[]homophones=index.Dictionaries.HomophoneDictionary.GetHomophones("braid");Console.WriteLine("Homophones for 'braid':");for(inti=0;i<homophones.Length;i++){Console.WriteLine(homophones[i]);}// Getting groups of homophones to which word 'braid' belongs tostring[][]groups=index.Dictionaries.HomophoneDictionary.GetHomophoneGroups("braid");Console.WriteLine("Homophone groups for 'braid':");for(inti=0;i<groups.Length;i++){string[]group=groups[i];for(intj=0;j<group.Length;j++){Console.Write(group[j]+" ");}Console.WriteLine();}if(index.Dictionaries.HomophoneDictionary.Count>0){// Removing all homophones from the dictionaryindex.Dictionaries.HomophoneDictionary.Clear();}// Adding homophones to the dictionarystring[][]homophoneGroups=newstring[][]{newstring[]{"awe","oar","or","ore"},newstring[]{"aye","eye","i"},};index.Dictionaries.HomophoneDictionary.AddRange(homophoneGroups);// Export homophones to a fileindex.Dictionaries.HomophoneDictionary.ExportDictionary(@"C:\Homophones.dat");// Import homophones from a fileindex.Dictionaries.HomophoneDictionary.ImportDictionary(@"C:\Homophones.dat");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: