Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,801 Members 44,284 Now Online
XDA Developers Android and Mobile Development Forum

[APP]Anagram (Word Finder) - Open Source

Tip us?
 
Nullstring
Old
(Last edited by Nullstring; 19th January 2011 at 07:45 AM.)
#1  
Nullstring's Avatar
Recognized Developer - OP
Thanks Meter 239
Posts: 1,170
Join Date: Jul 2009
Location: Baguio

 
DONATE TO ME
Smile [APP]Anagram (Word Finder) - Open Source



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, 165 views)
File Type: zip FilipinoWords.zip - [Click for QR Code] (24.0 KB, 17 views)


Gambit Mobile Applications for Windows Phone 7

-


 
Cassatta
Old
#2  
Cassatta's Avatar
Member
Thanks Meter 1
Posts: 73
Join Date: Apr 2007
Location: Coffrane / NE
Nice work!

Is it possible to have it in french?
Alain Berger
CH-2207 Coffrane / NE

Samsung Galaxy GT NT7000

No is a loss of time !
 
Nullstring
Old
#3  
Nullstring's Avatar
Recognized Developer - OP
Thanks Meter 239
Posts: 1,170
Join Date: Jul 2009
Location: Baguio

 
DONATE TO ME
Quote:
Originally Posted by Cassatta View Post
Nice work!

Is it possible to have it in french?
as long as you have a French word list, it'll be fine
 
the0ne
Old
#4  
the0ne's Avatar
Senior Member
Thanks Meter 52
Posts: 843
Join Date: Jan 2007
Location: Melbourne
nice app. have linked to it from here : 1800PocketPC
---

Windows Phone Apps || Windows Phone Games --- want to review apps and game for windows phone and get paid for it ? Get it touch



---
 
Nullstring
Old
#5  
Nullstring's Avatar
Recognized Developer - OP
Thanks Meter 239
Posts: 1,170
Join Date: Jul 2009
Location: Baguio

 
DONATE TO ME
Quote:
Originally Posted by the0ne View Post
nice app. have linked to it from here : 1800PocketPC
thanks so much!
 
harveydent
Old
#6  
harveydent's Avatar
Senior Member
Thanks Meter 208
Posts: 1,079
Join Date: Feb 2009
Great app!

Where the hell did you get the Tagalog word list? (:
 
Nullstring
Old
#7  
Nullstring's Avatar
Recognized Developer - OP
Thanks Meter 239
Posts: 1,170
Join Date: Jul 2009
Location: Baguio

 
DONATE TO ME
Quote:
Originally Posted by harveydent View Post
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.
 
naga01
Old
(Last edited by naga01; 10th August 2010 at 11:20 AM.)
#8  
Junior Member
Thanks Meter 0
Posts: 13
Join Date: Feb 2010
Nice App and Nice Title too
 
Nullstring
Old
#9  
Nullstring's Avatar
Recognized Developer - OP
Thanks Meter 239
Posts: 1,170
Join Date: Jul 2009
Location: Baguio

 
DONATE TO ME
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!


Gambit Mobile Applications for Windows Phone 7

-


The Following User Says Thank You to Nullstring For This Useful Post: [ Click to Expand ]
 
darthnol
Old
#10  
darthnol's Avatar
Junior Member
Thanks Meter 1
Posts: 10
Join Date: May 2010
Location: Bulacan, Philippines
Kabayan, thanks for sharing this great app.

Tags
anagram
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Enjoy Wallpaper Overload with PhotoPhase

We don’t usually feature live wallpapers on the XDA Portal unless they are somewhat innovative … more

Monitor What Your Phone’s Camera Sees with Android Wear

Having a smart device strapped to your wrist certainly has its merits. A … more

Mod Lets You Have Stereo Speakers on Your Sony Xperia Z1 (Sort Of)

The stereo speakers onthe Sony Xperia Z2areprobably a relatively large … more

Give Your Screen Some Color with HexaTime Live Wallpaper

We don’t often cover very many live wallpapers here on the XDA Portal. You may … more