Frequency of word occurrences in a statistical document

Source: Internet
Author: User

First, put out your own code.

1 ImportJava.io.BufferedReader;2 ImportJava.io.File;3 ImportJava.io.FileReader;4 Importjava.io.IOException;5 Importjava.util.Arrays;6 ImportJava.util.HashMap;7 ImportJava.util.Iterator;8 ImportJava.util.Map;9 ImportJava.util.Map.Entry;Ten  Public classSearch { One      Public voidReadbook ()throwsException A     { -String Book=book ("D:/book.txt"); - System.out.println (book); the     } -  -     Private StaticString Book (string file)throwsIOException -     { +         //TODO auto-generated Method Stub -File f=Newfile (file); +BufferedReader bf=NewBufferedReader (NewFileReader (f)); AString content= ""; at         intLenth=0; -         intX=0; -StringBuilder sb=NewStringBuilder (); -String[] sum= {""}; -          while(content!=NULL) -         { in              -Content=bf.readline (); to             if(content==NULL) +                  Break; -              theContent=content.replace (",", "" "); *Content=content.replace (".", "" "); $Content=content.replace (";", "" ");Panax NotoginsengContent=content.replace ("(", "" "); -Content=content.replace (")", ""); thestring[] temp = Content.split (""); +              A             intlength1=temp.length; the              +             intLength2=sum.length; -sum = arrays.copyof (sum, length2 + length1);//Expansion $ //System.out.println ("???"); $X=0; -              for(lenth=length2;lenth< (length1+length2); lenth++) -             { the                  -sum[lenth]=Temp[x];WuyiX + +; the             } - //for (int xx=0;xx<sum.length;xx++) Wu //            { - //System.out.println (sum[xx]); About //            } $Map<string,integer> map=NewHashmap<string,integer>(); -             for(String str:sum) { -                if(Map.containskey (str)) { -Map.put (str, map.get (str) + 1); A}Else{ +Map.put (str, 1); the                } -            } $Iterator<entry<string, integer>> it =Map.entryset (). iterator (); the              while(It.hasnext ()) { theEntry ex =(Entry) It.next (); theSystem.out.println (Ex.getkey () + ":" +Ex.getvalue ()); the  -         } in          the          the          About          the     } the bf.close (); the         returnsb.tostring (); +     } -}
1  Public classMain {2 3      Public Static voidMain (string[] args)throwsException {4         //TODO auto-generated Method Stub5Search s=NewSearch ();6 S.readbook ();7         8         9         Ten     } One  A}

Two. Ideas

1. The first response to the experiment was to read the document, and then, without much thought, to go ahead and get the papers.

2. After the document is finished, think about it. symbol is removed, and then all the words are integrated together

3. Finally, the method is used for statistics

Frequency of word occurrences in a statistical document

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.