Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 plagiarism;
- import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
- import java.awt.ScrollPane;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import org.apache.pdfbox.cos.COSDocument;
- import org.apache.pdfbox.io.RandomAccessFile;
- import org.apache.pdfbox.pdfparser.PDFParser;
- import org.apache.pdfbox.pdmodel.PDDocument;
- import org.apache.pdfbox.pdmodel.interactive.measurement.PDNumberFormatDictionary;
- import org.apache.pdfbox.text.PDFTextStripper;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import static java.lang.System.out;
- import java.sql.SQLException;
- import java.util.Scanner;
- import javax.swing.SwingUtilities;
- import javax.swing.filechooser.FileNameExtensionFilter;
- /**
- *
- * @author Munkhdelger
- */
- public class UI extends javax.swing.JFrame {
- JFileChooser filechooser = new JFileChooser("D:");
- FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt", "text");
- String url = "jdbc:mysql://localhost:3306/sys?autoReconnect=true&useSSL=false";
- String user = "root";
- String password = "1234";
- PDFParser parser = null;
- PDDocument pdDoc = null;
- COSDocument cosDoc = null;
- PDFTextStripper pdfStripper;
- String outs="";
- int a = 0;
- int c = 0;
- String array[] = new String [1000000];
- String parsedText;
- String fileName = "C:\\Users\\Munkhdelger\\Documents\\NetBeansProjects\\pdf.pdf";
- String name;
- /**
- * @param args
- * Creates new form UI
- */
- public UI() throws FileNotFoundException, IOException {
- 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")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jScrollPane6 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jScrollPane7 = new javax.swing.JScrollPane();
- jTextArea2 = new javax.swing.JTextArea();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jTextField1 = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane6.setViewportView(jTextArea1);
- jTextArea2.setColumns(20);
- jTextArea2.setRows(5);
- jScrollPane7.setViewportView(jTextArea2);
- jButton1.setText("баазаас авах");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("шалгах");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("Шалгах файл сонгох");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jButton4.setText("File унших");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jButton5.setText("Цэвэрлэгч");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGap(23, 23, 23)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jScrollPane6)
- .addComponent(jTextField1)
- .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton3))
- .addGap(7, 7, 7)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton5)
- .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addComponent(jButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- Connection conn = DriverManager.getConnection(url, user, password);
- Statement st = conn.createStatement();
- String sql = "SELECT pdfpath FROM pdfbase";
- ResultSet rs = st.executeQuery(sql);
- while(rs.next()){
- String w = rs.getString(1);
- array[c] = w;
- c++;
- }
- System.out.println(c);
- for(int q = 0; q < c; q++){
- fileName = array[q];
- System.out.println(fileName);
- File file = new File(fileName);
- String file_name = "Source";
- parser = new PDFParser(new RandomAccessFile(file, "r"));
- parser.parse();
- cosDoc = parser.getDocument();
- pdfStripper = new PDFTextStripper();
- pdDoc = new PDDocument(cosDoc);
- parsedText = pdfStripper.getText(pdDoc);
- name = file_name + (q + 1);
- File f = new File("D:\\DataSource\\" + name + ".txt");
- if(f.exists() && !f.isDirectory()) {
- continue;
- } else {
- PrintStream out = new PrintStream(new FileOutputStream("D:\\DataSource\\" + name + ".txt",true));
- out.print(parsedText);
- System.setOut(out);
- out.close();
- }
- }
- }
- catch (IOException e) {
- try {
- if (cosDoc != null)
- cosDoc.close();
- if (pdDoc != null)
- pdDoc.close();
- }
- catch (IOException e1) {}
- }
- catch (SQLException e){
- }
- // TODO add your handling code here:
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- {
- String ptrnLine, textLine,inpLine,sFilePath,srcLine;
- int srcLineIndex=1, inpLineIndex=1;
- RabinKarp rkComponent;
- int inputLen,srcLen,patterntextLength;
- int rkNumberOfMatches;
- int fullTextLength=0, fullPatternLength=0;
- int mainTimeCount= 0, rkComponentCount=0;
- boolean rkPlagarismStatus = false;
- final File folder = new File("D:\\DataSource");
- int coun = 0;
- //folder dotroos txt file uudiig shalgaj unshih
- for (final File fileEntry : folder.listFiles()) {
- sFilePath = fileEntry.getPath();
- srcLineIndex=1;
- File sourceFile = new File(sFilePath);
- File inputFile = new File(jTextField1.getText());
- @SuppressWarnings("resource")
- BufferedReader sReader = null;
- try {
- sReader = new BufferedReader( new FileReader(sourceFile));
- } catch (FileNotFoundException ex) {
- Logger.getLogger(UI.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- while((srcLine = sReader.readLine())!=null){
- BufferedReader reader = new BufferedReader( new FileReader(inputFile));
- inpLineIndex=1;
- fullTextLength = fullTextLength+srcLine.length();
- while((inpLine = reader.readLine())!=null){
- inputLen = inpLine.length();
- srcLen = srcLine.length();
- if(inputLen>0 && srcLen>0) //muriig unshin 0 esehiig shalgah
- {
- if(srcLen>inputLen)
- { textLine = srcLine;
- ptrnLine = inpLine;
- }
- else
- { textLine = inpLine;
- ptrnLine = srcLine;
- }
- patterntextLength = ptrnLine.length();
- if(coun<1)
- {
- fullPatternLength = fullPatternLength+ ptrnLine.length();
- }
- //algorithm ehlel
- rkComponent = new RabinKarp();
- if(patterntextLength!=0)
- {
- rkNumberOfMatches = rkComponent.search(ptrnLine,textLine);
- if(rkNumberOfMatches>0)
- {
- rkPlagarismStatus = true;
- }
- else
- {
- rkPlagarismStatus =false;
- }
- if(rkPlagarismStatus)
- {
- outs = outs + "Үр дүн\n";
- outs = outs + "Оруулсан файлын мөрийн дугаар = " +inpLineIndex + " хуулагдсан байна. \nДараах шалгаж буй файлаас = " +
- fileEntry.getName()+ ".\nХуулагдсан мөр = "+srcLineIndex+" Давхардсан илэрц = "+rkNumberOfMatches + "\n";
- System.out.println("------------------------------------------------------------------------------------------------------------------------------------------");
- }
- rkComponentCount = rkComponentCount+rkComponent.getTimeCount();
- System.out.println("Rabin karp: textnii urt "+textLine.length()+" bolon patternii urt " +ptrnLine.length()+" is "+
- rkComponentCount);
- mainTimeCount = rkComponentCount+mainTimeCount;
- }
- inpLineIndex++;
- }
- }
- coun++;
- srcLineIndex++;
- }
- } catch (IOException ex) {
- Logger.getLogger(UI.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- mainTimeCount = rkComponentCount;
- System.out.println("Rabin karp: textnii urt "+fullTextLength);
- jTextArea2.setText("Үр дүн");
- jTextArea2.setText(outs);
- jTextArea2.update(jTextArea2.getGraphics());
- }
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- final JFileChooser fc = new JFileChooser();
- fc.showOpenDialog(this);
- try {
- // Open an input stream
- Scanner reader = new Scanner(fc.getSelectedFile());
- String input = reader.nextLine();
- jTextField1.setText(fc.getSelectedFile().getAbsolutePath());
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JOptionPane.showMessageDialog(null, "Серверээс датагаа уншлаа");
- File folder = new File("D:\\DataSource");
- File[] listofFiles = folder.listFiles();
- for (int i = 0; i< listofFiles.length; i++){
- if(listofFiles[i].isFile()){
- System.out.println("file" + listofFiles[i].getName());
- jTextArea1.append(String.valueOf(listofFiles[i]+"\n"));
- }
- }
- jButton4.setEnabled(false);
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- File folder = new File("D:\\DataSource");
- for(File file : folder.listFiles()){
- if(!file.isDirectory())
- file.delete();
- }
- jTextArea2.setText("");
- jTextField1.setText("");
- jTextArea1.setText("");
- jButton4.setEnabled(true);
- }
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* 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(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- new UI().setVisible(true);
- } catch (IOException ex) {
- Logger.getLogger(UI.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- private javax.swing.JFileChooser jFileChooser1;
- private javax.swing.JFileChooser jFileChooser2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JScrollPane jScrollPane3;
- private javax.swing.JScrollPane jScrollPane4;
- private javax.swing.JScrollPane jScrollPane5;
- private javax.swing.JTabbedPane jTabbedPane2;
- private javax.swing.JTextArea jTextAreaLcss;
- private javax.swing.JTextArea jTextAreaNaive;
- private javax.swing.JTextArea jTextAreaKmp;
- private javax.swing.JTextArea jTextAreaBoyerMoore;
- private javax.swing.JTextArea jTextAreaRabinKarp;
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JScrollPane jScrollPane6;
- private javax.swing.JScrollPane jScrollPane7;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextArea jTextArea2;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement