From 81289d52a0b771de363a361c1d04ae3146e5d8cf Mon Sep 17 00:00:00 2001 From: Ben Linskey Date: Tue, 17 Dec 2013 09:15:23 -0500 Subject: Replace tabs with spaces. This commit also adds a missing documentation comment for the GreekTextParser class. --- src/com/benlinskey/grdbc/SyntaxCreator.java | 316 ++++++++++++++-------------- 1 file changed, 159 insertions(+), 157 deletions(-) (limited to 'src/com/benlinskey/grdbc/SyntaxCreator.java') diff --git a/src/com/benlinskey/grdbc/SyntaxCreator.java b/src/com/benlinskey/grdbc/SyntaxCreator.java index 172b53e..e5ccb17 100644 --- a/src/com/benlinskey/grdbc/SyntaxCreator.java +++ b/src/com/benlinskey/grdbc/SyntaxCreator.java @@ -31,169 +31,171 @@ import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; /** - * Reads in an XML file containing the Overview of Greek Syntax text and stores + * Reads in an XML file containing the Overview of Greek Syntax text and stores * sections of the text in an SQLite database. *
* Note that the Sources Cited section is omitted, as it is on Perseus. + * * @author Ben Linskey - * + * */ public class SyntaxCreator { - private final static String FILE = "../xml/Perseus_text_1999.04.0052.xml"; - private final static String DB = "syntax.db"; - private final static String TABLE_NAME = "syntax"; - private Connection connection; - private PreparedStatement insertStatement; - - /** - * Class constructor. - */ - public SyntaxCreator() { - // Load driver. - try { - Class.forName("org.sqlite.JDBC"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - System.exit(1); - } - - // Connect to database. - try { - connection = DriverManager.getConnection("jdbc:sqlite:" + DB); - } catch (SQLException e) { - e.printStackTrace(); - System.exit(1); - } - - // Use batch inserts for speed. - try { - connection.setAutoCommit(false); - } catch (SQLException e) { - e.printStackTrace(); - System.exit(1); - } - - createDatabase(); - - // Create a prepared statement to use when inserting entries. - try { - insertStatement = connection.prepareStatement("INSERT INTO " - + TABLE_NAME + " VALUES (NULL, ?, ?, ?)"); - } catch (SQLException e) { - e.printStackTrace(); - System.exit(1); - } - } - - /** - * Creates the Overview of Greek Syntax database. - */ - public void run() { - addSections(); - try { - insertStatement.close(); - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - System.exit(1); - } - System.out.println("Done."); - } - - /** - * Resets the database if it already exists and creates a new, empty - * database. - */ - private void createDatabase() { - System.out.println("Creating lexicon database..."); - try { - String dropTable = "DROP TABLE IF EXISTS " + TABLE_NAME; - String createTable = "CREATE TABLE " + TABLE_NAME + " (" + - "_ID INTEGER PRIMARY KEY, " + - "chapter VARCHAR(100), " + - "section VARCHAR(100), " + - "xml TEXT)"; - Statement statement = connection.createStatement(); - statement.executeUpdate(dropTable); - statement.executeUpdate(createTable); - connection.commit(); - statement.close(); - } catch (SQLException e) { - e.printStackTrace(); - System.exit(1); - } - } - - /** - * Parses the XML file, modifies the sections, and inserts the modified - * data into the database. - */ - private void addSections() { - System.out.println("Inserting data..."); - - String chapter = null; + private final static String FILE = "../xml/Perseus_text_1999.04.0052.xml"; + private final static String DB = "syntax.db"; + private final static String TABLE_NAME = "syntax"; + private Connection connection; + private PreparedStatement insertStatement; + + /** + * Class constructor. + */ + public SyntaxCreator() { + // Load driver. + try { + Class.forName("org.sqlite.JDBC"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + System.exit(1); + } + + // Connect to database. + try { + connection = DriverManager.getConnection("jdbc:sqlite:" + DB); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + + // Use batch inserts for speed. + try { + connection.setAutoCommit(false); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + + createDatabase(); + + // Create a prepared statement to use when inserting entries. + try { + insertStatement = connection.prepareStatement("INSERT INTO " + + TABLE_NAME + " VALUES (NULL, ?, ?, ?)"); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + } + + /** + * Creates the Overview of Greek Syntax database. + */ + public void run() { + addSections(); + try { + insertStatement.close(); + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + System.out.println("Done."); + } + + /** + * Resets the database if it already exists and creates a new, empty + * database. + */ + private void createDatabase() { + System.out.println("Creating lexicon database..."); + try { + String dropTable = "DROP TABLE IF EXISTS " + TABLE_NAME; + String createTable = "CREATE TABLE " + TABLE_NAME + " (" + + "_ID INTEGER PRIMARY KEY, " + + "chapter VARCHAR(100), " + "section VARCHAR(100), " + + "xml TEXT)"; + Statement statement = connection.createStatement(); + statement.executeUpdate(dropTable); + statement.executeUpdate(createTable); + connection.commit(); + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + } + + /** + * Parses the XML file, modifies the sections, and inserts the modified data + * into the database. + */ + private void addSections() { + System.out.println("Inserting data..."); + + String chapter = null; String section = null; StringBuilder xml = new StringBuilder(); - Pattern pattern = Pattern.compile("
(.*?)"); - - try { - BufferedReader in = new BufferedReader(new FileReader(FILE)); - while (in.ready()) { - String line = in.readLine(); - if (line.startsWith("