Results 1 to 1 of 1
Thread: Query about data structure
- 11-25-2012, 10:01 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 8
- Rep Power
- 0
Query about data structure
Hello,
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,
and then, i read the words from files and put them in wordCount and fileToWordCount:Java Code:LinkedHashMap<String, Integer> wordCount = new LinkedHashMap<String, Integer>(); Map<String, LinkedHashMap<String, Integer>> fileToWordCount = new HashMap<String, LinkedHashMap<String, Integer>>();
and finally, i print the fileToWordCount with the above code,Java Code:.... /*lineWords[i] is a word from a line in the file*/ if(wordCount.containsKey(lineWords[i])){ System.out.println("1111111::"+lineWords[i]); wordCount.put(lineWords[i], wordCount. get(lineWords[i]).intValue()+1); }else{ System.out.println("222222::"+lineWords[i]); wordCount.put(lineWords[i], 1); } fileToWordCount.put(filename, wordCount); //here we map filename and occurences of words
and prints,Java Code:Collection a; Set filenameset; filenameset = fileToWordCount.keySet(); a = fileToWordCount.values(); for(Object filenameFromMap: filenameset){ System.out.println("FILENAMEFROMAP::"+filenameFromMap); System.out.println("VALUES::"+a); }
FILENAMEFROMAP::a3.txt
VALUES::[{aaa=5, bbb=1}, {aaa=5, bbb=1}, {aaa=5, bbb=1}]
FILENAMEFROMAP::a1.txt
VALUES::[{aaa=5, bbb=1}, {aaa=5, bbb=1}, {aaa=5, bbb=1}]
FILENAMEFROMAP::a2.txt
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?
ThanksLast edited by chkontog; 11-25-2012 at 10:05 AM.
Similar Threads
-
Query about data structure
By chkontog in forum New To JavaReplies: 1Last Post: 11-15-2012, 07:26 PM -
Semantic data structure
By dacoolest in forum Advanced JavaReplies: 6Last Post: 01-12-2012, 06:25 PM -
Tree data structure
By Nacao in forum New To JavaReplies: 18Last Post: 08-23-2011, 06:26 PM -
Which data structure to use?
By malaguena in forum New To JavaReplies: 4Last Post: 04-05-2011, 04:41 PM -
data structure and data base??
By ahmed13 in forum Advanced JavaReplies: 8Last Post: 03-27-2009, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks