Skip to content

Commit

Permalink
Working project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshyAAAgrawal committed Mar 25, 2021
1 parent d501936 commit ce6d731
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 21 deletions.
2 changes: 0 additions & 2 deletions initial_run.sh

This file was deleted.

16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<neo4j.version>3.5.23</neo4j.version>
<neo4j-apoc.version>3.5.0.15</neo4j-apoc.version>
<driver.version>1.7.5</driver.version>
<neo4j-jdbc-version>4.0.1</neo4j-jdbc-version>
</properties>

<dependencies>
Expand All @@ -46,11 +47,18 @@
<version>${neo4j.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.neo4j</groupId> -->
<!-- <artifactId>neo4j-kernel</artifactId> -->
<!-- <version>${neo4j.version}</version> -->
<!-- </dependency> -->

<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>${neo4j.version}</version>
</dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jdbc-bolt</artifactId>
<version>${neo4j-jdbc-version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.neo4j.driver</groupId> -->
<!-- <artifactId>neo4j-java-driver</artifactId> -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.KRacR.s2c;

import org.neo4j.cypher.*;
import org.neo4j.cypher.internal.ast.Query;
//import org.neo4j.cypher.internal.ast.Query;
import org.apache.jena.*;

public class App {
public static void main( String[] args ){
Query q = new Query(null, null, null);
System.out.println(q.asCanonicalStringVal());
// Query q = new Query(null, null, null);
// System.out.println(q.asCanonicalStringVal());
org.apache.jena.query.Query q2 = new org.apache.jena.query.Query();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.KRacR.s2c;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.String;

public class SparqlToCypher {
Expand Down
40 changes: 31 additions & 9 deletions src/test/java/com/KRacR/s2c/SparqlToCypherTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package test.java.com.KRacR.s2c;
package com.KRacR.s2c;
//package test.java.com.KRacR.s2c;

//import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
Expand All @@ -11,7 +12,16 @@
import java.nio.file.Paths;
import java.util.Arrays;

import org.junit.Test;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.RDFDataMgr;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.v1.Config;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
Expand All @@ -21,14 +31,15 @@

import com.KRacR.s2c.SparqlToCypher;


/**
* Unit test for Sparql to Cypher
*/
public class SparqlToCypherTest{
private ServerControls embeddedDatabaseServer;
private static final Config driverConfig = Config.build().withoutEncryption().toConfig();

private void run_TTL_Automated_Test(String folder) {
private void run_TTL_Automated_Test(String folder){
Path rdf_path = Paths.get(folder, "rdf.ttl");
Path path_to_pg_bench = Paths.get("lib/RDFtoPGConverter.jar");

Expand All @@ -47,6 +58,9 @@ private void run_TTL_Automated_Test(String folder) {
fail("RDFtoPGConverter interrupted for folder " + folder);
}

// Create RDF model from ttl
Model rdf_model = RDFDataMgr.loadModel(rdf_path.toString()) ;

// Create in-memory neo4j database and load converted Output.json
try (Driver driver = GraphDatabase.driver(embeddedDatabaseServer.boltURI(), driverConfig);
Session session = driver.session()) {
Expand All @@ -62,7 +76,7 @@ private void run_TTL_Automated_Test(String folder) {
);
}

// Iterate over all sparql files in query
// Iterate over all sparql files in queries folder
FileFilter sparqlFilter = new FileFilter() {
public boolean accept(File file) {
String extension = "";
Expand All @@ -75,7 +89,6 @@ public boolean accept(File file) {
return file.isFile() && (extension.equals("sparql"));
}
};

File[] query_files = Paths.get(folder, "queries").toFile().listFiles(sparqlFilter);
for (File query_file : query_files) {
String sparql_query = null;
Expand All @@ -84,13 +97,22 @@ public boolean accept(File file) {
} catch (IOException e) {
e.printStackTrace();
}

// Run the Sparql to Cypher converter
String cypher_query = SparqlToCypher.convert(sparql_query);

// Execute the cypher query on the database

// Execute the sparql query on the database
Query query = QueryFactory.create(sparql_query);
QueryExecution qe = QueryExecutionFactory.create(query, rdf_model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
}

}

@Test
public void test_All_TTL_Automated() throws IOException{
public void All_TTL_Automated_Test() throws IOException{
// Code for iterating over all directories:
// Source: http://www.avajava.com/tutorials/lessons/how-do-i-use-a-filefilter-to-display-only-the-directories-within-a-directory.html
File f = new File("src/test/resources/ttl_automated_tests"); // current directory
Expand All @@ -104,12 +126,12 @@ public boolean accept(File file) {
File[] files = f.listFiles(directoryFilter);
setupNeo4jServer();
for (File folder : files) {
delete_all_from_database();
delete_all_from_neo4j();
run_TTL_Automated_Test(folder.getCanonicalPath());
}
}

private void delete_all_from_database() {
private void delete_all_from_neo4j() {
try (Driver driver = GraphDatabase.driver(embeddedDatabaseServer.boltURI(), driverConfig);
Session session = driver.session()) {
session.run("match (n) detach delete n;");
Expand Down

0 comments on commit ce6d731

Please sign in to comment.