Results 1 to 1 of 1
  1. #1
    chkontog is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Query about data structure


    i want to count word frequency from multiple files.

    Moreover, i have these words in these files

    a1.txt = {aaa, aaa, aaa}
    a2.txt = {aaa}
    a3.txt = {aaa, bbb}

    so, the results must be aaa = 3, bbb = 1.

    Then, i have define the above data structures,

    Java Code:
    LinkedHashMap<String, Integer> wordCount = new LinkedHashMap<String, Integer>();
    Map<String, LinkedHashMap<String, Integer>>
    fileToWordCount =
    new HashMap<String, LinkedHashMap<String, Integer>>();
    and then, i read the words from files and put them in wordCount and fileToWordCount:

    Java Code:
    /*lineWords[i] is a word from a line in the file*/
           wordCount.put(lineWords[i], wordCount.
           wordCount.put(lineWords[i], 1);
    fileToWordCount.put(filename, wordCount); //here we map filename and occurences of words
    and finally, i print the fileToWordCount with the above code,

    Java Code:
    Collection a;
    Set filenameset;
                filenameset = fileToWordCount.keySet();     
                a = fileToWordCount.values();           
                for(Object filenameFromMap: filenameset){
    and prints,

    VALUES::[{aaa=5, bbb=1}, {aaa=5, bbb=1}, {aaa=5, bbb=1}]
    VALUES::[{aaa=5, bbb=1}, {aaa=5, bbb=1}, {aaa=5, bbb=1}]
    VALUES::[{aaa=5, bbb=1}, {aaa=5, bbb=1}, {aaa=5, bbb=1}]

    So, how i can use the map fileToWordCount to find word frequency in the files?

    Last edited by chkontog; 11-25-2012 at 11:05 AM.

Similar Threads

  1. Query about data structure
    By chkontog in forum New To Java
    Replies: 1
    Last Post: 11-15-2012, 08:26 PM
  2. Semantic data structure
    By dacoolest in forum Advanced Java
    Replies: 6
    Last Post: 01-12-2012, 07:25 PM
  3. Tree data structure
    By Nacao in forum New To Java
    Replies: 18
    Last Post: 08-23-2011, 06:26 PM
  4. Which data structure to use?
    By malaguena in forum New To Java
    Replies: 4
    Last Post: 04-05-2011, 04:41 PM
  5. data structure and data base??
    By ahmed13 in forum Advanced Java
    Replies: 8
    Last Post: 03-27-2009, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts