PDA

View Full Version : Flash dictionary


EightySeven
11-11-2008, 03:24 AM
I was wondering if there was a flash dictionary out there I could use.

I need one where i can check a person's input to see if it is an actual word in the English language. Book Worm style

fitz
11-11-2008, 02:21 PM
Is this for a book worm type clone? If you go to tabbyware.com and download Textris (a game I made years and years ago), extract it, in a sub directory labeled dictionary (I think), you'll find lists of 3,4,5,6,6+ (I think, again lol) words that are primed up for that type of application. You would just need to make a class in flash for reading in the lists, then depending on how long the word is, check the appropriate list (faster than checking one master list). There are no swears in the lists either. This is something I want to do also once I finish my current project, so let me know how it goes if you go that route.

-fitz

EightySeven
11-15-2008, 03:25 AM
Thanks man, I didn't take your code I've enlisted the help of some friends and we're each gonna take a section of the dictionary :P

EDIT: I just dled ur code to peek at ur lists and I donno how to extract the words from your .LST file

What I'm trying to do is make a single player scrabble-esk game.

I was putting it off because well I was feeling uninspired lately but i got a good jolt today.

I'm basicly gonna make a class that takes in 7 characters and looks for words in the word list we make from the dictionary. all words 3-7 letters.

function check4words(a, b, c, d, e, f, g:String){
var newString:String = a+b+c+d+e+f+g;
for (var i:int; i < newString.length; i++){
if (newString.charAt(i) == "@"){//Where @ will be used as a null
newString = newString.slice(0, i);
}
}

if (newString is in my wordlist){
return true;
}
}

Any ideas how I might make this modular for peoples in future use? I'd hate to do all this work to not make it available to people who might want it

fitz
11-17-2008, 05:10 PM
I wasn't certain what you want your check4words function to do, but I took it as just checking to see if a word was on the world list or not (like a scrabble challenge).

But in either case, below is how you would load my file (you can just delete words > 7 letters from the file).

Loading it all into 1 flat array might yield slow results, so I broke it down by number of letters and starting letter. This makes the search pretty quick since as you can see in checkForWords, I actually use the length of the word and the starting letter to fill out the subscripts on the multi-dimensional array.

P.s. use my list, it's not code, just a list. you'd be silly not to :)


var Words : Array = new Array();

var theLoader = new URLLoader();
var theRequest = new URLRequest('WORD.LST');
theLoader.load(theRequest);
theLoader.addEventListener(Event.COMPLETE, loadComplete);

function trim(str:String):String
{
for(var i = 0; str.charCodeAt(i) < 33; i++);
for(var j = str.length-1; str.charCodeAt(j) < 33; j--);
return str.substring(i, j+1);
}

function loadComplete(e : Event):void
{
var arr = e.target.data.split('\n');

for (var i = 0; i < arr.length; i ++)
{
var word = trim(arr[i]);
var wordlen = word.length;
var firstletter : String = word.charAt(0);
if (Words[wordlen] == null) Words[wordlen] = new Array();
if (Words[wordlen][firstletter] == null) Words[wordlen][firstletter] = new Array();

Words[wordlen][firstletter].push(word);

if ((i % 1000) == 0)
trace('Loading list..' + Math.round((i / arr.length) * 100) + '%');

}

trace(check4words('Bar', Words));
trace(check4words('Smoking', Words));
trace(check4words('Hollar', Words));
trace(check4words('Braggin', Words));
}


function check4words(word : String, list : Array):Boolean
{
var word = word.toUpperCase();

for (var i:int; i < word.length; i++)
{
if (word.charAt(i) == "@")
{
word = word.slice(0, i);
}
}

var wordlen = word.length;
var firstletter = word.charAt(0);

for (var i = 0; i < list[wordlen][firstletter].length; i++)
{
if (list[wordlen][firstletter][i] == word)
{
return true;
}
}
return false;
}

rrh
11-17-2008, 09:23 PM
Woah, that'll be big and unweildly. I wouldn't store the full string in the array like that, and loop through the array.

I would either make the word storage an object and use the string as the index, like so:
if (wordObject[word] == true)

