Synonym dictionary

The SynonymDictionary class is designed to store synonyms in an index. For information on searching using synonyms, see the Synonym search page.

To get the number of synonyms in the dictionary, use the getCount method.

To add groups of synonyms to the dictionary, use the addRange method.

The clear method is used to remove all synonyms from the dictionary.

The getSynonyms method is used to get a list of synonyms for a given word.

The getSynonymGroups method is used to get all synonym groups to which a given word belongs.

To get all synonym groups from the dictionary, use the getAllSynonymGroups method.

To export synonyms to a file, use the exportDictionary method.

To import synonyms from a file, use the importDictionary method.

The following example demonstrates the use of methods of the synonym dictionary.

String indexFolder = "c:\\MyIndex\\";

// Creating an index from in specified folder
Index index = new Index(indexFolder);

// Creating an index in memory with default synonym dictionary
Index index = new Index();

// Getting synonyms for word 'make'
String[] synonyms = index.getDictionaries().getSynonymDictionary().getSynonyms("make");
System.out.println("Synonyms for 'make':");
for (String synonym : 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 (String group1 : 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 = new String[][] {
    new String[] { "achieve", "accomplish", "attain", "reach" },
    new String[] { "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:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.