Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Structures;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Types;
- import java.util.ArrayList;
- public class Comment {
- public String type = "";
- public String content = "";
- public String className = "";
- public String methodName = "";
- public int idMethod = -1;
- public int idClass = -1;
- public void insert(Connection connection) {
- try {
- if (methodName != null) {
- String queryMethod = "SELECT idMethod FROM method WHERE (Nom='" + methodName + "') LIMIT 1";
- Statement Stmt;
- Stmt = connection.createStatement();
- ResultSet rs = Stmt.executeQuery(queryMethod);
- if (rs.next() != false)
- idMethod = rs.getInt("idMethod");
- }
- String queryClass = "SELECT idClass FROM method WHERE (Nom='" + className + "') LIMIT 1";
- Statement Stmt;
- Stmt = connection.createStatement();
- ResultSet rs = Stmt.executeQuery(queryClass);
- if (rs.next() == false)
- System.err.println("Class Not Found for Comment");
- else {
- idClass = rs.getInt("idClass");
- String query = "INSERT INTO comment (Type, Content, idClass, idMethod) VALUES (?,?,?,?)";
- PreparedStatement preparedStmt;
- preparedStmt = connection.prepareStatement(query);
- preparedStmt.setString(1, this.type);
- preparedStmt.setString(2, this.content);
- preparedStmt.setInt(3, idClass);
- if (idMethod == -1)
- preparedStmt.setNull(4, Types.INTEGER);
- else
- preparedStmt.setInt(4, idMethod);
- preparedStmt.execute();
- }
- } catch (SQLException e) {
- System.err.println(e.getMessage());
- ;
- }
- }
- public static String extractContent(Connection connection) {
- String result = "";
- String query = "Select Content FROM comment";
- Statement Stmt;
- try {
- Stmt = connection.createStatement();
- ResultSet rs = Stmt.executeQuery(query);
- while (rs.next()) {
- result += " " + rs.getString("Content");
- }
- } catch (SQLException e) {
- System.err.println(e.getMessage());
- }
- result = result.replace(" ", " ");
- result = result.replace("''", "'");
- //result = result.replace(".", "");
- result = stopword(result);
- return result;
- }
- private static String stopword(String s){
- String result = "";
- int k=0;
- ArrayList<String> wordsList = new ArrayList<String>();
- String sCurrentLine;
- String[] stopwords = new String[2000];
- try{
- FileReader fr=new FileReader("stopwords.txt");
- BufferedReader br= new BufferedReader(fr);
- while ((sCurrentLine = br.readLine()) != null){
- stopwords[k]=sCurrentLine;
- k++;
- }
- StringBuilder builder = new StringBuilder(s);
- String[] words = builder.toString().split("\\s");
- for (String word : words){
- wordsList.add(word);
- }
- for(int i = 0; i < wordsList.size(); i++){
- for(int j = 0; j < k; j++){
- if(stopwords[j].contains(wordsList.get(i).toLowerCase())){
- wordsList.remove(i);
- i = i- 1;
- break;
- }
- }
- }
- result = wordsList.get(0);
- for (int i = 1; i<wordsList.size(); i++){
- result = result + " " + wordsList.get(i);
- }
- }catch(Exception ex){
- System.out.println(ex);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement