3
3
// Deployment:
4
4
// Maven add commons-csv-1.4, mongodb-driver-3.4.2
5
5
6
- import Entities .NodeRecord ;
7
- import Query .Engine .QueryIndexer ;
8
- import com .fasterxml .jackson .databind .ObjectMapper ;
9
- import org .antlr .v4 .runtime .ANTLRFileStream ;
10
- import org .antlr .v4 .runtime .CommonTokenStream ;
6
+ import Utility .FileParser ;
11
7
12
8
import java .io .IOException ;
13
- import java .io .Reader ;
14
- import java .sql .*;
15
9
16
10
17
- import java .io .BufferedReader ;
18
- import java .io .FileReader ;
19
- import org .apache .ibatis .jdbc .ScriptRunner ;
11
+ import java .util .Map ;
20
12
21
13
22
14
/* Graph"
@@ -28,82 +20,88 @@ public class Main {
28
20
public static void main (String [] args ) throws IOException {
29
21
//Parsing this CSV file:
30
22
31
- boolean importData = false ;
32
- try {
33
- // Connect to MySQL Database
34
- // Schema is in Tables.sql
35
- String url = "jdbc:mysql://localhost:3306/test" ;
36
- String username = "root" ;
37
- String password = "" ;
38
- Connection connection = DriverManager .getConnection (url , username , password );
39
-
40
- if (importData ) {
41
- //Create tables;
42
- ScriptRunner sr = new ScriptRunner (connection );
43
-
44
- System .out .println ("Creating tables..." );
45
- // Give the input file to Reader
46
- Reader reader = new BufferedReader (
47
- new FileReader ("src/Tables.sql" ));
48
- // Exctute script
49
- sr .runScript (reader );
50
-
51
- connection .close ();
52
- connection = DriverManager .getConnection (url , username , password );
53
-
54
- Utility .DBSetupUtil dbSetupUtil = new Utility .DBSetupUtil (connection );
55
- BufferedReader br = new BufferedReader (new FileReader ("src/sample.csv" ));
56
-
57
- // Parse file line by line.
58
- // Ignore first line containing schema of input.
59
- br .readLine ();
60
-
61
- String line ;
62
- System .out .println ("Importing data..." );
63
-
64
- while ((line = br .readLine ()) != null ) {
65
-
66
- // Carefully remove the quotes in string.
67
- line = line .substring (0 , line .indexOf ("biography" ) + 14 ) +
68
- line .substring (line .indexOf ("biography" ) + 14 , line .indexOf ("version" ) - 5 ).replace ("\" \" " , "`" ) +
69
- line .substring (line .indexOf ("version" ) - 5 );
70
-
71
- String line2 = line .replaceAll ("'" , "`" )
72
- .replaceAll ("\" \" ([:,\\ [\\ ]\\ {\\ }:])" , "'$1" )
73
- .replaceAll ("([:,\\ [\\ ]\\ {\\ }:])\" \" " , "$1'" )
74
- .replaceAll ("\" \" " , "`" )
75
- .replaceAll ("'" , "\" " )
76
- .substring (1 );
77
-
78
- line2 = line2 .substring (0 , line2 .length () - 1 );
79
-
80
- // Convert json string to object.
81
- ObjectMapper mapper = new ObjectMapper ();
82
- NodeRecord record = mapper .readValue (line2 , NodeRecord .class );
83
-
84
- // Insert into database.
85
- dbSetupUtil .insertRecord (record );
86
-
87
-
88
- }
89
- }
90
- System .out .println ("Parsing Cypher query..." );
91
-
92
- CypherLexer lexer = new CypherLexer (new ANTLRFileStream ("/Users/liuche/IdeaProjects/GraphDatabase/src/query.txt" ));
93
- CypherParser parser = new CypherParser (new CommonTokenStream (lexer ));
94
- CypherParser .CypherContext cypher = parser .cypher ();
95
- CypherCustomVisitor visitor = new CypherCustomVisitor ();
96
- visitor .setIndexer (new QueryIndexer (connection ));
97
- visitor .visit (cypher );
98
-
99
-
100
-
101
- connection .close ();
102
- }catch (Exception e ){
103
- e .printStackTrace ();
104
- }
105
-
106
-
23
+ // String url = "jdbc:mysql://localhost:3306/test";
24
+ // String username = "root";
25
+ // String password = "";
26
+ // boolean importData = false;
27
+
28
+ // try {
29
+ // // Connect to MySQL Database
30
+ // // Schema is in Tables.sql
31
+ //
32
+ // Connection connection = DriverManager.getConnection(url, username, password);
33
+ //
34
+ // if(importData) {
35
+ // //Create tables;
36
+ // ScriptRunner sr = new ScriptRunner(connection);
37
+ //
38
+ // System.out.println("Creating tables...");
39
+ // // Give the input file to Reader
40
+ // Reader reader = new BufferedReader(
41
+ // new FileReader("src/Tables.sql"));
42
+ // // Exctute script
43
+ // sr.runScript(reader);
44
+ //
45
+ // connection.close();
46
+ // connection = DriverManager.getConnection(url, username, password);
47
+ //
48
+ // Utility.DBSetupUtil dbSetupUtil = new Utility.DBSetupUtil(connection);
49
+ // BufferedReader br = new BufferedReader(new FileReader("src/sample.csv"));
50
+ //
51
+ // // Parse file line by line.
52
+ // // Ignore first line containing schema of input.
53
+ // br.readLine();
54
+ //
55
+ // String line;
56
+ // System.out.println("Importing data...");
57
+ //
58
+ // while ((line = br.readLine()) != null) {
59
+ //
60
+ // // Carefully remove the quotes in string.
61
+ // line = line.substring(0, line.indexOf("biography") + 14) +
62
+ // line.substring(line.indexOf("biography") + 14, line.indexOf("version") - 5).replace("\"\"", "`") +
63
+ // line.substring(line.indexOf("version") - 5);
64
+ //
65
+ // String line2 = line.replaceAll("'", "`")
66
+ // .replaceAll("\"\"([:,\\[\\]\\{\\}:])", "'$1")
67
+ // .replaceAll("([:,\\[\\]\\{\\}:])\"\"", "$1'")
68
+ // .replaceAll("\"\"", "`")
69
+ // .replaceAll("'", "\"")
70
+ // .substring(1);
71
+ //
72
+ // line2 = line2.substring(0, line2.length() - 1);
73
+ //
74
+ // // Convert json string to object.
75
+ // ObjectMapper mapper = new ObjectMapper();
76
+ // NodeRecord record = mapper.readValue(line2, NodeRecord.class);
77
+ //
78
+ // // Insert into database.
79
+ // dbSetupUtil.insertRecord(record);
80
+ //
81
+ //
82
+ // }
83
+ // }
84
+ // System.out.println("Parsing Cypher query...");
85
+ //
86
+ // CypherLexer lexer = new CypherLexer(new ANTLRFileStream("/Users/liuche/IdeaProjects/GraphDatabase/src/query.txt"));
87
+ // CypherParser parser = new CypherParser(new CommonTokenStream(lexer));
88
+ // CypherParser.CypherContext cypher = parser.cypher();
89
+ // CypherCustomVisitor visitor = new CypherCustomVisitor();
90
+ // visitor.setIndexer(new QueryIndexer(connection));
91
+ // visitor.visit(cypher);
92
+ //
93
+ //
94
+ //
95
+ // connection.close();
96
+ // }catch(Exception e){
97
+ // e.printStackTrace();
98
+ // }
99
+ //
100
+ //
101
+ //
102
+
103
+ FileParser fileParser = new FileParser ("src/sample.csv" );
104
+ fileParser .run ();
107
105
108
106
109
107
return ;
0 commit comments