Skip to content

Commit

Permalink
fix merge conflict with development
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed Aug 29, 2018
2 parents 7556522 + 2611cf9 commit 4f514de
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
target
rmlmapper.iml
.DS_Store
.settings
.vscode
16 changes: 7 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ variables:
# `showDateTime` will show the passed time in milliseconds.
# MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
# Postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
# SQLServer
ACCEPT_EULA: Y
SA_PASSWORD: "YourSTRONG!Passw0rd"

cache:
key: ${CI_JOB_NAME}
Expand All @@ -19,12 +26,3 @@ services:
- postgres:10.4
- name: microsoft/mssql-server-linux:latest
alias: sqlserver

variables:
# Postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
# SQLServer
ACCEPT_EULA: Y
SA_PASSWORD: "YourSTRONG!Passw0rd"
47 changes: 7 additions & 40 deletions src/main/java/be/ugent/rml/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import be.ugent.rml.records.Record;
import be.ugent.rml.store.Quad;
import be.ugent.rml.store.QuadStore;
import be.ugent.rml.store.TriplesQuads;
import be.ugent.rml.store.RDF4JStore;
import be.ugent.rml.term.Literal;
import be.ugent.rml.term.NamedNode;
Expand Down Expand Up @@ -333,20 +332,6 @@ public static QuadStore readTurtle(File mappingFile) {
return Utils.readTurtle(mappingFile, RDFFormat.TURTLE);
}

public static boolean isBlankNode(String value) {
return value.startsWith("_:");
}

public static String toNTriples(List<Quad> quads) {
StringBuilder output = new StringBuilder();

for (Quad q : quads) {
output.append(Utils.getNTripleOfQuad(q) + "\n");
}

return output.toString();
}

public static String toNQuads(List<Quad> quads) {
StringBuilder output = new StringBuilder();

Expand All @@ -357,39 +342,22 @@ public static String toNQuads(List<Quad> quads) {
return output.toString();
}

public static void toNTriples(List<Quad> quads, Writer out) throws IOException {
for (Quad q : quads) {
out.write(Utils.getNTripleOfQuad(q) + "\n");
}
}

public static void toNQuads(List<Quad> quads, Writer out) throws IOException {
for (Quad q : quads) {
out.write(Utils.getNQuadOfQuad(q) + "\n");
}
}

public static TriplesQuads getTriplesAndQuads(List<Quad> all) {
List<Quad> triples = new ArrayList<>();
List<Quad> quads = new ArrayList<>();
private static String getNQuadOfQuad(Quad q) {
String str = q.getSubject() + " " + q.getPredicate() + " " + q.getObject();

for (Quad q: all) {
if (q.getGraph() == null || q.getGraph().equals("")) {
triples.add(q);
} else {
quads.add(q);
}
if (q.getGraph() != null) {
str += " " + q.getGraph();
}

return new TriplesQuads(triples, quads);
}
str += ".";

private static String getNTripleOfQuad(Quad q) {
return q.getSubject() + " " + q.getPredicate() + " " + q.getObject() + ".";
}

private static String getNQuadOfQuad(Quad q) {
return q.getSubject() + " " + q.getPredicate() + " " + q.getObject() + " " + q.getGraph() + ".";
return str;
}

public static String encodeURI(String url) {
Expand Down Expand Up @@ -448,8 +416,7 @@ public static int selectedColumnHash(String query) {
throw new Error("Invalid query: " + query);
}

public static String readFile(String path, Charset encoding) throws IOException
{
public static String readFile(String path, Charset encoding) throws IOException {
if (encoding == null) {
encoding = StandardCharsets.UTF_8;
}
Expand Down
35 changes: 11 additions & 24 deletions src/main/java/be/ugent/rml/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import be.ugent.rml.records.RecordsFactory;
import be.ugent.rml.store.Quad;
import be.ugent.rml.store.QuadStore;
import be.ugent.rml.store.TriplesQuads;
import be.ugent.rml.term.NamedNode;
import be.ugent.rml.term.Term;
import ch.qos.logback.classic.Level;
Expand Down Expand Up @@ -130,17 +129,13 @@ public static void main(String [] args) {

QuadStore result = executor.execute(triplesMaps, checkOptionPresence(removeduplicatesOption, lineArgs, configFile));

TriplesQuads tq = Utils.getTriplesAndQuads(result.getQuads(null, null, null, null));

String outputFile = getPriorityOptionValue(outputfileOption, lineArgs, configFile);
if (!tq.getTriples().isEmpty()) {
//write triples
writeOutput("triple", tq.getTriples(), "nt", outputFile);
}
List<Quad> quads = result.getQuads(null, null, null);

if (!tq.getQuads().isEmpty()) {
if (!quads.isEmpty()) {
//write quads
writeOutput("quad", tq.getQuads(), "nq", outputFile);
writeOutput(quads, outputFile);
}
}
} catch( ParseException exp ) {
Expand Down Expand Up @@ -178,42 +173,34 @@ private static void setLoggerLevel(Level level) {
((ch.qos.logback.classic.Logger) root).setLevel(level);
}

private static void writeOutput(String what, List<Quad> output, String extension, String outputFile) {
private static void writeOutput(List<Quad> output, String outputFile) {
if (output.size() > 1) {
logger.info(output.size() + " " + what + "s were generated");
logger.info(output.size() + " quads were generated");
} else {
logger.info(output.size() + " " + what + " was generated");
logger.info(output.size() + " quad was generated");
}

//if output file provided, write to triples output file
if (outputFile != null) {
File targetFile = new File(outputFile + "." + extension);
logger.info("Writing " + what + " to " + targetFile.getPath() + "...");
File targetFile = new File(outputFile);
logger.info("Writing quads to " + targetFile.getPath() + "...");

if (!targetFile.isAbsolute()) {
targetFile = new File(System.getProperty("user.dir") + "/" + outputFile + "." + extension);
targetFile = new File(System.getProperty("user.dir") + "/" + outputFile);
}

try {
BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));

if (what.equals("triple")) {
Utils.toNTriples(output, out);
} else {
Utils.toNQuads(output, out);
}
Utils.toNQuads(output, out);

out.close();
logger.info("Writing to " + targetFile.getPath() + " is done.");
} catch(IOException e) {
System.err.println( "Writing output to file failed. Reason: " + e.getMessage() );
}
} else {
if (what.equals("triple")) {
System.out.println(Utils.toNTriples(output));
} else {
System.out.println(Utils.toNQuads(output));
}
System.out.println(Utils.toNQuads(output));
}
}
}
21 changes: 0 additions & 21 deletions src/main/java/be/ugent/rml/store/TriplesQuads.java

This file was deleted.

0 comments on commit 4f514de

Please sign in to comment.