### Perform Word Segmentation and Correction in C# Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This example demonstrates how to use SymSpell's `WordSegmentation` method to split and correct multi-word input strings, even those without spaces. It takes an input string and an edit distance, then outputs the corrected string and the total edit distance for the segmentation. ```csharp //word segmentation and correction for multi-word input strings with/without spaces inputTerm="thequickbrownfoxjumpsoverthelazydog"; maxEditDistance = 0; suggestion = symSpell.WordSegmentation(input); //display term and edit distance Console.WriteLine(suggestion.correctedString + " " + suggestion.distanceSum.ToString("N0")); //press any key to exit program Console.ReadKey(); ``` -------------------------------- ### Initialize SymSpell and Load Unigram Dictionary in C# Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This snippet demonstrates how to initialize the SymSpell object with a specified capacity and maximum edit distance for dictionary precalculation. It then proceeds to load a unigram frequency dictionary from a file, specifying the columns for the term and count. Error handling for file not found is included. ```csharp //create object int initialCapacity = 82765; int maxEditDistanceDictionary = 2; //maximum edit distance per dictionary precalculation var symSpell = new SymSpell(initialCapacity, maxEditDistanceDictionary); //load dictionary string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string dictionaryPath= baseDirectory + "../../../../SymSpell/frequency_dictionary_en_82_765.txt"; int termIndex = 0; //column of the term in the dictionary text file int countIndex = 1; //column of the term frequency in the dictionary text file if (!symSpell.LoadDictionary(dictionaryPath, termIndex, countIndex)) { Console.WriteLine("File not found!"); //press any key to exit program Console.ReadKey(); return; } ``` -------------------------------- ### SymSpell Project License and Metadata Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This snippet provides the copyright, version, author, maintainer, URL, and description for the SymSpell project, along with the full MIT License text. It outlines the permissions and limitations for using, modifying, and distributing the software. ```Text Copyright (c) 2025 Wolf Garbe Version: 6.7.3 Author: Wolf Garbe Maintainer: Wolf Garbe URL: https://github.com/wolfgarbe/symspell Description: https://seekstorm.com/blog/1000x-spelling-correction/ MIT License Copyright (c) 2025 Wolf Garbe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. https://opensource.org/licenses/MIT ``` -------------------------------- ### SymSpell Frequency Dictionary File Format Specification Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This specification describes the required format for plain text frequency dictionary files used by SymSpell. It details encoding, column structure, line termination, and case sensitivity, allowing for flexible integration with existing data sources. ```APIDOC SymSpell Frequency Dictionary File Format: Encoding: - Plain text file in UTF-8 encoding. Structure: - Word and Word Frequency are separated by space or tab. - Default column order: word in the first column, frequency in the second column. - Configurable: `termIndex` and `countIndex` parameters in `LoadDictionary()` allow changing the position and order of values, supporting rows with more than two values. Line Endings: - Every word-frequency-pair in a separate line. - A line is defined as a sequence of characters followed by: - Line feed ("\n") - Carriage return ("\r") - Carriage return immediately followed by line feed ("\r\n") Case Sensitivity: - Both dictionary terms and input terms are expected to be in **lower case**. ``` -------------------------------- ### Load Bigram Dictionary and Perform Multi-Word Spell Correction in C# Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This snippet illustrates loading a bigram frequency dictionary to enhance spell correction for multi-word inputs. It then uses the `LookupCompound` method to correct and split compound words, specifying the maximum edit distance per single word within the compound. The corrected terms, their distances, and frequencies are printed. ```csharp //load bigram dictionary string dictionaryPath= baseDirectory + "../../../../SymSpell/frequency_bigramdictionary_en_243_342.txt"; int termIndex = 0; //column of the term in the dictionary text file int countIndex = 2; //column of the term frequency in the dictionary text file if (!symSpell.LoadBigramDictionary(dictionaryPath, termIndex, countIndex)) { Console.WriteLine("File not found!"); //press any key to exit program Console.ReadKey(); return; } //lookup suggestions for multi-word input strings (supports compound splitting & merging) inputTerm="whereis th elove hehad dated forImuch of thepast who couqdn'tread in sixtgrade and ins pired him"; maxEditDistanceLookup = 2; //max edit distance per lookup (per single word, not per whole input string) suggestions = symSpell.LookupCompound(inputTerm, maxEditDistanceLookup); //display suggestions, edit distance and term frequency foreach (var suggestion in suggestions) { Console.WriteLine(suggestion.term +" "+ suggestion.distance.ToString() +" "+ suggestion.count.ToString("N0")); } ``` -------------------------------- ### Perform Single-Word Spell Correction Lookup in C# Source: https://github.com/wolfgarbe/symspell/blob/master/README.md This code shows how to use the initialized SymSpell object to look up suggestions for a single input term. It specifies the maximum edit distance for the lookup and the verbosity level for suggestions (e.g., Closest). The results, including the suggested term, edit distance, and term frequency, are then displayed. ```csharp //lookup suggestions for single-word input strings string inputTerm="house"; int maxEditDistanceLookup = 1; //max edit distance per lookup (maxEditDistanceLookup<=maxEditDistanceDictionary) var suggestionVerbosity = SymSpell.Verbosity.Closest; //Top, Closest, All var suggestions = symSpell.Lookup(inputTerm, suggestionVerbosity, maxEditDistanceLookup); //display suggestions, edit distance and term frequency foreach (var suggestion in suggestions) { Console.WriteLine(suggestion.term +" "+ suggestion.distance.ToString() +" "+ suggestion.count.ToString("N0")); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.