首页 > 编程知识 正文

java数据库关键字抽取,文本关键词抽取

时间:2023-12-24 21:58:46 阅读:322060 作者:LJBR

本文目录一览:

JAVA语言的关键字提取问题

能力有限用个最笨的办法了

public String matchName(String filePath){

    BufferedReader reader = new BufferedReader(new FileReader(filePath));

        // 读取文本

        StringBuffer sb = new StringBuffer();

        String str;

        while (null!=(str = reader.readLine())) {

            sb.append(str);

            sb.append("rn");

        }

        

        String rex = "项目名称";    

        

        String totalStr = sb.toString();

        // 获取rex第一次出现的位置

        int first = totalStr.indexOf(rex);

        // 从该位置截取30长度的字符串

        String result = totalStr.substring(first, first+30);

        

        // 返回第一行

        return result.split("rn")[0];

}

200分跪求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() {

return "文本文件";

}

});

chooser.showSaveDialog(Application2.this);

File file=chooser.getSelectedFile();

if(file==null)

return;

try {

PrintWriter pw=new PrintWriter(file);

pw.print(output1.getText());

pw.flush();

pw.print(output2.getText());

pw.flush();

}catch (IOException e1) {

e1.printStackTrace();

}

}

});

JPanel buttonPane=new JPanel();

buttonPane.add(open);

buttonPane.add(save);

this.add(buttonPane,BorderLayout.SOUTH);

}

public String[] getSentences(){

ArrayListString set=new ArrayListString();

int length=input.getText().length();

for(int i=0,last=0;ilength;i++){

String s=String.valueOf(input.getText().charAt(i));

if(s.equals("n"))

last=i+1;

if(s.equals(".")||s.equals(",")||s.equals("。")||s.equals("。")||s.equals("!")||s.equals("?")||s.equals("?")||s.equals("!")||s.equals(",")){

set.add(input.getText().substring(last,i)+s);

last=i+1;

}

}

return set.StringtoArray(new String[set.size()]);

}

public String getKeySentences(String[] key,String[] sentences){

String result="";

A: for(int i=0;isentences.length;i++){

for (int k = 0; k key.length; k++)

if (sentences[i].contains(key[k].subSequence(0, key[k].length()))) {

result += sentences[i] + "n";

continue A;

}

}

return result;

}

private JTextArea input;

private JTextArea output1;

private JTextArea output2;

private JButton open;

private JButton save;

private String[] keyWords1;

private String[] keyWords2;

public static void main(String... args){

EventQueue.invokeLater(new Runnable(){

public void run(){

new Application2().setVisible(true);

}

});

}

}

java 如何在一篇文章中取出某个关键字

这个方法是取出了含有keyword的那一行,你要去关键字,只要返回true,直接取就O了!!忘楼主采纳!

public void selectKeyWord(String keyWord){

String filepath = "";

try {

DataInputStream dis = new DataInputStream(new FileInputStream(filepath));

while(dis.read()!=-1){

String str = dis.readUTF();

if(str.contains(keyWord)){

System.out.println(str);

}

}

} catch (FileNotFoundException e) {

System.out.println("文件不存在");

System.exit(0);

} catch (IOException e) {

e.printStackTrace();

}

}

java 如何对某个数据库中所有数据进行关键词搜索并统计搜索所得结果的总数

select count(*) from tablename where 列 like '关键字1' or 列 like '关键字2';

意思就是查询 tablename 表中的 列 内容包括 关键字1 或者包涵 关键字2 的 一共有多少数据。。 count 是查询 受影响的 行数。 数据库关键字。

java word中提取关键字

给个思路吧。

读取word用doc4j,然后就是读成字符串进行处理了。

提取关键字首先是中文分词技术,就是把一段话划分成多个组成的词语,然后统计词语的出现次数,这个是主要依据。这个是有实现的jar包的,可以去baidu搜,搜java 中文分词就行。

分词之后,记录词语出现位置,这个是辅助的依据,记录词语一句话中的位置,越靠前越像关键字,权重越高。

甚至可能需要建立一个权重体系,次数设置一个权重,整体位置设置一个权重,不同位置权重也不同。不了解权重可以理解成系数(百分比的,然后计算那个词是关键词)。

同时需要注意,可能需要排除一些常用词,哪些次需要排除,这个需要根据程序反复运行,读取不同word文章的结果来定。

不明白的话在问吧。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。