spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Get words from a given word collection for proofreading


There are many algorithms available on internet that check similarity between two words. GetEdits is one of them.

The following code can be used. However it may not be very efficient.

static int GetEdits(string answer,
string guess)
{
    guess = guess.ToLower();
    answer = answer.ToLower();

    int[,] d = new int[answer.Length + 1,
guess.Length + 1];
    for (int i = 0; i <= answer.Length; i++)
        d[i, 0] = i;
    for (int j = 0; j <= guess.Length; j++)
        d[0, j] = j;
    for (int j = 1; j <= guess.Length; j++)
        for (int i = 1; i <= answer.Length;
i++)
            if (answer[i - 1] == guess[j - 1])
                d[i, j] = d[i - 1, j - 1];  //no
operation
            else
                d[i, j] = Math.Min(Math.Min(
                    d[i - 1, j] + 1,    //a
deletion

                    d[i, j - 1] + 1),   //an
insertion

                    d[i - 1, j - 1] + 1 //a
substitution

                );
    return d[answer.Length, guess.Length];
}

static void Main(string[] args)
{
    const string text = @"lorem ipsum is simply
dummy text of the printing and typesetting
industry. Loren Ipsum has been the industrys
standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and
scrambled it to make a type specimen book. It has
survived not only five centuries, but also the
leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the
1960s with the release of Letraset sheets
containing LorenIpsum passages, and more recently
with desktop publishing software like Aldus
PageMaker including versions of LoremIpsum.";

    var findWords = new string[]
    {
        "Lorem Ipsum",
        "Centuries",
        "Electronic"
    };

    const int MaxErrors = 2;

    // Tokenize text
    var tokens = text.Split(' ', ',' , '.');

    for (int i = 0; i < tokens.Length; i++)
    {
        if( tokens[i] != String.Empty)
        {
            foreach (var findWord in findWords)
            {
                if (GetEdits(findWord, tokens[i])
<= MaxErrors)
                {
                    Console.WriteLine(tokens[i]);
                    break;
                }
                // Join with the next word and
check again.
                else if(findWord.Contains(' ')
&& i + 1 < tokens.Length)
                {
                    string token = tokens[i] + " "
+ tokens[i + 1];
                    if (GetEdits(findWord, token)
<= MaxErrors)
                    {
                        Console.WriteLine(token);
                        i++;
                        break;
                    }
                }
            }
        }
    }
}

Categories : C#

Related to : Get words from a given word collection for proofreading
Filter words of a collection by characters typed in text box and show the resulting words in a listbox
The problem is that you're checking if the entire search string matches a key in the dictionary, where you actually only wanted to find words that start with the search text. You can do the following in your searchBox_TextChanged handler ising linq. // Get the words in the dictionary starting with the textbox text. var matching = sortedDic.Keys.Where(x => x.StartsWith(searchText.Text)).ToList

Categories : C#
Enhance my RegEx for proofreading
(?:"|'(?!s|s)|“)[^"'“”]+(?:"|'(?!s)|”) Try this.See demo. http://regex101.com/r/yP3iB0/13

Categories : C#
For Garbage Collection is it good idea that if we make object as null and clear collection after use at the end of method
It does not make a difference to garbage collection. Once your method is over and no more references to object/collection exists GC will be able to clean them. It does not make a difference if object/collection become inaccessible because you nulled a reference or method which locally hold last reference has finished.

Categories : Java
Copying collection A to collection B with including collections A's sub classes ? For taking online orders. Java
Maybe you are looking something like this: public class Order<T extends Product> { List<T> products; public void add(T productItem) { } } public class ComputerOrder extends Order<ComputerPart> { //I think, you don't need collection of ComputerParts here, cause you have it in the parent class //Maybe you either don't need method like addDrive — you can us

Categories : Java
Is it possible to create a backbone collection view without Collection instance
Short answer is No Standard Collection View work flow: Collection view iterate over collection. On every iteration instancing new ModelView and provide iteration model as data and delegate render to ModelView instance. ModelView instance render data and keeps template. So u have to keep collection to iterate with of replace it with something else to iterate with.

Categories : Backbone Js
Recently Add
How to call a method in .cs file which was implemented in code behind?
How To Prevent $variables In Restangular Post Request
Windows Phone 8 VoIP SIP Provider
How do we set the AutoCAD layer viewport override values
Load Dependent DLL using reflection
The code is not showing any error but still not displaying data on the datagrid of webform.?
Make an Image that can be flipped over in Unity 4.6
Storing JSON REST response in object
which is more efficient in conditional looping?
WebBrowser control's shortcut keys are not working
C# SQL INSERT not appearing in database table "no errors or exceptions thrown"
c# winfrom treeview class binding
How to Convert string "00h:03m:30s:793ms" to TimeSpan in c#
Calling a parameterized Stored Procedure that returns a value in C#
How to use the SQL statement to transform the data from row record to column record
How to Instantiate Enemy Prefabs Without Knowing the Name
MVC JQuery unobtrusive validation
How to draw at top left of metaFile
How to make Aggregate Root method only accessible for a Domain Event and nothing else.
how to create a list of lists from one list using LINQ?
Ignore user roles in ASP .Net MVC 5 Identity
Xpath Web scrape
add property to interface
How can I make controls added to existing mark-up be automatically hooked up to the code behind?
Too much data in C# windows form combobox, taking 30 sec to show the windows form
Creating a scrolling grid of images using WPF and XAML
PHP equivalent to asp.net routing
LINQ aggregate query
Custom Control won't fill dock correctly
Get ASP.NET Identity Current User In View
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.