1.1.5. Tabel Term_Document
1. CREATE TABLE `term_document` 2. `id_term_document` int11 NOT NULL AUTO_INCREMENT,
3. `id_document` int11 NOT NULL, 4. `id_term` int11 NOT NULL,
5. `tf` int11 NOT NULL DEFAULT 0, 6. `w` double NOT NULL DEFAULT 0,
7. PRIMARY KEY `id_term_document`, 8. KEY `fk_term_document_1_idx` `id_document`,
9. KEY `fk_term_document_2_idx` `id_term` 10. ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
1.1.6. Tabel Stopword
1. CREATE TABLE `stop_word` 2. `id_stop_word` int11 NOT NULL AUTO_INCREMENT,
3. `stop_word` varchar45 DEFAULT NULL, 4. PRIMARY KEY `id_stop_word`
5. ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
1.1.7. Tabel Rootword
1. CREATE TABLE `root_word` 2. `word` varchar25 NOT NULL,
3. `wordtype` varchar20 NOT NULL, 4. `definition` text NOT NULL
5. ENGINE=MyISAM DEFAULT CHARSET=latin1;
1.2. Implementasi Sistem Pemerolehan Informasi Berbasis Cluster 1.2.1. Source Code
1.2.1.1. Package database 1.2.1.1.1. Kelas Connection.java
1. 2. To change this license header, choose License Headers in Project Properties.
3. To change this template file, choose Tools | Templates 4. and open the template in the editor.
5. 6. package database;
7. 8. import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
9. import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; 10. import java.sql.SQLException;
11. import java.util.logging.Level;
12. import java.util.logging.Logger; 13.
14. 15.
16. author pacman 17.
18. public class Connection { 19.
20. private static final String DB_USERNAME = skripsi; 21. private static final String DB_PASSWORD = skripsi;
22. private static final String DB_DATABASE = skripsi; 23. private static final String DB_HOST = localhost;
24. 25. public static java.sql.Connection getConnection {
26. java.sql.Connection connection = null; 27. MysqlDataSource dataSource = new MysqlConnectionPoolDataSource;
28. dataSource.setURLjdbc:mysql: + DB_HOST + + DB_DATABASE; 29. dataSource.setUserDB_USERNAME;
30. dataSource.setPasswordDB_PASSWORD; 31.
32. try { 33. connection = dataSource.getConnection;
34. System.err.printlnKoneksi berhasil; 35. } catch SQLException ex {
36. System.err.printlnKoneksi gagal; 37. Logger.getLoggerConnection.class.getName.logLevel.SEVERE, null, ex;
38. } 39.
40. return connection; 41. }
42. 43. }
1.2.1.1.2. Kelas DatabaseOperationController
1. 2. To change this license header, choose License Headers in Project Properties.
3. To change this template file, choose Tools | Templates 4. and open the template in the editor.
5. 6.
7. package database; 8.
9. import gmeans.ClusterPool; 10. import gmeans.ModifiedLinkedList;
11. import java.sql.SQLException; 12. import java.util.logging.Level;
13. import java.util.logging.Logger; 14. import main.Main;
15. 16.
17. 18. author pacman
19. 20. public class DatabaseOperationController {
21. 22. public DatabaseOperationController {
23. } 24.
25. public void performDBOperationClusterPool pool, ModifiedLinkedList masterLinkedList { 26. DatabaseRWOperation dbrw = new DatabaseRWOperation;
27. try { 28. dbrw.truncateAllTables;
29. dbrw.writepool, masterLinkedList; 30. } catch SQLException ex {
31. Logger.getLoggerDatabaseOperationController.class.getName.logLevel.SEVERE, null,
ex; 32. }
33. } 34.
35. 36. }
1.2.1.1.3. Kelas DatabaseRWOperation.java
1. 2. To change this license header, choose License Headers in Project Properties.
3. To change this template file, choose Tools | Templates 4. and open the template in the editor.
5. 6. package database;
7. 8. import gmeans.Cluster;
9. import gmeans.ClusterPool; 10. import gmeans.ModifiedLinkedList;
11. import gmeans.Point; 12. import gmeans.Record;
13. import java.io.File; 14. import java.io.IOException;
15. import java.sql.PreparedStatement; 16. import java.sql.ResultSet;
17. import java.sql.SQLException; 18. import java.sql.Statement;
19. import java.util.ArrayList;
20. import java.util.HashMap; 21. import java.util.Iterator;
22. import java.util.LinkedList; 23. import java.util.List;
24. import java.util.logging.Level; 25. import java.util.logging.Logger;
26. import org.apache.commons.io.FileUtils; 27.
28. 29.
30. author pacman 31.
32. public class DatabaseRWOperation { 33.
34. public DatabaseRWOperation { 35. }
36. 37. public void truncateAllTables throws SQLException {
38. java.sql.Connection conn = Connection.getConnection; 39.
40. String[] tableNames = new String[]{cluster, centroid, document, term,
term_document}; 41.
42. for int i = 0; i tableNames.length; i++ { 43. String sql = TRUNCATE + tableNames[i];
44. conn.setAutoCommitfalse; 45.
46. PreparedStatement ps = conn.prepareStatementsql; 47. ps.execute;
48. 49. conn.commit;
50. } 51.
52. conn.close; 53. }
54. 55. public ClusterPool fastRead throws SQLException {
56. return fastFetchCluster; 57. }
58. 59. public Cluster readSingleClusterCluster cluster throws SQLException {
60. return fetchClustercluster; 61. }
62. 63. public Cluster readMultipleCluster throws SQLException {
64. return fetchMultipleCluster; 65. }
66.
67. public HashMapString, Integer mapPoint throws SQLException { 68. return fetchMapPoint;
69. } 70.
71. private HashMapString, Integer fetchMapPoint throws SQLException { 72. HashMapString, Integer map = new HashMap;
73. ModifiedLinkedList fetchMasterTerm = fetchMasterTerm; 74. IteratorPoint masterTermIterator = fetchMasterTerm.iterator;
75. while masterTermIterator.hasNext { 76. Point point = masterTermIterator.next;
77. String term = point.getTerm; 78. int df = fetchDocumentFrequencyterm;
79. map.putterm, df; 80. }
81. return map; 82. }
83. 84. private int fetchDocumentFrequencyString term throws SQLException {
85. java.sql.Connection conn = Connection.getConnection; 86.
87. String sql = SELECT COUNTid_document FROM skripsi.term_document WHERE id_term =
SELECT id_term FROM term WHERE term = ? AND tf 0; 88. conn.setAutoCommitfalse;
89. 90. PreparedStatement ps = conn.prepareStatementsql;
91. 92. ps.setString1, term;
93. 94. ResultSet rs = ps.executeQuery;
95. 96. conn.commit;
97. int df = 0; 98. while rs.next {
99. df = rs.getInt1; 100.
} 101.
102. conn.close;
103. return df;
104. }
105. 106.
public int allDocumentCount throws SQLException { 107.
return fetchAllDocumentCount; 108.
} 109.
110. private int fetchAllDocumentCount throws SQLException {
111. java.sql.Connection conn = Connection.getConnection;
112. 113.
String sql = SELECT countid_document FROM document;