Post Reply

[APP]Anagram (Word Finder) - Open Source

OP Nullstring

11th January 2010, 05:42 AM   |  #1  
Nullstring's Avatar
OP Recognized Developer
Flag Baguio
Thanks Meter: 240
 
1,170 posts
Join Date:Joined: Jul 2009
Donate to Me
More


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


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 Code:
// 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 wordstring separatorint 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(regexfalse);

                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(thisWordthisWord);
                            }
                        }
                    }

                    
ht_x nullht_y null;
                }
            }
            
#endregion

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

            
DateTime endTime DateTime.Now;

            
TimeSpan _duration endTime startTime;
            
ret = list.ToString();
            if (
ret != string.Empty) ret ret.Substring(0ret.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(c1);
                }
            }

            return 
ht;
        }

        protected 
Regex DoRegEx(string patternbool 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(regexoptions);
        }

        protected 
string[] Split(string sstring delimeter)
        {
            if (
== 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 == || sl == || sl dl)
                return new 
string[] { };

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

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

            
int start 0;
            for (
int i startsl dli++)
            {
                if (
>= start && dsum == ssum && s.Substring(idl) == delimeter)
                {
                    
retlist.Add(s.Substring(startstart));
                    
start dl;
                }

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

            if (
dsum == ssum && s.Substring(sl dldl) == delimeter)
            {
                
retlist.Add(s.Substring(startsl dl start));
                
retlist.Add("");
            }
            else
            {
                
retlist.Add(s.Substring(startsl 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; }
        }
    }

Attached Files
File Type: zip EnglishWords.zip - [Click for QR Code] (649.2 KB, 169 views)
File Type: zip FilipinoWords.zip - [Click for QR Code] (24.0 KB, 19 views)
Last edited by Nullstring; 19th January 2011 at 07:45 AM.
11th January 2010, 07:52 AM   |  #2  
Cassatta's Avatar
Member
Flag Coffrane / NE
Thanks Meter: 1
 
73 posts
Join Date:Joined: Apr 2007
More
Nice work!

Is it possible to have it in french?
11th January 2010, 10:56 AM   |  #3  
Nullstring's Avatar
OP Recognized Developer
Flag Baguio
Thanks Meter: 240
 
1,170 posts
Join Date:Joined: Jul 2009
Donate to Me
More
Quote:
Originally Posted by Cassatta

Nice work!

Is it possible to have it in french?

as long as you have a French word list, it'll be fine
12th January 2010, 12:32 AM   |  #4  
the0ne's Avatar
Senior Member
Flag Melbourne
Thanks Meter: 52
 
843 posts
Join Date:Joined: Jan 2007
More
nice app. have linked to it from here : 1800PocketPC
12th January 2010, 01:05 AM   |  #5  
Nullstring's Avatar
OP Recognized Developer
Flag Baguio
Thanks Meter: 240
 
1,170 posts
Join Date:Joined: Jul 2009
Donate to Me
More
Quote:
Originally Posted by the0ne

nice app. have linked to it from here : 1800PocketPC

thanks so much!
1st February 2010, 11:24 AM   |  #6  
harveydent's Avatar
Senior Member
Thanks Meter: 208
 
1,079 posts
Join Date:Joined: Feb 2009
More
Great app!

Where the hell did you get the Tagalog word list? (:
1st February 2010, 11:49 AM   |  #7  
Nullstring's Avatar
OP Recognized Developer
Flag Baguio
Thanks Meter: 240
 
1,170 posts
Join Date:Joined: Jul 2009
Donate to Me
More
Lightbulb
Quote:
Originally Posted by harveydent

Great app!

Where the hell did you get the Tagalog word list? (:

Well, you can't find it in hell

There's a lot of site providing Tagalog words.. and I put them all together then removed all duplicates and sorted them out using Excel.
10th August 2010, 11:13 AM   |  #8  
Junior Member
Thanks Meter: 0
 
13 posts
Join Date:Joined: Feb 2010
Nice App and Nice Title too
Last edited by naga01; 10th August 2010 at 11:20 AM.
9th January 2011, 03:28 PM   |  #9  
Nullstring's Avatar
OP Recognized Developer
Flag Baguio
Thanks Meter: 240
 
1,170 posts
Join Date:Joined: Jul 2009
Donate to Me
More
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!
The Following User Says Thank You to Nullstring For This Useful Post: [ View ]
19th January 2011, 07:29 AM   |  #10  
darthnol's Avatar
Junior Member
Flag Bulacan, Philippines
Thanks Meter: 1
 
10 posts
Join Date:Joined: May 2010
More
Kabayan, thanks for sharing this great app.

Post Reply Subscribe to Thread

Tags
anagram
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes