[APP]Anagram (Word Finder) - Open Source

Search This thread

Nullstring

Retired Recognized Developer
Jul 15, 2009
1,177
245
Baguio
www.jaysonragasa.net
image_thumb%5B2%5D.png
image_thumb%5B2%5D.png


Desktop version is faster than the Mobile version

This is a ported version of my Anagram Desktop version found here.

Using Regular Expression, RE, or RegEx. Though not purely RegEx way .. it has some help of Hashtable and StringBuilder for counting characters (which is MY WAY of counting characters) and appending the words found.

Anyway, at the left .. is the screenshot of the application (click to view larger version). If you noticed, I used “regular expression” as my word.. This is pretty much of a Beta version so.. it might hang your device for sometime (the search is taking too much time)

You can use this app on your scrabble game!

look at the total result.
1,905 words found in 1 minute and 16 seconds and I have total of 192,719 English words in textfile. Am not sure if that’s fast enough .. am using Xperia X1 device. Here’s the specs of this device. Desktop version is much faster. Look here

arrow_thumb%5B6%5D.png

Download here

How To Use
1. After downloading AnagramMobile.rar and extracting the .exe file in your device. Download english.txt or tagalog.txt.

2. Run the application and tap Open and select english.txt or tagalog.txt file in Open Window.

3. Wait for a few seconds or a minute to load the word list.

4. Enter word, a sentence, or a jumbled letters in “Enter word or sentence here” box

5. and click Find.

6. and wait for the results.

Code Snippet for Finder Class 3.
Fast string concatenation using StringBuilder.
Duplicates problem solved using Hashtable.

Methods
OpenWordDatabaseTextFile(string filename)
Find(string word, string separator, int min)
CountCharacters(string str)
DoRegEx(string pattern, bool UseAllRegexOptionFlag)
string[] Split(string s, string delimeter)

Properties
string TimeDuration
int TotalFound
int TotalWordsFoundInDatabase

PHP:
// Finder Class version 3
// Author: Jayson Ragasa, December 22, 2009
// Copyright© 2009 Jayson Ragasa, Baguio City, Philippines

