To import synonyms from a file, use the importDictionary method.
The following example demonstrates the use of methods of the synonym dictionary.
StringindexFolder="c:\\MyIndex\\";// Creating an index from in specified folder
Indexindex=newIndex(indexFolder);// Creating an index in memory with default synonym dictionary
Indexindex=newIndex();// Getting synonyms for word 'make'
String[]synonyms=index.getDictionaries().getSynonymDictionary().getSynonyms("make");System.out.println("Synonyms for 'make':");for(Stringsynonym:synonyms){System.out.println(synonym);}// Getting groups of synonyms to which word 'make' belongs to
String[][]groups=index.getDictionaries().getSynonymDictionary().getSynonymGroups("make");System.out.println("Synonym groups for 'make':");for(String[]group:groups){for(Stringgroup1:group){System.out.print(group1+" ");}System.out.println();}if(index.getDictionaries().getSynonymDictionary().getCount()>0){// Removing all synonyms from the dictionary
index.getDictionaries().getSynonymDictionary().clear();}// Adding synonyms to the dictionary
String[][]synonymGroups=newString[][]{newString[]{"achieve","accomplish","attain","reach"},newString[]{"accept","take","have"},};index.getDictionaries().getSynonymDictionary().addRange(synonymGroups);// Export synonyms to a file
index.getDictionaries().getSynonymDictionary().exportDictionary("C:\\Synonyms.dat");// Import synonyms from a file
index.getDictionaries().getSynonymDictionary().importDictionary("C:\\Synonyms.dat");
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: