把测试集里的文本用tfidf算法提取出关键词,求个java代码//直接粘贴就行 。
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.border.EtchedBorder;
import javax.swing.filechooser.FileFilter;
public class Application2 extends JFrame implements Cloneable{
public Application2(){
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(800,700);
this.setLayout(new BorderLayout());
keyWords1=new String[]{"那么","还是","sdf"};
keyWords2=new String[]{"所以","而且",};
input=new JTextArea();
JPanel ip=new JPanel();
ip.setLayout(new BorderLayout());
ip.add(input,BorderLayout.CENTER);
ip.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "输入文本"));
output1=new JTextArea();
JPanel o1p=new JPanel();
o1p.setLayout(new BorderLayout());
o1p.add(output1,BorderLayout.CENTER);
o1p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "以下为"));
output2=new JTextArea();
JPanel o2p=new JPanel();
o2p.setLayout(new BorderLayout());
o2p.add(output2,BorderLayout.CENTER);
o2p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "以下为"));
JSplitPane split1=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,o1p,o2p);
split1.setDividerLocation(350);
JSplitPane split2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,ip,split1);
split2.setDividerLocation(300);
this.add(split2,BorderLayout.CENTER);
open=new JButton("导入");
open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser chooser=new JFileChooser(".");
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileFilter(){
@Override
public boolean accept(File file) {
if(file.isDirectory())
return true;
int length=file.getName().length();
if(length5)
return false;
if(file.getName().substring(length-4).equals(".txt"))
return true;
return false;
}
@Override
public String getDescription() {
return "文本文件";
}
});
chooser.showOpenDialog(Application2.this);
File file=chooser.getSelectedFile();
if(file==null)
return;
try {
Scanner sc=new Scanner(file);
String text="";
while(sc.hasNextLine())
text+=sc.nextLine()+"\n";
input.setText(text);
String[] array=getSentences();
output1.setText(getKeySentences(keyWords1,array));
output2.setText(getKeySentences(keyWords2,array));
}catch (IOException e1) {
e1.printStackTrace();
}
}
});
save=new JButton("导出");
save.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser chooser=new JFileChooser(".");
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileFilter(){
@Override
public boolean accept(File file) {
if(file.isDirectory())
return true;
int length=file.getName().length();
if(length5)
return false;
if(file.getName().substring(length-4).equals(".txt"))
return true;
return false;
}
@Override
public String getDescription() {
推荐阅读
- 直播王者用什么屏幕最好,直播王者用什么屏幕最好用
- 拼多多免费模式如何做推广,拼多多免费产品怎么样才能拿到
- 鸿蒙系统插耳机无法使用,鸿蒙系统耳机用不了
- php返回raw数据 php raw
- js方法参考手册,js方法大全
- flutter是原生吗,flutter能替代ios原生开发吗
- 直播网红小偷,直播抓小偷
- php从数据库提出照片 php用img显示数据库中图片
- 显示屏需要什么格式的u盘,显示屏怎么用u盘