Friday, 15 April 2011

How do you pull data from a .FIC file in java? -



How do you pull data from a .FIC file in java? -

so writing scrabble word suggestion programme decided because wanted larn sets (don't worry, @ to the lowest degree got part) , referencing info/data not created within program. im pretty new java (and programming in general), wondering how pull words word list .fic file in order check them against words generated letters inputted.

to clarify, have written programme takes series of letters , returns set of every possible word created letters. example: input:

abc

would give set containing "words":

a, ab, ac, abc, acb, b, ba, bc, bac, bca, c, ca, cb, cab, cba

what asking, really, how check find ones contained in .fic file.

the file "official crosswords" file moby project word list , still (very) shaky on parsing , other file dealing-with methods. continuing research dont have prototype code that.

sorry if question isn't exclusively clear.

edit: here method makes "words" create easier understand idea. part don't understand how pull word(as string) .fic file.

private static set<string> words(string s) { set<string> tempwords = new treeset<string>(); if (s.length() == 1) { // base of operations case, lastly letter tempwords.add(s); // system.out.println(s); uncomment when debugging } else { //set add together each letter in s (int = 0; < s.length(); i++) { //cut letter out of string string remaining = s.substring(0, i) + s.substring(i+1); //recursion add together combinations of letters onto current letter/"word" (string permutation : words(remaining)) { // system.out.println(s.substring(i, i+1) + permutation); uncomment when debugging //add total length words tempwords.add(s.substring(i, i+1) + permutation); // system.out.println(permutation); uncomment when debugging //add not-full-length words tempwords.add(permutation); } } } // system.out.println(tempwords); uncomment when debugging homecoming tempwords; }

i dont know if best solution, figured out (hobbs line thing helped lot, give thanks you). found works:

public static void main(string[] args) throws filenotfoundexception { scanner s = new scanner(new filereader("c:/users/sean/workspace/imbored/bin/113809of.fic")); while(true) { words.clear(); string letters = enterletters(); words.addall(words(letters)); while(s.hasnextline()) { string line = s.nextline(); string finalword = checkwords(line, words); if (finalword != null) finalwordset.add(finalword); } s.reset(); system.out.println(finalwordset); system.out.println(); system.out.println("_________________________________________________________________________"); } }

a few things:

the checkwords method checks if current word file in generated list of "words" the enterletters method takes user inputted letters , returns them in string the words method returns set of strings of of possible combinations of characters in given string, each character used many times appears in string , no repeated "words" in returned set. finalwordset , words arraylists of strings defined instance variables(i set them in main method i'm lazy , doesn't matter case)

i sure there better/more efficient way this, @ to the lowest degree works.

finally: decided reply rather delete because didn't see answered anywhere else, if sense free delete question or link other reply or whatever, @ point help other people.

java

No comments:

Post a Comment