java資料庫關鍵字抽取,文本關鍵詞抽取

本文目錄一覽:

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(“\r\n”);

        }

        

        String rex = “項目名稱”;    

        

        String totalStr = sb.toString();

        // 獲取rex第一次出現的位置

        int first = totalStr.indexOf(rex);

        // 從該位置截取30長度的字元串

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

        

        // 返回第一行

        return result.split(“\r\n”)[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文章的結果來定。

不明白的話在問吧。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/190831.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-30 09:06
下一篇 2024-11-30 09:06

相關推薦

  • Python 常用資料庫有哪些?

    在Python編程中,資料庫是不可或缺的一部分。隨著互聯網應用的不斷擴大,處理海量數據已成為一種趨勢。Python有許多成熟的資料庫管理系統,接下來我們將從多個方面介紹Python…

    編程 2025-04-29
  • openeuler安裝資料庫方案

    本文將介紹在openeuler操作系統中安裝資料庫的方案,並提供代碼示例。 一、安裝MariaDB 下面介紹如何在openeuler中安裝MariaDB。 1、更新軟體源 sudo…

    編程 2025-04-29
  • 資料庫第三範式會有刪除插入異常

    如果沒有正確設計資料庫,第三範式可能導致刪除和插入異常。以下是詳細解釋: 一、什麼是第三範式和範式理論? 範式理論是關係資料庫中的一個規範化過程。第三範式是範式理論中的一種常見形式…

    編程 2025-04-29
  • 如何查看Python關鍵字

    Python是一種高級編程語言,具有很多有用的特性和優勢。在Python中,關鍵字被用於標識特定的語法結構。如果您正在學習Python編程,了解Python的關鍵字是非常重要的。在…

    編程 2025-04-29
  • Python文本居中設置

    在Python編程中,有時需要將文本進行居中設置,這個過程需要用到字元串的相關函數。本文將從多個方面對Python文本居中設置作詳細闡述,幫助讀者在實際編程中運用該功能。 一、字元…

    編程 2025-04-28
  • 文本數據挖掘與Python應用PDF

    本文將介紹如何使用Python進行文本數據挖掘,並將著重介紹如何應用PDF文件進行數據挖掘。 一、Python與文本數據挖掘 Python是一種高級編程語言,具有簡單易學、代碼可讀…

    編程 2025-04-28
  • leveldb和unqlite:兩個高性能的資料庫存儲引擎

    本文將介紹兩款高性能的資料庫存儲引擎:leveldb和unqlite,並從多個方面對它們進行詳細的闡述。 一、leveldb:輕量級的鍵值存儲引擎 1、leveldb概述: lev…

    編程 2025-04-28
  • Python怎麼導入資料庫

    Python是一種高級編程語言。它具有簡單、易讀的語法和廣泛的庫,讓它成為一個靈活和強大的工具。Python的資料庫連接類型可以多種多樣,其中包括MySQL、Oracle、Post…

    編程 2025-04-28
  • t3.js:一個全能的JavaScript動態文本替換工具

    t3.js是一個非常流行的JavaScript動態文本替換工具,它是一個輕量級庫,能夠很容易地實現文本內容的遞增、遞減、替換、切換以及其他各種操作。在本文中,我們將從多個方面探討t…

    編程 2025-04-28
  • Navicat導出欄位識別為文本而不是數值

    解決方法:使用特定的代碼將導出的欄位識別為文本,而不是數值,下面將從多個方面進行詳細闡述。 一、ASCII碼轉換 在導出的文件中,將數值欄位使用ASCII碼轉換,即可讓這些欄位被識…

    編程 2025-04-28

發表回復

登錄後才能評論