namespace Anagram
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;

    public class Finder
    {
        string _time_duration = string.Empty;
        int _ttl_found = 0;
        int _ttl_words_in_database = 0;
        string new_line_separated_words = string.Empty;

        public Finder() { }

        public void OpenWordDatabaseTextFile(string filename)
        {
            using (System.IO.StreamReader reader = new System.IO.StreamReader(filename))
            {
                new_line_separated_words = reader.ReadToEnd();
            }

            //_ttl_words_in_database = new_line_separated_words.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length;
            _ttl_words_in_database = Split(new_line_separated_words, "\r\n").Length;
        }

        public string Find(string word, string separator, int min)
        {
            string ret = string.Empty;

            StringBuilder list = new StringBuilder();

            string regex = "^[" + word + " ]+\\r\\n";

            DateTime startTime = DateTime.Now;

            Hashtable words = new Hashtable();
            IDictionaryEnumerator ide;

            #region start
            {
                Regex r = DoRegEx(regex, false);

                if (r.IsMatch(new_line_separated_words))
                {
                    Hashtable ht_x;
                    Hashtable ht_y;

                    bool notValid = false;

                    MatchCollection mc = r.Matches(new_line_separated_words);

                    foreach (Match m in mc)
                    {
                        string w = m.Value.Trim();

                        if (w.Length >= min)
                        {
                            ht_x = CountCharacters(m.Value.Trim());
                            ht_y = CountCharacters(word.Trim());

                            notValid = false;

                            ide = ht_x.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                if (Convert.ToInt32(ht_x[ide.Key]) > Convert.ToInt32(ht_y[ide.Key]))
                                {
                                    notValid = true;
                                }
                            }

                            if (notValid) { continue; }

                            string thisWord = m.Value.Replace("\r\n", string.Empty);
                            thisWord = thisWord.Trim();

                            // don't add the word if the word already exists
                            // in hashtable
                            if (!words.ContainsKey(thisWord))
                            {
                                words.Add(thisWord, thisWord);
                            }
                        }
                    }

                    ht_x = null; ht_y = null;
                }
            }
            #endregion

            #region build result
            {
                ide = words.GetEnumerator();
                while (ide.MoveNext())
                {
                    list.AppendFormat("{0}" + separator, ide.Value);
                }
            }
            #endregion

            DateTime endTime = DateTime.Now;

            TimeSpan _duration = endTime - startTime;
            ret = list.ToString();
            if (ret != string.Empty) ret = ret.Substring(0, ret.Length - separator.Length);
            this._time_duration = _duration.ToString();
            this._ttl_found = words.Count;

            return ret;
        }

        // Count instance of a character in a string
        protected Hashtable CountCharacters(string str)
        {
            Hashtable ht = new Hashtable();

            char[] a_chars = str.ToCharArray();

            foreach (char c in a_chars)
            {
                if (ht.ContainsKey(c))
                {
                    ht[c] = (Convert.ToInt32(ht[c]) + 1).ToString();
                }
                else
                {
                    ht.Add(c, 1);
                }
            }

            return ht;
        }

        protected Regex DoRegEx(string pattern, bool UseAllRegexOptionFlag)
        {
            string regex = pattern;

            RegexOptions options;

            if (UseAllRegexOptionFlag)
            {
                options = (((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Singleline) | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            }
            else
            {
                options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) | RegexOptions.IgnoreCase);
            }

            return new Regex(regex, options);
        }

        protected string[] Split(string s, string delimeter)
        {
            if (s == null)
                throw new ArgumentNullException("stringToBeSplitted is null.");
            if (delimeter == null)
                throw new ArgumentNullException("delimeter is null.");

            int dsum = 0;
            int ssum = 0;
            int dl = delimeter.Length;
            int sl = s.Length;

            if (dl == 0 || sl == 0 || sl < dl)
                return new string[] { s };

            char[] cd = delimeter.ToCharArray();
            char[] cs = s.ToCharArray();
            List<string> retlist = new List<string>();

            for (int i = 0; i < dl; i++)
            {
                dsum += cd[i];
                ssum += cs[i];
            }

            int start = 0;
            for (int i = start; i < sl - dl; i++)
            {
                if (i >= start && dsum == ssum && s.Substring(i, dl) == delimeter)
                {
                    retlist.Add(s.Substring(start, i - start));
                    start = i + dl;
                }

                ssum += cs[i + dl] - cs[i];
            }

            if (dsum == ssum && s.Substring(sl - dl, dl) == delimeter)
            {
                retlist.Add(s.Substring(start, sl - dl - start));
                retlist.Add("");
            }
            else
            {
                retlist.Add(s.Substring(start, sl - start));
            }

            return retlist.ToArray();
        }

        public string TimeDuration
        {
            get { return _time_duration; }
        }

        public int TotalFound
        {
            get { return _ttl_found; }
        }

        public int TotalWordsFoundInDatabase
        {
            get { return this._ttl_words_in_database; }
        }
    }
}
 

Attachments

  • EnglishWords.zip
    649.2 KB · Views: 187
  • FilipinoWords.zip
    24 KB · Views: 33
Last edited:

Nullstring

Retired Recognized Developer
Jul 15, 2009
1,177
245
Baguio
www.jaysonragasa.net
Am not getting any notifications from XDA about what's happening on my threads. So if you guys having some problems on my apps and not getting any support from me. Am so sorry.

This post will server as a Wake Up Thread!
 
  • Like
Reactions: darthnol

jjollyroger

Senior Member
Dec 5, 2009
896
188
hi, here's an italian words list
the app works good on PC but on my HD2 crashes each time I try to open a dictionary ,it looks like it does not support a large txt file on WM
could it be fixed?
 
Last edited:
  • Like
Reactions: Nullstring

Fresher8

Member
Apr 17, 2020
11
0
Thanks for sharing the app and the English word lists! Seems to me like you could improve performance greatly by using a database instead of loading the words directly from the word file. For better speed you could even compile several word files and order words by what letter they are starting with.

Scrabble actually has it's own dictionaries on what words are allowed. To unscramble words I have been using this word search for Scrabble.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Am not getting any notifications from XDA about what's happening on my threads. So if you guys having some problems on my apps and not getting any support from me. Am so sorry.

    This post will server as a Wake Up Thread!
    1
    hi, here's an italian words list
    the app works good on PC but on my HD2 crashes each time I try to open a dictionary ,it looks like it does not support a large txt file on WM
    could it be fixed?