last day (21 days later) » 

9:11 AM
0
A: How to read duplicatewordcounts from a directory or a folder

maytham-ɯɐɥıλɐɯI do suggest using streams and Collections.frequency. I have chopped the solution in different methods so it can be clear to understand. What is required from your question is to check text files in specific folder for duplicated words and count them. First of all we built a stream method. We...

 
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token ",", TypeArgument1 expected after this token Syntax error on token "=", <= expected Syntax error on token(s), misplaced construct(s) Syntax error, insert ">>" to complete ReferenceType2 Syntax error, insert "( )" to complete Expression Syntax error, insert ")" to complete MethodInvocation Syntax error, insert ";" to complete Statement Syntax error, insert "}" to complete MethodBody at ramki.maxoccurrence.main(maxoccurrence.java:38) I got these errors :/
 
can you upload one of your test files some where so I can help you with it.
Remember this is java 8 with lambda expressions
 
Yeah I have changed my compilation to JAVA8 too
 
ok, please link your test file so I can test it on my platform to see what could it be, and java8 alone is not enought you need to put it java8 with lambda expression
 
9:12 AM
cool stay with me I will come back shortly
 
okay :)
 
the file you send me what format, is it text file_
 
Yes
It should be encoded in UTF-8 format
 
ok
can you upload the original file some where, it won't help sharing it this way, I need the file it selfes
 
Then, Ill send the content here.You can save it as .txt file :)
 
9:17 AM
do you also have an english word list, it is always easier to start with english word based list
 
[அதிதி தேவோ பவ- விருந்தினர் உபசரிப்பு ஏன் முக்கியம்?_IshaTamilBlog]
கலாச்சாரம், வாழ்க்கைNovember , ‘அதிதி தேவோ பவ’ – விருந்தினர் உபசரிப்பு ஏன் முக்கியம்? எதிரி நாட்டு ஒற்றன் போர் அறிவிக்கும் ஓலையோடு வரும்போதும்கூட, அவனை உபசரித்து பாதுகாப்பாக வழியனுப்பிய பாரம்பரியம் நம்முடையது. ஆனால் இன்றோ விருந்தினரை சுமையாகப் பார்க்கும் நிலைதான் பரவலாக உள்ளது. விருந்தினரை உபசரிப்பது பற்றி சத்குருவின் வார்த்தைகள்… கேள்வி ‘அதிதி தேவோ பவ’ ஏன் இப்படி சொல்றாங்க… விருந்தாளியா வர்றவங்க அவ்வளவு முக்கியமானவங்களா? சத்குரு: உங்கள் வீடு என்னும் எல்லை உங்கள் கன்ட்ரோலில் இருக்கிறது. அதற்குள் ஒருவர் வரும்போது, அங்
okay here are the english texts
[Anaadhi: A Dip into Your Eternal Nature_IshaTamilBlog]
சத்குரு ஸ்பாட்June , Anaadhi: A Dip into Your Eternal Nature twocol_one] click on photo to zoom /twocol_one] twocol_one_last] translate lang=english] There is no profoundness to your life unless you realize the mortal nature of who you are.  You are profound if you have become eternal.  You’re profound if you become Anaadhi, or profoundness will enter you at least when you realize the mortal nature of who you are. Two men over years of age were at a place. One, looking at the last name of the other guy, recognized him and said,
 
So we agree that the program should read the text find all duplicated words and count them
 
For example: "maytham maytham maytham maytham ram ram sam sam sam" the output should be maytham=4 sam=3 ram=2.IT should be in max to min count order.Like this I have to find for 100+text files from an directory and save it in an separate excel(.xls) files for each text files
 
it works now
I will update my code
 
okay :)
 
9:26 AM
btw you still need to use java 8 lambda other wise it wont work, I will update the answer
 
okay Ill download retrolambda.jar file
 
Example of output I do not understand it, but you can clarify
Duplicates of filename: data/india.txt
பவ’ => 2
அவரால் => 2
பார்த்தவுடன் => 2
உபசரித்தனர். => 2
ஆனால் => 4
நாம் => 2
கும்பிட => 2
ஒரு => 5
பார்க்கும் => 2
இல்லத்தில் => 2
வரும் => 5
அந்த => 2
etc.....
the code is updated
no you do not ned to download retrolambda
wait a minute
do you use IDE or use text mode in console?
 
Yeah like this:)But I want these from max to min count order.வரும் => 5
ஒரு => 5
ஆனால் => 4
பவ’ => 2
அவரால் => 2
பார்த்தவுடன் => 2
உபசரித்தனர். => 2
நாம் => 2
கும்பிட => 2
பார்க்கும் => 2
இல்லத்தில் => 2
அந்த => 2
I use ecplise IDE
 