or maybe make a whole tree structure, where each node has up to 26 children, and you test it like so:
public class dictTree {
private var children:Array;
private var isWord:Boolean=false;
public function dictTree() {
//fill children with 26 nulls
}
public function addWord(s:String):void {
//if s is empty, set isWord=true
//if child corresponding with first letter of s does not exist
//then create it
//strip the first letter from s
//call child.addWord(s)
}
public function testWord(s:String):Boolean {
//if s is empty, return isWord
//strip the first letter from s
//find child corresponding with first letter
//call child.addWord(s)
}
}

But try the way with just an object first, because they would hopefully access objects as efficiently as any tree structure I could come up with with a lot less trouble.

fitz
11-18-2008, 03:04 PM
Ah yes, I still forget sometimes you can do that with AS. But unless you're making a ton of checks you probably won't notice a difference. But it looks a hell of a lot better :) Here's the updated code using the word as the array/object subscript. Indeed, testing for null on words[word] works just fine.


var Words : Array = new Array(); // Or Object(), work the same.

var theLoader = new URLLoader();
var theRequest = new URLRequest('WORD.LST');
theLoader.load(theRequest);
theLoader.addEventListener(Event.COMPLETE, loadComplete);

function trim(str:String):String
{
for(var i = 0; str.charCodeAt(i) < 33; i++);
for(var j = str.length-1; str.charCodeAt(j) < 33; j--);
return str.substring(i, j+1);
}

function loadComplete(e : Event):void
{
var arr = e.target.data.split('\n');

for (var i = 0; i < arr.length; i ++)
{
var word = trim(arr[i]);
var wordlen = word.length;
Words[word] = true;

if ((i % 1000) == 0)
trace('Loading list..' + Math.round((i / arr.length) * 100) + '%');

}

trace(check4words('Bar', Words));
trace(check4words('Smoking', Words));
trace(check4words('Hollar', Words));
trace(check4words('Braggin', Words));
}


function check4words(word : String, list : Array):Boolean
{
var word = word.toUpperCase();

for (var i:int; i < word.length; i++)
{
if (word.charAt(i) == "@")
{
word = word.slice(0, i);
}
}
if (list[word] != null) return true;

return false;
}

dialectric
12-02-2008, 01:17 AM
I'm guessing that it would be much faster to do the check against a dictionary in some other, faster language, (C? python?) and share the results back to a flash interface - I'm looking into whether this has been done in an open source package now.

And here is a site with a range of dictionaries and tools which might be helpful, though its not Flash-specific:

http://personal.riverusers.com/~thegrendel/software.html

and the open source project Quackle would also be worth a look:

http://web.mit.edu/jasonkb/www/quackle/

- dialectric

fitz
12-02-2008, 03:16 PM
Doubt it would be worth the effort honestly.

rrh
12-02-2008, 05:52 PM
Well they recently came out with alchemy, which could let you use a C++ dictionary.

dialectric
12-03-2008, 01:39 PM
And there's already a number of C / C++ dictionary projects out there which would only need minimal modification - I mention one in http://www.actionscript.org/forums/showthread.php3?t=190722, which has uncompiled C source which I can't make sense of, but looks like it could do the job. Hadn't heard of adobe alchemy before - maybe that would make this C code usable for this purpose.

- dialectric

dialectric
04-07-2009, 01:36 AM
An update on the dictionary-in-flash - I looked into this problem again after a few months of other projects, and found an active discussion on flashkit about cramming the scrabble dictionary (sowpods) into an as3 program, which seems to work.

link: http://board.flashkit.com/board/showthread.php?t=792153

-dialectric

bluemagica
04-07-2009, 05:46 AM
I would suggest using http://wordlist.sourceforge.net/
and reading the files into an array and use!

I made a word game long ago in flash8. I stored the wordlists in a mysql database, and retrieved them as needed via php! I used query based on word length and sorted on start and end character, and going through 10,000+ words to find a match took less than 1 second!

jamesmcness
12-19-2009, 01:05 AM
Hi all, I've begun work on a word game and have followed this thread regarding the use of SOWPODS. I've managed to throw it together in a class and and include the words for each letter in their own static Array const.

My problem is with compile times. It actually compiles fairly quickly with Flash, but when I compile with Flashdevelop it's taking a few minutes. Wondering if anyone has had any compile time problems and/or if they know a way to use SWC's or compiled clips to reduce the need for recompiling?

I always thought SWC files wouldn't recompile when used through Flashdevelop (I thought that was part of the point) - but it looks like it is going through it all again as it's taking so long to compile.

Any hints or pointers would much appreciated!