+
+
+
+
+
+
\ No newline at end of file
diff --git a/001003/001003.iml b/001003/001003.iml
new file mode 100644
index 0000000000000000000000000000000000000000..c90834f2d607afe55e6104d8aa2cdfffb713f688
--- /dev/null
+++ b/001003/001003.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/001003/001003.jar b/001003/001003.jar
new file mode 100644
index 0000000000000000000000000000000000000000..2dba220e475999acc2df436295bd80707ae10063
Binary files /dev/null and b/001003/001003.jar differ
diff --git a/001003/FileFunctionTest.java b/001003/FileFunctionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3cb372cf13fce541c260301e514d40edbbc51a3b
--- /dev/null
+++ b/001003/FileFunctionTest.java
@@ -0,0 +1,25 @@
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import org.junit.jupiter.api.Test;
+
+class FileFunctionTest {
+ FileFunction fi=new FileFunction();
+ @Test
+ void testReadFromFile() throws IOException {
+ String path="input.txt";
+ assertTrue(fi.ReadFromFile(path).equals("Monday Tuesday Wednesday Thursday"));
+ }
+
+
+ @Test
+ void testWriteToFile() throws Exception {
+ String outpath="output.txt";
+ fi.WriteToFile(outpath, "hello i am test");
+ fi.ReadFromFile(outpath).equals( "hello i am test");
+ }
+
+}
diff --git a/001003/WordTest.java b/001003/WordTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..84579792d9b3d9e1627a71dc05ffeed01f1493a9
--- /dev/null
+++ b/001003/WordTest.java
@@ -0,0 +1,61 @@
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class WordTest {
+
+
+
+ Word myWord = new Word("input.txt");
+ //input.txt 内的内容为Monday Tuesday Wednesday Thursday
+ @Test
+ public void testCharCount1() throws Exception{
+ //测试字符函数
+ assertEquals("characters: 33",myWord.charCount());
+ }
+ @Test
+ public void testWordCount1() throws Exception{
+ //测试单词函数
+ assertEquals("words: 4",myWord.wordCount());
+ }
+
+
+ @Test
+ public void testLineCount1() throws Exception {
+ //测试文本行数
+ assertEquals("lines: 1",myWord.lineCount());
+ }
+
+ @Test
+ public void PhraseTest1() throws Exception {
+ //当测试数据为文本的单词数
+ myWord.wordCount();
+ assertEquals("Monday Tuesday Wednesday Thursday: 1"+"\n",myWord.Phrase(4));
+ }
+ @Test
+ public void PhraseTest2() throws Exception {
+ //当测试数据大于文本的单词数
+ myWord.wordCount();
+ assertEquals("the number is too long",myWord.Phrase(5));
+ }
+ @Test
+ public void PhraseTest3() throws Exception {
+ //当测试数据小于文本的单词数
+ myWord.wordCount();
+ assertEquals("Monday Tuesday Wednesday: 1" + "\n"+
+ "Tuesday Wednesday Thursday: 1"+"\n",myWord.Phrase(3));
+ }
+
+ @Test
+ public void WordTest1() throws Exception {
+ //输出词频第一的词
+// String path ="input.txt";
+// Word myWord = new Word("input.txt");
+ myWord.wordCount();
+ assertEquals(":1"+"\n",myWord.sortWord(1));
+ }
+
+
+
+
+}
diff --git a/001003/gui/.keep b/001003/gui/.keep
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/001003/gui/NewJFrame.java b/001003/gui/NewJFrame.java
new file mode 100644
index 0000000000000000000000000000000000000000..9ed67b15d529e9448f37eb41b9bfff744ca1451f
--- /dev/null
+++ b/001003/gui/NewJFrame.java
@@ -0,0 +1,138 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package wordcount;
+
+/**
+ *
+ * @author Administrator
+ */
+public class NewJFrame extends javax.swing.JFrame {
+
+ /**
+ * Creates new form NewJFrame
+ */
+ public NewJFrame() {
+ initComponents();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTextArea1 = new javax.swing.JTextArea();
+ jLabel1 = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ jTextField1 = new javax.swing.JTextField();
+ jButton1 = new javax.swing.JButton();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+ jTextArea1.setColumns(20);
+ jTextArea1.setRows(5);
+ jScrollPane1.setViewportView(jTextArea1);
+
+ jLabel1.setText("词频统计结果如下:");
+
+ jLabel2.setText("请输入文件名:");
+
+ jTextField1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jTextField1ActionPerformed(evt);
+ }
+ });
+
+ jButton1.setText("统计词频");
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(32, 32, 32)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(85, 85, 85)
+ .addComponent(jButton1)))
+ .addContainerGap(76, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(48, 48, 48)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jButton1))
+ .addGap(30, 30, 30)
+ .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(86, Short.MAX_VALUE))
+ );
+
+ pack();
+ }// //GEN-END:initComponents
+
+ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
+ // TODO add your handling code here:
+ }//GEN-LAST:event_jTextField1ActionPerformed
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new NewJFrame().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton jButton1;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTextArea jTextArea1;
+ private javax.swing.JTextField jTextField1;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/001003/input.txt b/001003/input.txt
new file mode 100644
index 0000000000000000000000000000000000000000..59cc7495d29f97585bdb93524fc85d6192f55848
--- /dev/null
+++ b/001003/input.txt
@@ -0,0 +1,3 @@
+ Today, people's lifestyle pace is very fast and a lot of young people feel the great pressure when they come to the job market. Before I graduated from college, I started to come to the job market. It was hard for me to get the job I wanted. I got rejected many times, but when the moment I was hired, I felt the victory.
+ I still remembered the day when I was interviewed. Before I came to the company, I had practised many times and my friends pretended to be the employers, asking me all kinds of questions. So I made some preparations and believed that I wouldn't lose control. At the beginning, the employers asked me some simple questions, which I had prepared, so I felt confident.But when they asked me about the company, I forgot to search enough information. But I told myself to calm down,so I expressed my wish to work here. Two days later, I was informed that I got the job. My heart was beating very fast,just liked I had conquered the world.
+ The experience of being success helps me to be stronger and gain more confidence.
\ No newline at end of file
diff --git a/001003/out/production/001003/FileFunction.class b/001003/out/production/001003/FileFunction.class
new file mode 100644
index 0000000000000000000000000000000000000000..8af73b3a50a1798f3fcc70ff0eee801a89f1ab54
Binary files /dev/null and b/001003/out/production/001003/FileFunction.class differ
diff --git a/001003/out/production/001003/Main.class b/001003/out/production/001003/Main.class
new file mode 100644
index 0000000000000000000000000000000000000000..06788813bf3bb263771c2393f48f453c8a091262
Binary files /dev/null and b/001003/out/production/001003/Main.class differ
diff --git a/001003/out/production/001003/Word.class b/001003/out/production/001003/Word.class
new file mode 100644
index 0000000000000000000000000000000000000000..838d6b750627b0dfe833613c09d36ce8c55072af
Binary files /dev/null and b/001003/out/production/001003/Word.class differ
diff --git a/001003/out/production/001003/input.txt b/001003/out/production/001003/input.txt
new file mode 100644
index 0000000000000000000000000000000000000000..59cc7495d29f97585bdb93524fc85d6192f55848
--- /dev/null
+++ b/001003/out/production/001003/input.txt
@@ -0,0 +1,3 @@
+ Today, people's lifestyle pace is very fast and a lot of young people feel the great pressure when they come to the job market. Before I graduated from college, I started to come to the job market. It was hard for me to get the job I wanted. I got rejected many times, but when the moment I was hired, I felt the victory.
+ I still remembered the day when I was interviewed. Before I came to the company, I had practised many times and my friends pretended to be the employers, asking me all kinds of questions. So I made some preparations and believed that I wouldn't lose control. At the beginning, the employers asked me some simple questions, which I had prepared, so I felt confident.But when they asked me about the company, I forgot to search enough information. But I told myself to calm down,so I expressed my wish to work here. Two days later, I was informed that I got the job. My heart was beating very fast,just liked I had conquered the world.
+ The experience of being success helps me to be stronger and gain more confidence.
\ No newline at end of file
diff --git a/001003/src/FileFunction.java b/001003/src/FileFunction.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a81aa991630f9cd5cc0cab1cd881188c96ccf37
--- /dev/null
+++ b/001003/src/FileFunction.java
@@ -0,0 +1,42 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author zhangyilin
+ */
+
+import java.io.*;
+public class FileFunction {
+ public BufferedReader ReadFromFile(String path) throws IOException {
+ //读取文件
+
+ File file = new File(path);
+ if (!file.exists() || file.isDirectory()) {
+ System.out.println("请输入正确文件名!");
+ throw new FileNotFoundException();
+ }
+
+ InputStreamReader isr = new InputStreamReader(new FileInputStream(path));// 建立一个输入流对象
+ BufferedReader br = new BufferedReader(isr);
+
+ return br;
+ }
+
+
+ public void WriteToFile(String path,String content) {
+ //写入文件
+ try {
+// String resultFile = "result.txt";
+ OutputStream out = new FileOutputStream(path);
+ out.write(content.getBytes());
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/001003/src/Main.java b/001003/src/Main.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d3052933fb6a23c7352ad91921835e3999dee5a
--- /dev/null
+++ b/001003/src/Main.java
@@ -0,0 +1,233 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author zhangyilin
+ */
+
+import java.util.*;
+import java.io.FileNotFoundException;
+public class Main extends javax.swing.JFrame {
+
+ /**
+ * Creates new form WordCount
+ */
+ public Main(){
+ initComponents();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jTextField1 = new javax.swing.JTextField();
+ jTextField2 = new javax.swing.JTextField();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTextArea1 = new javax.swing.JTextArea();
+ jButton1 = new javax.swing.JButton();
+ jLabel1 = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+
+ jTextField1.setText("jTextField1");
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+ jTextField2.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jTextField2ActionPerformed(evt);
+ }
+ });
+
+ jTextArea1.setColumns(20);
+ jTextArea1.setRows(5);
+ jScrollPane1.setViewportView(jTextArea1);
+
+ jButton1.setText("统计");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ jLabel1.setText("-i:设定读入的文件路径");
+
+ jLabel2.setText("-m:设定统计的词组长度");
+
+ jLabel3.setText("-n:设定输出的单词数量");
+
+ jLabel4.setText("-o:设定生成文件的存储路径");
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(14, 14, 14)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addGap(12, 12, 12)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel2)
+ .addGap(18, 18, 18)
+ .addComponent(jLabel4))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel1)
+ .addGap(26, 26, 26)
+ .addComponent(jLabel3))))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jButton1)))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(20, 20, 20)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jButton1))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel1)
+ .addComponent(jLabel3))
+ .addGap(12, 12, 12)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel2)
+ .addComponent(jLabel4))
+ .addGap(36, 36, 36)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+
+ pack();
+ }// //GEN-END:initComponents
+
+ private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
+ // TODO add your handling code here:
+ }//GEN-LAST:event_jTextField2ActionPerformed
+
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+ // TODO add your handling code here:
+ String str = jTextField2.getText();
+ String file = null;
+ int numM =0;
+ int numN =0;
+ String resultFile= null;
+ String strarr[] = str.split("\\s+");
+ List list = new ArrayList<>();
+ for (String word:strarr) {
+ list.add(word);
+ }
+// System.out.println(list);
+ for (int i = 0; i
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new Main().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton jButton1;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTextArea jTextArea1;
+ private javax.swing.JTextField jTextField1;
+ private javax.swing.JTextField jTextField2;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/001003/src/Word.java b/001003/src/Word.java
new file mode 100644
index 0000000000000000000000000000000000000000..3719a99db4ff01e7c79c09f50f6852c0a9515273
--- /dev/null
+++ b/001003/src/Word.java
@@ -0,0 +1,174 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author zhangyilin
+ */
+
+import java.io.BufferedReader;
+import java.util.*;
+public class Word {
+
+ String path;
+ private List lists = new ArrayList<>();
+ public Word(String path) {
+ this.path = path;
+ }
+
+ public String charCount() throws Exception {//统计字符
+ int charNum = 0;
+// InputStreamReader isr = new InputStreamReader(new FileInputStream(path));// 建立一个输入流对象
+// BufferedReader br = new BufferedReader(isr);
+ BufferedReader br = new FileFunction().ReadFromFile(path);
+ int getchar;
+ while ((getchar = br.read()) != -1) {
+ //忽略汉字,换行也算字符(ascii码为10),数字字母符号的ascii码在32-126
+ if (getchar > 31 && getchar < 127 || getchar == 10) {
+ charNum++;
+ }
+ }
+ return "characters: " + charNum;
+ }
+
+ public String wordCount()throws Exception{//统计单词总数
+ int wordsNum = 0;//单词总数
+ BufferedReader br = new FileFunction().ReadFromFile(path);
+ String str = br.readLine();
+ while (str != null) {//统计有效行的字符
+ String wordsArr[] = str.split("\\s*[^0-9a-zA-Z]+");//根据分隔符为数字字母以外的存放在数组//"\\w+"
+ for (String word : wordsArr) {
+ //以4个英文字母开头,跟上字母数字符号
+ if (word.matches("[a-zA-Z]{4,}[a-zA-Z0-9]*")) {
+ lists.add(word);
+ }
+ }
+ str = br.readLine();
+ }
+ wordsNum = lists.size();
+
+ return "words: " + wordsNum;
+ }
+
+
+
+ public String lineCount()throws Exception{//统计行
+ int lineNum = 0;
+// InputStreamReader isr = new InputStreamReader(new FileInputStream(path));// 建立一个输入流对象
+// BufferedReader br = new BufferedReader(isr);
+ BufferedReader br = new FileFunction().ReadFromFile(path);
+ String str = br.readLine();
+ while (str != null) {//统计有效行的字符
+ lineNum++;
+ str = br.readLine();
+ }
+
+ return "lines: " + lineNum;
+ }
+
+ public String Phrase(int number) throws Exception{
+
+ if(number>lists.size()){
+ return "the number is too long";
+ }
+ String wordGroup[] = new String[lists.size()-number+1];
+ for (int i = 0; i treeMap =new TreeMap();
+ for (int i = 0; i < wordGroup.length; i++) {
+ String s = wordGroup[i];
+ if (!treeMap.containsKey(s)) {
+ //不存在
+ treeMap.put(s, 1);
+ } else {
+ //已经存在
+ int n = treeMap.get(s);
+ treeMap.put(s, n + 1);
+ }
+ }
+ List> list = new ArrayList>(treeMap.entrySet());
+
+ Collections.sort(list, new Comparator>() {
+ public int compare(Map.Entry o1, Map.Entry o2) {
+ return o2.getValue().compareTo(o1.getValue());
+ }
+ });
+
+// Collections.sort(list, ((o1, o2) -> o2.getValue().compareTo(o1.getValue())));
+ String s[] = new String[wordGroup.length];
+ int i =0;
+ for (Map.Entryentry:list) {
+ String key = entry.getKey();
+ Integer value = entry.getValue();
+ s[i] = key + ": " + value;
+// System.out.println(s[i]);
+ i++;
+ }
+ String string = s[0]+"\n";
+ for (int j = 1; j treeMap = new TreeMap();
+
+ for (int i = 0; i < lists.size(); i++) {
+ String s = lists.get(i).toLowerCase();//忽略大小写
+ if (!treeMap.containsKey(s)) {
+ //不存在
+ treeMap.put(s, 1);
+ } else {
+ //已经存在
+ int n = treeMap.get(s);
+ treeMap.put(s, n + 1);
+ }
+ }
+
+ List> list = new ArrayList>(treeMap.entrySet());
+
+ Collections.sort(list, new Comparator>() {
+ public int compare(Map.Entry o1, Map.Entry o2) {
+ return o2.getValue().compareTo(o1.getValue());
+ }
+ });
+
+
+
+
+// Collections.sort(list, ((o1, o2) -> o2.getValue().compareTo(o1.getValue())));
+// int n = 10;
+ String s[] = new String[number];
+
+ int i =0;
+ for (Map.Entry entry : list) {
+ if (number-- == 0)
+ break;
+ String key = entry.getKey();
+ Integer value = entry.getValue();
+ s[i] = "<" + key + ">:" + value;
+// System.out.print("<" + key + ">:" + value);
+// System.out.println(s[i]);
+ i++;
+ }
+ String string = s[0]+"\n";
+ for (int j = 1; j