Tuesday, December 6, 2011

Search Algorithm


public class FuzzySearch
    {
        public static int LevenshteinDistance(string src, string dest)
        {
            int[,] d = new int[src.Length + 1, dest.Length + 1];
            int i, j, cost;
            char[] str1 = src.ToCharArray();
            char[] str2 = dest.ToCharArray();

            for (i = 0; i <= str1.Length; i++)
            {
                d[i, 0] = i;
            }
            for (j = 0; j <= str2.Length; j++)
            {
                d[0, j] = j;
            }
            for (i = 1; i <= str1.Length; i++)
            {
                for (j = 1; j <= str2.Length; j++)
                {

                    if (str1[i - 1] == str2[j - 1])
                        cost = 0;
                    else
                        cost = 1;

                    d[i, j] =
                        Math.Min(
                            d[i - 1, j] + 1,     // Deletion
                            Math.Min(
                                d[i, j - 1] + 1,    // Insertion
                                d[i - 1, j - 1] + cost));  // Substitution

                    if ((i > 1) && (j > 1) && (str1[i - 1] == str2[j - 2]) && (str1[i - 2] == str2[j - 1]))
                    {
                        d[i, j] = Math.Min(d[i, j], d[i - 2, j - 2] + cost);
                    }
                }
            }

            return d[str1.Length, str2.Length];
        }


        public static List<string> Search(string word, List<string> wordList, double fuzzyness)
        {
            
            //List<string> foundWords = new List<string>();

            //foreach (string s in wordList)
            //{
            //    // Calculate the Levenshtein-distance:
            //    int levenshteinDistance =
            //        LevenshteinDistance(word, s);

            //    // Length of the longer string:
            //    int length = Math.Max(word.Length, s.Length);

            //    // Calculate the score:
            //    double score = 1.0 - (double)levenshteinDistance / length;

            //    // Match?
            //    if (score > fuzzyness)
            //        foundWords.Add(s);
            //}

   // Tests have prove that the !LINQ-variant is about 3 times
   // faster!
   List<string> foundWords =(from s in wordList
     let levenshteinDistance = LevenshteinDistance(word, s)
     let length = Math.Max(s.Length, word.Length)
     let score = 1.0 - (double)levenshteinDistance / length
     where score > fuzzyness
     select s
    ).ToList();

            return foundWords;
        }

    }
 

Tuesday, October 4, 2011

Monday, September 19, 2011

Could not load file or assembly Microsoft.SqlServer.Management.Sdk.Sfc

This error comes when you are trying to access SQL 2005 stuff from Visual Studio 2008. Download the following stuff

Microsoft SQL Server System CLR Types
Microsoft SQL Server 2008 Management Objects
Microsoft SQL Server 2008 Native Client

Monday, September 12, 2011

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

This error came because, in my master page there was a java script function like below

document.getElementById("<%=lblShoppingCart.ClientID %>").style.color = "#6CA2DE"

I used <%# instead of using <%=. It's work fine.

Here some valuable links related to this topic.

http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/

http://www.west-wind.com/weblog/posts/2006/May/27/The-Controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie-

I Built a New Kind of Number Puzzle Game (And You Can Play It Free)

 For a long time, I wanted to play a mobile puzzle game that felt genuinely strategic—something that required real brainpower, skipped the a...