• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dictionary in java.  RSS feed

 
Ash Acharya
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I have a requirement where in I generate some random words in a method, and return them. in the calling function, I need to check if these words are indeed valid words of the english dictionary. How do I accomplish this in Java? Any pointers would be highly helpful.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, there are two points to this,

  • What data structure you would use to represent the dictionary in memory?
  • How would you populate this data structure with valid words?


  • The simplest of both the answers is that you store the words in a List. Create a text file to have all the words from the dictionary, parse and populate the list with the words. Do a list.contains() for validating a word.

    If you want to have a complex data structure then you can have a look at Tries.
     
    salvin francis
    Bartender
    Posts: 1660
    37
    Eclipse IDE Google Web Toolkit Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ash Acharya wrote:How do I accomplish this in Java?


    I wont provide you with code, but i can definately guide you on how this can be done,

    You would probably require a class that has a static (at least i would prefer so) method that returns a meaning of a word (lets call this WordQuery).
    Now you would probably have a class that represents a word meaning pair.

    Now when WordQuery searches for a word, it should read a config (probably a file) that tells the location of words

    depending on choice, you may store words and meanings in

    1. Text files
    2. XML (better than simple text + extensible so you may include grammer as well later)
    3. Database (prefarable)
    4. Database containing xml entries (my personal favorite)
    5. Plain old collections like vectors or arraylists (i wont suggest you go here)
    6. Website (you can query an existing website or make a new one)

    There are tons of ways of solving this problem, i just mentioned a few of them, feel free to comment on these, i would be more than glad to hear more answers on this.


    If you just want to know the existence of a word and not its meaning in particular, then too these sources can be used, i would then suggest XML.



     
    Campbell Ritchie
    Marshal
    Posts: 56553
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wouldn't a Set be better than a List? And a SortedSet better than an ordinary Set? Actually, HashSet is pretty fast for that sort of thing, too.
     
    Nitesh Kant
    Bartender
    Posts: 1638
    IntelliJ IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:Wouldn't a Set be better than a List? And a SortedSet better than an ordinary Set? Actually, HashSet is pretty fast for that sort of thing, too.


    So, the choice between a list and a set depends on how the dictionary source is? If you expect the source to have duplicates then you need to go with a set.

    Yeah, Hashing will be fast but with the number of words increasing in the dictionary, hash collisions will increase i guess and reduce the effectiveness. As specified earlier, Tries may be better in such cases.
     
    Campbell Ritchie
    Marshal
    Posts: 56553
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, that trie looks a good idea, too.
     
    Ash Acharya
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ash Acharya wrote:Dear all,
    I have a requirement where in I generate some random words in a method, and return them. in the calling function, I need to check if these words are indeed valid words of the english dictionary. How do I accomplish this in Java? Any pointers would be highly helpful.


    Basically I do not want to be implementing it. I'm looking for a Dictionary class which has a list of methods to operate on a dictionary. I want to be passing words to the method, which would return a true/false indicating whether a specific word is valid or not.
     
    Ash Acharya
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ash Acharya wrote:
    Ash Acharya wrote:Dear all,
    I have a requirement where in I generate some random words in a method, and return them. in the calling function, I need to check if these words are indeed valid words of the english dictionary. How do I accomplish this in Java? Any pointers would be highly helpful.


    Basically I do not want to be implementing it. I'm looking for a Dictionary class which has a list of methods to operate on a dictionary. I want to be passing words to the method, which would return a true/false indicating whether a specific word is valid or not.


    If someone can help me find downloadable class and jar files pertaining to the dictionary implementation, that would also be very helpful.
    thanks in advance.
     
    Henry Wong
    author
    Sheriff
    Posts: 23295
    125
    C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Basically I do not want to be implementing it. I'm looking for a Dictionary class which has a list of methods to operate on a dictionary. I want to be passing words to the method, which would return a true/false indicating whether a specific word is valid or not.


    You want a class that can store words, and can tell you that a word is in it or not? How's is that different from the collections classes that everyone have been discussing?

    Henry
     
    William Brogden
    Author and all-around good cowpoke
    Rancher
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    When you get ready to look for word lists, the Moby Project is a good place to start.

    I used Moby lists for my phonetic lookup project.

    Bill
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!