no problem I will update my code,
I do not have ecplise but you need some how to let ecplise use java 8 with Lambda I do not think you need to install extra stuff, it is included in latest java
I will fix the count order from max to min and get back to you
 
okay
 
9:56 AM
have you fixed your java8 lambda?
 
yes I think Let me run your updated code!
:)
 
try, I still working on sorting from max to min, but you can test it so far with unsort results
 
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Map.Entry;


public class MaxDuplicateWordCount {

public Map<String, Integer> getWordCount(String fileName){
I got this code for max to min counts!.It works good for one text file.When I load from a folder(100+textfiles) it reads all words in combine.
Can you look on this code.From this code We need to read each text files and get Separate output for each textfiles one by one.(saving each output to an excel format(.xls) is welcomed too). :)
 
ok so you want a method to read multiple files using this program
from specifc folder
 
Yeah
Im looking this for long time:/ Text1.txt
 
10:09 AM
I can safe it in text format to start with, and if there is time we can do it to xls,
 
okay
 
no problem the only reason I used streams it is faster, but I will update my question using your methode in stead of stream
 
:)
 
10:43 AM
are you there?
It is done
 
yeah
duplicateWords(fileName).forEach(s -> System.out.println(s + " => " + countWords(fileName, s))
this one is not executing
 
No matter now I have made a new methode for your old code to do the job
I am updating my answer now
this main method should now read all files from speicfic folder, and create new files with resutls on the same folder with differnt name
 
Ill run it :)
 
if every thing works find we can twickt a bit and safe it as CSV for excel
 
11:05 AM
Exception in thread "main" java.lang.NullPointerException
at dict.maxoccurrence2.main(maxoccurrence2.java:43)
java:43 for (Map.Entry<String, Integer> entry : list) {
writer.write(entry.getKey() + " =" + entry.getValue());
writer.newLine();
package dict;
//Updated code

import java.io.BufferedWriter;
import java.io.File;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class maxoccurrence2

{
final static Charset ENCODING = StandardCharsets.UTF_8;

public static void main(String a[]) throws IOException {

String path = "E:\\testfolder\\";
String fileNameIn;
 
if you return null then you get this problem
you can do some thing like htis
put if statement to see if the list empty or not
right now the program trys for ittrate and null list, that won't work
 
oh
 
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Map.Entry;


public class MaxDuplicateWordCount {

final static Charset ENCODING = StandardCharsets.UTF_8;
 
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 50: E:\testfolder\Weekend special Weekend special 75D:\Ram\workspace\dict\put.txt
I cant understand this error
 
minut please
can you do me a faviur
 
11:22 AM
yea
 
your folder structure name Weekend special Weekend special 75D:\
se the last thing D:\ it thinks it is D:\ drive
maybe for testing it is a good idea to put some test files wiht out spaces
under E:\testfolder
just put 2-3 test files call them
test1.txt
test3.txt
other wise we will never solve it like this
when every things work correct then you can put files back
I have corrected the code a bit
you need to create also output folder inside E:\testfolder
and update the code so all output files go there to output folder
 
yeah it does for english word content.
all files are in output folder
thank you
Now it reads tamil language also(utf-8)
if I save as output.xls will it change in excel format?
 
so now every thing is working
the only thing, I can look at to make output files as CSV so we can read it in excel is that correct
are you there?
 
yeah :) I did change to output.xls It saves to excel but not in Tamil language(UTF 8)
SO is it possible to do like this or we should make output as CSV(table) ?
 
I suggest saving it as CSV format that might help,
 
11:37 AM
okay then :)
 
btw
I wold like to help you with tamil language but I sugget you accept my question as answer and if you happy for my support vote up for it, so I can paralley work on tamil verison
 
Yeah I do for sure you need not to ask it
You have done help like more than others in this Stack community :)
 
You got also my vote, I will work on Tamil and keep you update. keep it up
 
:)
 
thanks I preciate your vote too thanks
 
11:44 AM
okay:)
 
so the text I got from you earlier is a Tamil language?
Which excel versin do you use
 
Yeah.And excel version is 2010.
 
cool, I work on it and let you know
 
NOW my next is to to Research and development for this code to represent as GUI
I am going to use SWING JAVA
is it best of best GUI ?
 
Ja Swing is fine
a lot of developers use it
Ram Ki have you forgot to voteup?
 
11:50 AM
I did 50+ for bounty
 
;) I know I was think about (giving a plus)
 
Did that long age
ago*
Didnt that recieve?
 
Yes thx
I am working on tamil now and get back to you
 
okay :)
 
12:51 PM
Hi again are you there
I have fixed the CSV and how to import it to Excel
I will update the code so I can save as correct CSV format
and regarding excel
You open excel -> create empty sheet -> Data -> Get External Data from text and follow the guideline, you need to select 57004 : ISCII Tamil
 

  last day (21 days later) »