Skip to content

Commit

Permalink
do not print null when no graph provided
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed Aug 27, 2018
1 parent 8720ba8 commit 08fdb50
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 80 deletions.
4 changes: 2 additions & 2 deletions buildNumber.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Fri Aug 17 13:40:48 CEST 2018
buildNumber0=43
#Mon Aug 27 13:58:09 CEST 2018
buildNumber0=45
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
27 changes: 10 additions & 17 deletions src/main/java/be/ugent/rml/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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,9 +129,11 @@ public static void main(String [] args) {


String outputFile = getPriorityOptionValue(outputfileOption, lineArgs, configFile);
if (!result.getQuads(null, null, null).isEmpty()) {
List<Quad> quads = result.getQuads(null, null, null);

if (!quads.isEmpty()) {
//write quads
writeOutput("quad", result.getQuads(null, null, null, null), outputFile);
writeOutput(quads, outputFile);
}
}
} catch( ParseException exp ) {
Expand Down Expand Up @@ -170,17 +171,17 @@ private static void setLoggerLevel(Level level) {
((ch.qos.logback.classic.Logger) root).setLevel(level);
}

private static void writeOutput(String what, List<Quad> output, 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);
logger.info("Writing " + what + " to " + targetFile.getPath() + "...");
logger.info("Writing quads to " + targetFile.getPath() + "...");

if (!targetFile.isAbsolute()) {
targetFile = new File(System.getProperty("user.dir") + "/" + outputFile);
Expand All @@ -189,23 +190,15 @@ private static void writeOutput(String what, List<Quad> output, String outputFil
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 08fdb50

Please sign in to comment.